|
|
@@ -20,131 +20,70 @@ namespace UAS_MES.PublicMethod
|
|
|
|
|
|
public Print() { }
|
|
|
|
|
|
- /// <summary>
|
|
|
- /// 默认打印一份
|
|
|
- /// </summary>
|
|
|
- /// <param name="Url"></param>
|
|
|
- /// <param name="LabelCode"></param>
|
|
|
- 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
|
|
|
- {
|
|
|
- Regex ConnoteA = new Regex("{\\w+}");
|
|
|
- foreach (Match mch in ConnoteA.Matches(sql))
|
|
|
- {
|
|
|
- string x = mch.Value.Trim();
|
|
|
- sql = sql.Replace(x,"'" + 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 LaID, string PrinterName, string SnCode, int PrintNum)
|
|
|
{
|
|
|
//打开模板路径
|
|
|
//查询模板对应的取值SQL和参数名称
|
|
|
DataTable dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
|
|
|
- //比对模板维护的参数和在系统中维护的参数,名称对应进行SQL取值赋给变量
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- for (int i = 0; i < doc.Variables.FormVariables.Count; i++)
|
|
|
+ //执行全部的SQL
|
|
|
+ for (int i = 0; i < dt.Rows.Count; i++)
|
|
|
{
|
|
|
- for (int j = 0; j < dt.Rows.Count; j++)
|
|
|
+ string sql = dt.Rows[i]["lp_sql"].ToString();
|
|
|
+ try
|
|
|
{
|
|
|
- if (doc.Variables.FormVariables.Item(i + 1).Name == dt.Rows[j]["lp_name"].ToString())
|
|
|
+ Regex ConnoteA = new Regex("{\\w+}");
|
|
|
+ foreach (Match mch in ConnoteA.Matches(sql))
|
|
|
+ {
|
|
|
+ string x = mch.Value.Trim();
|
|
|
+ sql = sql.Replace(x, "'" + SnCode + "'");
|
|
|
+ }
|
|
|
+ DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
|
|
|
+ if (Param.Rows.Count == 0)
|
|
|
+ return;
|
|
|
+ //查询的结果的参数个数大于1需要给标签的多个参数赋值
|
|
|
+ if (Param.Rows.Count > 1)
|
|
|
{
|
|
|
- string sql = dt.Rows[j]["lp_sql"].ToString();
|
|
|
- try
|
|
|
+ int LoopTime = Param.Rows.Count > 100 ? 100 : Param.Rows.Count;
|
|
|
+ for (int j = 0; j < LoopTime; j++)
|
|
|
{
|
|
|
- Regex ConnoteA = new Regex("{\\w+}");
|
|
|
- foreach (Match mch in ConnoteA.Matches(sql))
|
|
|
+ for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
|
|
|
{
|
|
|
- string x = mch.Value.Trim();
|
|
|
- sql = sql.Replace(x, "'" + SnCode + "'");
|
|
|
+ if (doc.Variables.FormVariables.Item(k + 1).Name == dt.Rows[i]["lp_name"].ToString())
|
|
|
+ {
|
|
|
+ doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[0][0].ToString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //使用SN开头的参数赋值SN1,SN2,SN3等参数
|
|
|
+ if (doc.Variables.FormVariables.Item(k + 1).Name == dt.Rows[i]["lp_name"].ToString() + j)
|
|
|
+ {
|
|
|
+ doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[j][0].ToString();
|
|
|
+ break;
|
|
|
+ }
|
|
|
}
|
|
|
- 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, "");
|
|
|
- }
|
|
|
-
|
|
|
- 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())
|
|
|
+ //否则只查询名称相等的参数赋值
|
|
|
+ else
|
|
|
{
|
|
|
- string sql = dt.Rows[j]["lp_sql"].ToString();
|
|
|
- try
|
|
|
+ for (int j = 0; j < doc.Variables.FormVariables.Count; j++)
|
|
|
{
|
|
|
- Regex ConnoteA = new Regex("{\\w+}");
|
|
|
- foreach (Match mch in ConnoteA.Matches(sql))
|
|
|
+ if (doc.Variables.FormVariables.Item(j + 1).Name == dt.Rows[i]["lp_name"].ToString())
|
|
|
{
|
|
|
- string x = mch.Value.Trim();
|
|
|
- sql = sql.Replace(x, "'" + SnCode + "'");
|
|
|
+ doc.Variables.FormVariables.Item(j + 1).Value = Param.Rows[0][0].ToString();
|
|
|
+ break;
|
|
|
}
|
|
|
- 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 + "维护不正确");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ catch (System.Exception)
|
|
|
+ {
|
|
|
+ BaseUtil.ShowError("SQL" + sql + "维护不正确");
|
|
|
+ }
|
|
|
}
|
|
|
LogManager.DoLog(sb.ToString());
|
|
|
//保存本次赋值进行打印
|
|
|
- doc.Save();
|
|
|
+ //doc.Save();
|
|
|
doc.Printer.SwitchTo(PrinterName);
|
|
|
doc.PrintDocument(PrintNum);
|
|
|
LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
|