Make_Decompose_Ex.cs 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using UAS_MES_NEW.DataOperate;
  10. using UAS_MES_NEW.Entity;
  11. using UAS_MES_NEW.PublicMethod;
  12. namespace UAS_MES_NEW.Make
  13. {
  14. public partial class Make_Decompose_Ex : Form
  15. {
  16. AutoSizeFormClass asc = new AutoSizeFormClass();
  17. DataTable dt;
  18. DataTable dt1;
  19. DataTable dtbar;
  20. DataTable dtst;
  21. LogStringBuilder sql = new LogStringBuilder();
  22. DataHelper dh;
  23. //记录当前序列号的ms_id
  24. string ms_id;
  25. //采集计数
  26. int count;
  27. //Bom版本
  28. string ms_bomversion;
  29. string ms_craftcode_;
  30. string ms_prodcode_;
  31. int rowindex;
  32. Make_NewBadCode_DE badcode;
  33. //记录当前输入框的值
  34. string sncode_1;
  35. string sncode_2;
  36. string[] bccode;
  37. string[] bgcode;
  38. string[] id;
  39. public Make_Decompose_Ex()
  40. {
  41. InitializeComponent();
  42. }
  43. private void Make_Decompose_Load(object sender, EventArgs e)
  44. {
  45. asc.controllInitializeSize(this);
  46. sn_code.Focus();
  47. OperateResult.AppendText(">>请输入序列号\n");
  48. count = 0;
  49. deccount.Text = count + "";
  50. dh = SystemInf.dh;
  51. }
  52. private void sn_code_KeyDown(object sender, KeyEventArgs e)
  53. {
  54. if (e.KeyCode == Keys.Enter)
  55. {
  56. sql.Clear();
  57. sql.Append("select max(ms_id) from makeserial where ms_sncode ='" + sn_code.Text + "' or ms_sncode = (select max(SN)");
  58. sql.Append(" from makesnrelation left join makeserial on ms_makecode=makecode where beforesn='" + sn_code.Text + "')");
  59. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  60. ms_id = dt.Rows[0][0].ToString();
  61. sncode_1 = sn_code.Text;
  62. deccount.Text = count + "";
  63. if (ms_id != "")
  64. {
  65. if (LabelDataGridView.Rows.Count > 0)
  66. {
  67. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  68. {
  69. if (LabelDataGridView.Rows[i].Cells["cm_barcode"].Value.ToString() == sn_code.Text)
  70. {
  71. LabelDataGridView.Rows[i].Cells["Choose"].Value = true;
  72. return;
  73. }
  74. }
  75. }
  76. BaseUtil.CleanForm(this);
  77. sql.Clear();
  78. sql.Append("select ms_id,ms_status,ms_makecode,ms_prodcode,pr_detail pr_name,ms_sncode,ms_firstsn,ms_craftcode,ms_craftname,ms_wccode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'");
  79. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  80. BaseUtil.SetFormValue(this.Controls, dt);
  81. LoadData(ms_sncode.Text, sender, e);
  82. }
  83. else
  84. {
  85. if (LabelDataGridView.Rows.Count > 0)
  86. {
  87. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  88. {
  89. if (LabelDataGridView.Rows[i].Cells["cm_barcode"].Value.ToString() == sn_code.Text)
  90. {
  91. LabelDataGridView.Rows[i].Cells["Choose"].Value = true;
  92. return;
  93. }
  94. }
  95. }
  96. ms_id = null;
  97. OperateResult.AppendText(">>序列号" + sncode_1 + "不存在\n", Color.Red, sn_code);
  98. BaseUtil.CleanForm(this);
  99. sn_code.Focus();
  100. return;
  101. }
  102. }
  103. }
  104. //加载此序列号上料记录
  105. private void LoadData(string sncode, object sender, KeyEventArgs e)
  106. {
  107. //cm_wccode
  108. sncode_1 = sncode;
  109. sql.Clear();
  110. sql.Append("select cm_craftcode,cm_spid,cm_craftname,cm_firstsn,cm_makecode,cm_stepcode,cm_stepname,cm_maprodcode,cm_fsoncode,cm_wccode,cm_maid,cm_soncode,cm_materialtype,");
  111. sql.Append("max(cm_status) cm_status,max(cm_id) cm_id from craftmaterial where(cm_sncode in (select '" + sncode_1 + "' from dual union select firstsn from makesnrelation where sn ");
  112. sql.Append(" ='" + sncode_1 + "'union select sn from makesnrelation where firstsn = '" + sncode_1 + "' union select ms_code from makeserial where ms_sncode = '" + sncode_1 + "')");
  113. sql.Append(") group by cm_craftcode,cm_firstsn,cm_stepcode,cm_stepname,cm_spid,cm_makecode,cm_maprodcode,cm_maid,cm_soncode,cm_wccode,cm_materialtype,cm_craftname,cm_fsoncode ORDER BY cm_status DESC");
  114. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  115. if (dt.Rows.Count > 0)
  116. {
  117. BaseUtil.FillDgvWithDataTable(LabelDataGridView, dt);
  118. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  119. {
  120. DataTable datatable = (DataTable)dh.ExecuteSql("select cm_barcode,cm_sncode from CRAFTMATERIAL where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'", "select");
  121. LabelDataGridView.Rows[i].Cells["cm_barcode"].Value = datatable.Rows[0]["cm_barcode"].ToString();
  122. LabelDataGridView.Rows[i].Cells["cm_sncode"].Value = datatable.Rows[0]["cm_sncode"].ToString();
  123. string[] cm_sncodedetail = LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString().Split(',');
  124. string pr_name = "";
  125. foreach (string item in cm_sncodedetail)
  126. {
  127. pr_name += "'" + item + "',";
  128. }
  129. pr_name = pr_name.TrimEnd(',');
  130. LabelDataGridView.Rows[i].Cells["pr_detail_"].Value = dh.getFieldDataByCondition("product", "wm_concat(pr_detail)", "pr_code in (" + pr_name + ")");
  131. LabelDataGridView.Rows[i].Cells["cm_status_1"].Value = (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() == "-1") ? "已拆解" : "上线";
  132. }
  133. }
  134. else
  135. {
  136. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "无上料数据\n", Color.Red);
  137. }
  138. }
  139. private void Make_Decompose_SizeChanged(object sender, EventArgs e)
  140. {
  141. asc.controlAutoSize(this);
  142. }
  143. private void LabelDataGridView_CellContentClick(object sender, DataGridViewCellEventArgs e)
  144. {
  145. if (e.ColumnIndex >= 0 && e.RowIndex >= 0)
  146. {
  147. if (LabelDataGridView.Columns[e.ColumnIndex].Name == "AddBad")
  148. {
  149. if (ms_sncode.Text == "" || ms_makecode.Text == "")
  150. {
  151. OperateResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red);
  152. }
  153. else
  154. {
  155. rowindex = e.RowIndex;
  156. badcode = new Make_NewBadCode_DE(ms_sncode.Text, ms_makecode.Text);
  157. badcode.Controls["Save"].Click += LoadBadcode;
  158. BaseUtil.SetFormCenter(badcode);
  159. badcode.ShowDialog();
  160. }
  161. }
  162. }
  163. }
  164. //加载之前在新增不良代码界面选择的不良代码
  165. private void LoadBadcode(object sender, EventArgs e)
  166. {
  167. sql.Clear();
  168. for (int i = 0; i < badcode.bccode.Length; i++)
  169. {
  170. sql.Append(badcode.bgcode[i] + " : " + badcode.bccode[i] + " |");
  171. }
  172. LabelDataGridView.Rows[rowindex].Cells["mb_badcode"].Value = sql.GetString();
  173. badcode.Close();
  174. }
  175. private void Decompose_Click(object sender, EventArgs e)
  176. {
  177. sql.Clear();
  178. sql.Append("select max(ms_id) from makeserial where ms_sncode ='" + ms_sncode.Text + "' or ms_sncode = (select max(SN)");
  179. sql.Append(" from makesnrelation left join makeserial on ms_makecode=makecode where beforesn='" + ms_sncode.Text + "')");
  180. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  181. ms_id = dt.Rows[0][0].ToString();
  182. if (ms_id != "")
  183. {
  184. sql.Clear();
  185. sql.Append("select ms_id,ms_status,ms_makecode,ms_prodcode,pr_detail pr_name,ms_sncode,ms_firstsn,ms_craftcode,ms_craftname,ms_wccode from makeserial left join product on pr_code=ms_prodcode where ms_id='" + ms_id + "'");
  186. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  187. //if (!(dt.Rows[0]["ms_status"].ToString() == "0" || dt.Rows[0]["ms_status"].ToString() == "3"))
  188. //{
  189. // OperateResult.AppendText(">>序列号" + ms_sncode.Text + "必须处于维修或未采集状态才能做拆解\n", Color.Red, sn_code);
  190. // BaseUtil.CleanForm(this);
  191. // sn_code.Focus();
  192. // return;
  193. //}
  194. }
  195. else
  196. {
  197. ms_id = null;
  198. OperateResult.AppendText(">>序列号" + ms_sncode.Text + "不存在\n", Color.Red, sn_code);
  199. BaseUtil.CleanForm(this);
  200. sn_code.Focus();
  201. return;
  202. }
  203. Boolean decompose = false;
  204. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  205. {
  206. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  207. {
  208. if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && change.Checked && (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value == null || LabelDataGridView.Rows[i].Cells["New_BarCode"].Value == null) && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1")
  209. {
  210. OperateResult.AppendText("第" + (i + 1) + "行没有采集不良代码或新批号\n", Color.Red);
  211. return;
  212. }
  213. if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && change.Checked && LabelDataGridView.Rows[i].Cells["New_BarCode"].Value == null && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() == "-1")
  214. {
  215. OperateResult.AppendText("第" + (i + 1) + "行没有采集新批号\n", Color.Red);
  216. return;
  217. }
  218. if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true && nochange.Checked && (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value == null) && LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1")
  219. {
  220. OperateResult.AppendText("第" + (i + 1) + "行没有采集不良代码\n", Color.Red);
  221. return;
  222. }
  223. }
  224. }
  225. for (int i = 0; i < LabelDataGridView.Rows.Count; i++)
  226. {
  227. if (LabelDataGridView.Rows[i].Cells["Choose"].Value != null)
  228. {
  229. if ((Boolean)LabelDataGridView.Rows[i].Cells["Choose"].Value == true)
  230. {
  231. if (LabelDataGridView.Rows[i].Cells["mb_badcode"].Value != null)
  232. {
  233. String[] badcodetol = LabelDataGridView.Rows[i].Cells["mb_badcode"].Value.ToString().Split('|');
  234. bgcode = new string[badcodetol.Length - 1];
  235. bccode = new string[badcodetol.Length - 1];
  236. for (int h = 0; h < badcodetol.Length - 1; h++)
  237. {
  238. bgcode[h] = badcodetol[h].Split(':')[0].Trim();
  239. bccode[h] = badcodetol[h].Split(':')[1].Trim();
  240. }
  241. }
  242. if (change.Checked)
  243. {
  244. dt1 = new DataTable();
  245. sql.Clear();
  246. sql.Append("select nvl(ms_bomversion,ma_bomversion) ms_bomversion,ms_craftcode,ms_prodcode from makeserial left join make on ma_code=ms_makecode ");
  247. sql.Append("left join product on ms_prodcode=pr_code where ms_makecode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "' order by ms_id desc");
  248. dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  249. if (dt1.Rows.Count > 0)
  250. {
  251. ms_bomversion = dt1.Rows[0]["ms_bomversion"].ToString();
  252. ms_craftcode_ = dt1.Rows[0]["ms_craftcode"].ToString();
  253. ms_prodcode_ = dt1.Rows[0]["ms_prodcode"].ToString();
  254. }
  255. dtbar = new DataTable();
  256. sql.Clear();
  257. sql.Append("select max(sp_repcode)sp_repcode,max(sp_id)sp_id,max(sp_detno)sp_detno,max(sp_instr)sp_instr,min(sp_ifrepeat)sp_ifrepeat,sp_fsoncode,max(sp_barcoderule)");
  258. sql.Append("sp_barcoderule, min(sp_checksalecode)sp_checksalecode,sp_tracekind,wm_concat(sp_soncode) sp_soncode,max(sp_ifuseregex)sp_ifuseregex,max(sp_ifforsn)");
  259. sql.Append("sp_ifforsn,max(sp_length)sp_length,max(sp_type)sp_type,replace(wm_concat(sp_prefix),',','|')sp_prefix,max(sp_regex)");
  260. sql.Append("sp_regex,max(pr_detail)pr_detail from stepproduct left join product on pr_code=sp_fsoncode where ");
  261. sql.Append("sp_bomversion='" + ms_bomversion + "' and sp_craftcode='" + ms_craftcode_ + "'and sp_mothercode ='" + ms_prodcode_ + "'");
  262. sql.Append(" group by sp_fsoncode,sp_tracekind order by SP_DETNO asc");
  263. dtbar = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  264. DataRow[] dtrows = dtbar.Select("sp_soncode like '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'");
  265. dtbar = BaseUtil.ToDataTable(dtrows);
  266. if (dtbar.Rows.Count > 0)
  267. {
  268. String ErrorMessage;
  269. string sp_tracekind = dtbar.Rows[0]["sp_tracekind"].ToString();
  270. string sp_soncode = dtbar.Rows[0]["sp_soncode"].ToString();
  271. string sp_prefix = dtbar.Rows[0]["sp_prefix"].ToString();
  272. string sp_fsoncode = dtbar.Rows[0]["sp_fsoncode"].ToString();
  273. string length = dtbar.Rows[0]["sp_length"].ToString();
  274. string sp_ifrepeat = dtbar.Rows[0]["sp_ifrepeat"].ToString();
  275. string sp_barcoderule = dtbar.Rows[0]["sp_barcoderule"].ToString();
  276. string sp_checksalecode = dtbar.Rows[0]["sp_checksalecode"].ToString();
  277. if (sp_tracekind == "1")
  278. {
  279. //上料校验规则判断
  280. if (!LogicHandler.CheckSNBeforeLoad(LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString(), LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString(), sp_fsoncode, sp_soncode, sp_barcoderule, sp_prefix, length, sp_ifrepeat, sp_checksalecode, out ErrorMessage))
  281. {
  282. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  283. LoadData(sncode_1, sender, new KeyEventArgs(Keys.Enter));
  284. continue;
  285. }
  286. dh.UpdateByCondition("makeserial", "ms_nextmacode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'", "ms_id=(select max(ms_id) from makeserial where ms_sncode='" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "')");
  287. }
  288. else if (sp_tracekind == "2")
  289. {
  290. if (!dh.CheckExist("makesourcestock", " (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"))
  291. {
  292. OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "岗位备料无条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "\n", Color.Red);
  293. continue;
  294. }
  295. else
  296. {
  297. sql.Clear();
  298. sql.Append("select mss_id,MSS_REMAIN,MSS_BASEQTY from makesourcestock where (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'");
  299. dtst = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  300. int MSS_REMAIN = int.Parse(dtst.Rows[0]["MSS_REMAIN"].ToString());
  301. int MSS_BASEQTY = int.Parse(dtst.Rows[0]["MSS_BASEQTY"].ToString());
  302. if (MSS_REMAIN < MSS_BASEQTY)
  303. {
  304. OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "备料不足\n", Color.Red);
  305. continue;
  306. }
  307. else
  308. {
  309. dh.UpdateByCondition("makesourcestock", "MSS_REMAIN = NVL(MSS_REMAIN, 0) - MSS_BASEQTY,MSS_USEQTY = NVL(MSS_USEQTY, 0) + MSS_BASEQTY,mss_madeqty=NVL(mss_madeqty,0)+ceil(MSS_USEQTY/MSS_BASEQTY)", " mss_id = '" + dtst.Rows[0]["mss_id"].ToString() + "' and (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'");
  310. }
  311. }
  312. }
  313. }
  314. else
  315. {
  316. //当前备料信息不再工序BOM中,为BOM之外的批管控物料备料
  317. if (!dh.CheckExist("makesourcestock", " (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'"))
  318. {
  319. OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "不在当前工序BOM" + ms_bomversion + "中\n", Color.Black);
  320. OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "岗位备料无条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "\n", Color.Red);
  321. continue;
  322. }
  323. else
  324. {
  325. sql.Clear();
  326. sql.Append("select mss_id,MSS_REMAIN,MSS_BASEQTY from makesourcestock where (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'");
  327. dtst = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  328. int MSS_REMAIN = int.Parse(dtst.Rows[0]["MSS_REMAIN"].ToString());
  329. int MSS_BASEQTY = int.Parse(dtst.Rows[0]["MSS_BASEQTY"].ToString());
  330. if (MSS_REMAIN < MSS_BASEQTY)
  331. {
  332. OperateResult.AppendText(">>物料" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "条码" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "备料不足\n", Color.Red);
  333. continue;
  334. }
  335. else
  336. {
  337. dh.UpdateByCondition("makesourcestock", "MSS_REMAIN = NVL(MSS_REMAIN, 0) - MSS_BASEQTY,MSS_USEQTY = NVL(MSS_USEQTY, 0) + MSS_BASEQTY,mss_madeqty=NVL(mss_madeqty,0)+ceil(MSS_USEQTY/MSS_BASEQTY)", " mss_id = '" + dtst.Rows[0]["mss_id"].ToString() + "' and (MSS_FPRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "' or MSS_PRODCODE = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value.ToString() + "') and mss_barcode = '" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value.ToString() + "'");
  338. }
  339. }
  340. }
  341. if (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1")
  342. {
  343. //判断生产信息
  344. sql.Clear();
  345. sql.Append("select ms_id,ms_sncode,cm_barcode from craftmaterial left join makeserial on cm_barcode = ms_sncode and cm_soncode = ms_prodcode where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and cm_materialtype ='1' and ms_id>'0' and ms_nextmacode = '" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'");
  346. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  347. //制造件
  348. if (dt.Rows.Count > 0)
  349. {
  350. string makecode = (String)dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode = '" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "' and ms_prodcode = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'");
  351. string mss_id = dt.Rows[0]["ms_id"].ToString();
  352. ////MakeBad表插入物料批号不良信息
  353. sql.Clear();
  354. sql.Append(" insert into makebad (mb_id, mb_inman,mb_indate,mb_stepcode,mb_sourcecode, mb_bgcode,mb_mscode,mb_sncode, mb_badcode, mb_makecode)");
  355. sql.Append("values (MakeBad_seq.nextval,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bg_code ,'" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "',");
  356. sql.Append(":bc_code,'" + makecode + "')");
  357. dh.BatchInsert(sql.GetString(), new string[] { "bg_code", "bc_code" }, bgcode, bccode);
  358. //更新子件序列号为待维修
  359. sql.Clear();
  360. sql.Append("update makeserial set ms_status=3 ,ms_badtimes = ms_badtimes+1,ms_nextmacode = '' where ms_id='" + mss_id + "' ");
  361. dh.ExecuteSql(sql.GetString(), "update");
  362. }
  363. //没有生产信息,判定为采购件,则将不良信息插入不良零件表中MAKEBADRSPART
  364. else
  365. {
  366. sql.Clear();
  367. sql.Append("insert into MAKEBADRSPART(mbp_id,mbp_indate,mbp_inman,mbp_sncode, mbp_badcode, mbp_part, mbp_makecode, mbp_sccode,mbp_barcode)values");
  368. sql.Append("(MAKEBADRSPART_seq.nextval, sysdate, '" + User.UserCode + "','" + ms_sncode.Text + "',:bc_code,'" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "','" + ms_makecode.Text + "','" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "')");
  369. dh.BatchInsert(sql.GetString(), new string[] { "bc_code" }, bccode);
  370. }
  371. dh.ExecuteSql("update makeserial set ms_nextmacode = '' where ms_sncode = '" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "' and ms_nextmacode = '" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'", "update");
  372. }
  373. //此物料上线状态更新为-1,代表被拆解
  374. sql.Clear();
  375. sql.Append("update craftmaterial set cm_status=-1,cm_lastdeco=-1,cm_dropman='" + User.UserCode + "',");
  376. sql.Append("cm_dropdate =sysdate,cm_dropstep='" + User.CurrentStepCode + "',");
  377. sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_id='" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'");
  378. dh.ExecuteSql(sql.GetString(), "update");
  379. ////将新批号绑定到序列号中
  380. //dt = (DataTable)dh.ExecuteSql("select sp_id from stepproduct where sp_mothercode='" + LabelDataGridView.Rows[i].Cells["cm_maprodcode"].Value + "'", "select");
  381. //string sp_id = dt.Rows[0]["sp_id"].ToString();
  382. sql.Clear();
  383. sql.Append("insert into craftmaterial (cm_id, cm_makecode,cm_maid,cm_maprodcode,cm_soncode,cm_mscode,cm_sncode,cm_stepcode,cm_stepname,");
  384. sql.Append("cm_craftcode,cm_craftname,cm_barcode,cm_inqty,cm_indate,cm_inman,cm_linecode,cm_wccode,cm_sourcecode,cm_spid, cm_materialtype,cm_status,cm_fsoncode,cm_firstsn)");
  385. sql.Append("values(Craftmaterial_seq.nextval,'" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_maid"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_maprodcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'");
  386. sql.Append(",'" + LabelDataGridView.Rows[i].Cells["cm_sncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_sncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_stepcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_stepname"].Value + "',");
  387. sql.Append("'" + LabelDataGridView.Rows[i].Cells["cm_craftcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_craftname"].Value + "','" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "',1,sysdate,'" + User.UserCode + "','" + User.UserLineCode + "','" + LabelDataGridView.Rows[i].Cells["cm_wccode"].Value + "',");
  388. sql.Append("'" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_spid"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_materialtype"].Value + "','0','" + LabelDataGridView.Rows[i].Cells["cm_fsoncode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_firstsn"].Value + "')");
  389. dh.ExecuteSql(sql.GetString(), "insert");
  390. dh.ExecuteSql("update makeserial set ms_nextmacode='" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value + "' where ms_id=(select max(ms_id) from makeserial where ms_sncode='" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "' and ms_makecode<>'" + ms_makecode.Text + "')", "update");
  391. OperateResult.AppendText("物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解换料成功\n", Color.Green);
  392. decompose = true;
  393. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解换料", "拆解换料成功", ms_sncode.Text, "");
  394. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["New_BarCode"].Value + "拆解换料上料", "拆解换料上料成功", ms_sncode.Text, "");
  395. }
  396. else if (nochange.Checked)
  397. {
  398. if (LabelDataGridView.Rows[i].Cells["cm_status"].Value.ToString() != "-1")
  399. {
  400. //判断生产信息
  401. sql.Clear();
  402. sql.Append("select ms_id,ms_sncode,cm_barcode from craftmaterial left join makeserial on cm_barcode = ms_sncode and cm_soncode = ms_prodcode where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and cm_materialtype ='1' and ms_id>'0' and ms_nextmacode = '" + LabelDataGridView.Rows[i].Cells["cm_makecode"].Value.ToString() + "'");
  403. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  404. //制造件
  405. if (dt.Rows.Count > 0)
  406. {
  407. string makecode = (String)dh.getFieldDataByCondition("makeserial", "ms_makecode", "ms_sncode = '" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "' and ms_prodcode = '" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "'");
  408. string mss_id = dt.Rows[0]["ms_id"].ToString();
  409. ////MakeBad表插入物料批号不良信息
  410. sql.Clear();
  411. sql.Append(" insert into makebad (mb_id, mb_inman,mb_indate,mb_stepcode,mb_sourcecode, mb_bgcode,mb_mscode,mb_sncode, mb_badcode, mb_makecode)");
  412. sql.Append("values (MakeBad_seq.nextval,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "','" + User.UserSourceCode + "',:bg_code ,'" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "',");
  413. sql.Append(":bc_code,'" + makecode + "')");
  414. dh.BatchInsert(sql.GetString(), new string[] { "bg_code", "bc_code" }, bgcode, bccode);
  415. //更新子件序列号为待维修
  416. sql.Clear();
  417. sql.Append("update makeserial set ms_status=3 ,ms_badtimes = ms_badtimes+1,ms_nextmacode = '' where ms_id='" + mss_id + "' ");
  418. dh.ExecuteSql(sql.GetString(), "update");
  419. }
  420. //没有生产信息,判定为采购件,则将不良信息插入不良零件表中MAKEBADRSPART
  421. else
  422. {
  423. sql.Clear();
  424. sql.Append("insert into MAKEBADRSPART(mbp_id,mbp_indate,mbp_inman,mbp_sncode, mbp_badcode, mbp_part, mbp_makecode, mbp_sccode,mbp_barcode)values");
  425. sql.Append("(MAKEBADRSPART_seq.nextval, sysdate, '" + User.UserCode + "','" + ms_sncode.Text + "',:bc_code,'" + LabelDataGridView.Rows[i].Cells["cm_soncode"].Value + "','" + ms_makecode.Text + "','" + User.UserSourceCode + "','" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "')");
  426. dh.BatchInsert(sql.GetString(), new string[] { "bc_code" }, bccode);
  427. }
  428. //craftmaterial解除相应物料绑定
  429. sql.Clear();
  430. sql.Append("update craftmaterial set cm_status=-1,cm_dropman='" + User.UserCode + "',");
  431. sql.Append("cm_dropdate =sysdate,cm_dropstep='" + User.CurrentStepCode + "',");
  432. sql.Append("cm_dropsccode='" + User.UserSourceCode + "' where cm_id='" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "'");
  433. dh.ExecuteSql(sql.GetString(), "update");
  434. }
  435. //更新序列号信息
  436. sql.Clear();
  437. sql.Append("update makeserial set ms_nextmacode = '' where ms_sncode = (select cm_barcode from craftmaterial where cm_id = '" + LabelDataGridView.Rows[i].Cells["cm_id"].Value + "' and CM_MATERIALTYPE = '1') and ms_nextmacode='" + ms_makecode.Text + "'");
  438. dh.ExecuteSql(sql.GetString(), "update");
  439. OperateResult.AppendText("物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解成功\n", Color.Green);
  440. decompose = true;
  441. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ms_makecode.Text, User.UserLineCode, User.UserSourceCode, "物料" + LabelDataGridView.Rows[i].Cells["cm_barcode"].Value + "拆解", "拆解成功", ms_sncode.Text, "");
  442. }
  443. else
  444. {
  445. OperateResult.AppendText(">>>没有选择拆解方式\n", Color.Red);
  446. return;
  447. }
  448. }
  449. }
  450. }
  451. if (decompose)
  452. {
  453. count++;
  454. deccount.Text = count + "";
  455. LoadData(sncode_1, sender, new KeyEventArgs(Keys.Enter));
  456. }
  457. else
  458. {
  459. OperateResult.AppendText("没有成功拆解项\n", Color.Red);
  460. }
  461. }
  462. private void LabelDataGridView_Sorted(object sender, EventArgs e)
  463. {
  464. }
  465. }
  466. }