Make_FuselageLabelPrintGetIMEI.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  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_FuselageLabelPrintGetIMEI : 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_FuselageLabelPrintGetIMEI()
  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_code='"+sncode.Text+"' or 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. string BarCode = "";
  216. if (!LogicHandler.GetBarcode(sncode.Text, out BarCode, out oErrorMessage))
  217. {
  218. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red);
  219. return;
  220. }
  221. if (!LogicHandler.GetMEIOrNetCodeRange(BarCode, ma_code.Text,"", "", out oIMEI1, out oIMEI2, out oMEID, out oNetcode, out oPSN, out oID1, out oID2, out oID3, out oErrorMessage))
  222. {
  223. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red);
  224. return;
  225. };
  226. dh.ExecuteSql("update makeserial set ms_sncode='" + oPSN + "',ms_firstsn='" + oPSN + "',ms_tsn='" + sncode.Text + "' where ms_id='" + oMsId + "' ", "update");
  227. string oBT = "";
  228. string oWifi = "";
  229. string oCode1 = "";
  230. string oCode2 = "";
  231. string oCode3 = "";
  232. LogicHandler.GetAddressRangeByMO(oPSN, out oWifi, out oBT, out oCode1, out oCode2, out oCode3, out oErrorMessage);
  233. //清空输入框的值,聚焦
  234. //doc = lbl.Documents.Open(PrintLabel.Text);
  235. 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))
  236. {
  237. //提示用户打印成功
  238. OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green);
  239. }
  240. else
  241. {
  242. OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  243. }
  244. //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))
  245. //{
  246. // //提示用户打印成功
  247. // OperateResult.AppendText(">>序列号:" + sncode.Text + "打印成功\n", Color.Green);
  248. //}
  249. //else
  250. //{
  251. // OperateResult.AppendText(oErrorMessage + "\n", Color.Red);
  252. //}
  253. //记录日志
  254. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, oMakeCode, User.UserLineCode, User.UserSourceCode, "机身标打印", "机身标打印成功", sncode.Text, "");
  255. //更新打印的数据
  256. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, oPSN, "机身标打印", "机身标打印成功", User.UserCode, out oErrorMessage))
  257. {
  258. //提示正确返回时传递的信息
  259. if (oErrorMessage.Contains("AFTERSUCCESS"))
  260. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  261. if (CollectRemark.Checked && Remark.Text != "")
  262. {
  263. LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, ma_prodcode.Text, Remark.Text);
  264. }
  265. sncode.Text = "";
  266. sncode.Focus();
  267. //刷新打印数量和剩余数量
  268. 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");
  269. BaseUtil.SetFormValue(Controls, dt);
  270. mcd_okqty.Text = int.Parse(mcd_okqty.Text) + 1 + "";
  271. //IF 剩余数=0,则清空form中的数据, 提示用户“工单:xx已经打印完成,>>请输入SN”, 清空mapB,listC 中的数据
  272. if (int.Parse(mcd_remainqty.Text) == 0 && ma_unlimitin == "0")
  273. {
  274. OperateResult.AppendText(">>工单:" + ma_code.Text + "打印完成,>>请输入SN\n", Color.Green);
  275. }
  276. //剩余数量不为0
  277. else
  278. {
  279. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  280. }
  281. }
  282. else
  283. {
  284. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  285. //清空输入框的值,聚焦
  286. sncode.Text = "";
  287. sncode.Focus();
  288. }
  289. }
  290. //标签为空
  291. else
  292. {
  293. OperateResult.AppendText(">>产品编号:" + ma_prodcode.Text + "未维护机身标签\n", Color.Red, sncode);
  294. }
  295. }
  296. else
  297. {
  298. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  299. }
  300. }
  301. else
  302. {
  303. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  304. }
  305. }
  306. }
  307. private void pr_code_TextChanged(object sender, EventArgs e)
  308. {
  309. 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");
  310. if (_dt.Rows.Count == 0)
  311. {
  312. _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");
  313. }
  314. if (_dt.Rows.Count > 0)
  315. {
  316. string la_id = _dt.Rows[0]["la_id"].ToString();
  317. _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");
  318. PrintLabel.DataSource = _dt;
  319. PrintLabel.DisplayMember = "la_url";
  320. PrintLabel.ValueMember = "la_id";
  321. pr_change = true;
  322. }
  323. }
  324. private void Make_FuselageLabelPrint_Activated(object sender, EventArgs e)
  325. {
  326. sncode.Focus();
  327. }
  328. private void Make_FuselageLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
  329. {
  330. BaseUtil.ClosePrint(lbl);
  331. }
  332. private void Make_FuselageLabelPrint_SizeChanged(object sender, EventArgs e)
  333. {
  334. asc.controlAutoSize(this);
  335. }
  336. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  337. {
  338. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  339. {
  340. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  341. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  342. }
  343. }
  344. private void StepCount_Load(object sender, EventArgs e)
  345. {
  346. }
  347. }
  348. }