Make_FuselageLabelPrint.cs 14 KB

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