Make_RePrintLabel.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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_NEW.DataOperate;
  12. using UAS_MES_NEW.Entity;
  13. using UAS_MES_NEW.PublicForm;
  14. using UAS_MES_NEW.PublicMethod;
  15. namespace UAS_MES_NEW.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.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)
  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", "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
  156. type = "卡通箱标";
  157. 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";
  158. listA = (DataTable)dh.ExecuteSql(getlabel, "select");
  159. if (listA.Rows.Count == 0)
  160. {
  161. OperateResult.AppendText("<<产品:" + pr_code.Text + "未维护" + type + "模板\n", Color.Red);
  162. }
  163. PrintLabel.DataSource = listA;
  164. PrintLabel.DisplayMember = "la_url";
  165. PrintLabel.ValueMember = "la_id";
  166. }
  167. private void print_Click(object sender, EventArgs e)
  168. {
  169. //输入值字段值不为空,打印不为空,有选中打印模板,才可以进行打印,打印前再次判断
  170. if (inputValue.Text == "")
  171. {
  172. OperateResult.AppendText("<<无箱号或者序列号\n", Color.Red);
  173. return;
  174. }
  175. if (PrintLabel.Text == "")
  176. {
  177. OperateResult.AppendText("<<无打印模板\n", Color.Red);
  178. return;
  179. }
  180. //打印类型 彩盒或者标签,再次判断是否已装箱,未转号
  181. if (giftBox.Checked || fuselagel.Checked)
  182. {
  183. 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");
  184. if (mapB.Rows.Count == 0)
  185. {
  186. //无值提示用户序列号错误,不存在或者已经发生转号
  187. OperateResult.AppendText("<<序列号错误,不存在或已经发生转号\n", Color.Red);
  188. return;
  189. }
  190. //如果ms_outboxcode 不为空,则提示用户,已经装箱不允许单独打印
  191. if (mapB.Rows[0]["ms_outboxcode"].ToString() != "")
  192. {
  193. OperateResult.AppendText("<<SN:" + inputValue.Text + "已经装箱" + mapB.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red);
  194. return;
  195. }
  196. //判定通过进行打印
  197. //doc = lbl.Documents.Open(PrintLabel.Text);
  198. 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))
  199. {
  200. //按照打印张数打印
  201. OperateResult.AppendText("<<打印成功\n", Color.Green);
  202. printBtn.Enabled = false;
  203. }
  204. else
  205. {
  206. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  207. }
  208. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  209. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, giftBox.Checked ? "彩盒标补打印" : "机身标补打印", "补打印成功", inputValue.Text, "");
  210. //如果ms_downstatus<>0,则更新ms_downstatus=-1 where ms_id=?id,同时插入记录至表 MAKEDOWN
  211. if (mapB.Rows[0]["ms_downstatus"].ToString() == "0")
  212. {
  213. dh.ExecuteSql("update makeserial set ms_downstatus='-1' where ms_id='" + ms_id + "'", "update");
  214. //插入数据
  215. putInfo2MakeDown();
  216. }
  217. }
  218. //打印类型为卡通箱标签
  219. else if (CartonBox.Checked)
  220. {
  221. //select pa_downstatus from package where pa_outboxcode=? 输入值code
  222. mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select");
  223. //无值提示用户箱号错误,不存在。
  224. if (mapB.Rows.Count == 0)
  225. {
  226. OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red);
  227. return;
  228. }
  229. //doc = lbl.Documents.Open(PrintLabel.Text);
  230. 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))
  231. {
  232. //判断通过,打印
  233. OperateResult.AppendText("<<打印成功\n", Color.Green);
  234. printBtn.Enabled = false;
  235. }
  236. else
  237. {
  238. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  239. }
  240. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  241. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, "");
  242. //如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN
  243. if (mapB.Rows[0]["pa_downstatus"].ToString() == "0")
  244. {
  245. dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update");
  246. //插入MakeDown表
  247. putInfo2MakeDown();
  248. }
  249. }
  250. }
  251. /// <summary>
  252. /// 判断彩盒和机身标序列是否已经装箱
  253. /// </summary>
  254. /// <returns></returns>
  255. private bool checkPacked()
  256. {
  257. //如果存在,则判断是否装箱
  258. 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");
  259. //判断ms_outboxcode 是否为空,如果有值,则返回提示用户“已经装箱
  260. if (dt.Rows.Count == 0)
  261. {
  262. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  263. return true;
  264. }
  265. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  266. {
  267. OperateResult.AppendText("<<SN:" + inputText.Text + "已经装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red, inputText);
  268. return true;
  269. }
  270. return false;
  271. }
  272. /// <summary>
  273. /// 插入表MAKEDOWN
  274. /// </summary>
  275. private void putInfo2MakeDown()
  276. {
  277. //插入数据至表MAKEDOWN
  278. string md_code = "";
  279. LogicHandler.GetSerialNumByCaller("MakeDown", out md_code);
  280. sql.Clear();
  281. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_LINECODE,MD_SCCODE,MD_STEPCODE,");
  282. sql.Append((CartonBox.Checked ? "MD_OUTBOXCODE" : "MD_SNCODE") + ",MD_PRODCODE,MD_MACODE, MD_DOWNREASON, MD_CODE,");
  283. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) values (MAKEDOWN_seq.nextval,'" + User.UserLineCode + "','" + User.UserSourceCode + "',");
  284. sql.Append("'" + User.CurrentStepCode + "','" + inputValue.Text + "','" + pr_code.Text + "','" + ms_makecode.Text + "','补打标签','" + md_code + "',sysdate,'" + User.UserCode + "','-1')");
  285. dh.ExecuteSql(sql.GetString(), "insert");
  286. }
  287. private void rePrintCheck_KeyDown(object sender, KeyEventArgs e)
  288. {
  289. //输入ENTER
  290. if (e.KeyCode == Keys.Enter)
  291. {
  292. if (rePrintCheck.Text == "")
  293. {
  294. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  295. return;
  296. }
  297. OperateResult.AppendText(">>" + rePrintCheck.Text + "\n", Color.Black);
  298. if (giftBox.Checked || fuselagel.Checked)
  299. {
  300. //TSN为空,说明是第一次
  301. if (TSN == "")
  302. {
  303. re_ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + rePrintCheck.Text + "'").ToString();
  304. //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN
  305. if (re_ms_id == "")
  306. {
  307. OperateResult.AppendText("<<SN:" + rePrintCheck.Text + "不存在\n", Color.Red, rePrintCheck);
  308. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  309. return;
  310. }
  311. //存在则记录下这一次输入的SN
  312. TSN = rePrintCheck.Text;
  313. //查询其他的数据
  314. infoc = (DataTable)dh.ExecuteSql("select ms_downstatus,ms_prodcode,ms_makecode from makeserial where ms_id='" + re_ms_id + "'", "select");
  315. //提示用户输入核对SN
  316. OperateResult.AppendText(">>请输入核对SN\n", Color.Green, rePrintCheck);
  317. }
  318. //说明输入的是核对的SN
  319. else
  320. {
  321. //两次输入的序列号一致
  322. if (rePrintCheck.Text == TSN)
  323. {
  324. OperateResult.AppendText("<<核对成功\n", Color.Green);
  325. //如果序列号是下地状态 ms_downstatus<>0 ,更新ms_downstatus=0;
  326. if (infoc.Rows[0]["ms_downstatus"].ToString() != "0")
  327. {
  328. ////判断下地原因是否是补打标签,是才能取消下地
  329. if (dh.CheckExist("makedown", "Md_SNCODE='" + TSN + "' AND Md_MACODE='" + infoc.Rows[0]["ms_makecode"].ToString() + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'"))
  330. {
  331. //同时更新 update makedown set ms_status=0,MS_UPREASON=’标签补打核对’,MS_UPMAN=’人员编号’,MS_UPDATE=SYSDATE WHERE MS_SNCODE=? AND MS_MACODE=? AND MS_STATUS=-1
  332. sql.Clear();
  333. 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='补打标签'");
  334. dh.ExecuteSQLTran("update makeserial set ms_downstatus='0' where ms_id='" + re_ms_id + "'", sql.GetString());
  335. }
  336. }
  337. printBtn.Enabled = true;
  338. //记录操作日志commandlog , 补打核对,核对成功
  339. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, infoc.Rows[0]["ms_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "标签补打核对", "核对成功", TSN, "");
  340. }
  341. else
  342. {
  343. OperateResult.AppendText("<<核对失败\n", Color.Red);
  344. }
  345. //清空TSN的值
  346. TSN = "";
  347. rePrintCheck.Text = "";
  348. }
  349. }
  350. //勾选的是卡通箱
  351. else if (CartonBox.Checked)
  352. {
  353. //第一次输入
  354. if (TSN == "")
  355. {
  356. infoc = (DataTable)dh.ExecuteSql("select pa_prodcode,pa_makecode,pa_downstatus from package where pa_outboxcode='" + rePrintCheck.Text + "' and pa_type=1", "select");
  357. //如果查询无值,提示用户卡通箱号不存在,请输入卡通箱号
  358. if (infoc.Rows.Count == 0)
  359. {
  360. OperateResult.AppendText("<<卡通箱号:" + rePrintCheck.Text + "不存在\n", Color.Red, rePrintCheck);
  361. OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black);
  362. return;
  363. }
  364. //存在则保存,用于和第二次的比对
  365. TSN = rePrintCheck.Text;
  366. //提示用户输入卡通箱号
  367. OperateResult.AppendText(">>请输入核对卡通箱号\n", Color.Green, rePrintCheck);
  368. }
  369. else
  370. {
  371. //比对两次输入的是否一致
  372. if (TSN == rePrintCheck.Text)
  373. {
  374. //提示用户核对成功
  375. OperateResult.AppendText("<<核对成功\n", Color.Green);
  376. //如果卡通箱号是下地状态 pa_downstatus<>0 ,更新pa_downstatus=0;
  377. if (infoc.Rows[0]["pa_downstatus"].ToString() != "0")
  378. {
  379. //判断下地原因是否是补打标签,是才能取消下地
  380. if (dh.CheckExist("makedown", "Md_OUTBOXCODE='" + TSN + "' AND Md_PRODCODE='" + infoc.Rows[0]["pa_prodcode"].ToString() + "' AND Md_STATUS=-1 AND MD_DOWNREASON='补打标签'"))
  381. {
  382. sql.Clear();
  383. 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='补打标签'");
  384. dh.ExecuteSQLTran("update package set pa_downstatus='0' where pa_outboxcode='" + TSN + "'", sql.GetString());
  385. }
  386. }
  387. printBtn.Enabled = true;
  388. //记录操作日志commandlog , 补打核对,核对成功
  389. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, infoc.Rows[0]["pa_makecode"].ToString(), User.UserLineCode, User.UserSourceCode, "标签补打核对,卡通箱号:" + TSN, "核对成功", TSN, "");
  390. }
  391. else
  392. {
  393. OperateResult.AppendText("<<核对失败\n", Color.Red);
  394. }
  395. //清空TSN的值
  396. TSN = "";
  397. rePrintCheck.Text = "";
  398. }
  399. }
  400. }
  401. }
  402. /// <summary>
  403. /// 清除信息
  404. /// </summary>
  405. private void clearAll()
  406. {
  407. //清除输入值、工单代码、产品编号,名称、打印模板、核对第一次输入的SN
  408. inputValue.Text = "";
  409. ms_makecode.Text = "";
  410. pr_code.Text = "";
  411. pr_detail.Text = "";
  412. TSN = "";
  413. if (listA != null)
  414. {
  415. listA.Clear();
  416. }
  417. }
  418. }
  419. }