SystemSetting_PrinterTest.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. Engine engine = new Engine();
  20. LabelFormatDocument 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. /*DataTable dt = (DataTable)dh.ExecuteSql("select pr_machinetype from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'", "select");
  58. if (dt.Rows.Count > 0)
  59. {
  60. string pr_machinetype = dt.Rows[0]["pr_machinetype"].ToString();
  61. if (pr_machinetype != Prefix.Text)
  62. {
  63. MessageBox.Show("前缀和产品机型" + pr_machinetype + "不匹配");
  64. return;
  65. }
  66. }*/
  67. if (OneColumn.Checked)
  68. {
  69. format = engine.Documents.Open(Application.StartupPath + "/单排.btw");
  70. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 1)
  71. {
  72. int temp = i;
  73. for (int j = 0; j < format.SubStrings.Count; j++)
  74. {
  75. switch (format.SubStrings[j].Name)
  76. {
  77. case "SN":
  78. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  79. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
  80. 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.SubStrings[j].Value + "','before',-1)", "insert");
  81. break;
  82. case "COLOR":
  83. format.SubStrings[j].Value = Color.Text;
  84. break;
  85. case "MACHINE":
  86. format.SubStrings[j].Value = MachineType.Text;
  87. break;
  88. case "RAM":
  89. format.SubStrings[j].Value = Ram.Text;
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. format.PrintSetup.PrinterName = PrinterList.Text;
  96. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  97. format.Print();
  98. 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='" + ma_code.Text + "'", "select");
  99. if (dt.Rows.Count > 0)
  100. {
  101. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  102. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  103. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  104. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  105. }
  106. }
  107. }
  108. if (TwoColumn.Checked)
  109. {
  110. format = engine.Documents.Open(Application.StartupPath + "/双排.btw");
  111. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 2)
  112. {
  113. int temp = i;
  114. for (int j = 0; j < format.SubStrings.Count; j++)
  115. {
  116. switch (format.SubStrings[j].Name)
  117. {
  118. case "SN":
  119. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  120. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  122. break;
  123. case "SN2":
  124. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  125. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
  126. 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.SubStrings[j].Value + "','before',-1)", "insert");
  127. break;
  128. default:
  129. break;
  130. }
  131. }
  132. format.PrintSetup.PrinterName = PrinterList.Text;
  133. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  134. format.Print();
  135. 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='" + ma_code.Text + "'", "select");
  136. if (dt.Rows.Count > 0)
  137. {
  138. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  139. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  140. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  141. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  142. }
  143. }
  144. }
  145. if (ThreeColumn.Checked)
  146. {
  147. format = engine.Documents.Open(Application.StartupPath + "/Label.btw");
  148. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 3)
  149. {
  150. int temp = i;
  151. for (int j = 0; j < format.SubStrings.Count; j++)
  152. {
  153. switch (format.SubStrings[j].Name)
  154. {
  155. case "SN":
  156. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  157. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  159. break;
  160. case "SN2":
  161. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  162. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  164. break;
  165. case "SN3":
  166. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
  167. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
  168. 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.SubStrings[j].Value + "','before',-1)", "insert");
  169. break;
  170. default:
  171. break;
  172. }
  173. }
  174. format.PrintSetup.PrinterName = PrinterList.Text;
  175. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  176. format.Print();
  177. 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='" + ma_code.Text + "'", "select");
  178. if (dt.Rows.Count > 0)
  179. {
  180. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  181. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  182. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  183. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  184. }
  185. }
  186. }
  187. if (FourColumn.Checked)
  188. {
  189. format = engine.Documents.Open(Application.StartupPath + "/四排.btw");
  190. for (int i = int.Parse(Rn.Text); i < (int.Parse(Num.Text) + int.Parse(Rn.Text)); i = i + 4)
  191. {
  192. int temp = i;
  193. for (int j = 0; j < format.SubStrings.Count; j++)
  194. {
  195. switch (format.SubStrings[j].Name)
  196. {
  197. case "SN":
  198. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp).ToString()));
  199. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  201. break;
  202. case "SN2":
  203. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 1).ToString()));
  204. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  206. break;
  207. case "SN3":
  208. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 2).ToString()));
  209. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].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.SubStrings[j].Value + "','before',-1)", "insert");
  211. break;
  212. case "SN4":
  213. format.SubStrings[j].Value = (ma_code.Text + Date.Value.ToString("yyMMdd") + lpad(int.Parse(numericUpDown1.Value.ToString()), (temp + 3).ToString()));
  214. if (!dh.CheckExist("makesnlist", "msl_sncode='" + format.SubStrings[j].Value + "' and msl_makecode='" + ma_code.Text + "'"))
  215. 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.SubStrings[j].Value + "','before',-1)", "insert");
  216. break;
  217. default:
  218. break;
  219. }
  220. }
  221. format.PrintSetup.PrinterName = PrinterList.Text;
  222. format.PrintSetup.IdenticalCopiesOfLabel = 1;
  223. format.Print();
  224. 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='" + ma_code.Text + "'", "select");
  225. if (dt.Rows.Count > 0)
  226. {
  227. pr_code.Text = dt.Rows[0]["ma_prodcode"].ToString();
  228. ma_qty.Text = dt.Rows[0]["ma_qty"].ToString();
  229. ma_printcount.Text = dt.Rows[0]["ma_printnum"].ToString();
  230. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  231. }
  232. }
  233. }
  234. }
  235. private static string lpad(int length, string number)
  236. {
  237. while (number.Length < length)
  238. {
  239. number = "0" + number;
  240. }
  241. number = number.Substring(number.Length - length, length);
  242. return number;
  243. }
  244. private void SystemSetting_PrinterTest_Load(object sender, EventArgs e)
  245. {
  246. engine.Start();
  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. }