Make_RePrintLabel.cs 20 KB

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