Make_ColorBoxLabelPrint.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using UAS_MES.DataOperate;
  7. using UAS_MES.PublicMethod;
  8. using UAS_MES.Entity;
  9. using LabelManager2;
  10. using System.Threading;
  11. using UAS_MES.PublicForm;
  12. namespace UAS_MES.Make
  13. {
  14. public partial class Make_ColorBoxLabelPrint : Form
  15. {
  16. DataHelper dh;
  17. DataTable dt;
  18. Document doc;
  19. LogStringBuilder sql = new LogStringBuilder();
  20. AutoSizeFormClass asc = new AutoSizeFormClass();
  21. System.DateTime[] indate;
  22. //保存StepProduct查询出来的数据
  23. DataTable ListA = new DataTable();
  24. //保存make left join makecraftdetail left join product的数据
  25. // DataTable ListB;
  26. //保存ProductLabel数据
  27. DataTable ListC;
  28. //工序编号
  29. string stepcode;
  30. //下一工序编号
  31. string nextstepcode;
  32. //工艺路线编号
  33. string craftcode;
  34. //制造单号
  35. string macode;
  36. //当前提示的索引
  37. int RemainIndex = 0;
  38. //保存TSN编号
  39. string ms_id = null;
  40. string PR_CHECKCARTONW = "0";
  41. bool pr_change = false;
  42. Thread InitPrint;
  43. ApplicationClass lbl;
  44. DataTable Dbfind;
  45. public Make_ColorBoxLabelPrint()
  46. {
  47. InitializeComponent();
  48. }
  49. private void Make_ColorBoxLabelPrint_Load(object sender, EventArgs e)
  50. {
  51. sncode.Focus();
  52. asc.controllInitializeSize(this);
  53. InitPrint = new Thread(InPrint);
  54. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  55. BaseUtil.SetFormCenter(stw);
  56. stw.ShowDialog();
  57. //设置锁定工单
  58. LockMakeCode.GetMakeCodeCtl(ma_code);
  59. ma_code.SetLockCheckBox(LockMakeCode);
  60. //工单号放大镜配置
  61. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  62. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
  63. ma_code.FormName = Name;
  64. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
  65. ma_code.Condition = "ma_statuscode='STARTED'";
  66. ma_code.DbChange += Ma_code_DbChange;
  67. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  68. dh = SystemInf.dh;
  69. StepCount.StepCode = User.CurrentStepCode;
  70. StepCount.Source = User.UserSourceCode;
  71. StepCount.LineCode = User.UserLineCode;
  72. StepCount.Dh = dh;
  73. StepCount.Start();
  74. }
  75. private void Ma_code_DbChange(object sender, EventArgs e)
  76. {
  77. Dbfind = ma_code.ReturnData;
  78. BaseUtil.SetFormValue(this.Controls, Dbfind);
  79. //获取工单的其他信息
  80. sql.Clear();
  81. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  82. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  83. 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 + "'");
  84. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  85. if (dt.Rows.Count > 0)
  86. {
  87. BaseUtil.SetFormValue(this.Controls, dt);
  88. }
  89. }
  90. private void InPrint()
  91. {
  92. try
  93. {
  94. lbl = new ApplicationClass();
  95. BaseUtil.WriteLbl();
  96. }
  97. catch (Exception ex)
  98. {
  99. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  100. }
  101. }
  102. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  103. {
  104. if (e.KeyCode == Keys.Enter)
  105. {
  106. if (CheckTSN.Checked == true && ms_id == null)
  107. {
  108. if (sncode.Text == "")
  109. {
  110. OperateResult.AppendText(">>TSN不能为空\n", Color.Red);
  111. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  112. return;
  113. }
  114. OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
  115. sql.Clear();
  116. sql.Append("select max(ms_id) ms_id from makeserial where ms_code = '" + sncode.Text + "'");
  117. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  118. if (dt.Rows[0][0].ToString() != "")
  119. {
  120. ms_id = dt.Rows[0][0].ToString();
  121. sncode.Focus();
  122. OperateResult.AppendText(">>请输入SN\n", Color.Black, sncode);
  123. return;
  124. }
  125. else
  126. {
  127. OperateResult.AppendText(">>TSN" + sncode.Text + "错误,不存在\n", Color.Red, sncode);
  128. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  129. return;
  130. }
  131. }
  132. if (sncode.Text == "")
  133. {
  134. OperateResult.AppendText(">>序列号不能为空\n", Color.Red);
  135. return;
  136. }
  137. OperateResult.AppendText(">>" + sncode.Text + "\n", Color.Black);
  138. if (CheckTSN.Checked == true && ms_id != null)
  139. {
  140. sql.Clear();
  141. sql.Append("select ms_id from makeserial where ms_id='" + ms_id + "' and ms_sncode = '"+sncode.Text+"'");
  142. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  143. if (dt.Rows.Count > 0)
  144. {
  145. OperateResult.AppendText(">>TSN和SN一致\n", Color.Green);
  146. }
  147. else
  148. {
  149. OperateResult.AppendText(">>TSN和SN不一致\n", Color.Red, sncode);
  150. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  151. ms_id = null;
  152. return;
  153. }
  154. }
  155. string oMsID;
  156. string ErrorMessage;
  157. string oMakeCode;
  158. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  159. {
  160. //判断界面工单是否为空时的序列号是否自动归属工单
  161. string oStatus = "";
  162. //是否提示过工单切换框,检测前执行
  163. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  164. if (!NoteAlready)
  165. {
  166. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode);
  167. return;
  168. }
  169. if (ma_code.Text != oMakeCode && oMakeCode != null)
  170. {
  171. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_detail,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  172. if (dt.Rows.Count > 0)
  173. {
  174. BaseUtil.SetFormValue(this.Controls, dt);
  175. LockMakeCode.Checked = true;
  176. }
  177. }
  178. // 获取工单归属工单下一工序是否正确
  179. if (LogicHandler.CheckStepSNAndMacode(ma_code.Text, User.UserSourceCode, sncode.Text, User.UserCode, out oMakeCode, out oMsID, out ErrorMessage))
  180. {
  181. //获取工单的其他信息
  182. sql.Clear();
  183. sql.Append("select ma_code,nvl(ma_unlimitin,0)ma_unlimitin,pr_code,pr_detail,pr_spec from ");
  184. sql.Append("make left join product on pr_code=ma_prodcode where ma_code='" + oMakeCode + "'");
  185. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  186. if (dt.Rows.Count > 0)
  187. {
  188. PR_CHECKCARTONW = dh.getFieldDataByCondition("craftdetail left join craft on cr_id=cd_crid left join makeserial on ms_craftcode =cr_code and cr_prodcode = ms_prodcode", "nvl(cd_ifweigh,'0') cd_ifweigh", "ms_sncode='" + sncode.Text + "' and ms_makecode='" + oMakeCode + "' and cd_stepcode = '" + User.CurrentStepCode + "'").ToString();
  189. if (PR_CHECKCARTONW != "0")
  190. {
  191. OperateResult.AppendText(">>彩盒" + sncode.Text + "当前处于称重工序,无法在此界面采集,需去彩盒称重界面进行采集\n", Color.Black, sncode);
  192. return;
  193. }
  194. BaseUtil.SetFormValue(this.Controls, dt);
  195. LockMakeCode.Checked = true;
  196. //提示用户“<<工单号:取ma_makecode”
  197. OperateResult.AppendText("<<工单号:" + ma_code.Text + "\n", Color.Black);
  198. //提示用户“<< 序列号:XXXX”
  199. OperateResult.AppendText("<<序列号:" + sncode.Text + "\n", Color.Black);
  200. if (pr_change)
  201. {
  202. String dialog = MessageBox.Show("是否使用当前标签模板", "提示", MessageBoxButtons.OKCancel).ToString();
  203. if (dialog != "OK")
  204. {
  205. OperateResult.AppendText(">>请重新选择标签模板\n", Color.Green);
  206. return;
  207. }
  208. else pr_change = false;
  209. }
  210. }
  211. else
  212. {
  213. OperateResult.AppendText(">>无序列号" + sncode.Text + "对应工单信息\n", Color.Red, sncode);
  214. sncode.Focus();
  215. return;
  216. }
  217. string result = "";
  218. if (int.Parse(mcd_remainqty.Text) <= 0 && dt.Rows[0]["ma_unlimitin"].ToString() == "0")
  219. {
  220. macode = ma_code.Text;
  221. ErrorMessage = "工单" + macode + "打印结束\n>请输入SN";
  222. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Green);
  223. sncode.Focus();
  224. }
  225. else
  226. {
  227. //所选标签不为空
  228. if (PrintLabel.SelectedValue != null)
  229. {
  230. //如果打印张数为空,返回
  231. if (PrintNum.Text == "" || int.Parse(PrintNum.Text) == 0)
  232. {
  233. OperateResult.AppendText(">>打印张数不可空或者为0\n", Color.Red, sncode);
  234. //清空输入框的值,聚焦
  235. sncode.Focus();
  236. //提示用户“>>请输入SN”
  237. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  238. return;
  239. }
  240. //更新至下一步工序
  241. if (LogicHandler.SetStepResult(oMakeCode, User.UserSourceCode, sncode.Text, "彩盒打印", "彩盒打印成功", User.UserCode, out ErrorMessage))
  242. {
  243. //提示正确返回时传递的信息
  244. if (ErrorMessage.Contains("AFTERSUCCESS"))
  245. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  246. // doc = lbl.Documents.Open(PrintLabel.Text);
  247. if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, sncode.Text, int.Parse(PrintNum.Text), oMakeCode, pr_code.Text, "彩盒标", "0", out ErrorMessage))
  248. {
  249. //提示用户打印成功
  250. OperateResult.AppendText(">>序列号:" + sncode.Text + "打印结束\n", Color.Green);
  251. }
  252. else
  253. {
  254. OperateResult.AppendText(ErrorMessage + "\n", Color.Red);
  255. }
  256. if (CollectRemark.Checked && Remark.Text != "")
  257. {
  258. LogicHandler.CollectRemarkInf(sncode.Text, "", "", oMakeCode, pr_code.Text, Remark.Text);
  259. }
  260. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "彩盒打印", "彩盒打印成功", sncode.Text, "");
  261. //刷新打印数量和剩余数量
  262. dt = (DataTable)dh.ExecuteSql("select ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,mcd_okqty 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. sncode.Text = "";
  265. ms_id = null;
  266. sncode.Focus();
  267. }
  268. else
  269. {
  270. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, sncode);
  271. ms_id = null;
  272. sncode.Focus();
  273. }
  274. }
  275. else
  276. {
  277. OperateResult.AppendText(">>产品编号:" + pr_code.Text + "未维护彩盒标签\n", Color.Red, sncode);
  278. return;
  279. }
  280. if (CheckTSN.Checked == true)
  281. {
  282. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  283. ms_id = null;
  284. }
  285. else
  286. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  287. }
  288. }
  289. else
  290. {
  291. OperateResult.AppendText(ErrorMessage + "\n", Color.Red, sncode);
  292. if (CheckTSN.Checked == true)
  293. {
  294. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  295. ms_id = null;
  296. }
  297. else
  298. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  299. }
  300. }
  301. else
  302. {
  303. OperateResult.AppendText(ErrorMessage + "\n", Color.Red, sncode);
  304. if (CheckTSN.Checked == true)
  305. {
  306. OperateResult.AppendText(">>请输入TSN\n", Color.Black);
  307. ms_id = null;
  308. }
  309. else
  310. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  311. }
  312. }
  313. }
  314. //根据产品编号获取打印模板
  315. private void pr_code_TextChanged(object sender, EventArgs e)
  316. {
  317. DataTable _dt = (DataTable)dh.ExecuteSql("select la_id,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='彩盒标' and la_statuscode='AUDITED' order by la_isdefault", "select");
  318. PrintLabel.DataSource = _dt;
  319. PrintLabel.DisplayMember = "la_url";
  320. PrintLabel.ValueMember = "la_id";
  321. pr_change = true;
  322. }
  323. private void Make_ColorBoxLabelPrint_Activated(object sender, EventArgs e)
  324. {
  325. sncode.Focus();
  326. }
  327. private void Make_ColorBoxLabelPrint_FormClosing(object sender, FormClosingEventArgs e)
  328. {
  329. BaseUtil.ClosePrint(lbl);
  330. }
  331. private void Make_ColorBoxLabelPrint_SizeChanged(object sender, EventArgs e)
  332. {
  333. asc.controlAutoSize(this);
  334. }
  335. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  336. {
  337. if (ma_code.Text.Length > 4)
  338. {
  339. //获取工单的其他信息
  340. sql.Clear();
  341. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  342. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty from make left join makecraftdetail on ");
  343. 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 + "'");
  344. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  345. if (dt.Rows.Count > 0)
  346. {
  347. BaseUtil.SetFormValue(this.Controls, dt);
  348. }
  349. else
  350. {
  351. sncode.Text = "";
  352. }
  353. }
  354. }
  355. private void CheckTSN_CheckedChanged(object sender, EventArgs e)
  356. {
  357. if (CheckTSN.Checked == true)
  358. {
  359. ms_id = null;
  360. OperateResult.AppendText(">>切换至检查TSN\n", Color.Green);
  361. OperateResult.AppendText(">>请输入TSN\n", Color.Black, sncode);
  362. sncode.Focus();
  363. }
  364. else
  365. {
  366. ms_id = null;
  367. OperateResult.AppendText(">>切换至不检查TSN\n", Color.Green);
  368. OperateResult.AppendText(">>请输入SN\n", Color.Black, sncode);
  369. sncode.Focus();
  370. }
  371. }
  372. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  373. {
  374. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  375. {
  376. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  377. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  378. }
  379. }
  380. }
  381. }