Print.cs 18 KB

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