Print.cs 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. using UAS_MES_NEW.DataOperate;
  2. using LabelManager2;
  3. using System.Data;
  4. using System.Text;
  5. using System.IO;
  6. using UAS_MES_NEW.Entity;
  7. using System.Text.RegularExpressions;
  8. using System.Windows.Forms;
  9. using Seagull.BarTender.Print;
  10. using System.Net;
  11. using System;
  12. using System.Linq;
  13. namespace UAS_MES_NEW.PublicMethod
  14. {
  15. class Print
  16. {
  17. static DataHelper dh = SystemInf.dh;
  18. //CodeSoft打印的驱动和文件
  19. static Document doc;
  20. ////CodeSoft的打印机
  21. //string CodeSpft_Printer;
  22. static BarTender.Format doc2;
  23. static LabelFormatDocument format;
  24. public Print() { }
  25. public static bool CodeSoft(string iCaller, Document doc, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
  26. {
  27. ErrorMessage = "";
  28. DataTable dt = new DataTable();
  29. if (IfRePrint != "-1")
  30. {
  31. if (LabelType == "卡通箱标" || LabelType == "大箱标" || LabelType == "栈板标")
  32. {
  33. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  34. }
  35. else
  36. {
  37. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_makecode='" + MakeCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  38. }
  39. ////如果已经打印过了,则不允许再打印
  40. if (dt.Rows.Count > 0)
  41. {
  42. ErrorMessage = SnCode + LabelType + "已打印";
  43. return false;
  44. }
  45. }
  46. //打开模板路径
  47. //查询模板对应的取值SQL和参数名称
  48. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
  49. StringBuilder sb = new StringBuilder();
  50. if (doc == null)
  51. {
  52. MessageBox.Show("打印文件不存在");
  53. return false;
  54. }
  55. //执行全部的SQL
  56. for (int i = 0; i < dt.Rows.Count; i++)
  57. {
  58. string sql = dt.Rows[i]["lp_sql"].ToString();
  59. try
  60. {
  61. Regex ConnoteA = new Regex("{\\w+}");
  62. foreach (Match mch in ConnoteA.Matches(sql))
  63. {
  64. string x = mch.Value.Trim();
  65. sql = sql.Replace(x, "'" + SnCode + "'");
  66. }
  67. DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  68. if (Param.Rows.Count == 0)
  69. continue;
  70. //查询的结果的参数个数大于1需要给标签的多个参数赋值
  71. if (Param.Rows.Count > 0)
  72. {
  73. int LoopTime = Param.Rows.Count > 200 ? 200 : Param.Rows.Count;
  74. for (int j = 0; j < LoopTime; j++)
  75. {
  76. for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
  77. {
  78. if (j == 0 & doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
  79. {
  80. doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[0][0].ToString();
  81. }
  82. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  83. if (doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
  84. {
  85. doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[j][0].ToString();
  86. }
  87. }
  88. }
  89. }
  90. }
  91. catch (System.Exception)
  92. {
  93. MessageBox.Show("SQL维护不正确");
  94. }
  95. }
  96. LogManager.DoLog(sb.ToString());
  97. //保存本次赋值进行打印
  98. doc.Printer.SwitchTo(PrinterName);
  99. doc.PrintDocument(PrintNum);
  100. LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
  101. for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
  102. {
  103. doc.Variables.FormVariables.Item(k + 1).Value = null;
  104. }
  105. LogicHandler.doLabelPrintLog(SnCode, LabelType, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
  106. return true;
  107. }
  108. public static bool CodeSoft(string iCaller, ref ApplicationClass lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
  109. {
  110. ErrorMessage = "";
  111. DataTable dt = new DataTable();
  112. if (IfRePrint != "-1")
  113. {
  114. if (LabelType == "卡通箱标" || LabelType == "大箱标" || LabelType == "栈板标")
  115. {
  116. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + LabelName + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  117. }
  118. else
  119. {
  120. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_makecode='" + MakeCode + "' and lpl_type='" + LabelType + LabelName + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  121. }
  122. ////如果已经打印过了,则不允许再打印
  123. if (dt.Rows.Count > 0)
  124. {
  125. ErrorMessage = SnCode + LabelType + "已打印";
  126. return false;
  127. }
  128. }
  129. string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + LaID + "'").ToString();
  130. FileInfo PrintFile = new FileInfo(LabelName);
  131. //打开模板路径
  132. //查询模板对应的取值SQL和参数名称
  133. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "' order by to_number(lp_detno)", "select");
  134. StringBuilder sb = new StringBuilder();
  135. if (!PrintFile.Exists)
  136. {
  137. MessageBox.Show("打印文件不存在");
  138. return false;
  139. }
  140. string filechangetime = PrintFile.LastWriteTime.ToString();
  141. if (filechangetime != filelastwritetime)
  142. {
  143. lbl.Quit();
  144. lbl = new ApplicationClass();
  145. BaseUtil.WriteLbl();
  146. filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
  147. string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
  148. dh.UpdateByCondition("label", update, "la_id = '" + LaID + "'");
  149. }
  150. doc = lbl.Documents.Open(LabelName, true);
  151. if (doc == null)
  152. {
  153. MessageBox.Show("标签文件打开失败");
  154. return false;
  155. }
  156. //执行全部的SQL
  157. for (int i = 0; i < dt.Rows.Count; i++)
  158. {
  159. string sql = dt.Rows[i]["lp_sql"].ToString();
  160. try
  161. {
  162. Regex ConnoteA = new Regex("{\\w+}");
  163. foreach (Match mch in ConnoteA.Matches(sql))
  164. {
  165. string x = mch.Value.Trim();
  166. sql = sql.Replace(x, "'" + SnCode + "'");
  167. }
  168. DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  169. if (Param.Rows.Count == 0)
  170. continue;
  171. //查询的结果的参数个数大于1需要给标签的多个参数赋值
  172. if (Param.Rows.Count > 0)
  173. {
  174. int LoopTime = Param.Rows.Count > 200 ? 200 : Param.Rows.Count;
  175. for (int j = 0; j < LoopTime; j++)
  176. {
  177. for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
  178. {
  179. if (j == 0 & doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
  180. {
  181. doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[0][0].ToString();
  182. }
  183. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  184. if (doc.Variables.FormVariables.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
  185. {
  186. doc.Variables.FormVariables.Item(k + 1).Value = Param.Rows[j][0].ToString();
  187. }
  188. }
  189. }
  190. }
  191. }
  192. catch (System.Exception)
  193. {
  194. MessageBox.Show("SQL维护不正确");
  195. }
  196. }
  197. LogManager.DoLog(sb.ToString());
  198. //保存本次赋值进行打印
  199. doc.Printer.SwitchTo(PrinterName);
  200. doc.PrintDocument(PrintNum);
  201. LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
  202. for (int k = 0; k < doc.Variables.FormVariables.Count; k++)
  203. {
  204. doc.Variables.FormVariables.Item(k + 1).Value = null;
  205. }
  206. LogicHandler.doLabelPrintLog(SnCode, LabelType + LabelName, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
  207. return true;
  208. }
  209. public static bool SinglePrint(string iCaller, BarTender.Application lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
  210. {
  211. ErrorMessage = "";
  212. DataTable dt = new DataTable();
  213. if (IfRePrint != "-1")
  214. {
  215. if (LabelType == "卡通箱标" || LabelType == "彩盒标" || LabelType == "栈板标" || LabelType == "机身标")
  216. {
  217. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  218. }
  219. else
  220. {
  221. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_makecode='" + MakeCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  222. }
  223. //////如果已经打印过了,则不允许再打印
  224. //if (dt.Rows.Count > 0)
  225. //{
  226. // ErrorMessage = SnCode + LabelType + "已打印";
  227. // return false;
  228. //}
  229. }
  230. // string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + LaID + "'").ToString();
  231. // FileInfo PrintFile = new FileInfo(LabelName);
  232. //打开模板路径
  233. //查询模板对应的取值SQL和参数名称
  234. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
  235. //StringBuilder sb = new StringBuilder();
  236. //if (!PrintFile.Exists)
  237. //{
  238. // MessageBox.Show("打印文件不存在");
  239. // return false;
  240. //}
  241. //string filechangetime = PrintFile.LastWriteTime.ToString();
  242. //if (filechangetime != filelastwritetime)
  243. //{
  244. // lbl.Dispose();
  245. // lbl = new Engine();
  246. // // BaseUtil.WriteLbl();
  247. // filechangetime = PrintFile.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss");
  248. // string update = "la_lastwritetime = to_date((regexp_substr('" + filechangetime + "','\\d+.+\\d+')),'yyyy-mm-dd hh24:mi:ss')";
  249. // dh.UpdateByCondition("label", update, "la_id = '" + LaID + "'");
  250. //}
  251. doc2 = lbl.Formats.Open(LabelName);
  252. if (doc2 == null)
  253. {
  254. MessageBox.Show("标签文件打开失败");
  255. return false;
  256. }
  257. //执行全部的SQL
  258. for (int i = 0; i < dt.Rows.Count; i++)
  259. {
  260. string sql = dt.Rows[i]["lp_sql"].ToString();
  261. try
  262. {
  263. Regex ConnoteA = new Regex("{\\w+}");
  264. foreach (Match mch in ConnoteA.Matches(sql))
  265. {
  266. string x = mch.Value.Trim();
  267. sql = sql.Replace(x, "'" + SnCode + "'");
  268. }
  269. DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  270. if (Param.Rows.Count == 0)
  271. continue;
  272. //查询的结果的参数个数大于1需要给标签的多个参数赋值
  273. if (Param.Rows.Count > 0)
  274. {
  275. int LoopTime = Param.Rows.Count > 200 ? 200 : Param.Rows.Count;
  276. for (int j = 0; j < LoopTime; j++)
  277. {
  278. for (int k = 0; k < doc2.NamedSubStrings.Count; k++)
  279. {
  280. if (j == 0 & doc2.NamedSubStrings.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
  281. {
  282. doc2.SetNamedSubStringValue(doc2.NamedSubStrings.Item(k + 1).Name, Param.Rows[0][0].ToString());
  283. }
  284. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  285. //if (j != 0 & doc2.NamedSubStrings.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j))
  286. //{
  287. // doc2.SetNamedSubStringValue(doc2.NamedSubStrings.Item(k + 1).Name, Param.Rows[j][0].ToString());
  288. //}
  289. if (doc2.NamedSubStrings.Item(k + 1).Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
  290. {
  291. doc2.SetNamedSubStringValue(doc2.NamedSubStrings.Item(k + 1).Name, Param.Rows[j][0].ToString());
  292. }
  293. }
  294. }
  295. }
  296. }
  297. catch (System.Exception ex)
  298. {
  299. MessageBox.Show("SQL维护不正确" + ex.Message);
  300. }
  301. }
  302. // LogManager.DoLog(sb.ToString());
  303. //保存本次赋值进行打印
  304. // doc2.Printer.SwitchTo(PrinterName);
  305. // 同样标签的份数
  306. doc2.PrintSetup.IdenticalCopiesOfLabel = PrintNum;
  307. // 序列标签数
  308. doc2.PrintSetup.NumberSerializedLabels = 1;
  309. doc2.PrintSetup.Printer = PrinterName;
  310. doc2.PrintOut(false, false);
  311. doc2.Close(BarTender.BtSaveOptions.btDoNotSaveChanges);
  312. LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
  313. LogicHandler.doLabelPrintLog(SnCode, LabelType, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode);
  314. //打印完毕
  315. lbl.Quit(BarTender.BtSaveOptions.btDoNotSaveChanges);
  316. return true;
  317. }
  318. public static bool BarTenderS(string iCaller, ref Engine lbl, string LabelName, string LaID, string PrinterName, string SnCode, int PrintNum, string MakeCode, string ProdCode, string LabelType, string IfRePrint, out string ErrorMessage)
  319. {
  320. ErrorMessage = "";
  321. DataTable dt = new DataTable();
  322. if (PrintNum == 0)
  323. {
  324. PrintNum = 1;
  325. }
  326. if (IfRePrint == "-1")
  327. {
  328. string printNumber = dh.getFieldDataByCondition("CONFIGS", "DATA", "code='printNumber' and caller='MESSetting'").ToString();
  329. if (dh.getRowCount("labelprintlog", "lpl_type='" + LabelType + "' and lpl_value='" + SnCode + "'") > int.Parse(printNumber))
  330. {
  331. ErrorMessage = "标签补打超出允许打印次数【" + printNumber + "】";
  332. return false;
  333. }
  334. }
  335. if (IfRePrint != "-1" && LabelType != "机身标")
  336. {
  337. bool allowPallte = true;
  338. if ((SystemInf.dh.getFieldDataByCondition("master", "MA_FUNCTION", "ma_user='" + SystemInf.CurrentDB + "'").ToString() == "万年MES系统(正式)"))
  339. {
  340. allowPallte = false;
  341. }
  342. if (LabelType == "卡通箱标" || LabelType == "大箱标" || (LabelType == "栈板标" && allowPallte) || LabelType == "彩盒标")
  343. {
  344. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "' and lpl_file='" + LabelName + "'", "select");
  345. }
  346. else
  347. {
  348. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_makecode='" + MakeCode + "' and lpl_type='" + LabelType + "' and lpl_stepcode='" + User.CurrentStepCode + "'", "select");
  349. }
  350. ////如果已经打印过了,则不允许再打印
  351. if (dt.Rows.Count > 0)
  352. {
  353. ErrorMessage = SnCode + LabelType + "已打印";
  354. return false;
  355. }
  356. }
  357. else
  358. {
  359. if (LabelType == "卡通箱标" || LabelType == "大箱标" || LabelType == "彩盒标")
  360. {
  361. dt = (DataTable)dh.ExecuteSql("select lpl_id from labelprintlog where lpl_value='" + SnCode + "' and lpl_type='" + LabelType + "'", "select");
  362. if (dt.Rows.Count == 0)
  363. {
  364. ErrorMessage = SnCode + LabelType + "未打印,不允许补打";
  365. return false;
  366. }
  367. }
  368. }
  369. string filelastwritetime = dh.getFieldDataByCondition("label", "la_lastwritetime", "la_id = '" + LaID + "'").ToString();
  370. string LA_SOFTTYPE = dh.getFieldDataByCondition("label", "LA_SOFTTYPE", "la_id = '" + LaID + "'").ToString();
  371. //如果有附件上传的话
  372. string fp_name = "";
  373. //下载附件
  374. FileInfo PrintFile = new FileInfo(@"C:\打印标签\" + LabelName);
  375. if (!PrintFile.Exists)
  376. {
  377. if (LA_SOFTTYPE != "")
  378. {
  379. string[] fpid = LA_SOFTTYPE.Split(';');
  380. for (int i = 0; i < fpid.Length; i++)
  381. {
  382. if (fpid[i] != "")
  383. {
  384. DataTable label = (DataTable)dh.ExecuteSql("select FP_PATH, FP_DATE, FP_NAME from FILEPATH where fp_id='" + fpid[i] + "'", "select");
  385. if (label.Rows.Count > 0)
  386. {
  387. string fp_path = label.Rows[0]["FP_PATH"].ToString().Replace("/app/uas/webapps/", "");
  388. fp_name = label.Rows[0]["fp_name"].ToString();
  389. WebClient wc = new WebClient();
  390. wc.DownloadFile("http://192.168.110.18:8099/" + fp_path, @"C:\打印标签\" + fp_name);
  391. }
  392. }
  393. }
  394. lbl.Stop();
  395. lbl = new Engine(true);
  396. BaseUtil.WriteLbl();
  397. }
  398. }
  399. else
  400. {
  401. string filechangetime = PrintFile.LastWriteTime.ToString();
  402. System.DateTime dateTime1 = System.DateTime.Parse(filechangetime);
  403. System.DateTime dateTime2 = System.DateTime.Parse(filelastwritetime);
  404. if (dateTime1 < dateTime2)
  405. {
  406. if (LA_SOFTTYPE != "")
  407. {
  408. string[] fpid = LA_SOFTTYPE.Split(';');
  409. for (int i = 0; i < fpid.Length; i++)
  410. {
  411. if (fpid[i] != "")
  412. {
  413. DataTable label = (DataTable)dh.ExecuteSql("select FP_PATH, FP_DATE, FP_NAME from FILEPATH where fp_id='" + fpid[i] + "'", "select");
  414. if (label.Rows.Count > 0)
  415. {
  416. string fp_path = label.Rows[0]["FP_PATH"].ToString().Replace("/app/uas/webapps/", "");
  417. fp_name = label.Rows[0]["fp_name"].ToString();
  418. WebClient wc = new WebClient();
  419. wc.DownloadFile("http://192.168.110.18:8099/" + fp_path, @"C:\打印标签\" + fp_name);
  420. FileInfo file = new FileInfo(@"C:\打印标签\" + fp_name);
  421. file.CreationTime = Convert.ToDateTime(filelastwritetime);
  422. }
  423. }
  424. }
  425. }
  426. lbl.Stop();
  427. lbl = new Engine(true);
  428. BaseUtil.WriteLbl();
  429. }
  430. }
  431. PrintFile = new FileInfo(@"C:\打印标签\" + LabelName);
  432. if (!PrintFile.Exists)
  433. {
  434. MessageBox.Show("打印文件不存在");
  435. return false;
  436. }
  437. //查询模板对应的取值SQL和参数名称
  438. dt = (DataTable)dh.ExecuteSql("select lp_name,lp_sql from label left join LABELPARAMETER on la_id=lp_laid where la_id='" + LaID + "'", "select");
  439. StringBuilder sb = new StringBuilder();
  440. if (!PrintFile.Exists)
  441. {
  442. MessageBox.Show("打印文件不存在");
  443. return false;
  444. }
  445. format = lbl.Documents.Open(@"C:\打印标签\" + LabelName);
  446. if (format == null)
  447. {
  448. MessageBox.Show("标签文件打开失败");
  449. return false;
  450. }
  451. string ParamValue = format.SubStrings.GetAll("#", "$");
  452. string[] paramname = ParamValue.Split('$');
  453. for (int i = 0; i < paramname.Length; i++)
  454. {
  455. paramname[i] = paramname[i].Split('#')[0];
  456. }
  457. //执行全部的SQL
  458. for (int i = 0; i < dt.Rows.Count; i++)
  459. {
  460. string sql = dt.Rows[i]["lp_sql"].ToString();
  461. try
  462. {
  463. Regex ConnoteA = new Regex("{\\w+}");
  464. foreach (Match mch in ConnoteA.Matches(sql))
  465. {
  466. string x = mch.Value.Trim();
  467. sql = sql.Replace(x, "'" + SnCode + "'");
  468. }
  469. DataTable Param = (DataTable)dh.ExecuteSql(sql.ToString(), "select");
  470. if (Param.Rows.Count == 0)
  471. continue;
  472. //查询的结果的参数个数大于1需要给标签的多个参数赋值
  473. if (Param.Rows.Count > 0)
  474. {
  475. int LoopTime = Param.Rows.Count > 200 ? 200 : Param.Rows.Count;
  476. for (int j = 0; j < LoopTime; j++)
  477. {
  478. //if (paramname.Contains(dt.Rows[i]["lp_name"].ToString().ToUpper()))
  479. //{
  480. // if (format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper()] != null)
  481. // {
  482. // format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper()].Value = Param.Rows[0][0].ToString();
  483. // }
  484. //}
  485. //if (paramname.Contains(dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1)))
  486. //{
  487. // if (format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1)] != null)
  488. // {
  489. // format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1)].Value = Param.Rows[j][0].ToString(); ;
  490. // }
  491. //}
  492. //try
  493. //{
  494. // if (format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper()] != null)
  495. // {
  496. // format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper()].Value = Param.Rows[0][0].ToString();
  497. // }
  498. // if (format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1)] != null)
  499. // {
  500. // format.SubStrings[dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1)].Value = Param.Rows[j][0].ToString(); ;
  501. // }
  502. //}
  503. //catch (Exception e)
  504. //{
  505. // Console.WriteLine( e.Message);
  506. //}
  507. for (int k = 0; k < format.SubStrings.Count; k++)
  508. {
  509. if (j == 0 & format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper())
  510. {
  511. format.SubStrings[k].Value = Param.Rows[0][0].ToString();
  512. break;
  513. }
  514. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  515. if (format.SubStrings[k].Name.ToUpper() == dt.Rows[i]["lp_name"].ToString().ToUpper() + (j + 1))
  516. {
  517. format.SubStrings[k].Value = Param.Rows[j][0].ToString();
  518. break;
  519. }
  520. }
  521. }
  522. }
  523. }
  524. catch (System.Exception)
  525. {
  526. MessageBox.Show("SQL维护不正确");
  527. }
  528. }
  529. LogManager.DoLog(sb.ToString());
  530. //保存本次赋值进行打印a
  531. format.PrintSetup.PrinterName = PrinterName;
  532. format.PrintSetup.IdenticalCopiesOfLabel = PrintNum;
  533. format.Print();
  534. LogicHandler.DoCommandLog(iCaller, User.UserCode, "", User.UserLineCode, User.UserSourceCode, "打印", "成功打印", SnCode, "");
  535. try
  536. {
  537. for (int k = 0; k < format.SubStrings.Count; k++)
  538. {
  539. format.SubStrings[k].Value = null;
  540. }
  541. }
  542. catch (Exception ex)
  543. {
  544. LogManager.DoLog(ex.Message + ex.StackTrace);
  545. }
  546. LogicHandler.doLabelPrintLog(SnCode, LabelType, MakeCode, ProdCode, User.UserSourceCode, User.CurrentStepCode, IfRePrint, User.UserCode, PrintFile.Name);
  547. return true;
  548. }
  549. }
  550. }