using UAS_MES.DataOperate;
using LabelManager2;
using System.Data;
using System.Text;
using System.IO;
using UAS_MES.Entity;
using System.Windows;
namespace UAS_MES.PublicMethod
{
class Print
{
static DataHelper dh = new DataHelper();
//CodeSoft打印的驱动和文件
static Document doc;
////CodeSoft的打印机
//string CodeSpft_Printer;
static FileInfo info;
public Print() { }
///
/// 默认打印一份
///
///
///
public static void CodeSoft(string iCaller, ApplicationClass lbl, string LabelName, string LabelCode, string PrinterName, string SnCode, int PrintNum, System.DateTime intime)
{
//打开模板路径
doc = lbl.Documents.Open(ftpOperater.DownLoadTo + LabelName);
//查询模板对应的取值SQL和参数名称
DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_code='" + LabelCode + "'", "select");
//比对模板维护的参数和在系统中维护的参数,名称对应进行SQL取值赋给变量
StringBuilder sb = new StringBuilder();
for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
if (doc.Variables.FormVariables.Item(i + 1).Name == dt.Rows[j]["lp_name"].ToString())
{
string sql = dt.Rows[j]["lp_sql"].ToString();
try
{
sql = sql.Substring(0, sql.IndexOf("{")) + "'" + SnCode + "'";
doc.Variables.FormVariables.Item(i + 1).Value = dh.GetLabelParam(sql).ToString();
sb.AppendLine("打印参数【" + doc.Variables.FormVariables.Item(i + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + doc.Variables.FormVariables.Item(i + 1).Value);
}
catch (System.Exception)
{
BaseUtil.ShowError("SQL" + sql + "维护不正确");
}
}
}
}
LogManager.DoLog(sb.ToString());
//保存本次赋值进行打印
doc.Save();
doc.Printer.SwitchTo(PrinterName);
doc.PrintDocument(PrintNum);
doc.Close();
LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
//讲文件最后写入时间改成数据库中拿到的时间
info = new FileInfo(ftpOperater.DownLoadTo + LabelName);
info.LastWriteTime = intime;
}
public static void CodeSoft(string iCaller, Document doc, string LabelName, string LabelCode, string PrinterName, string SnCode, int PrintNum, System.DateTime intime)
{
//打开模板路径
//查询模板对应的取值SQL和参数名称
DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_code='" + LabelCode + "'", "select");
//比对模板维护的参数和在系统中维护的参数,名称对应进行SQL取值赋给变量
StringBuilder sb = new StringBuilder();
for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
{
for (int j = 0; j < dt.Rows.Count; j++)
{
if (doc.Variables.FormVariables.Item(i + 1).Name == dt.Rows[j]["lp_name"].ToString())
{
string sql = dt.Rows[j]["lp_sql"].ToString();
try
{
sql = sql.Substring(0, sql.IndexOf("{")) + "'" + SnCode + "'";
doc.Variables.FormVariables.Item(i + 1).Value = dh.GetLabelParam(sql).ToString();
sb.AppendLine("打印参数【" + doc.Variables.FormVariables.Item(i + 1).Name + "】赋值," + "取值SQL:" + sql + ",取到值" + doc.Variables.FormVariables.Item(i + 1).Value);
}
catch (System.Exception)
{
BaseUtil.ShowError("SQL" + sql + "维护不正确");
}
}
}
}
LogManager.DoLog(sb.ToString());
//保存本次赋值进行打印
doc.Save();
doc.Printer.SwitchTo(PrinterName);
doc.PrintDocument(PrintNum);
LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
}
}
}