Print.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  1. using LabelManager2;
  2. using Seagull.BarTender.Print;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_LabelMachine.Entity;
  10. namespace UAS_LabelMachine.PublicMethod
  11. {
  12. class Print
  13. {
  14. public class CodeSoft
  15. {
  16. public static void SinglePrint(Document SingleDoc, DataTable SingleLabelParam, string pib_id)
  17. {
  18. StringBuilder sql = new StringBuilder();
  19. sql.Clear();
  20. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  21. {
  22. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  23. if (dr1.Length > 0)
  24. {
  25. if (dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  26. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  27. }
  28. }
  29. sql.Append("1,");
  30. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  31. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  32. {
  33. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  34. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  35. {
  36. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  37. }
  38. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  39. {
  40. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  41. if (dt1.Rows.Count > 0)
  42. {
  43. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt1.Rows[0][0].ToString();
  44. }
  45. }
  46. else if (dr1.Length > 0)
  47. {
  48. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  49. }
  50. if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "")
  51. {
  52. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  53. if (dr1.Length > 0)
  54. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  55. }
  56. }
  57. SingleDoc.PrintDocument();
  58. }
  59. public static void MidPrint(Document MidDoc, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  60. {
  61. StringBuilder sql = new StringBuilder();
  62. //查询参数名称相同的获取到取值字段
  63. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  64. {
  65. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  66. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  67. {
  68. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  69. }
  70. }
  71. sql.Append("1,");
  72. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1), "select");
  73. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  74. {
  75. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  76. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  77. {
  78. MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  79. }
  80. //SQL判断多个值的时候
  81. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  82. {
  83. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  84. for (int i = 0; i < dt1.Rows.Count; i++)
  85. {
  86. for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
  87. {
  88. if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  89. {
  90. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  91. }
  92. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  93. if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  94. {
  95. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  96. }
  97. }
  98. }
  99. }
  100. if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "")
  101. {
  102. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  103. if (dr1.Length > 0)
  104. MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  105. }
  106. }
  107. MidDoc.PrintDocument();
  108. }
  109. public static void OutPrint(Document OutBoxDoc, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2, bool iCustProdCode, bool iCustPo, bool iDC, bool iLotNo)
  110. {
  111. StringBuilder sql = new StringBuilder();
  112. sql.Clear();
  113. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  114. {
  115. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  116. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  117. {
  118. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  119. }
  120. }
  121. //界面设定的分组条件
  122. string GroupByCondition = "";
  123. if (iCustProdCode)
  124. {
  125. GroupByCondition += "pd_custprodcode,";
  126. }
  127. if (iCustPo)
  128. {
  129. GroupByCondition += "pd_pocode,";
  130. }
  131. if (iDC)
  132. {
  133. GroupByCondition += "pib_datecode,";
  134. }
  135. if (iLotNo)
  136. {
  137. GroupByCondition += "pib_lotno,";
  138. }
  139. if (iCustProdCode || iCustPo || iDC || iLotNo)
  140. {
  141. GroupByCondition = " group by " + (GroupByCondition.Substring(0, GroupByCondition.Length - 1));
  142. }
  143. sql.Append("1,");
  144. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition, "select");
  145. if (dt.Rows.Count > 0)
  146. {
  147. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  148. {
  149. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  150. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  151. {
  152. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  153. }
  154. //SQL判断多个值的时候
  155. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  156. {
  157. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  158. for (int i = 0; i < dt1.Rows.Count; i++)
  159. {
  160. for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
  161. {
  162. if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  163. {
  164. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  165. }
  166. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  167. if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  168. {
  169. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  170. }
  171. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  172. {
  173. string date = dt1.Rows[0][0].ToString();
  174. }
  175. }
  176. }
  177. }
  178. if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
  179. {
  180. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  181. if (dr1.Length > 0)
  182. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  183. }
  184. }
  185. OutBoxDoc.PrintDocument();
  186. }
  187. }
  188. }
  189. public class BarTender
  190. {
  191. public static void SinglePrint(LabelFormatDocument SingleFormat, DataTable SingleLabelParam, string pib_id)
  192. {
  193. StringBuilder sql = new StringBuilder();
  194. sql.Clear();
  195. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  196. {
  197. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  198. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  199. {
  200. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  201. }
  202. }
  203. sql.Append("1,");
  204. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  205. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  206. {
  207. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  208. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  209. {
  210. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  211. }
  212. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  213. {
  214. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  215. if (dt1.Rows.Count > 0)
  216. {
  217. SingleFormat.SubStrings[j].Value = dt1.Rows[0][0].ToString();
  218. }
  219. }
  220. else if (dr1.Length > 0)
  221. {
  222. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  223. }
  224. if (SingleFormat.SubStrings[j].Value == "")
  225. {
  226. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  227. if (dr2.Length > 0)
  228. SingleFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  229. }
  230. //启用了校验Dc和LotNo不为空的设置
  231. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && SingleFormat.SubStrings[j].Value == "")
  232. {
  233. //如果SQL用到了DC和LotNo字段
  234. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  235. {
  236. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  237. return;
  238. }
  239. }
  240. }
  241. try
  242. {
  243. SingleFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  244. }
  245. catch (Exception)
  246. {
  247. }
  248. SingleFormat.Print();
  249. }
  250. public static void MidPrint(LabelFormatDocument MidFormat, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  251. {
  252. StringBuilder sql = new StringBuilder();
  253. //查询参数名称相同的获取到取值字段
  254. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  255. {
  256. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  257. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  258. {
  259. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  260. }
  261. }
  262. sql.Append("1,");
  263. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode1=" + (pib_outboxcode1 == "" ? "0" : pib_outboxcode1) + " limit 0,1", "select");
  264. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  265. {
  266. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  267. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  268. {
  269. MidFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  270. }
  271. //SQL判断多个值的时候
  272. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  273. {
  274. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  275. for (int i = 0; i < dt1.Rows.Count; i++)
  276. {
  277. for (int k = 0; k < MidFormat.SubStrings.Count; k++)
  278. {
  279. if (i == 0 & MidFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  280. {
  281. MidFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  282. }
  283. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  284. if (MidFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  285. {
  286. MidFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  287. }
  288. }
  289. }
  290. }
  291. if (MidFormat.SubStrings[j].Value == "")
  292. {
  293. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  294. if (dr2.Length > 0)
  295. MidFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  296. }
  297. //启用了校验Dc和LotNo不为空的设置
  298. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && MidFormat.SubStrings[j].Value == "")
  299. {
  300. //如果SQL用到了DC和LotNo字段
  301. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  302. {
  303. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  304. return;
  305. }
  306. }
  307. }
  308. try
  309. {
  310. MidFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  311. }
  312. catch (Exception)
  313. {
  314. }
  315. MidFormat.Print();
  316. }
  317. public static void OutPrint(LabelFormatDocument OutFormat, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2, bool iCustProdCode, bool iCustPo, bool iDC, bool iLotNo)
  318. {
  319. StringBuilder sql = new StringBuilder();
  320. sql.Clear();
  321. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  322. {
  323. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  324. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  325. {
  326. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  327. }
  328. }
  329. //界面设定的分组条件
  330. string GroupByCondition = "";
  331. if (iCustProdCode)
  332. {
  333. GroupByCondition += "pd_custprodcode,";
  334. }
  335. if (iCustPo)
  336. {
  337. GroupByCondition += "pd_pocode,";
  338. }
  339. if (iDC)
  340. {
  341. GroupByCondition += "pib_datecode,";
  342. }
  343. if (iLotNo)
  344. {
  345. GroupByCondition += "pib_lotno,";
  346. }
  347. if (iCustProdCode || iCustPo || iDC || iLotNo)
  348. {
  349. GroupByCondition = " group by " + (GroupByCondition.Substring(0, GroupByCondition.Length - 1));
  350. }
  351. sql.Append("1,");
  352. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_inoutno='" + pi_inoutno + "' and pib_outboxcode2=" + (pib_outboxcode2 == "" ? "0" : pib_outboxcode2) + GroupByCondition, "select");
  353. for (int m = 0; m < dt.Rows.Count; m++)
  354. {
  355. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  356. {
  357. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  358. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  359. {
  360. OutFormat.SubStrings[j].Value = dt.Rows[m][dr1[0]["lp_sql"].ToString()].ToString();
  361. }
  362. //SQL判断多个值的时候
  363. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  364. {
  365. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  366. for (int i = 0; i < dt1.Rows.Count; i++)
  367. {
  368. for (int k = 0; k < OutFormat.SubStrings.Count; k++)
  369. {
  370. if (i == 0 & OutFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  371. {
  372. OutFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  373. }
  374. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  375. if (OutFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  376. {
  377. OutFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  378. }
  379. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  380. {
  381. string date = dt1.Rows[0][0].ToString();
  382. }
  383. }
  384. }
  385. }
  386. if (OutFormat.SubStrings[j].Value == "")
  387. {
  388. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  389. if (dr2.Length > 0)
  390. OutFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  391. }
  392. //启用了校验Dc和LotNo不为空的设置
  393. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && OutFormat.SubStrings[j].Value == "")
  394. {
  395. //如果SQL用到了DC和LotNo字段
  396. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  397. {
  398. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  399. return;
  400. }
  401. }
  402. }
  403. try
  404. {
  405. OutFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  406. }
  407. catch (Exception)
  408. {
  409. }
  410. OutFormat.Print();
  411. }
  412. }
  413. }
  414. }
  415. }