Print.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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 UAS_LabelMachine.Entity;
  9. namespace UAS_LabelMachine.PublicMethod
  10. {
  11. class Print
  12. {
  13. public class CodeSoft
  14. {
  15. public static void SinglePrint(Document SingleDoc, DataTable SingleLabelParam, string pib_id)
  16. {
  17. StringBuilder sql = new StringBuilder();
  18. sql.Clear();
  19. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  20. {
  21. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  22. if (dr1.Length > 0)
  23. {
  24. if (dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  25. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  26. }
  27. }
  28. sql.Append("1,");
  29. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  30. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  31. {
  32. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  33. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  34. {
  35. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  36. }
  37. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  38. {
  39. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  40. if (dt1.Rows.Count > 0)
  41. {
  42. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt1.Rows[0][0].ToString();
  43. }
  44. }
  45. else if (dr1.Length > 0)
  46. {
  47. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  48. }
  49. if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "")
  50. {
  51. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  52. if (dr1.Length > 0)
  53. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  54. }
  55. }
  56. SingleDoc.PrintDocument();
  57. }
  58. public static void MidPrint(Document MidDoc, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  59. {
  60. StringBuilder sql = new StringBuilder();
  61. //查询参数名称相同的获取到取值字段
  62. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  63. {
  64. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  65. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  66. {
  67. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  68. }
  69. }
  70. sql.Append("1,");
  71. 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");
  72. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  73. {
  74. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  75. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  76. {
  77. MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  78. }
  79. //SQL判断多个值的时候
  80. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  81. {
  82. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  83. for (int i = 0; i < dt1.Rows.Count; i++)
  84. {
  85. for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
  86. {
  87. if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  88. {
  89. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  90. }
  91. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  92. if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  93. {
  94. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  95. }
  96. }
  97. }
  98. }
  99. if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "")
  100. {
  101. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  102. if (dr1.Length > 0)
  103. MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  104. }
  105. }
  106. MidDoc.PrintDocument();
  107. }
  108. public static void OutPrint(Document OutBoxDoc, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2)
  109. {
  110. StringBuilder sql = new StringBuilder();
  111. sql.Clear();
  112. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  113. {
  114. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  115. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  116. {
  117. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  118. }
  119. }
  120. sql.Append("1,");
  121. 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");
  122. if (dt.Rows.Count > 0)
  123. {
  124. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  125. {
  126. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  127. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  128. {
  129. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  130. }
  131. //SQL判断多个值的时候
  132. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  133. {
  134. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  135. for (int i = 0; i < dt1.Rows.Count; i++)
  136. {
  137. for (int k = 0; k < OutBoxDoc.Variables.FormVariables.Count; k++)
  138. {
  139. if (i == 0 & OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  140. {
  141. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  142. }
  143. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  144. if (OutBoxDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  145. {
  146. OutBoxDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  147. }
  148. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  149. {
  150. string date = dt1.Rows[0][0].ToString();
  151. }
  152. }
  153. }
  154. }
  155. if (OutBoxDoc.Variables.FormVariables.Item(j + 1).Value == "")
  156. {
  157. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  158. if (dr1.Length > 0)
  159. OutBoxDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  160. }
  161. }
  162. OutBoxDoc.PrintDocument();
  163. }
  164. }
  165. }
  166. public class BarTender
  167. {
  168. public static void SinglePrint(LabelFormatDocument SingleFormat, DataTable SingleLabelParam, string pib_id)
  169. {
  170. StringBuilder sql = new StringBuilder();
  171. sql.Clear();
  172. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  173. {
  174. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  175. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  176. {
  177. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  178. }
  179. }
  180. sql.Append("1,");
  181. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  182. for (int j = 0; j < SingleFormat.SubStrings.Count; j++)
  183. {
  184. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  185. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  186. {
  187. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  188. }
  189. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  190. {
  191. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  192. if (dt1.Rows.Count > 0)
  193. {
  194. SingleFormat.SubStrings[j].Value = dt1.Rows[0][0].ToString();
  195. }
  196. }
  197. else if (dr1.Length > 0)
  198. {
  199. SingleFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  200. }
  201. if (SingleFormat.SubStrings[j].Value == "")
  202. {
  203. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleFormat.SubStrings[j].Name + "'");
  204. if (dr1.Length > 0)
  205. SingleFormat.SubStrings[j].Value = dr1[0]["lp_sql"].ToString();
  206. }
  207. }
  208. SingleFormat.Print();
  209. }
  210. public static void MidPrint(LabelFormatDocument MidFormat, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  211. {
  212. StringBuilder sql = new StringBuilder();
  213. //查询参数名称相同的获取到取值字段
  214. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  215. {
  216. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  217. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  218. {
  219. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  220. }
  221. }
  222. sql.Append("1,");
  223. 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");
  224. for (int j = 0; j < MidFormat.SubStrings.Count; j++)
  225. {
  226. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  227. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  228. {
  229. MidFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  230. }
  231. //SQL判断多个值的时候
  232. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  233. {
  234. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  235. for (int i = 0; i < dt1.Rows.Count; i++)
  236. {
  237. for (int k = 0; k < MidFormat.SubStrings.Count; k++)
  238. {
  239. if (i == 0 & MidFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  240. {
  241. MidFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  242. }
  243. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  244. if (MidFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  245. {
  246. MidFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  247. }
  248. }
  249. }
  250. }
  251. if (MidFormat.SubStrings[j].Value == "")
  252. {
  253. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + MidFormat.SubStrings[j].Name + "'");
  254. if (dr1.Length > 0)
  255. MidFormat.SubStrings[j].Value = dr1[0]["lp_sql"].ToString();
  256. }
  257. }
  258. MidFormat.Print();
  259. }
  260. public static void OutPrint(LabelFormatDocument OutFormat, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2)
  261. {
  262. StringBuilder sql = new StringBuilder();
  263. sql.Clear();
  264. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  265. {
  266. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  267. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  268. {
  269. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  270. }
  271. }
  272. sql.Append("1,");
  273. 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) + " limit 0,1", "select");
  274. if (dt.Rows.Count > 0)
  275. {
  276. for (int j = 0; j < OutFormat.SubStrings.Count; j++)
  277. {
  278. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  279. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串" && dr1[0]["lp_sql"].ToString() != "")
  280. {
  281. OutFormat.SubStrings[j].Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  282. }
  283. //SQL判断多个值的时候
  284. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  285. {
  286. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode2), "select");
  287. for (int i = 0; i < dt1.Rows.Count; i++)
  288. {
  289. for (int k = 0; k < OutFormat.SubStrings.Count; k++)
  290. {
  291. if (i == 0 & OutFormat.SubStrings[k].Name == dr1[0]["lp_name"].ToString())
  292. {
  293. OutFormat.SubStrings[k].Value = dt1.Rows[0][0].ToString();
  294. }
  295. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  296. if (OutFormat.SubStrings[k].Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  297. {
  298. OutFormat.SubStrings[k].Value = dt1.Rows[i][0].ToString();
  299. }
  300. if (dr1[0]["lp_sql"].ToString().Contains("pib_year"))
  301. {
  302. string date = dt1.Rows[0][0].ToString();
  303. }
  304. }
  305. }
  306. }
  307. if (OutFormat.SubStrings[j].Value == "")
  308. {
  309. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + OutFormat.SubStrings[j].Name + "'");
  310. if (dr1.Length > 0)
  311. OutFormat.SubStrings[j].Value = dr1[0]["lp_sql"].ToString();
  312. }
  313. }
  314. OutFormat.Print();
  315. }
  316. }
  317. }
  318. }
  319. }