Make_RePrintLabel.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  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.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. else if (btn.Name == "fuselagel" && btn.Checked)
  89. {
  90. OperateResult.AppendText(">>请输入栈板号\n", Color.Black);
  91. clearAll();
  92. }
  93. }
  94. private void inputText_KeyDown(object sender, KeyEventArgs e)
  95. {
  96. //按下enter键
  97. if (e.KeyCode == Keys.Enter)
  98. {
  99. if (inputText.Text == "")
  100. {
  101. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  102. return;
  103. }
  104. OperateResult.AppendText(">>" + inputText.Text + "\n", Color.Black);
  105. //打印类型为彩盒或者机身标
  106. if (giftBox.Checked)
  107. {
  108. //select max(ms_id)ms_id from makeserial where ms_sncode=?
  109. ms_id = dh.getFieldDataByCondition("makeserial", "max(ms_id) ms_id", "ms_sncode='" + inputText.Text + "'").ToString();
  110. //如果ms_id 无值或者为空,提示用户SN不存在,请输入SN
  111. if (ms_id == "")
  112. {
  113. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  114. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  115. return;
  116. }
  117. ////判断是否装箱通过
  118. //if (checkPacked())
  119. //{
  120. // return;
  121. //}
  122. //界面赋值
  123. 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");
  124. BaseUtil.SetFormValue(this.Controls, formValue);
  125. //无值,可补打
  126. inputValue.Text = inputText.Text;
  127. inputText.Text = "";
  128. }
  129. //打印类型为卡通箱
  130. else if (CartonBox.Checked)
  131. {
  132. //查询箱号是否存在
  133. 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");
  134. if (dt.Rows.Count == 0)
  135. {
  136. //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号”
  137. OperateResult.AppendText("<<箱号:" + inputText.Text + "不存在\n", Color.Red, inputText);
  138. OperateResult.AppendText(">>请输入卡通箱号\n", Color.Black);
  139. return;
  140. }
  141. //界面赋值
  142. BaseUtil.SetFormValue(this.Controls, dt);
  143. //有值,可以打
  144. //展示产品编号和标签模板到界面
  145. inputValue.Text = inputText.Text;
  146. inputText.Text = "";
  147. }//打印类型为栈板
  148. else if (fuselagel.Checked)
  149. {
  150. //查询箱号是否存在
  151. 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");
  152. if (dt.Rows.Count == 0)
  153. {
  154. //无值,返回提示用户“箱号不存在”, “>>请输入卡通箱号”
  155. OperateResult.AppendText("<<栈板号:" + inputText.Text + "不存在\n", Color.Red, inputText);
  156. OperateResult.AppendText(">>请输入栈板号\n", Color.Black);
  157. return;
  158. }
  159. //界面赋值
  160. BaseUtil.SetFormValue(this.Controls, dt);
  161. //有值,可以打
  162. //展示产品编号和标签模板到界面
  163. inputValue.Text = inputText.Text;
  164. inputText.Text = "";
  165. }
  166. print_Click(sender, new EventArgs());
  167. }
  168. }
  169. private void PrintLabel_TextChanged(object sender, EventArgs e)
  170. {
  171. if (pr_code.Text == "")
  172. {
  173. return;
  174. }
  175. if (fuselagel.Checked)
  176. type = "栈板标";
  177. else if (giftBox.Checked)
  178. type = "彩盒标";
  179. else
  180. type = "卡通箱标";
  181. 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";
  182. listA = (DataTable)dh.ExecuteSql(getlabel, "select");
  183. if (listA.Rows.Count == 0)
  184. {
  185. OperateResult.AppendText("<<产品:" + pr_code.Text + "未维护" + type + "模板\n", Color.Red);
  186. }
  187. PrintLabel.DataSource = listA;
  188. PrintLabel.DisplayMember = "la_url";
  189. PrintLabel.ValueMember = "la_id";
  190. }
  191. private void print_Click(object sender, EventArgs e)
  192. {
  193. //输入值字段值不为空,打印不为空,有选中打印模板,才可以进行打印,打印前再次判断
  194. if (inputValue.Text == "")
  195. {
  196. OperateResult.AppendText("<<无箱号或者序列号\n", Color.Red);
  197. return;
  198. }
  199. if (PrintLabel.Text == "")
  200. {
  201. OperateResult.AppendText("<<无打印模板\n", Color.Red);
  202. return;
  203. }
  204. //打印类型 彩盒或者标签,再次判断是否已装箱,未转号
  205. if (giftBox.Checked)
  206. {
  207. 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");
  208. if (mapB.Rows.Count == 0)
  209. {
  210. //无值提示用户序列号错误,不存在或者已经发生转号
  211. OperateResult.AppendText("<<序列号错误,不存在或已经发生转号\n", Color.Red);
  212. return;
  213. }
  214. ////如果ms_outboxcode 不为空,则提示用户,已经装箱不允许单独打印
  215. //if (mapB.Rows[0]["ms_outboxcode"].ToString() != "")
  216. //{
  217. // OperateResult.AppendText("<<SN:" + inputValue.Text + "已经装箱" + mapB.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red);
  218. // return;
  219. //}
  220. //判定通过进行打印
  221. //doc = lbl.Documents.Open(PrintLabel.Text);
  222. 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))
  223. {
  224. //按照打印张数打印
  225. OperateResult.AppendText("<<打印成功\n", Color.Green);
  226. }
  227. else
  228. {
  229. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  230. }
  231. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  232. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, giftBox.Checked ? "彩盒标补打印" : "机身标补打印", "补打印成功", inputValue.Text, "");
  233. ////如果ms_downstatus<>0,则更新ms_downstatus=-1 where ms_id=?id,同时插入记录至表 MAKEDOWN
  234. //if (mapB.Rows[0]["ms_downstatus"].ToString() == "0")
  235. //{
  236. // dh.ExecuteSql("update makeserial set ms_downstatus='-1' where ms_id='" + ms_id + "'", "update");
  237. // //插入数据
  238. // putInfo2MakeDown();
  239. //}
  240. }
  241. //打印类型为卡通箱标签
  242. else if (CartonBox.Checked)
  243. {
  244. //select pa_downstatus from package where pa_outboxcode=? 输入值code
  245. mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select");
  246. //无值提示用户箱号错误,不存在。
  247. if (mapB.Rows.Count == 0)
  248. {
  249. OperateResult.AppendText("<<箱号:" + inputValue.Text + "错误,不存在\n", Color.Red);
  250. return;
  251. }
  252. //doc = lbl.Documents.Open(PrintLabel.Text);
  253. 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))
  254. {
  255. //判断通过,打印
  256. OperateResult.AppendText("<<打印成功\n", Color.Green);
  257. }
  258. else
  259. {
  260. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  261. }
  262. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  263. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "卡通箱标签补打印,箱号:" + inputValue.Text, "补打印成功", inputValue.Text, "");
  264. ////如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN
  265. //if (mapB.Rows[0]["pa_downstatus"].ToString() == "0")
  266. //{
  267. // dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update");
  268. // //插入MakeDown表
  269. // putInfo2MakeDown();
  270. //}
  271. }
  272. //打印类型为栈板标签
  273. else if (fuselagel.Checked)
  274. {
  275. //select pa_downstatus from package where pa_outboxcode=? 输入值code
  276. mapB = (DataTable)dh.ExecuteSql("select pa_downstatus from package where pa_outboxcode='" + inputValue.Text + "'", "select");
  277. //无值提示用户箱号错误,不存在。
  278. if (mapB.Rows.Count == 0)
  279. {
  280. OperateResult.AppendText("<<栈板标号:" + inputValue.Text + "错误,不存在\n", Color.Red);
  281. return;
  282. }
  283. //doc = lbl.Documents.Open(PrintLabel.Text);
  284. 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))
  285. {
  286. //判断通过,打印
  287. OperateResult.AppendText("<<打印成功\n", Color.Green);
  288. }
  289. else
  290. {
  291. OperateResult.AppendText(errorMessage + "\n", Color.Red);
  292. }
  293. //打印成功,记录日志commandlog , cl_operate彩盒或者机身标补打印,cl_result补打印成功
  294. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "栈板标标签补打印,栈板标号:" + inputValue.Text, "补打印成功", inputValue.Text, "");
  295. ////如果pa_downstatus<>0,则更新pa_downstatus=-1 where pa_outboxcode=?code,同时插入记录至表 MAKEDOWN
  296. //if (mapB.Rows[0]["pa_downstatus"].ToString() == "0")
  297. //{
  298. // dh.ExecuteSql("update package set pa_downstatus='-1' where pa_outboxcode='" + inputValue.Text + "'", "update");
  299. // //插入MakeDown表
  300. // putInfo2MakeDown();
  301. //}
  302. }
  303. }
  304. /// <summary>
  305. /// 判断彩盒和机身标序列是否已经装箱
  306. /// </summary>
  307. /// <returns></returns>
  308. private bool checkPacked()
  309. {
  310. //如果存在,则判断是否装箱
  311. 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");
  312. //判断ms_outboxcode 是否为空,如果有值,则返回提示用户“已经装箱
  313. if (dt.Rows.Count == 0)
  314. {
  315. OperateResult.AppendText("<<SN:" + inputText.Text + "不存在\n", Color.Red, inputText);
  316. return true;
  317. }
  318. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  319. {
  320. OperateResult.AppendText("<<SN:" + inputText.Text + "已经装箱" + dt.Rows[0]["ms_outboxcode"].ToString() + "不允许单独补打\n", Color.Red, inputText);
  321. return true;
  322. }
  323. return false;
  324. }
  325. /// <summary>
  326. /// 插入表MAKEDOWN
  327. /// </summary>
  328. private void putInfo2MakeDown()
  329. {
  330. //插入数据至表MAKEDOWN
  331. string md_code = "";
  332. LogicHandler.GetSerialNumByCaller("MakeDown", out md_code);
  333. sql.Clear();
  334. sql.Append("INSERT INTO MAKEDOWN (MD_ID,MD_LINECODE,MD_SCCODE,MD_STEPCODE,");
  335. sql.Append((CartonBox.Checked ? "MD_OUTBOXCODE" : "MD_SNCODE") + ",MD_PRODCODE,MD_MACODE, MD_DOWNREASON, MD_CODE,");
  336. sql.Append("MD_DOWNDATE,MD_DOWNMAN,MD_STATUS) values (MAKEDOWN_seq.nextval,'" + User.UserLineCode + "','" + User.UserSourceCode + "',");
  337. sql.Append("'" + User.CurrentStepCode + "','" + inputValue.Text + "','" + pr_code.Text + "','" + ms_makecode.Text + "','补打标签','" + md_code + "',sysdate,'" + User.UserCode + "','-1')");
  338. dh.ExecuteSql(sql.GetString(), "insert");
  339. }
  340. private void rePrintCheck_KeyDown(object sender, KeyEventArgs e)
  341. {
  342. }
  343. /// <summary>
  344. /// 清除信息
  345. /// </summary>
  346. private void clearAll()
  347. {
  348. //清除输入值、工单代码、产品编号,名称、打印模板、核对第一次输入的SN
  349. inputValue.Text = "";
  350. ms_makecode.Text = "";
  351. pr_code.Text = "";
  352. pr_detail.Text = "";
  353. TSN = "";
  354. if (listA != null)
  355. {
  356. listA.Clear();
  357. }
  358. }
  359. }
  360. }