Make_FuselageLabelPrint.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES_NEW.DataOperate;
  7. using UAS_MES_NEW.PublicMethod;
  8. using UAS_MES_NEW.Entity;
  9. using LabelManager2;
  10. using System.IO;
  11. using System.Threading;
  12. using UAS_MES_NEW.PublicForm;
  13. using Seagull.BarTender.Print;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_FuselageLabelPrint : Form
  17. {
  18. DataHelper dh;
  19. DataTable dt;
  20. LogStringBuilder sql = new LogStringBuilder();
  21. AutoSizeFormClass asc = new AutoSizeFormClass();
  22. //保存StepProduct查询出来的数据
  23. // DataTable ListA = new DataTable();
  24. //保存make left join makecraftdetail left join product的数据
  25. // DataTable ListB;
  26. DataTable mapB;
  27. string ma_unlimitin = "";
  28. ApplicationClass lbl;
  29. string oMakeCode = "";
  30. string oMsId = "";
  31. string oErrorMessage = "";
  32. Thread InitPrint;
  33. bool pr_change = false;
  34. Engine engine;
  35. public Make_FuselageLabelPrint()
  36. {
  37. InitializeComponent();
  38. }
  39. private void Make_FuselageLabelPrint_Load(object sender, EventArgs e)
  40. {
  41. asc.controllInitializeSize(this);
  42. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  43. InitPrint = new Thread(InPrint);
  44. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  45. BaseUtil.SetFormCenter(stw);
  46. stw.ShowDialog();
  47. sncode.Focus();
  48. dh = SystemInf.dh;
  49. StepCount.StepCode = User.CurrentStepCode;
  50. StepCount.Source = User.UserSourceCode;
  51. StepCount.LineCode = User.UserLineCode;
  52. StepCount.Dh = dh;
  53. StepCount.Start();
  54. }
  55. private void InPrint()
  56. {
  57. try
  58. {
  59. engine = new Engine(true);
  60. //lbl = new ApplicationClass();
  61. //BaseUtil.WriteLbl();
  62. }
  63. catch (Exception)
  64. {
  65. OperateResult.AppendText("未正确安装BarTender软件\n", Color.Red);
  66. }
  67. }
  68. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  69. {
  70. //按下enter键
  71. if (e.KeyCode == Keys.Enter)
  72. {
  73. //如果输入的值为空的话,提示不能为空
  74. if (sncode.Text == "")
  75. {
  76. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  77. return;
  78. }
  79. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  80. {
  81. //调用公共方法CheckStepSNAndMacode判断工序是否正确
  82. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out oErrorMessage))
  83. {
  84. //IF (如果ma_code 为空)THEN
  85. if (ma_code.Text == "" || ma_code.Text != oMakeCode)
  86. {
  87. //获取工单的其他信息
  88. sql.Clear();
  89. sql.Append("select ma_code,nvl(mcd_okqty,0),ma_prodcode,pr_detail,nvl(ma_unlimitin,0)ma_unlimitin,");
  90. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  91. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  92. mapB = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  93. //如果有数据的话
  94. if (mapB.Rows.Count > 0)
  95. {
  96. ma_unlimitin = mapB.Rows[0]["ma_unlimitin"].ToString();
  97. //将工单的其他信息赋值到对应的控件
  98. BaseUtil.SetFormValue(this.Controls, mapB);
  99. //提示用户“<<工单号:取ma_makecode”
  100. OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black);
  101. //提示用户“<< 序列号:XXXX”
  102. if (PrintLabel.SelectedValue == null)
  103. {
  104. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  105. return;
  106. }
  107. if (pr_change)
  108. {
  109. pr_change = false;
  110. if (MessageBox.Show("是否使用默认标签", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  111. {
  112. OperateResult.AppendText(">>请选择标签模板\n", Color.Green, sncode);
  113. return;
  114. }
  115. }
  116. }
  117. //没有数据
  118. else
  119. {
  120. OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red);
  121. return;
  122. }
  123. }
  124. //所选标签不为空
  125. if (PrintLabel.SelectedValue != null)
  126. {
  127. //如果打印张数为空,返回
  128. if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0)
  129. {
  130. OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode);
  131. //清空输入框的值,聚焦
  132. sncode.Focus();
  133. //提示用户“>>请输入SN”
  134. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  135. return;
  136. }
  137. OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black);
  138. //按照打印张数打印
  139. //doc = lbl.Documents.Open(PrintLabel.Text);
  140. if (Print.BarTender(Tag.ToString(), ref engine, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, ma_prodcode.Text, "机身标", "0", out oErrorMessage))
  141. {
  142. //提示用户打印成功
  143. OperateResult.AppendText(">>序列号:" + sncode.Text + "打印成功\n", Color.Green);
  144. }
  145. else
  146. {
  147. OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  148. }
  149. //记录日志
  150. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "机身标打印", "机身标打印成功", sncode.Text, "");
  151. //更新打印的数据
  152. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sncode.Text, "机身标打印", "机身标打印成功", User.UserCode, out oErrorMessage))
  153. {
  154. //提示正确返回时传递的信息
  155. if (oErrorMessage.Contains("AFTERSUCCESS"))
  156. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  157. if (CollectRemark.Checked && Remark.Text != "")
  158. {
  159. LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  160. }
  161. //清空输入框的值,聚焦
  162. sncode.Text = "";
  163. sncode.Focus();
  164. //刷新打印数量和剩余数量
  165. dt = (DataTable)dh.ExecuteSql("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,nvl(ma_unlimitin,0)ma_unlimitin from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  166. BaseUtil.SetFormValue(Controls, dt);
  167. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  168. //IF 剩余数=0,则清空form中的数据, 提示用户“工单:xx已经打印完成,>>请输入SN”, 清空mapB,listC 中的数据
  169. if (int.Parse(mcd_remainqty.Text) == 0 && ma_unlimitin == "0")
  170. {
  171. OperateResult.AppendText(">>工单:" + ma_code.Text + "打印完成,>>请输入SN\n", Color.Green);
  172. }
  173. //剩余数量不为0
  174. else
  175. {
  176. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  177. }
  178. }
  179. else
  180. {
  181. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  182. //清空输入框的值,聚焦
  183. sncode.Text = "";
  184. sncode.Focus();
  185. }
  186. }
  187. //标签为空
  188. else
  189. {
  190. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  191. }
  192. }
  193. else
  194. {
  195. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  196. }
  197. }
  198. else
  199. {
  200. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  201. }
  202. }
  203. }
  204. private void pr_code_TextChanged(object sender, EventArgs e)
  205. {
  206. DataTable dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + ma_prodcode.Text + "' and la_templatetype='机身标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  207. if (dt.Rows.Count == 0)
  208. {
  209. return;
  210. }
  211. PrintLabel.DataSource = dt;
  212. PrintLabel.DisplayMember = "la_url";
  213. PrintLabel.ValueMember = "la_id";
  214. pr_change = true;
  215. }
  216. private void Make_FuselageLabelPrint_Activated(object sender, EventArgs e)
  217. {
  218. sncode.Focus();
  219. }
  220. private void Make_FuselageLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
  221. {
  222. BaseUtil.ClosePrint(lbl);
  223. }
  224. private void Make_FuselageLabelPrint_SizeChanged(object sender, EventArgs e)
  225. {
  226. asc.controlAutoSize(this);
  227. }
  228. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  229. {
  230. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  231. {
  232. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  233. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  234. }
  235. }
  236. }
  237. }