Make_RePrintLabel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. using LabelManager2;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading;
  10. using System.Windows.Forms;
  11. using UAS_MES.DataOperate;
  12. using UAS_MES.Entity;
  13. using UAS_MES.PublicForm;
  14. using UAS_MES.PublicMethod;
  15. namespace UAS_MES.Make
  16. {
  17. public partial class Make_RePrintLabel : Form
  18. {
  19. DataHelper dh;
  20. LogStringBuilder sql = new LogStringBuilder();
  21. AutoSizeFormClass asc = new AutoSizeFormClass();
  22. ApplicationClass lbl;
  23. Document doc;
  24. Thread InitPrint;//实例化打印进程
  25. DataTable dt;
  26. ftpOperater ftp;
  27. DataTable listA;
  28. string getlabel = "";
  29. DataTable mapB;
  30. String TSN = "";//记录第一次输入的SN
  31. DataTable infoc;
  32. string re_ms_id = "";
  33. string ms_id = "";
  34. DataTable formValue;//界面赋值
  35. string type = "";
  36. string errorMessage = "";
  37. public Make_RePrintLabel()
  38. {
  39. InitializeComponent();
  40. }
  41. private void Make_RePrintLabel_Load(object sender, EventArgs e)
  42. {
  43. asc.controllInitializeSize(this);
  44. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  45. InitPrint = new Thread(InPrint);
  46. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  47. BaseUtil.SetFormCenter(stw);
  48. stw.ShowDialog();
  49. inputText.Focus();
  50. dh = SystemInf.dh;
  51. }
  52. private void InPrint()
  53. {
  54. try
  55. {
  56. lbl = new ApplicationClass();
  57. BaseUtil.WriteLbl();
  58. }
  59. catch (Exception ex)
  60. {
  61. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  62. }
  63. }
  64. private void Make_RePrintLabel_SizeChanged(object sender, EventArgs e)
  65. {
  66. //窗体大小变化的时候
  67. asc.controlAutoSize(this);
  68. }
  69. private void Make_RePrintLabel_FormClosing(object sender, FormClosingEventArgs e)
  70. {
  71. //窗口关闭的时候
  72. BaseUtil.ClosePrint(lbl);
  73. }
  74. private void radioButton_CheckedChange(object sender, EventArgs e)
  75. {
  76. RadioButton btn = sender as RadioButton;
  77. if ((btn.Name == "giftBox" || btn.Name == "fuselagel") && btn.Checked)
  78. {
  79. //如果是切换成彩盒或者机身标提示用户 输入SN
  80. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  81. clearAll();
  82. }
  83. else if ((btn.Name == "CartonBox" || btn.Name == "BigBox" || btn.Name == "Pallte") && btn.Checked)
  84. {
  85. OperateResult.AppendText(">>请输入箱号\n", Color.Black);
  86. clearAll();
  87. }
  88. }
  89. private void inputText_KeyDown(object sender, KeyEventArgs e)
  90. {
  91. //按下enter键
  92. if (e.KeyCode == Keys.Enter)
  93. {
  94. if (inputText.Text == "")
  95. {
  96. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  97. return;
  98. }
  99. OperateResult.AppendText(">>" + inputText.Text + "\n", Color.Black);
  100. //打印类型为彩盒或者机身标
  101. if (giftBox.Checked || fuselagel.Checked)
  102. {
  103. //select max(ms_id)ms_id from makeserial where ms_sncode=?
  104. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + inputText.Text + "'").ToString();
  105. //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN
  106. if (ms_id == "")
  107. {
  108. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  109. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  110. return;
  111. }
  112. //判断是否装箱通过
  113. if (checkPacked())
  114. {
  115. return;
  116. }
  117. //界面赋值
  118. formValue = (DataTable)dh.ExecuteSql("select ms_makecode,pr_code,pr_detail from makeserial left join product on MS_PRODCODE=pr_code where ms_id='" + ms_id + "'", "select");
  119. BaseUtil.SetFormValue(this.Controls, formValue);
  120. //无值,可补打
  121. inputValue.Text = inputText.Text;
  122. inputText.Text = "";
  123. }
  124. //打印类型为卡通箱
  125. else if (CartonBox.Checked || BigBox.Checked || Pallte.Checked)
  126. {
  127. //查询箱号是否存在
  128. dt = (DataTable)dh.ExecuteSql("select pa_id,pa_prodcode pr_code,pa_makecode ms_makecode,pr_detail from package left join product on pr_code=pa_prodcode where pa_outboxcode='" + inputText.Text + "' and (pa_type=1 OR PA_TYPE = 2 or PA_TYPE=3)", "select");
  129. if (dt.Rows.Count == 0)
  130. {
  131. //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号”
  132. OperateResult.AppendText("<<箱号:" + inputText.Text + "不存在\n", Color.Red, inputText);
  133. OperateResult.AppendText(">>请输入箱号\n", Color.Black);
  134. return;
  135. }
  136. //界面赋值
  137. BaseUtil.SetFormValue(this.Controls, dt);
  138. //有值,可以打
  139. //展示产品编号和标签模板到界面
  140. inputValue.Text = inputText.Text;
  141. inputText.Text = "";
  142. }
  143. }
  144. }
  145. private void PrintLabel_TextChanged(object sender, EventArgs e)
  146. {
  147. if (pr_code.Text == "")
  148. {
  149. return;
  150. }
  151. if (fuselagel.Checked)
  152. type = "机身标";
  153. else if (giftBox.Checked)
  154. type = "彩盒标";
  155. else if (CartonBox.Checked)
  156. type = "卡通箱标";
  157. else if (BigBox.Checked)
  158. type = "大箱标";
  159. else
  160. type = "栈板标";
  161. getlabel = "select la_id,substr(la_url,instr(la_url,'\\',-1)+1)la_name,la_url,la_isdefault from label where la_prodcode='" + pr_code.Text + "' and la_templatetype='" + type + "' and la_statuscode='AUDITED' order by la_isdefault";
  162. listA = (DataTable)dh.ExecuteSql(getlabel, "select");
  163. if (listA.Rows.Count == 0)
  164. {
  165. OperateResult.AppendText("<<产品:" + pr_code.Text + "未维护" + type + "模板\n", Color.Red);
  166. }
  167. PrintLabel.DataSource = listA;
  168. PrintLabel.DisplayMember = "la_url";
  169. PrintLabel.ValueMember = "la_id";
  170. }
  171. private void print_Click(object sender, EventArgs e)
  172. {
  173. //输入值字段值不为空,打印不为空,有选中打印模板,才可以进行打印,打印前再次判断
  174. if (inputValue.Text == "")
  175. {
  176. OperateResult.AppendText("<<无箱号或者序列号\n", Color.Red);
  177. return;
  178. }
  179. if (PrintLabel.Text == "")
  180. {
  181. OperateResult.AppendText("<<无打印模板\n", Color.Red);
  182. return;
  183. }
  184. //打印类型 彩盒或者标签,再次判断是否已装箱,未转号
  185. if (giftBox.Checked || fuselagel.Checked)
  186. {
  187. mapB = (DataTable)dh.ExecuteSql("select ms_outboxcode, nvl(ms_downstatus,0) ms_downstatus from makeserial where ms_id='" + ms_id + "' and ms_sncode='" + inputValue.Text + "'", "select");
  188. if (mapB.Rows.Count == 0)
  189. {
  190. //无值提示用户序列号错误,不存在或者已经发生转号
  191. OperateResult.AppendText("<<序列号错误,不存在或已经发生转号\n", Color.Red);
  192. return;
  193. }
  194. //如果ms_outboxcode 不为空,则提示用户,已经装箱不允许单独打印
  195. if (mapB.Rows[0]["ms_outboxcode"].ToString() != "")
  196. {
  197. OperateResult.AppendText("<<SN:" + inputValue.Text + "已经装箱" + mapB.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red);
  198. return;
  199. }
  200. //判定通过进行打印
  201. //doc = lbl.Documents.Open(PrintLabel.Text);
  202. if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, giftBox.Checked ? "彩盒标" : "机身标", "-1", out errorMessage))
  203. {
  204. //按照打印张数打印
  205. OperateResult.AppendText("<<打印成功\n", Color.Green);
  206. printBtn.Enabled = false;
  207. }
  208. else
  209. {
  210. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  211. }
  212. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  213. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, giftBox.Checked ? "彩盒标补打印" : "机身标补打印", "补打印成功", inputValue.Text, "");
  214. //如果ms_downstatus<>0,则更新ms_downstatus=-1 where ms_id=?id,同时插入记录至表 MAKEDOWN
  215. if (mapB.Rows[0]["ms_downstatus"].ToString() == "0")
  216. {
  217. dh.ExecuteSql("update makeserial set ms_downstatus='-1' where ms_id='" + ms_id + "'", "update");
  218. //插入数据
  219. putInfo2MakeDown();
  220. }
  221. }
  222. //打印类型为卡通箱标签
  223. else if (CartonBox.Checked || BigBox.Checked || Pallte.Checked)
  224. {
  225. //select pa_downstatus from package where pa_outboxcode=? 输入值code
  226. mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select");
  227. //无值提示用户箱号错误,不存在。
  228. if (mapB.Rows.Count == 0)
  229. {
  230. OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red);
  231. return;
  232. }
  233. //doc = lbl.Documents.Open(PrintLabel.Text);
  234. if (Print.CodeSoft(Tag.ToString(), ref lbl, PrintLabel.Text, PrintLabel.SelectedValue.ToString(), Printer.Text, inputValue.Text, int.Parse(printNum.Text), ms_makecode.Text, pr_code.Text, "卡通箱标", "-1", out errorMessage))
  235. {
  236. //判断通过,打印
  237. OperateResult.AppendText("<<打印成功\n", Color.Green);
  238. printBtn.Enabled = false;
  239. }
  240. else
  241. {
  242. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  243. }
  244. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  245. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, "");
  246. //如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN
  247. if (mapB.Rows[0]["pa_downstatus"].ToString() == "0")
  248. {
  249. dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update");
  250. //插入MakeDown表
  251. putInfo2MakeDown();
  252. }
  253. }
  254. }
  255. /// <summary>
  256. /// 判断彩盒和机身标序列是否已经装箱
  257. /// </summary>
  258. /// <returns></returns>
  259. private bool checkPacked()
  260. {
  261. //如果存在,则判断是否装箱
  262. dt = (DataTable)dh.ExecuteSql("select ms_id,ms_prodcode,ms_makecode,pr_detail, ms_outboxcode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'", "select");
  263. //判断ms_outboxcode 是否为空,如果有值,则返回提示用户“已经装箱
  264. if (dt.Rows.Count == 0)
  265. {
  266. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  267. return true;
  268. }
  269. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  270. {
  271. OperateResult.AppendText("<<SN:" + inputText.Text + "已经装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red, inputText);
  272. return true;
  273. }
  274. return false;
  275. }
  276. /// <summary>
  277. /// 插入表MAKEDOWN
  278. /// </summary>
  279. private void putInfo2MakeDown()
  280. {
  281. //插入数据至表MAKEDOWN
  282. string md_code = "";
  283. LogicHandler.GetSerialNumByCaller("MakeDown", out md_code);
  284. sql.Clear();
  285. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_LINECODE,MD_SCCODE,MD_STEPCODE,");
  286. sql.Append(((CartonBox.Checked || BigBox.Checked || Pallte.Checked) ? "MD_OUTBOXCODE" : "MD_SNCODE") + ",MD_PRODCODE,MD_MACODE, MD_DOWNREASON, MD_CODE,");
  287. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) values (MAKEDOWN_seq.nextval,'" + User.UserLineCode + "','" + User.UserSourceCode + "',");
  288. sql.Append("'" + User.CurrentStepCode + "','" + inputValue.Text + "','" + pr_code.Text + "','" + ms_makecode.Text + "','补打标签','" + md_code + "',sysdate,'" + User.UserCode + "','-1')");
  289. dh.ExecuteSql(sql.GetString(), "insert");
  290. }
  291. private void rePrintCheck_KeyDown(object sender, KeyEventArgs e)
  292. {
  293. //输入ENTER
  294. if (e.KeyCode == Keys.Enter)
  295. {
  296. if (rePrintCheck.Text == "")
  297. {
  298. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  299. return;
  300. }
  301. OperateResult.AppendText(">>" + rePrintCheck.Text + "\n", Color.Black);
  302. if (giftBox.Checked || fuselagel.Checked)
  303. {
  304. //TSN为空,说明是第一次
  305. if (TSN == "")
  306. {
  307. re_ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + rePrintCheck.Text + "'").ToString();
  308. //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN
  309. if (re_ms_id == "")
  310. {
  311. OperateResult.AppendText("<<SN:" + rePrintCheck.Text + "不存在\n", Color.Red, rePrintCheck);
  312. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  313. return;
  314. }
  315. //存在则记录下这一次输入的SN
  316. TSN = rePrintCheck.Text;
  317. //查询其他的数据
  318. infoc = (DataTable)dh.ExecuteSql("select ms_downstatus,ms_prodcode,ms_makecode from makeserial where ms_id='" + re_ms_id + "'", "select");
  319. //提示用户输入核对SN
  320. OperateResult.AppendText(">>请输入核对SN\n", Color.Green, rePrintCheck);
  321. }
  322. //说明输入的是核对的SN
  323. else
  324. {
  325. //两次输入的序列号一致
  326. if (rePrintCheck.Text == TSN)
  327. {
  328. OperateResult.AppendText("<<核对成功\n", Color.Green);
  329. //如果序列号是下地状态 ms_downstatus<>0 ,更新ms_downstatus=0;
  330. if (infoc.Rows[0]["ms_downstatus"].ToString() != "0")
  331. {
  332. ////判断下地原因是否是补打标签,是才能取消下地
  333. if (dh.CheckExist("makedown", "Md_SNCODE='" + TSN + "' AND Md_MACODE='" + infoc.Rows[0]["ms_makecode"].ToString() + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'"))
  334. {
  335. //同时更新 update makedown set ms_status=0,MS_UPREASON=’标签补打核对’,MS_UPMAN=’人员编号’,MS_UPDATE=SYSDATE WHERE MS_SNCODE=? AND MS_MACODE=? AND MS_STATUS=-1
  336. sql.Clear();
  337. sql.Append("update makedown set md_status=0,Md_UPREASON='标签补打核对',Md_UPMAN='" + User.UserCode + "',Md_UPDATE=SYSDATE WHERE Md_SNCODE='" + TSN + "' AND Md_MACODE='" + infoc.Rows[0]["ms_makecode"].ToString() + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'");
  338. dh.ExecuteSQLTran("update makeserial set ms_downstatus='0' where ms_id='" + re_ms_id + "'", sql.GetString());
  339. }
  340. }
  341. printBtn.Enabled = true;
  342. //记录操作日志commandlog , 补打核对,核对成功
  343. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, infoc.Rows[0]["ms_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "标签补打核对", "核对成功", TSN, "");
  344. }
  345. else
  346. {
  347. OperateResult.AppendText("<<核对失败\n", Color.Red);
  348. }
  349. //清空TSN的值
  350. TSN = "";
  351. rePrintCheck.Text = "";
  352. }
  353. }
  354. //勾选的是卡通箱
  355. else if (CartonBox.Checked || BigBox.Checked || Pallte.Checked)
  356. {
  357. //第一次输入
  358. if (TSN == "")
  359. {
  360. infoc = (DataTable)dh.ExecuteSql("select pa_prodcode,pa_makecode,pa_downstatus from package where pa_outboxcode='" + rePrintCheck.Text + "' and (pa_type=1 or pa_type =2 or pa_type=3)", "select");
  361. //如果查询无值,提示用户卡通箱号不存在,请输入卡通箱号
  362. if (infoc.Rows.Count == 0)
  363. {
  364. OperateResult.AppendText("<<箱号:" + rePrintCheck.Text + "不存在\n", Color.Red, rePrintCheck);
  365. OperateResult.AppendText(">>请输入箱号\n", Color.Black);
  366. return;
  367. }
  368. //存在则保存,用于和第二次的比对
  369. TSN = rePrintCheck.Text;
  370. //提示用户输入卡通箱号
  371. OperateResult.AppendText(">>请输入核对箱号\n", Color.Green, rePrintCheck);
  372. }
  373. else
  374. {
  375. //比对两次输入的是否一致
  376. if (TSN == rePrintCheck.Text)
  377. {
  378. //提示用户核对成功
  379. OperateResult.AppendText("<<核对成功\n", Color.Green);
  380. //如果卡通箱号是下地状态 pa_downstatus<>0 ,更新pa_downstatus=0;
  381. if (infoc.Rows[0]["pa_downstatus"].ToString() != "0")
  382. {
  383. //判断下地原因是否是补打标签,是才能取消下地
  384. if (dh.CheckExist("makedown", "Md_OUTBOXCODE='" + TSN + "' AND nvl(Md_PRODCODE,' ')='" + (infoc.Rows[0]["pa_prodcode"].ToString() == "" ? " " : infoc.Rows[0]["pa_prodcode"].ToString()) + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'"))
  385. {
  386. sql.Clear();
  387. sql.Append("update makedown set md_status=0,Md_UPREASON='标签补打核对',Md_UPMAN='" + User.UserCode + "',Md_UPDATE=SYSDATE WHERE Md_OUTBOXCODE='" + TSN + "' AND Md_PRODCODE='" + infoc.Rows[0]["pa_prodcode"].ToString() + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'");
  388. dh.ExecuteSQLTran("update package set pa_downstatus='0' where pa_outboxcode='" + TSN + "'", sql.GetString());
  389. }
  390. }
  391. printBtn.Enabled = true;
  392. //记录操作日志commandlog , 补打核对,核对成功
  393. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, infoc.Rows[0]["pa_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "标签补打核对,箱号:" + TSN, "核对成功", TSN, "");
  394. }
  395. else
  396. {
  397. OperateResult.AppendText("<<核对失败\n", Color.Red);
  398. }
  399. //清空TSN的值
  400. TSN = "";
  401. rePrintCheck.Text = "";
  402. }
  403. }
  404. }
  405. }
  406. /// <summary>
  407. /// 清除信息
  408. /// </summary>
  409. private void clearAll()
  410. {
  411. //清除输入值、工单代码、产品编号,名称、打印模板、核对第一次输入的SN
  412. inputValue.Text = "";
  413. ms_makecode.Text = "";
  414. pr_code.Text = "";
  415. pr_detail.Text = "";
  416. TSN = "";
  417. if (listA != null)
  418. {
  419. listA.Clear();
  420. }
  421. }
  422. }
  423. }