Make_RePrintLabel.cs 22 KB

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