Print.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  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)
  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. sql.Append("1,");
  122. 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), "select");
  123. if (dt.Rows.Count > 0)
  124. {
  125. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  126. {
  127. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  128. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  129. {
  130. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  131. }
  132. //SQL判断多个值的时候
  133. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  134. {
  135. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  136. for (int i = 0; i < dt1.Rows.Count; i++)
  137. {
  138. for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
  139. {
  140. if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  141. {
  142. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  143. }
  144. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  145. if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  146. {
  147. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  148. }
  149. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  150. {
  151. string date = dt1.Rows[0][0].ToString();
  152. }
  153. }
  154. }
  155. }
  156. if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
  157. {
  158. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  159. if (dr1.Length > 0)
  160. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  161. }
  162. }
  163. OutBoxDoc.PrintDocument();
  164. }
  165. }
  166. }
  167. public class BarTender
  168. {
  169. public static void SinglePrint(LabelFormatDocument SingleFormat, DataTable SingleLabelParam, string pib_id)
  170. {
  171. StringBuilder sql = new StringBuilder();
  172. sql.Clear();
  173. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  174. {
  175. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  176. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  177. {
  178. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  179. }
  180. }
  181. sql.Append("1,");
  182. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  183. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  184. {
  185. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  186. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  187. {
  188. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  189. }
  190. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  191. {
  192. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  193. if (dt1.Rows.Count > 0)
  194. {
  195. SingleFormat.SubStrings[j].Value = dt1.Rows[0][0].ToString();
  196. }
  197. }
  198. else if (dr1.Length > 0)
  199. {
  200. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  201. }
  202. if (SingleFormat.SubStrings[j].Value == "")
  203. {
  204. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  205. if (dr2.Length > 0)
  206. SingleFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  207. }
  208. //启用了校验Dc和LotNo不为空的设置
  209. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && SingleFormat.SubStrings[j].Value == "")
  210. {
  211. //如果SQL用到了DC和LotNo字段
  212. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  213. {
  214. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  215. return;
  216. }
  217. }
  218. }
  219. try
  220. {
  221. SingleFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  222. }
  223. catch (Exception)
  224. {
  225. }
  226. SingleFormat.Print();
  227. }
  228. public static void MidPrint(LabelFormatDocument MidFormat, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  229. {
  230. StringBuilder sql = new StringBuilder();
  231. //查询参数名称相同的获取到取值字段
  232. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  233. {
  234. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  235. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  236. {
  237. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  238. }
  239. }
  240. sql.Append("1,");
  241. 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");
  242. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  243. {
  244. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  245. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  246. {
  247. MidFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  248. }
  249. //SQL判断多个值的时候
  250. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  251. {
  252. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  253. for (int i = 0; i < dt1.Rows.Count; i++)
  254. {
  255. for (int k = 0; k < MidFormat.SubStrings.Count; k++)
  256. {
  257. if (i == 0 & MidFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  258. {
  259. MidFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  260. }
  261. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  262. if (MidFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  263. {
  264. MidFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  265. }
  266. }
  267. }
  268. }
  269. if (MidFormat.SubStrings[j].Value == "")
  270. {
  271. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  272. if (dr2.Length > 0)
  273. MidFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  274. }
  275. //启用了校验Dc和LotNo不为空的设置
  276. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && MidFormat.SubStrings[j].Value == "")
  277. {
  278. //如果SQL用到了DC和LotNo字段
  279. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  280. {
  281. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  282. return;
  283. }
  284. }
  285. }
  286. try
  287. {
  288. MidFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  289. }
  290. catch (Exception)
  291. {
  292. }
  293. MidFormat.Print();
  294. }
  295. 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)
  296. {
  297. StringBuilder sql = new StringBuilder();
  298. sql.Clear();
  299. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  300. {
  301. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  302. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  303. {
  304. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  305. }
  306. }
  307. //界面设定的分组条件
  308. string GroupByCondition = "";
  309. if (iCustProdCode)
  310. {
  311. GroupByCondition += "pd_custprodcode,";
  312. }
  313. if (iCustPo)
  314. {
  315. GroupByCondition += "pd_pocode,";
  316. }
  317. if (iDC)
  318. {
  319. GroupByCondition += "pib_datecode,";
  320. }
  321. if (iLotNo)
  322. {
  323. GroupByCondition += "pib_lotno,";
  324. }
  325. if (iCustProdCode || iCustPo || iDC || iLotNo)
  326. {
  327. GroupByCondition = " group by "+(GroupByCondition.Substring(0, GroupByCondition.Length - 1));
  328. }
  329. sql.Append("1,");
  330. 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");
  331. for (int m = 0; m < dt.Rows.Count; m++)
  332. {
  333. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  334. {
  335. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  336. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  337. {
  338. OutFormat.SubStrings[j].Value = dt.Rows[m][dr1[0]["lp_sql"].ToString()].ToString();
  339. }
  340. //SQL判断多个值的时候
  341. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  342. {
  343. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  344. for (int i = 0; i < dt1.Rows.Count; i++)
  345. {
  346. for (int k = 0; k < OutFormat.SubStrings.Count; k++)
  347. {
  348. if (i == 0 & OutFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  349. {
  350. OutFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  351. }
  352. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  353. if (OutFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  354. {
  355. OutFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  356. }
  357. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  358. {
  359. string date = dt1.Rows[0][0].ToString();
  360. }
  361. }
  362. }
  363. }
  364. if (OutFormat.SubStrings[j].Value == "")
  365. {
  366. DataRow[] dr2 = UAS_出货标签打印.Attach.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  367. if (dr2.Length > 0)
  368. OutFormat.SubStrings[j].Value = dr2[0]["lp_sql"].ToString();
  369. }
  370. //启用了校验Dc和LotNo不为空的设置
  371. if (SystemInf.CheckDcAndLotNo && dr1.Length > 0 && OutFormat.SubStrings[j].Value == "")
  372. {
  373. //如果SQL用到了DC和LotNo字段
  374. if ((dr1[0]["lp_sql"].ToString().Contains("pib_lotno") || dr1[0]["lp_sql"].ToString().Contains("pib_datecode")))
  375. {
  376. MessageBox.Show("标签含有DC或者LotNo参数未赋值,请采集数据");
  377. return;
  378. }
  379. }
  380. }
  381. try
  382. {
  383. OutFormat.PrintSetup.IdenticalCopiesOfLabel = 1;
  384. }
  385. catch (Exception)
  386. {
  387. }
  388. OutFormat.Print();
  389. }
  390. }
  391. }
  392. }
  393. }