Make_FuselageLabelPrintGetIMEI.cs 16 KB

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