Make_FuselageLabelPrintGetIMEIWatch.cs 19 KB

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