SystemSetting_PrinterTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Drawing.Printing;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.Entity;
  8. using UAS_MES_NEW.PublicMethod;
  9. namespace UAS_MES_NEW.SystemSetting
  10. {
  11. public partial class SystemSetting_PrinterTest : Form
  12. {
  13. public BarTender.Application engine = new BarTender.Application();
  14. BarTender.Format format;
  15. DataHelper dh = SystemInf.dh;
  16. DataTable Dbfind;
  17. public SystemSetting_PrinterTest()
  18. {
  19. InitializeComponent();
  20. }
  21. private void PrintTest_Click(object sender, EventArgs e)
  22. {
  23. PrintDocument print = new PrintDocument();
  24. print.PrinterSettings.PrinterName = PrinterList.Text;
  25. print.PrintPage += Print_PrintPage;
  26. print.Print();
  27. }
  28. private void Print_PrintPage(object sender, PrintPageEventArgs e)
  29. {
  30. Graphics g = e.Graphics;
  31. float leftMargin = 10f; //左边距
  32. SolidBrush myBrush = new SolidBrush(System.Drawing.Color.Black);//刷子
  33. float yPosition = 5f;//行定位
  34. Font printFont = new Font("微软雅黑", 20f, FontStyle.Bold);//设置字体
  35. yPosition += printFont.GetHeight(g);//另起一行
  36. g.DrawString("成功连接此打印机", printFont, myBrush, leftMargin, yPosition, new StringFormat());
  37. }
  38. private void Setting_Click(object sender, EventArgs e)
  39. {
  40. PrintDialog printd = new PrintDialog();
  41. printd.PrinterSettings.PrinterName = PrinterList.Text;
  42. printd.ShowDialog();
  43. }
  44. private void Export_Click(object sender, EventArgs e)
  45. {
  46. if (!dh.CheckExist("make", "ma_code='" + ma_code.Text + "'"))
  47. {
  48. MessageBox.Show("工单号不存在");
  49. return;
  50. }
  51. string macode = ma_code.Text.Split('-')[1];
  52. /*DataTable dt = (DataTable)dh.ExecuteSql("select pr_machinetype from make left join product on ma_prodcode=pr_code where ma_code='" + macode + "'", "select");
  53. if (dt.Rows.Count > 0)
  54. {
  55. string pr_machinetype = dt.Rows[0]["pr_machinetype"].ToString();
  56. if (pr_machinetype != Prefix.Text)
  57. {
  58. MessageBox.Show("前缀和产品机型" + pr_machinetype + "不匹配");
  59. return;
  60. }
  61. }*/
  62. if (OneColumn.Checked)
  63. {
  64. format = engine.Formats.Open(Application.StartupPath + "/单排.btw");
  65. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 1)
  66. {
  67. int temp = i;
  68. for (int j = 0; j < format.NamedSubStrings.Count; j++)
  69. {
  70. switch (format.NamedSubStrings.Item(j + 1).Name)
  71. {
  72. case "SN":
  73. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  74. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  75. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  76. break;
  77. case "COLOR":
  78. format.NamedSubStrings.Item(j + 1).Value = Color.Text;
  79. break;
  80. case "MACHINE":
  81. format.NamedSubStrings.Item(j + 1).Value = MachineType.Text;
  82. break;
  83. case "RAM":
  84. format.NamedSubStrings.Item(j + 1).Value = Ram.Text;
  85. break;
  86. default:
  87. break;
  88. }
  89. }
  90. format.PrintSetup.Printer = PrinterList.Text;
  91. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  92. format.PrintOut(false, false);
  93. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + macode + "'", "select");
  94. if (dt.Rows.Count > 0)
  95. {
  96. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  97. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  98. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  99. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  100. }
  101. }
  102. }
  103. if (TwoColumn.Checked)
  104. {
  105. format = engine.Formats.Open(Application.StartupPath + "/双排.btw");
  106. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 2)
  107. {
  108. int temp = i;
  109. for (int j = 0; j < format.NamedSubStrings.Count; j++)
  110. {
  111. switch (format.NamedSubStrings.Item(j + 1).Name)
  112. {
  113. case "SN":
  114. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  115. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  116. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  117. break;
  118. case "SN2":
  119. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  120. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  121. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  122. break;
  123. default:
  124. break;
  125. }
  126. }
  127. format.PrintSetup.Printer = PrinterList.Text;
  128. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  129. format.PrintOut(false, false);
  130. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + macode + "'", "select");
  131. if (dt.Rows.Count > 0)
  132. {
  133. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  134. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  135. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  136. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  137. }
  138. }
  139. }
  140. if (ThreeColumn.Checked)
  141. {
  142. format = engine.Formats.Open(Application.StartupPath + "/Label.btw");
  143. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 3)
  144. {
  145. int temp = i;
  146. for (int j = 0; j < format.NamedSubStrings.Count; j++)
  147. {
  148. switch (format.NamedSubStrings.Item(j + 1).Name)
  149. {
  150. case "SN":
  151. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  152. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  153. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  154. break;
  155. case "SN2":
  156. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  157. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  158. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  159. break;
  160. case "SN3":
  161. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
  162. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  163. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  164. break;
  165. default:
  166. break;
  167. }
  168. }
  169. format.PrintSetup.Printer = PrinterList.Text;
  170. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  171. format.PrintOut(false, false);
  172. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + macode + "'", "select");
  173. if (dt.Rows.Count > 0)
  174. {
  175. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  176. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  177. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  178. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  179. }
  180. }
  181. }
  182. if (FourColumn.Checked)
  183. {
  184. format = engine.Formats.Open(Application.StartupPath + "/四排.btw");
  185. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 4)
  186. {
  187. int temp = i;
  188. for (int j = 0; j < format.NamedSubStrings.Count; j++)
  189. {
  190. switch (format.NamedSubStrings.Item(j + 1).Name)
  191. {
  192. case "SN":
  193. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  194. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  195. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  196. break;
  197. case "SN2":
  198. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  199. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  200. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  201. break;
  202. case "SN3":
  203. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
  204. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  205. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  206. break;
  207. case "SN4":
  208. format.NamedSubStrings.Item(j + 1).Value = (macode + ";" + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 3).ToString()));
  209. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.NamedSubStrings.Item(j + 1).Value + "' and msl_makecode='" + ma_code.Text + "'"))
  210. dh.ExecuteSql("insert into makesnlist(msl_id,msl_indate,msl_makecode,msl_sncode,msl_type,msl_printstatus)values(makesnlist_seq.nextval,sysdate,'" + ma_code.Text + "','" + format.NamedSubStrings.Item(j + 1).Value + "','before',-1)", "insert");
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. format.PrintSetup.Printer = PrinterList.Text;
  217. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  218. format.PrintOut(false, false);
  219. DataTable dt = (DataTable)dh.ExecuteSql("select ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,msl_makecode from makesnlist where msl_printstatus=-1 group by msl_makecode) on msl_makecode=ma_code where ma_code='" + macode + "'", "select");
  220. if (dt.Rows.Count > 0)
  221. {
  222. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  223. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  224. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  225. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  226. }
  227. }
  228. }
  229. }
  230. private static string lpad(int length, string number)
  231. {
  232. while (number.Length < length)
  233. {
  234. number = "0" + number;
  235. }
  236. number = number.Substring(number.Length - length, length);
  237. return number;
  238. }
  239. private void SystemSetting_PrinterTest_Load(object sender, EventArgs e)
  240. {
  241. ma_code.TableName = " make left join product on ma_prodcode=pr_code";
  242. ma_code.SelectField = "ma_code # 工单编号,pr_code # 产品编号,pr_spec # 型号";
  243. ma_code.FormName = Name;
  244. ma_code.SetValueField = new string[] { "ma_code" };
  245. ma_code.Condition = "ma_statuscode='STARTED'";
  246. ma_code.DbChange += pr_code_DbChange;
  247. }
  248. private void pr_code_DbChange(object sender, EventArgs e)
  249. {
  250. Dbfind = ma_code.ReturnData;
  251. BaseUtil.SetFormValue(this.Controls, Dbfind);
  252. DataTable dt = (DataTable)dh.ExecuteSql("select ma_submodel,ma_color,ma_qty,ma_prodcode,pr_detail,ma_printnum from make left join product on ma_prodcode=pr_code left join (select count(1)ma_printnum,mil_makecode from makeimeilist where mil_printstatus=-1 group by mil_makecode) on mil_makecode=ma_code where ma_code='" + ma_code.Text + "'", "select");
  253. if (dt.Rows.Count > 0)
  254. {
  255. Color.Text = dt.Rows[0]["ma_color"].ToString();
  256. MachineType.Text = dt.Rows[0]["ma_submodel"].ToString();
  257. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  258. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  259. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  260. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  261. }
  262. }
  263. }
  264. }