Make_FuselageLabelPrint1.cs 19 KB

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