Make_GetReMakeSN.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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.DataOperate;
  12. using UAS_MES.Entity;
  13. using UAS_MES.PublicForm;
  14. using UAS_MES.PublicMethod;
  15. namespace UAS_MES.Make
  16. {
  17. public partial class Make_GetReMakeSN : Form
  18. {
  19. //打印进程
  20. ApplicationClass lbl;
  21. //初始化打印进程
  22. Thread InitPrint;
  23. LogStringBuilder sql = new LogStringBuilder();
  24. AutoSizeFormClass asc = new AutoSizeFormClass();
  25. DataHelper dh;
  26. DataTable dt;
  27. Document doc;
  28. private System.DateTime[] indate;
  29. string ErrMessage;
  30. public Make_GetReMakeSN()
  31. {
  32. InitializeComponent();
  33. }
  34. private void InPrint()
  35. {
  36. try
  37. {
  38. lbl = new ApplicationClass();
  39. BaseUtil.WriteLbl(lbl);
  40. }
  41. catch (Exception ex)
  42. {
  43. OperateResult.AppendText("未正确安装CodeSoft软件\n", Color.Red);
  44. }
  45. }
  46. private void Make_GetReMakeSN_Load(object sender, EventArgs e)
  47. {
  48. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  49. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,ma_qty # 工单数量,pr_detail # 产品名称,pr_spec # 产品规格,ma_craftcode # 途程编号";
  50. ma_code.FormName = Name;
  51. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "ma_qty", "pr_detail", "pr_spec", "ma_craftcode" };
  52. ma_code.Condition = "ma_kind='返工' and ma_statuscode='STARTED'";
  53. ma_code.DbChange += Ma_code_DbChange;
  54. ma_code.SetLockCheckBox(LockCheckBox);
  55. LockCheckBox.GetMakeCodeCtl(ma_code);
  56. dh = new DataHelper();
  57. OperateResult.AppendText(">>请输入返工工单号\n", Color.Black);
  58. asc.controllInitializeSize(this);
  59. InitPrint = new Thread(InPrint);
  60. SetLoadingWindow stw = new SetLoadingWindow(InitPrint, "初始化打印程序");
  61. BaseUtil.SetFormCenter(stw);
  62. stw.ShowDialog();
  63. sn_code.Focus();
  64. }
  65. private void Ma_code_DbChange(object sender, EventArgs e)
  66. {
  67. DataTable dt = ma_code.ReturnData;
  68. BaseUtil.SetFormValue(this.Controls, dt);
  69. }
  70. private void Make_GetReMakeSN_SizeChanged(object sender, EventArgs e)
  71. {
  72. asc.controlAutoSize(this);
  73. }
  74. private void pr_code_TextChanged(object sender, EventArgs e)
  75. {
  76. DataTable _dt = (DataTable)dh.ExecuteSql("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='SN标签' and la_statuscode='AUDITED' order by la_isdefault", "select");
  77. PrintLabel.DataSource = _dt;
  78. PrintLabel.DisplayMember = "la_name";
  79. PrintLabel.ValueMember = "la_id";
  80. ftpOperater ftp = new ftpOperater();
  81. indate = new System.DateTime[_dt.Rows.Count];
  82. for (int i = 0; i < _dt.Rows.Count; i++)
  83. {
  84. BaseUtil.GetPrintLabel(_dt.Rows[i]["la_name"].ToString(), _dt.Rows[i]["la_url"].ToString());
  85. }
  86. }
  87. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  88. {
  89. if (e.KeyCode == Keys.Enter)
  90. {
  91. if (ma_code.Text != "")
  92. {
  93. //判断是否是途程第一道工序
  94. sql.Clear();
  95. sql.Append("select cd_id from craft left join craftdetail on cd_crid=cr_id where cr_code='" + ma_craftcode.Text + "' ");
  96. sql.Append("and cr_prodcode='" + pr_code.Text + "' and nvl(cd_firststep,0)<>0 and cd_stepcode='" + User.CurrentStepCode + "'");
  97. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  98. if (dt.Rows.Count > 0)
  99. {
  100. if (sn_code.Text != "")
  101. {
  102. //判断序列号是否有效
  103. string Msid = dh.getFieldDataByCondition("makeserial ", "max(ms_id)", "ms_sncode='" + sn_code.Text + "' and ms_makecode<>'" + ma_code.Text + "'").ToString();
  104. if (Msid != "")
  105. {
  106. //序列号信息
  107. sql.Clear();
  108. sql.Append("select ms_beforesn,ms_status,ms_makecode,ms_firstsn,ms_outboxcode,ms_nextmacode,ms_prodcode,ms_salecode,");
  109. sql.Append("MS_IMEI1,MS_MAC,MS_NETCODE,MS_MEID,ms_imei2,ms_imei3,ms_othid1,ms_othid2,ms_othid3");
  110. sql.Append(",MS_OTHCODE3,MS_OTHCODE2,MS_OTHCODE1,ms_bt from makeserial where ms_id='" + Msid + "'");
  111. DataTable SnInf = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  112. string ms_prodcode = SnInf.Rows[0]["ms_prodcode"].ToString();
  113. string ms_salecode = SnInf.Rows[0]["ms_salecode"].ToString();
  114. string ms_beforesn = SnInf.Rows[0]["ms_beforesn"].ToString();
  115. string ms_makecode = SnInf.Rows[0]["ms_makecode"].ToString();
  116. string ms_status = SnInf.Rows[0]["ms_status"].ToString();
  117. string ms_outboxcode = SnInf.Rows[0]["ms_outboxcode"].ToString();
  118. //判断序列号是否已经被使用
  119. if (SnInf.Rows[0]["ms_nextmacode"].ToString() != "")
  120. {
  121. OperateResult.AppendText(">>序列号已经被工单号:" + SnInf.Rows[0]["ms_nextmacode"].ToString() + "使用\n", Color.Red, sn_code);
  122. return;
  123. }
  124. //工单信息
  125. sql.Clear();
  126. sql.Append("select ma_salecode,ma_prodcode,ma_craftname,ma_inqty,ma_craftcode,ma_qty,nvl(ma_inqty,0) ma_inqty,");
  127. sql.Append("nvl(ma_scrapqty,0)ma_scrapqty,ma_id,nvl(ma_unlimitin,0) ma_unlimitin,ma_wccode,NVL(re_autodecom,0)");
  128. sql.Append("re_autodecom,re_code from make left join rework on ma_screcode=re_code where ");
  129. sql.Append("ma_code='" + ma_code.Text + "'and ma_kind='返工' and ma_statuscode='STARTED'");
  130. DataTable MaInf = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  131. string ma_prodcode = MaInf.Rows[0]["ma_prodcode"].ToString();
  132. string ma_salecode = MaInf.Rows[0]["ma_salecode"].ToString();
  133. string re_autodecom = MaInf.Rows[0]["re_autodecom"].ToString();
  134. string re_code = MaInf.Rows[0]["re_code"].ToString();
  135. int ma_unlimitin = int.Parse(MaInf.Rows[0]["ma_unlimitin"].ToString());
  136. int ma_inqty = int.Parse(MaInf.Rows[0]["ma_inqty"].ToString());
  137. int ma_scrapqty = int.Parse(MaInf.Rows[0]["ma_scrapqty"].ToString());
  138. int ma_qty = int.Parse(MaInf.Rows[0]["ma_qty"].ToString());
  139. if (ma_prodcode != ms_prodcode)
  140. {
  141. OperateResult.AppendText(">>序列号所属产品" + ms_prodcode + "与返工工单产品不一致\n", Color.Red, sn_code);
  142. return;
  143. }
  144. if (ms_salecode != "" && ma_salecode != "" && ms_salecode != ma_salecode)
  145. {
  146. OperateResult.AppendText(">>序列号所属合同" + ms_salecode + "与返工工单合同不一致\n", Color.Red, sn_code);
  147. return;
  148. }
  149. if (ma_unlimitin == 0 && ma_inqty - ma_scrapqty + 1 > ma_qty)
  150. {
  151. OperateResult.AppendText(">>工单不允许超数投产\n", Color.Red, sn_code);
  152. return;
  153. }
  154. string Sn = sn_code.Text;
  155. //if (ReWorkAsRelateTSN.Checked)
  156. //{
  157. // if (ms_beforesn != "")
  158. // {
  159. // Sn = ms_beforesn;
  160. // }
  161. // else
  162. // {
  163. // OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在TSN\n", Color.Red, sn_code);
  164. // return;
  165. // }
  166. //}
  167. string netcode = "";
  168. string imeid = "";
  169. string imei1 = "";
  170. string imei2 = "";
  171. string imei3 = "";
  172. string othid1 = "";
  173. string othid2 = "";
  174. string othid3 = "";
  175. string mac = "";
  176. string bt = "";
  177. string othcode1 = "";
  178. string othcode2 = "";
  179. string othcode3 = "";
  180. if (ma_saveimei.Checked)
  181. {
  182. netcode = SnInf.Rows[0]["MS_NETCODE"].ToString();
  183. imeid = SnInf.Rows[0]["MS_MEID"].ToString();
  184. imei1 = SnInf.Rows[0]["MS_IMEI1"].ToString();
  185. imei2 = SnInf.Rows[0]["ms_imei2"].ToString();
  186. imei3 = SnInf.Rows[0]["ms_imei3"].ToString();
  187. othid1 = SnInf.Rows[0]["ms_othid1"].ToString();
  188. othid2 = SnInf.Rows[0]["ms_othid2"].ToString();
  189. othid3 = SnInf.Rows[0]["ms_othid3"].ToString();
  190. }
  191. if (ma_savemacbt.Checked)
  192. {
  193. mac = SnInf.Rows[0]["ms_mac"].ToString();
  194. bt = SnInf.Rows[0]["ms_bt"].ToString();
  195. othcode1 = SnInf.Rows[0]["MS_OTHCODE1"].ToString();
  196. othcode2 = SnInf.Rows[0]["MS_OTHCODE2"].ToString();
  197. othcode3 = SnInf.Rows[0]["MS_OTHCODE3"].ToString();
  198. }
  199. string craftcode = MaInf.Rows[0]["ma_craftcode"].ToString();
  200. string craftname = MaInf.Rows[0]["ma_craftname"].ToString();
  201. string firstsn = SnInf.Rows[0]["ms_firstsn"].ToString();
  202. //工作中心为空的时候取工单的工作中心
  203. string workcenter = User.WorkCenter;
  204. if (workcenter == "")
  205. workcenter = MaInf.Rows[0]["ma_wccode"].ToString();
  206. //工单合同为空的时候取序列号合同,更新合同回工单
  207. string salecode = MaInf.Rows[0]["ma_salecode"].ToString();
  208. List<string> SQLS = new List<string>();
  209. if (salecode == "")
  210. {
  211. salecode = SnInf.Rows[0]["ms_salecode"].ToString();
  212. SQLS.Add("update make set ma_salecode='" + salecode + "' where ma_id='" + ma_id.Text + "'");
  213. }
  214. sql.Clear();
  215. sql.Append("insert into MakeSerial(ms_id,ms_code,ms_sncode,ms_prodcode,ms_indate,ms_wccode");
  216. sql.Append(",ms_craftcode,ms_craftname,ms_nextstepcode,ms_status,ms_makecode,ms_linecode");
  217. sql.Append(",ms_sourcecode,ms_maid,ms_firstsn,ms_salecode,ms_mac,ms_bt,ms_othcode1,ms_othcode2,");
  218. sql.Append("ms_othcode3,ms_netcode,ms_imei1,ms_imei2,ms_imei3,ms_meid,ms_othid1,ms_othid2,ms_othid3)");
  219. sql.Append("values(MakeSerial_seq.nextval,'" + Sn + "','" + Sn + "','" + pr_code.Text + "',");
  220. sql.Append("sysdate,'" + workcenter + "','" + craftcode + "','" + craftname + "','" + User.CurrentStepCode + "',");
  221. sql.Append("" + (ms_status != "3" ? "0" : "3") + ",'" + ma_code.Text + "','" + User.UserLineCode + "','" + User.UserSourceCode + "','" + ma_id.Text + "',");
  222. sql.Append("'" + firstsn + "','" + salecode + "','" + mac + "','" + bt + "','" + othcode1 + "','" + othcode2 + "','" + othcode3 + "',");
  223. sql.Append("'" + netcode + "','" + imei1 + "','" + imei2 + "','" + imei3 + "','" + imeid + "','" + othid1 + "','" + othid2 + "','" + othid3 + "')");
  224. SQLS.Add(sql.GetString());
  225. SQLS.Add("update make set ma_inqty=nvl(ma_inqty,0)+1 where ma_id='" + ma_id.Text + "'");
  226. SQLS.Add("update makeserial set ms_nextmacode='" + ma_code.Text + "' where ms_id='" + Msid + "'");
  227. if (ms_outboxcode != "")
  228. {
  229. //更新箱号失效
  230. sql.Clear();
  231. sql.Append("update package set pa_status=-1 where pa_outboxcode='" + ms_outboxcode + "' and pa_status<>-1");
  232. SQLS.Add(sql.GetString());
  233. }
  234. sql.Clear();
  235. sql.Append("update makebad set mb_makecode='" + ms_makecode + "' where mb_sncode ='" + sn_code.Text + "' and mb_status=0");
  236. SQLS.Add(sql.GetString());
  237. if (re_autodecom != "0")
  238. {
  239. sql.Clear();
  240. sql.Append("update craftmaterial set cm_status=-1,cm_dropcode='" + re_code + "',cm_dropman='" + User.UserCode + "',cm_dropdate=sysdate where ");
  241. sql.Append("cm_firstsn='" + firstsn + "' and nvl(cm_status,0)=0 and exists (select 1 from makesndecompose ");
  242. sql.Append("where msd_recode='" + re_code + "' and msd_fsoncode=cm_fsoncode and msd_stepcode=cm_stepcode)");
  243. SQLS.Add(sql.GetString());
  244. }
  245. dh.ExecuteSQLTran(SQLS.ToArray());
  246. //if (ReWorkAsRelateTSN.Checked)
  247. //{
  248. // dh.ExecuteSql("update makeserial set ms_nextmacode='" + ma_code.Text + "' where ms_sncode='" + ms_beforesn + "' and ms_nextmacode='" + ms_makecode + "'", "update");
  249. //}
  250. OperateResult.AppendText(">>序列号" + sn_code.Text + "归属工单" + ma_code.Text + "成功。\n", Color.Green);
  251. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "返工信息采集", "序列号归属成功", sn_code.Text, "");
  252. getsnqty.Text = dh.getFieldDataByCondition("makeserial ", "count(1)", "ms_makecode='" + ma_code.Text + "'").ToString();
  253. if (AutoPrint.Checked)
  254. {
  255. if (PrintLabel.Items.Count != 0)
  256. {
  257. OperateResult.AppendText(">>打印序列号" + sn_code.Text + "\n", Color.Black);
  258. doc = lbl.Documents.Open(ftpOperater.DownLoadTo + PrintLabel.Text.Split(':')[1]);
  259. Print.CodeSoft(Tag.ToString(), doc, PrintLabel.Text.Split(':')[1], PrintLabel.SelectedValue.ToString(), PrinterList.Text, sn_code.Text, int.Parse(PrintNum.Text));
  260. dh.UpdateByCondition("makeserial", "ms_printcount=nvl(ms_printcount,0)+1", "ms_sncode='" + sn_code.Text + "'");
  261. }
  262. else OperateResult.AppendText(">>" + pr_code.Text + "未维护标签\n", Color.Black);
  263. }
  264. sn_code.Clear();
  265. }
  266. else OperateResult.AppendText(">>序列号" + sn_code.Text + "不存在或者已绑定工单\n", Color.Red, sn_code);
  267. }
  268. else OperateResult.AppendText(">>序列号不允许为空\n", Color.Red, sn_code);
  269. }
  270. else OperateResult.AppendText(">>该岗位资源对应的工序不是当前返工工单途程中的第一道工序,请切换资源编号\n", Color.Red, sn_code);
  271. }
  272. else OperateResult.AppendText(">>工单号不允许为空\n", Color.Red, sn_code);
  273. }
  274. }
  275. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  276. {
  277. if (ma_code.Text.Length >= 5)
  278. {
  279. if (dh.CheckExist("make", "ma_kind='返工' and ma_statuscode='STARTED' and ma_code='" + ma_code.Text + "'"))
  280. {
  281. sql.Clear();
  282. sql.Append("select ma_id,ma_craftcode,ma_code,pr_code,pr_detail,pr_spec,ma_qty,nvl(ma_savemacbt,0) ma_savemacbt,nvl(ma_saveimei, 0)");
  283. sql.Append("ma_saveimei from make left join product on ma_prodcode=pr_code where ma_code='" + ma_code.Text + "'");
  284. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  285. BaseUtil.SetFormValue(this.Controls, dt);
  286. if (dt.Rows[0]["ma_saveimei"].ToString() != "0")
  287. {
  288. ma_saveimei.Checked = true;
  289. }
  290. if (dt.Rows[0]["ma_savemacbt"].ToString() != "0")
  291. {
  292. ma_savemacbt.Checked = true;
  293. }
  294. }
  295. }
  296. }
  297. private void PrintLabel_SelectedValueChanged(object sender, EventArgs e)
  298. {
  299. if (PrintLabel.SelectedValue != null && PrintLabel.SelectedValue.ToString() != "System.Data.DataRowView")
  300. {
  301. string PrintNums = dh.getFieldDataByCondition("label", "la_printnos", "la_id='" + PrintLabel.SelectedValue.ToString() + "'").ToString();
  302. PrintNum.Text = (PrintNums == "" ? "1" : PrintNums);
  303. }
  304. }
  305. }
  306. }