Make_FuselageLabelPrint.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_FuselageLabelPrint : Form
  16. {
  17. DataHelper dh;
  18. DataTable dt;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. Document doc;
  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. ftpOperater ftp;
  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. lbl = new ApplicationClass();
  60. BaseUtil.WriteLbl();
  61. }
  62. catch (Exception ex)
  63. {
  64. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  65. }
  66. }
  67. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  68. {
  69. //按下enter键
  70. if (e.KeyCode == Keys.Enter)
  71. {
  72. //如果输入的值为空的话,提示不能为空
  73. if (sncode.Text == "")
  74. {
  75. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  76. return;
  77. }
  78. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  79. {
  80. //定义临时变量
  81. string oStatus = "";
  82. //调用公共方法CheckStepSNAndMacode判断工序是否正确
  83. if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsId, out oErrorMessage))
  84. {
  85. //IF (如果ma_code 为空)THEN
  86. if (ma_code.Text == "" || ma_code.Text != oMakeCode)
  87. {
  88. //获取工单的其他信息
  89. sql.Clear();
  90. sql.Append("select ma_code,nvl(mcd_okqty,0),ma_prodcode,pr_detail,nvl(ma_unlimitin,0)ma_unlimitin,");
  91. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  92. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  93. mapB = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  94. //如果有数据的话
  95. if (mapB.Rows.Count > 0)
  96. {
  97. ma_unlimitin = mapB.Rows[0]["ma_unlimitin"].ToString();
  98. //将工单的其他信息赋值到对应的控件
  99. BaseUtil.SetFormValue(this.Controls, mapB);
  100. //提示用户“<<工单号:取ma_makecode”
  101. OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black);
  102. //提示用户“<< 序列号:XXXX”
  103. if (PrintLabel.SelectedValue == null)
  104. {
  105. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  106. return;
  107. }
  108. if (pr_change)
  109. {
  110. pr_change = false;
  111. if (MessageBox.Show("是否使用默认标签", "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  112. {
  113. OperateResult.AppendText(">>请选择标签模板\n", Color.Green, sncode);
  114. return;
  115. }
  116. }
  117. }
  118. //没有数据
  119. else
  120. {
  121. OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red);
  122. return;
  123. }
  124. }
  125. //所选标签不为空
  126. if (PrintLabel.SelectedValue != null)
  127. {
  128. //如果打印张数为空,返回
  129. if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0)
  130. {
  131. OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode);
  132. //清空输入框的值,聚焦
  133. sncode.Focus();
  134. //提示用户“>>请输入SN”
  135. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  136. return;
  137. }
  138. OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black);
  139. //按照打印张数打印
  140. //doc = lbl.Documents.Open(PrintLabel.Text);
  141. 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))
  142. {
  143. //提示用户打印成功
  144. OperateResult.AppendText(">>序列号:" + sncode.Text + "打印成功\n", Color.Green);
  145. }
  146. else
  147. {
  148. OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  149. }
  150. //记录日志
  151. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "机身标打印", "机身标打印成功", sncode.Text, "");
  152. //更新打印的数据
  153. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, sncode.Text, "机身标打印", "机身标打印成功", User.UserCode, out oErrorMessage))
  154. {
  155. //提示正确返回时传递的信息
  156. if (oErrorMessage.Contains("AFTERSUCCESS"))
  157. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  158. if (CollectRemark.Checked && Remark.Text != "")
  159. {
  160. LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  161. }
  162. //清空输入框的值,聚焦
  163. sncode.Text = "";
  164. sncode.Focus();
  165. //刷新打印数量和剩余数量
  166. 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");
  167. BaseUtil.SetFormValue(Controls, dt);
  168. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  169. //IF 剩余数=0,则清空form中的数据, 提示用户“工单:xx已经打印完成,>>请输入SN”, 清空mapB,listC 中的数据
  170. if (int.Parse(mcd_remainqty.Text) == 0 && ma_unlimitin == "0")
  171. {
  172. OperateResult.AppendText(">>工单:" + ma_code.Text + "打印完成,>>请输入SN\n", Color.Green);
  173. }
  174. //剩余数量不为0
  175. else
  176. {
  177. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  178. }
  179. }
  180. else
  181. {
  182. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  183. //清空输入框的值,聚焦
  184. sncode.Text = "";
  185. sncode.Focus();
  186. }
  187. }
  188. //标签为空
  189. else
  190. {
  191. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  192. }
  193. }
  194. else
  195. {
  196. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  197. }
  198. }
  199. else
  200. {
  201. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  202. }
  203. }
  204. }
  205. private void pr_code_TextChanged(object sender, EventArgs e)
  206. {
  207. 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");
  208. if (dt.Rows.Count == 0)
  209. {
  210. return;
  211. }
  212. PrintLabel.DataSource = dt;
  213. PrintLabel.DisplayMember = "la_url";
  214. PrintLabel.ValueMember = "la_id";
  215. pr_change = true;
  216. }
  217. private void Make_FuselageLabelPrint_Activated(object sender, EventArgs e)
  218. {
  219. sncode.Focus();
  220. }
  221. private void Make_FuselageLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
  222. {
  223. BaseUtil.ClosePrint(lbl);
  224. }
  225. private void Make_FuselageLabelPrint_SizeChanged(object sender, EventArgs e)
  226. {
  227. asc.controlAutoSize(this);
  228. }
  229. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  230. {
  231. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  232. {
  233. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  234. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  235. }
  236. }
  237. }
  238. }