Make_Decompose.cs 41 KB

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