SystemSetting_PrinterTest.cs 18 KB

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