Make_RePrintLabel.cs 15 KB

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