Print.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using LabelManager2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Linq;
  6. using System.Text;
  7. using UAS_LabelMachine.Entity;
  8. namespace UAS_LabelMachine.PublicMethod
  9. {
  10. class Print
  11. {
  12. public class CodeSoft
  13. {
  14. public static void SinglePrint(Document SingleDoc, DataTable SingleLabelParam, string pib_id)
  15. {
  16. StringBuilder sql = new StringBuilder();
  17. sql.Clear();
  18. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  19. {
  20. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  21. if (dr1.Length > 0)
  22. {
  23. if (dr1[0]["lp_valuetype"].ToString() == "字符串")
  24. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  25. }
  26. }
  27. sql.Append("1,");
  28. DataTable dt = (DataTable)SystemInf.sdh.ExecuteSql("select " + sql.ToString().Substring(0, sql.Length - 1) + " from prodiobarcode where pib_id=" + pib_id, "select");
  29. for (int j = 0; j < SingleDoc.Variables.FormVariables.Count; j++)
  30. {
  31. DataRow[] dr1 = SingleLabelParam.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  32. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  33. {
  34. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", pib_id), "select");
  35. if (dt1.Rows.Count > 0)
  36. {
  37. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt1.Rows[0][0].ToString();
  38. }
  39. }
  40. else if (dr1.Length > 0)
  41. {
  42. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  43. }
  44. if (SingleDoc.Variables.FormVariables.Item(j + 1).Value == "")
  45. {
  46. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + SingleDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  47. if (dr1.Length > 0)
  48. SingleDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  49. }
  50. }
  51. SingleDoc.PrintDocument();
  52. }
  53. public static void MidPrint(Document MidDoc, DataTable MidLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode1)
  54. {
  55. StringBuilder sql = new StringBuilder();
  56. //查询参数名称相同的获取到取值字段
  57. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  58. {
  59. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  60. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  61. {
  62. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  63. }
  64. }
  65. sql.Append("1,");
  66. 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");
  67. for (int j = 0; j < MidDoc.Variables.FormVariables.Count; j++)
  68. {
  69. DataRow[] dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  70. if (dr1.Length == 0)
  71. dr1 = MidLabelParam.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
  72. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  73. {
  74. MidDoc.Variables.FormVariables.Item(j + 1).Value = dt.Rows[0][dr1[0]["lp_sql"].ToString()].ToString();
  75. }
  76. //SQL判断多个值的时候
  77. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "SQL值")
  78. {
  79. DataTable dt1 = (DataTable)SystemInf.sdh.ExecuteSql(dr1[0]["lp_sql"].ToString().Replace("{1}", "'" + pi_inoutno + "'").Replace("{2}", pib_outboxcode1), "select");
  80. for (int i = 0; i < dt1.Rows.Count; i++)
  81. {
  82. for (int k = 0; k < MidDoc.Variables.FormVariables.Count; k++)
  83. {
  84. if (i == 0 & MidDoc.Variables.FormVariables.Item(k + 1).Name == dr1[0]["lp_name"].ToString())
  85. {
  86. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[0][0].ToString();
  87. }
  88. //使用SN开头的参数赋值SN1,SN2,SN3等参数
  89. if (MidDoc.Variables.FormVariables.Item(k + 1).Name == (dr1[0]["lp_name"].ToString() + "_" + (i + 1)))
  90. {
  91. MidDoc.Variables.FormVariables.Item(k + 1).Value = dt1.Rows[i][0].ToString();
  92. }
  93. }
  94. }
  95. }
  96. if (MidDoc.Variables.FormVariables.Item(j + 1).Value == "")
  97. {
  98. dr1 = UAS_出货标签打印.Attach.Select("lp_name='" + MidDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  99. if (dr1.Length > 0)
  100. MidDoc.Variables.FormVariables.Item(j + 1).Value = dr1[0]["lp_sql"].ToString();
  101. }
  102. }
  103. MidDoc.PrintDocument();
  104. }
  105. public static void OutPrint(Document OutBoxDoc, DataTable OutLabelParam, string pi_inoutno, string pib_id, string pib_outboxcode2)
  106. {
  107. StringBuilder sql = new StringBuilder();
  108. sql.Clear();
  109. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  110. {
  111. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  112. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].ToString() == "字符串")
  113. {
  114. sql.Append(dr1[0]["lp_sql"].ToString() + ",");
  115. }
  116. }
  117. sql.Append("1,");
  118. 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");
  119. if (dt.Rows.Count > 0)
  120. {
  121. for (int j = 0; j < OutBoxDoc.Variables.FormVariables.Count; j++)
  122. {
  123. DataRow[] dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name + "'");
  124. //多参数命名
  125. if (dr1.Length == 0)
  126. dr1 = OutLabelParam.Select("lp_name='" + OutBoxDoc.Variables.FormVariables.Item(j + 1).Name.Replace("_1", "") + "'");
  127. if (dr1.Length > 0 && dr1[0]["lp_valuetype"].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()
  169. {
  170. }
  171. public static void MidPrint()
  172. {
  173. }
  174. public static void OutPrint()
  175. {
  176. }
  177. }
  178. }
  179. }