Make_RePrintLabel.cs 23 KB

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