Make_RepairOk.cs 76 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using UAS_MES_NEW.CustomControl.DataGrid_View;
  9. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_RepairOk : Form
  16. {
  17. string mb_id = "";
  18. string mbr_id = "";
  19. /// <summary>
  20. /// 存放父节点信息
  21. /// </summary>
  22. Dictionary<string, Dictionary<string, string>> BadInf_1 = new Dictionary<string, Dictionary<string, string>>();
  23. /// <summary>
  24. /// 存放子节点信息
  25. /// </summary>
  26. Dictionary<string, Dictionary<string, string>> BadInf_2 = new Dictionary<string, Dictionary<string, string>>();
  27. DataHelper dh = null;
  28. LogStringBuilder sql = new LogStringBuilder();
  29. List<string> sqls = new List<string>();
  30. DataTable dt = null;
  31. AutoSizeFormClass asc = new AutoSizeFormClass();
  32. string macode;
  33. string msid = "";
  34. string ifrework = "";
  35. string reworkstatus = "";
  36. string firstsn = "";
  37. string ms_stepcode = "";
  38. string ms_beforesn = "";
  39. DataTable Dbfind;
  40. public Make_RepairOk()
  41. {
  42. InitializeComponent();
  43. }
  44. private void Make_Repair_Load(object sender, EventArgs e)
  45. {
  46. //为DBFind配置Call和Form的名称
  47. cr_code.FormName = Name;
  48. cr_code.TableName = "craft";
  49. cr_code.SelectField = "cr_name # 工艺名称,cr_code # 工艺编号,cr_prodcode # 物料编号";
  50. cr_code.SetValueField = new string[] { "cr_code" };
  51. cr_code.DBTitle = "回流工艺";
  52. cr_code.DbChange += Cr_code_DbChange;
  53. cd_stepcode.FormName = Name;
  54. cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id";
  55. cd_stepcode.SetValueField = new string[] { "cd_stepcode" };
  56. cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序";
  57. cd_stepcode.DBTitle = "回流工序";
  58. cd_stepcode.DbChange += Cd_stepcode_DbChange;
  59. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ST_IFOFFLINE = -1 order by cd_stepno";
  60. bd_soncode.FormName = Name;
  61. bd_soncode.TableName = "bom left join bomdetail on bd_bomid=bo_id left join product on bd_soncode=pr_code";
  62. bd_soncode.SetValueField = new string[] { "bd_soncode" };
  63. bd_soncode.SelectField = "bd_soncode # 子件编号,pr_detail # 物料名称,pr_spec # 物料规格,bd_location # 位号";
  64. bd_soncode.DBTitle = "不良零件";
  65. bd_soncode.DbChange += Prodcode_DbChange;
  66. //nrg_name.BringToFront();
  67. nrg_name.TableName = "(select nrg_name,nrg_code from QUA_NGREASONGROUP left join DATAINPUTRECORD ON NRG_NAME = DIR_COMMENT AND DIR_GROUP = '不良原因组' and DIR_SOURCECODE = '" + User.UserSourceCode + "' ORDER BY NVL(DIR_NUMBER,0) DESC)";
  68. nrg_name.Field = "nrg_name";
  69. nrg_name.ValueField = "nrg_code";
  70. nrg_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  71. nr_name.TableName = "QUA_NGREASONGROUPDET left join QUA_NGREASONGROUP on nrgd_nrgid=nrg_id left join QUA_NGReason on nrgd_nrcode=nr_code left join DATAINPUTRECORD ON nr_name = DIR_COMMENT AND DIR_GROUP = '不良原因' and DIR_SOURCECODE = '" + User.UserSourceCode + "' ";
  72. nr_name.Field = "nr_name";
  73. nr_name.ValueField = "nr_code";
  74. mbr_dutyname.TableName = "(select nd_name,nd_code from ngduty left join DATAINPUTRECORD ON nd_name = DIR_COMMENT AND DIR_GROUP = '责任别' and DIR_SOURCECODE = '" + User.UserSourceCode + "' ORDER BY NVL(DIR_NUMBER,0) DESC) ";
  75. mbr_dutyname.Field = "nd_name";
  76. mbr_dutyname.ValueField = "nd_code";
  77. mbr_dutyname.Condition = " 1=1 ORDER BY ROWNUM asc";
  78. so_name.TableName = "(select so_name,so_code from solution left join DATAINPUTRECORD ON so_name = DIR_COMMENT AND DIR_GROUP = '解决方案' and DIR_SOURCECODE = '" + User.UserSourceCode + "' ORDER BY NVL(DIR_NUMBER,0) DESC)";
  79. so_name.Field = "so_name";
  80. so_name.ValueField = "so_code";
  81. so_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  82. if (User.UserAccountType != "admin")
  83. {
  84. retsnlabel.Visible = false;
  85. retsn.Visible = false;
  86. }
  87. asc.controllInitializeSize(this);
  88. mbc_component.SendToBack();
  89. so_name.SendToBack();
  90. mbl_loc.SendToBack();
  91. bd_soncode.SendToBack();
  92. mbp_partdgv.SendToBack();
  93. mbp_part_label.SendToBack();
  94. dh = SystemInf.dh;
  95. GetSNCode.Focus();
  96. }
  97. private void LoadBadcodeGroup()
  98. {
  99. sql.Clear();
  100. sql.Append("select ri_id,ri_name from RepairItem where ri_statuscode='AUDITED' ");
  101. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  102. badgroup.DataSource = dt;
  103. badgroup.DisplayMember = "ri_name";
  104. badgroup.ValueMember = "ri_id";
  105. LoadBadCodeListView();
  106. }
  107. private void LoadBadCodeListView()
  108. {
  109. string ri_id = badgroup.SelectedValue.ToString();
  110. if (ri_id != "System.Data.DataRowView") {
  111. sql.Clear();
  112. sql.Append("select rid_code from RepairItemdetail where rid_riid='" + ri_id + "' ");
  113. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  114. BadInfo.DataSource = dt;
  115. //往listview中添加数据
  116. WaitRejectList.Items.Clear();
  117. WaitRejectList.BeginUpdate();
  118. for (int i = 0; i < dt.Rows.Count; i++)
  119. {
  120. ListViewItem lvi = new ListViewItem();
  121. //第一列是勾选列,设置列头文本为空
  122. lvi.Text = "";
  123. for (int j = 0; j < dt.Columns.Count; j++)
  124. lvi.SubItems.Add(dt.Rows[i][j].ToString());
  125. WaitRejectList.Items.Add(lvi);
  126. }
  127. WaitRejectList.EndUpdate();
  128. }
  129. }
  130. private void Prodcode_DbChange(object sender, EventArgs e)
  131. {
  132. Dbfind = bd_soncode.ReturnData;
  133. BaseUtil.SetFormValue(this.Controls, Dbfind);
  134. if (bd_soncode.Text != "")
  135. {
  136. if (mbr_id != "")
  137. {
  138. if (!dh.CheckExist("makebadrspart", "mbp_sncode='" + GetSNCode.Text + "' and mbp_part='" + bd_soncode.Text + "' and mbp_badcode='" + bc_code.Text + "'"))
  139. {
  140. sql.Clear();
  141. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  142. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  143. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  144. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  145. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  146. dh.ExecuteSql(sql.GetString(), "insert");
  147. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  148. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  149. }
  150. }
  151. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  152. }
  153. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  154. }
  155. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  156. {
  157. Dbfind = cd_stepcode.ReturnData;
  158. BaseUtil.SetFormValue(this.Controls, Dbfind);
  159. }
  160. private void Cr_code_DbChange(object sender, EventArgs e)
  161. {
  162. Dbfind = cr_code.ReturnData;
  163. BaseUtil.SetFormValue(this.Controls, Dbfind);
  164. }
  165. private void GetSNCode_KeyDown(object sender, KeyEventArgs e)
  166. {
  167. if (e.KeyCode == Keys.Enter)
  168. {
  169. if (GetSNCode.Text == "")
  170. {
  171. OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  172. string cdstepcode = cd_stepcode.Text;
  173. //cd_stepcode.Enabled = true;
  174. BaseUtil.CleanForm(this);
  175. cd_stepcode.Text = cdstepcode;
  176. BadCodeTree.Nodes.Clear();
  177. return;
  178. }
  179. sql.Clear();
  180. sql.Append("select ms_status,ms_outboxcode,ms_paststep,ms_reworkstatus,nvl(ms_ifrework,0)ms_ifrework,ms_sncode from makeserial left join make ");
  181. sql.Append("on ms_makecode=ma_code where ms_sncode = '" + GetSNCode.Text + "' or ms_firstsn = '" + GetSNCode.Text + "' order by ms_id desc");
  182. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  183. string ms_paststep = "";
  184. if (dt.Rows.Count > 0)
  185. {
  186. string ms_status = dt.Rows[0]["ms_status"].ToString();
  187. ms_paststep = dt.Rows[0]["ms_paststep"].ToString();
  188. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  189. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  190. GetSNCode.Text = dt.Rows[0]["ms_sncode"].ToString();
  191. //if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  192. //{
  193. // OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已装箱,请先进行拆箱\n", Color.Red);
  194. // BaseUtil.CleanForm(this);
  195. // BadCodeTree.Nodes.Clear();
  196. // return;
  197. //}
  198. //如果不是返修序列号执行原来的步骤
  199. if (ifrework == "0")
  200. {
  201. if (ms_status == "4")
  202. {
  203. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已处于报废状态\n", Color.Red);
  204. string cdstepcode = cd_stepcode.Text;
  205. //cd_stepcode.Enabled = true;
  206. BaseUtil.CleanForm(this);
  207. cd_stepcode.Text = cdstepcode;
  208. BadCodeTree.Nodes.Clear();
  209. return;
  210. }
  211. if (ms_status != "3")
  212. {
  213. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不处于维修状态\n", Color.Red);
  214. string cdstepcode = cd_stepcode.Text;
  215. //cd_stepcode.Enabled = true;
  216. BaseUtil.CleanForm(this);
  217. cd_stepcode.Text = cdstepcode;
  218. BadCodeTree.Nodes.Clear();
  219. return;
  220. }
  221. }
  222. else
  223. {
  224. if (reworkstatus == "4")
  225. {
  226. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已处于报废状态\n", Color.Red);
  227. string cdstepcode = cd_stepcode.Text;
  228. //cd_stepcode.Enabled = true;
  229. BaseUtil.CleanForm(this);
  230. cd_stepcode.Text = cdstepcode;
  231. BadCodeTree.Nodes.Clear();
  232. return;
  233. }
  234. if (reworkstatus != "0" && reworkstatus != "3")
  235. {
  236. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不处于维修状态\n", Color.Red);
  237. string cdstepcode = cd_stepcode.Text;
  238. //cd_stepcode.Enabled = true;
  239. BaseUtil.CleanForm(this);
  240. cd_stepcode.Text = cdstepcode;
  241. BadCodeTree.Nodes.Clear();
  242. return;
  243. }
  244. }
  245. }
  246. else
  247. {
  248. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不存在\n", Color.Red);
  249. string cdstepcode = cd_stepcode.Text;
  250. //cd_stepcode.Enabled = true;
  251. BaseUtil.CleanForm(this);
  252. cd_stepcode.Text = cdstepcode;
  253. BadCodeTree.Nodes.Clear();
  254. return;
  255. }
  256. //dt = (DataTable)dh.ExecuteSql("select mb_stepcode from makebad where mb_sncode='" + GetSNCode.Text + "' and mb_status=0 order by mb_id desc", "select");
  257. ////打不良的资源和当前资源相等可以快速维修,无须登录维修资源
  258. //bool QuickRepair = false;
  259. //if (dt.Rows.Count > 0)
  260. //{
  261. // if (dt.Rows[0]["mb_stepcode"].ToString() == User.CurrentStepCode)
  262. // {
  263. // QuickRepair = true;
  264. // }
  265. //}
  266. string ErrorMessage = "";
  267. //验证工序是否正确
  268. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  269. {
  270. BadInf_1.Clear();
  271. string oStatus = "";
  272. if (LogicHandler.GetMakeInfo(GetSNCode.Text, out macode, out oStatus, out ErrorMessage))
  273. {
  274. //验证makeserial或者ms_firstsn表序列号是否存在
  275. sql.Clear();
  276. sql.Append("select nvl(ms_badtimes,0)ms_badtimes,max(ms_id) ms_id,ms_makecode,ma_craftcode,ms_stepcode,ms_firstsn,ms_prodcode,ms_sncode,ma_bomversion,pr_detail,ms_craftcode,ms_checkno,ms_ifrework,ms_reworkcheckno,ms_beforesn ");
  277. sql.Append("from makeserial left join make on ms_makecode=ma_code left join product on pr_code=ms_prodcode where ms_makecode ='" + macode + "' and ms_sncode in(");
  278. sql.Append("select '" + GetSNCode.Text + "' from dual union select firstsn from makesnrelation where ");
  279. sql.Append("sn='" + GetSNCode.Text + "') group by ms_makecode,ms_stepcode,ms_prodcode,ma_craftcode,ms_sncode,ma_bomversion,pr_detail,ms_firstsn,ms_craftcode,ms_checkno,ms_ifrework,ms_reworkcheckno,ms_badtimes,ms_beforesn");
  280. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  281. if (dt.Rows.Count > 0)
  282. {
  283. msid = dt.Rows[0]["ms_id"].ToString();
  284. ms_beforesn = dt.Rows[0]["ms_beforesn"].ToString();
  285. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  286. BaseUtil.SetFormValue(this.Controls, dt);
  287. //判断是否当前工单途程的上料记录
  288. firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  289. string ma_bomversion = dt.Rows[0]["ma_bomversion"].ToString();
  290. int ms_badtimes = int.Parse(dt.Rows[0]["ms_badtimes"].ToString());
  291. string cdstepcode = "";
  292. //sql.Clear();
  293. //sql.Append("select cm_craftcode,cm_stepcode,cm_soncode,min(cm_indate)cm_indate,sum(case when cm_status=-1 ");
  294. //sql.Append("then 0 else 1 end)qty from craftmaterial left join product on pr_code=cm_soncode where(cm_sncode ");
  295. //sql.Append("in (select sn from makesnrelation where firstsn='" + firstsn + "' union select '" + firstsn + "' from dual)) ");
  296. //sql.Append("and cm_craftcode='" + cr_code.Text + "'and nvl(cm_lastdeco,0)<>0 group by cm_craftcode,cm_stepcode,cm_soncode having ");
  297. //sql.Append("sum(case when cm_status=-1 then 0 else 1 end)=0 order by cm_indate");
  298. sql.Clear();
  299. sql.Append("select sp_stepcode cm_stepcode,sp_craftcode cm_craftcode from stepproduct left join product on pr_code=sp_fsoncode where sp_bomversion='" + ma_bomversion + "' and ");
  300. sql.Append("sp_craftcode='" + cr_code.Text + "' And sp_mothercode ='" + ms_prodcode.Text + "' and sp_tracekind=1 ");
  301. //sql.Append("sp_craftcode=v_v_mscraftcode and sp_stepcode='' And sp_mothercode ='"+ms_prodcode.Text+"' and sp_tracekind=1");
  302. sql.Append("and not exists(select 1 from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union ");
  303. sql.Append("select sn from makesnrelation where firstsn='" + firstsn + "') and cm_makecode='" + macode + "' and ");
  304. sql.Append("cm_fsoncode=sp_fsoncode and cm_status=0) and instr((select ms_paststep from makeserial where ms_firstsn='" + firstsn + "'),sp_stepcode)>0 order by SP_DETNO asc");
  305. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  306. if (dt.Rows.Count < 0)
  307. {
  308. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  309. //如果本工序包含老化则默认选择本工序,否则选择上料的后一道工序
  310. if (dh.getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid", "nvl(cd_ifburnin,0)", "cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_stepcode='" + dt.Rows[0]["cm_stepcode"].ToString() + "'").ToString() != "0")
  311. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  312. else
  313. {
  314. string nextstep = LogicHandler.GetNextStep(dt.Rows[0]["cm_craftcode"].ToString(), dt.Rows[0]["cm_stepcode"].ToString(), ms_prodcode.Text);
  315. if (ms_paststep.Contains(nextstep))
  316. {
  317. cdstepcode = nextstep;
  318. }
  319. else
  320. {
  321. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  322. }
  323. }
  324. }
  325. else
  326. {
  327. sql.Clear();
  328. sql.Append("select cm_craftcode,cm_stepcode,cm_soncode,min(cm_indate)cm_indate,sum(case when cm_status=-1 ");
  329. sql.Append("then 0 else 1 end)qty from craftmaterial left join product on pr_code=cm_soncode where(cm_sncode ");
  330. sql.Append("in (select sn from makesnrelation where firstsn='" + firstsn + "' union select '" + firstsn + "' from dual)) ");
  331. sql.Append("and cm_craftcode='" + cr_code.Text + "' group by cm_craftcode,cm_stepcode,cm_soncode having ");
  332. sql.Append("sum(case when cm_status=-1 then 0 else 1 end)=0 order by cm_indate");
  333. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  334. if (dt.Rows.Count > 0)
  335. {
  336. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  337. }
  338. }
  339. if (cdstepcode == "")
  340. {
  341. //序号小于等于当前不良的序号
  342. string currentdetno = dh.getFieldDataByCondition("craft left join craftdetail on cr_id=cd_crid", "cd_detno", "cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and cd_stepcode='" + ms_stepcode + "'").ToString();
  343. sql.Clear();
  344. sql.Append("select cd_stepcode from craft left join craftdetail on cr_id =cd_crid where ");
  345. sql.Append("cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ");
  346. sql.Append("nvl(cd_ifburnin,0)<>0 and cd_detno <='" + currentdetno + "'");
  347. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  348. if (dt.Rows.Count > 0)
  349. {
  350. cdstepcode = dt.Rows[0][0].ToString();
  351. }
  352. }
  353. //如果ms_stepcode和扣料工序均没有查到返修的工序
  354. if (cdstepcode == "")
  355. {
  356. string flowback = dh.getFieldDataByCondition("craftdetail left JOIN craft on cr_id = cd_crid", "cd_stepcode", "cr_code= '" + cr_code.Text + "' and cr_prodcode = '" + ms_prodcode.Text + "' and nvl(cd_ifflowback,0)=-1").ToString();
  357. if (flowback != "")
  358. {
  359. cdstepcode = flowback;
  360. }
  361. else
  362. {
  363. cdstepcode = ms_stepcode;
  364. }
  365. }
  366. //cd_stepcode.Text = cdstepcode;
  367. //if (dh.getFieldDataByCondition("craftdetail left JOIN craft on cr_id = cd_crid", "nvl(cd_ifinput,0)cd_ifinput", "cr_code= '" + cr_code.Text + "' and cr_prodcode = '" + ms_prodcode.Text + "' and cd_stepcode = '" + cd_stepcode.Text + "'").ToString() == "-1")
  368. // cd_stepcode.Enabled = false;
  369. //else
  370. // cd_stepcode.Enabled = true;
  371. LoadBadInfTree(sender, e);
  372. if (ms_badtimes > 3)
  373. {
  374. OperatResult.AppendText(">>SN:" + ms_sncode.Text + "累计维修次数超过3次,提示\n", Color.Red);
  375. }
  376. if (autoin.Checked)
  377. {
  378. RepairComplete_Click(sender, e);
  379. }
  380. }
  381. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  382. }
  383. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  384. }
  385. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  386. }
  387. }
  388. private void Make_Repair_SizeChanged(object sender, EventArgs e)
  389. {
  390. mbc_component.BringToFront();
  391. so_name.BringToFront();
  392. mbl_loc.BringToFront();
  393. bd_soncode.BringToFront();
  394. mbp_partdgv.BringToFront();
  395. mbp_part_label.BringToFront();
  396. asc.controlAutoSize(this);
  397. mbc_component.SendToBack();
  398. so_name.SendToBack();
  399. mbl_loc.SendToBack();
  400. bd_soncode.SendToBack();
  401. mbp_partdgv.SendToBack();
  402. mbp_part_label.SendToBack();
  403. }
  404. private void BadCodeTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  405. {
  406. if (e.Node.Level == 0)
  407. {
  408. mb_id = e.Node.Tag.ToString();
  409. BaseUtil.CleanControlsText(bc_name, bc_code, bg_name, bg_code, mb_badremark, nrg_name, nrg_code, nr_name, nr_code, so_name, so_code, mbr_dutyname, mbr_dutycode, mbc_component);
  410. mbl_locdgv.DataSource = null;
  411. mbp_partdgv.DataSource = null;
  412. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  413. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  414. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  415. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  416. //mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  417. mbr_id = "";
  418. SaveRepairInf.Enabled = true;
  419. }
  420. if (e.Node.Level == 1)
  421. {
  422. //展示父节点信息
  423. mb_id = e.Node.Parent.Tag.ToString();
  424. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  425. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  426. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  427. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  428. //展示子节点信息
  429. mbr_id = e.Node.Tag.ToString();
  430. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  431. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  432. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  433. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  434. so_code.Text = BadInf_2[mbr_id]["so_code"];
  435. so_name.Text = BadInf_2[mbr_id]["so_name"];
  436. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  437. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];//mbr_remark
  438. mb_badremark.Text = BadInf_2[mbr_id]["mbr_remark"];
  439. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  440. //加载两个Grid的数据源
  441. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  442. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  443. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc,mbl_orispeccode from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  444. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  445. SaveRepairInf.Enabled = false;
  446. }
  447. }
  448. private void LoadBadInfTree(object sender, EventArgs e)
  449. {
  450. BadCodeTree.Nodes.Clear();
  451. sql.Clear();
  452. //不是返工工单时的取当前工单
  453. sql.Append("select mb_id,mb_sncode,mb_badcode,mb_bgcode,nvl(bc_name,mb_badcode) bc_name,nvl(bg_name,mb_bgcode) bg_name,");
  454. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup ");
  455. sql.Append("on bg_code=mb_bgcode where mb_sncode='" + (GetSNCode.Text == "" ? ms_sncode.Text : GetSNCode.Text) + "' and mb_makecode='" + macode + "' and mb_status=0");
  456. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  457. if (dt.Rows.Count == 0)
  458. {
  459. sql.Clear();
  460. sql.Append("select mb_id,mb_sncode,mb_badcode,mb_bgcode,nvl(bc_name,mb_badcode) bc_name,nvl(bg_name,mb_bgcode) bg_name, ");
  461. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup on bg_code=mb_bgcode ");
  462. sql.Append("left join make on ma_code=mb_makecode where mb_sncode='" + (GetSNCode.Text == "" ? ms_sncode.Text : GetSNCode.Text) + "' and mb_makecode<>'" + macode + "' and mb_status=0");
  463. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  464. }
  465. for (int i = 0; i < dt.Rows.Count; i++)
  466. {
  467. //添加根节点
  468. TreeNode tnode_0 = new TreeNode();
  469. string bg_name = dt.Rows[i]["bg_name"].ToString();
  470. string bc_name = dt.Rows[i]["bc_name"].ToString();
  471. string mb_badcode = dt.Rows[i]["mb_badcode"].ToString();
  472. string mb_bgcode = dt.Rows[i]["mb_bgcode"].ToString();
  473. tnode_0.Text = (bg_name == "" ? mb_bgcode : bg_name) + ":" + (bc_name == "" ? mb_bgcode : bc_name);
  474. tnode_0.Name = dt.Rows[i]["mb_bgcode"].ToString();
  475. //作为Dictionary的主标识
  476. string mb_id = dt.Rows[i]["mb_id"].ToString();
  477. tnode_0.Tag = mb_id;
  478. Dictionary<string, string> dic = new Dictionary<string, string>();
  479. dic.Add("mb_id", mb_id);
  480. dic.Add("mb_sncode", dt.Rows[i]["mb_sncode"].ToString());
  481. dic.Add("mb_badcode", dt.Rows[i]["mb_badcode"].ToString());
  482. dic.Add("mb_bgcode", dt.Rows[i]["mb_bgcode"].ToString());
  483. dic.Add("bc_name", dt.Rows[i]["bc_name"].ToString());
  484. dic.Add("bg_name", dt.Rows[i]["bg_name"].ToString());
  485. //dic.Add("mb_badremark", dt.Rows[i]["mb_badremark"].ToString());
  486. if (!BadInf_1.ContainsKey(tnode_0.Tag.ToString()))
  487. BadInf_1.Add(tnode_0.Tag.ToString(), dic);
  488. BadCodeTree.Nodes.Add(tnode_0);
  489. BadCodeTree.SelectedNode = BadCodeTree.Nodes[0];
  490. //添加子节点
  491. sql.Clear();
  492. sql.Append("select mbr_id,mbr_brcode,mbr_brgcode,mbr_solutioncode,so_code,so_name,mbr_dutycode,mbr_dutyname,nd_name,nrg_name");
  493. sql.Append(",nr_name,nr_code,nrg_code,mbr_remark from makebadreason left join QUA_NGReason on nr_code=mbr_brcode left join ");
  494. sql.Append("QUA_NGREASONGROUPdet on nrgd_nrcode=nr_code left join QUA_NGREASONGROUP on nrg_id=nrgd_nrgid and ");
  495. sql.Append("mbr_brgcode=nrg_code left join solution on so_code=mbr_solutioncode left join ngduty on nd_code=mbr_dutycode ");
  496. sql.Append("where mbr_mbid=" + mb_id);
  497. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  498. for (int j = 0; j < dt1.Rows.Count; j++)
  499. {
  500. TreeNode tnode_1 = new TreeNode();
  501. //存放子节点的信息
  502. Dictionary<string, string> dic1 = new Dictionary<string, string>();
  503. string mbr_id = dt1.Rows[j]["mbr_id"].ToString();
  504. tnode_1.Tag = mbr_id;
  505. dic1.Add("mbr_id", mbr_id);
  506. dic1.Add("mbr_brcode", dt1.Rows[j]["mbr_id"].ToString());
  507. dic1.Add("mbr_brgcode", dt1.Rows[j]["mbr_brcode"].ToString());
  508. dic1.Add("mbr_solutioncode", dt1.Rows[j]["mbr_solutioncode"].ToString());
  509. dic1.Add("mbr_dutycode", dt1.Rows[j]["mbr_dutycode"].ToString());
  510. dic1.Add("mbr_dutyname", dt1.Rows[j]["mbr_dutyname"].ToString());
  511. dic1.Add("mbr_remark", dt1.Rows[j]["mbr_remark"].ToString());
  512. dic1.Add("nd_name", dt1.Rows[j]["nd_name"].ToString());
  513. dic1.Add("so_name", dt1.Rows[j]["so_name"].ToString());
  514. dic1.Add("so_code", dt1.Rows[j]["so_code"].ToString());
  515. dic1.Add("nrg_name", dt1.Rows[j]["nrg_name"].ToString());
  516. dic1.Add("nrg_code", dt1.Rows[j]["nrg_code"].ToString());
  517. dic1.Add("nr_name", dt1.Rows[j]["nr_name"].ToString());
  518. dic1.Add("nr_code", dt1.Rows[j]["nr_code"].ToString());
  519. tnode_1.Text = dt1.Rows[j]["nr_name"].ToString();
  520. if (!BadInf_2.ContainsKey(mbr_id))
  521. BadInf_2.Add(mbr_id, dic1);
  522. tnode_0.Nodes.Add(tnode_1);
  523. }
  524. }
  525. try
  526. {
  527. if (bg_code.Text != "")
  528. BadCodeTree.Nodes[bg_code.Text].Expand();
  529. LoadBadcodeGroup();
  530. }
  531. catch (Exception) { }
  532. }
  533. private void RefreshTreeView_Click(object sender, EventArgs e)
  534. {
  535. LoadBadInfTree(sender, e);
  536. }
  537. private void RepairComplete_Click(object sender, EventArgs e)
  538. {
  539. if (ms_sncode.Text == "")
  540. {
  541. OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  542. return;
  543. }
  544. if (ifrework != "0" && reworkstatus == "0")
  545. {
  546. if (dh.getRowCount("Makebad", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status=0") == 0)
  547. {
  548. OperatResult.AppendText(">>维修必须维护不良代码\n", Color.Red);
  549. return;
  550. }
  551. }
  552. //判断是否所有的不良信息都有维护不良原因
  553. DataTable dt = (DataTable)dh.ExecuteSql("select mb_id,bc_name,mbr_mbid from makebad left join makebadreason on mbr_mbid=mb_id left join badcode on mb_badcode=bc_code where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status=0", "select");
  554. string ErrorMessage = "";
  555. for (int i = 0; i < dt.Rows.Count; i++)
  556. {
  557. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  558. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  559. }
  560. if (ErrorMessage != "")
  561. {
  562. OperatResult.AppendText(">>" + ErrorMessage + "未维护不良原因\n", Color.Red);
  563. return;
  564. }
  565. //如果岗位资源对应工序的版面不为空的时候
  566. if (dh.getFieldDataByCondition("makeserial left join step on ms_stepcode=st_code", "st_table", "ms_id='" + msid + "'").ToString() != "")
  567. {
  568. if (!dh.CheckExist("makebadrsloc", "mbl_mbrid='" + mbr_id + "' and mbl_makecode='" + ms_makecode.Text + "' and mbl_sncode='" + GetSNCode.Text + "' "))
  569. {
  570. OperatResult.AppendText(">>工序存在版面必须维护不良位置\n", Color.Red);
  571. return;
  572. }
  573. }
  574. if (dh.getFieldDataByCondition("product", "nvl(pr_isreturn,0)", "pr_code='" + ms_prodcode.Text + "'").ToString() == "-1")
  575. {
  576. OperatResult.AppendText(">>产品" + ms_prodcode.Text + "不允许回流\n", Color.Red);
  577. return;
  578. }
  579. ////查询拆解的物料
  580. //sql.Clear();
  581. //sql.Append("select distinct cm_soncode from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union ");
  582. //sql.Append("select sn from makesnrelation where firstsn='" + firstsn + "') and cm_craftcode<>'" + cr_code.Text + "' and cm_makecode<>'" + ms_makecode.Text + "' and cm_status=-1 ");
  583. //dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  584. ////如果含有序列号物料有被拆解过
  585. //if (dt.Rows.Count > 0)
  586. //{
  587. // string soncode = "";
  588. // for (int i = 0; i < dt.Rows.Count; i++)
  589. // {
  590. // soncode += "'" + dt.Rows[i][0].ToString() + "',";
  591. // }
  592. // //查询对应的上料记录
  593. // sql.Clear();
  594. // sql.Append("select cm_soncode from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union select sn from ");
  595. // sql.Append(" makesnrelation where firstsn='" + firstsn + "') and cm_status=0 and cm_soncode in (" + soncode.Substring(0, soncode.Length - 1) + ")");
  596. // DataTable LoadSoncode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  597. // //查询的结果不相等表示未完成上料
  598. // if (dt.Rows.Count != LoadSoncode.Rows.Count)
  599. // {
  600. // for (int i = 0; i < LoadSoncode.Rows.Count; i++)
  601. // {
  602. // if (soncode.Contains(LoadSoncode.Rows[i][0].ToString()))
  603. // {
  604. // soncode = soncode.Replace(LoadSoncode.Rows[i][0].ToString(), "");
  605. // }
  606. // }
  607. // OperatResult.AppendText(">>" + soncode.Replace("'", "") + "物料尚未备料,不允许回流\n", Color.Red);
  608. // return;
  609. // }
  610. //}
  611. dt = (DataTable)dh.ExecuteSql("select cr_id from craft where cr_statuscode='AUDITED' and cr_code='" + cr_code.Text + "'", "select");
  612. if (dt.Rows.Count == 0)
  613. OperatResult.AppendText(">>回流工序不存在\n", Color.Red);
  614. else
  615. {
  616. string cr_id = dt.Rows[0]["cr_id"].ToString();
  617. dt = (DataTable)dh.ExecuteSql("select cd_ifinput from craftdetail left join step on st_code=cd_stepcode where cd_crid='" + cr_id + "' and cd_stepcode='" + cd_stepcode.Text + "' and st_statuscode='AUDITED'", "select");
  618. if (dt.Rows.Count == 0)
  619. OperatResult.AppendText(">>回流工序不在回流工艺中\n", Color.Red);
  620. else
  621. {
  622. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0) ms_ifrework", "ms_paststep" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  623. List<string> SQLS = new List<string>();
  624. if (dt.Rows.Count > 0)
  625. {
  626. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  627. string ms_paststep = dt.Rows[0]["ms_paststep"].ToString();
  628. //如果回流的执行过的工序为空
  629. //if (!ms_paststep.Contains(cd_stepcode.Text) && ms_paststep != "")
  630. //{
  631. // OperatResult.AppendText(">>不允许回流到未执行的工序\n", Color.Red);
  632. // return;
  633. //}
  634. if (ms_ifrework == "0")
  635. SQLS.Add("update makeserial set ms_checkno='',ms_paststep = ms_paststep || case when instr(','||ms_paststep||',','" + User.CurrentStepCode + "')=0 then ','||'" + User.CurrentStepCode + "' end , ms_nextstepcode ='" + cd_stepcode.Text + "',ms_craftcode='" + cr_code.Text + "',ms_stepcode='" + User.CurrentStepCode + "',ms_status=1 where ms_id='" + msid + "'");
  636. else
  637. SQLS.Add("update makeserial set ms_checkno='',ms_paststep = ms_paststep || case when instr(','||ms_paststep||',','" + User.CurrentStepCode + "')=0 then ','||'" + User.CurrentStepCode + "' end , ms_nextstepcode ='" + cd_stepcode.Text + "',ms_craftcode='" + cr_code.Text + "',ms_stepcode='" + User.CurrentStepCode + "',ms_reworkstatus=1 where ms_id='" + msid + "'");
  638. }
  639. SQLS.Add("update makebad set mb_status=-1,mb_okman ='" + User.UserName + "',MB_OKTIME = sysdate where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status = 0");
  640. //取消最近拆解部件
  641. SQLS.Add("update craftmaterial set cm_status=-1 where cm_sncode='" + ms_sncode.Text + "' and cm_makecode='" + ms_makecode.Text + "' and CM_MATERIALTYPE = 1 ");
  642. if (ms_beforesn != "")
  643. {
  644. SQLS.Add("update makeserial set ms_sncode = ms_firstsn,ms_beforesn = '' where ms_id='" + msid + "'");
  645. SQLS.Add("update makebad set mb_sncode = mb_mscode where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' ");
  646. SQLS.Add("update MAKEBADREASON set mbr_sncode = '" + ms_beforesn + "' where mbr_sncode='" + ms_sncode.Text + "' and mbr_makecode='" + ms_makecode.Text + "' ");
  647. SQLS.Add("delete MAKESNRELATION where beforesn = '" + ms_beforesn + "'");
  648. }
  649. //if (checkBox1.Checked)
  650. //{
  651. // if (dh.CheckExist("makeserial", "ms_sncode = '" + ms_sncode.Text + "' and ms_makecode = '" + ms_makecode.Text + "' and ms_key is not null"))
  652. // {
  653. // SQLS.Add("update makeserial set ms_bs = '',MS_IFCCLEAN ='Y',ms_key='',ms_keyid='',MS_HARDWREID='',MS_KEYSTATEID='',MS_BIOS='',ms_ec='',ms_uuid='',MS_KEYPARTNUMBER='',ms_bt='',ms_mac='',ms_imei='',ms_imei1='' where ms_sncode = '" + ms_sncode.Text + "' and ms_makecode = '" + ms_makecode.Text + "'");
  654. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "需要清空写入信息", "需要清空写入信息", ms_sncode.Text, ms_checkno.Text);
  655. // }
  656. // else {
  657. // SQLS.Add("update makeserial set ms_bs = '',ms_key='',ms_keyid='',MS_HARDWREID='',MS_KEYSTATEID='',MS_BIOS='',ms_ec='',ms_uuid='',MS_KEYPARTNUMBER='',ms_bt='',ms_mac='',ms_imei='',ms_imei1='' where ms_sncode = '" + ms_sncode.Text + "' and ms_makecode = '" + ms_makecode.Text + "'");
  658. // }
  659. // }
  660. //SQLS.Add("update MakeBadCount set mbc_status=-1 where mbc_sncode='" + ms_sncode.Text + "'");
  661. dh.ExecuteSQLTran(SQLS.ToArray());
  662. LogicHandler.InsertMakeProcess(ms_sncode.Text, ms_makecode.Text, User.UserSourceCode, "回流工序", "完成维修回流", User.UserCode);
  663. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "回流工序", "完成维修回流", ms_sncode.Text, ms_checkno.Text);
  664. OperatResult.AppendText(">>序列号" + ms_sncode.Text + "回流成功\n", Color.Green);
  665. string cdstepcode = cd_stepcode.Text;
  666. cd_stepcode.Enabled = true;
  667. BaseUtil.CleanForm(this);
  668. cd_stepcode.Text = cdstepcode;
  669. BadCodeTree.Nodes.Clear();
  670. GetSNCode.Clear();
  671. GetSNCode.Focus();
  672. i = 0;
  673. }
  674. }
  675. }
  676. private void Scrap_Click(object sender, EventArgs e)
  677. {
  678. if (ms_sncode.Text != "")
  679. {
  680. //判断是否有无法维修的记录
  681. int ScrapNum = int.Parse(dh.getFieldDataByCondition("makebadreason left join makebad on mb_id=mbr_mbid", "count(0) cn", "mb_sncode='" + ms_sncode.Text + "' and mb_status=0").ToString());
  682. if (ScrapNum == 0)
  683. OperatResult.AppendText(">>" + ms_sncode.Text + "报废必须维护不良原因\n", Color.Red);
  684. else
  685. {
  686. string confirm = MessageBox.Show(this.ParentForm, "此操作不可撤销,是否确认报废", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk).ToString();
  687. if (confirm == "Yes")
  688. {
  689. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcode", "ms_code" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  690. if (dt.Rows.Count > 0)
  691. {
  692. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  693. string reworkcode = dt.Rows[0]["ms_reworkcode"].ToString();
  694. string ms_code = dt.Rows[0]["ms_code"].ToString();
  695. if (ms_ifrework == "0")
  696. {
  697. dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=4,ms_nextstepcode=''", "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  698. }
  699. else
  700. {
  701. sqls.Clear();
  702. sqls.Add("update makeserial set ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=4,ms_reworkstatus= 4,ms_nextstepcode='' where ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  703. sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_reworkcheckno.Text + "'");
  704. sqls.Add("delete from oqcbatchdetail where obd_sncode='" + ms_sncode.Text + "' and obd_checkno='" + ms_reworkcheckno.Text + "'");
  705. sqls.Add("update ReworkDetail set rd_rwstatus='报废' where rd_reid=(select re_id from rework where re_code='" + reworkcode + "') and rd_sncode='" + reworkcode + "'");
  706. dh.ExecuteSQLTran(sqls.ToArray());
  707. }
  708. dh.ExecuteSql("update MAKESOURCESTOCK set mss_remain = mss_remain + MSS_BASEQTY,MSS_INVALIDTIME = null,mss_useqty = mss_useqty-MSS_BASEQTY where mss_barcode in (select cm_barcode from CRAFTMATERIAL where cm_mscode = '" + ms_code + "' and cm_makecode = '" + macode + "' and cm_status = 0) and mss_makecode = '" + macode + "' ", "update");
  709. dh.ExecuteSql(" merge into barcode using (select cm_barcode,cm_inqty from CRAFTMATERIAL where cm_mscode = '" + ms_code + "' and cm_makecode = '" + macode + "' and cm_status = 0) A on (barcode.bar_code = A.cm_barcode) when matched then update set bar_remain = bar_remain + cm_inqty ", "update");
  710. }
  711. dh.ExecuteSql("update makebad set mb_status=-2,mb_okman ='" + User.UserName + "' where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status = 0", "update");
  712. dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1", "mcd_macode='" + ms_makecode.Text + "' and mcd_stepcode='" + ms_stepcode + "'");
  713. dh.UpdateByCondition("make", "MA_NGMADEQTY=nvl(MA_NGMADEQTY,0)+1,ma_qty = ma_qty+1", "ma_code='" + macode + "'");
  714. LogicHandler.InsertMakeProcess(ms_sncode.Text, ms_makecode.Text, User.UserSourceCode, "报废", "序列号报废", User.UserCode);
  715. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "报废", "序列号报废", ms_sncode.Text, ms_checkno.Text);
  716. OperatResult.AppendText(">>报废成功\n", Color.Green);
  717. GetSNCode.Clear();
  718. GetSNCode.Focus();
  719. BaseUtil.CleanForm(this);
  720. BadCodeTree.Nodes.Clear();
  721. }
  722. }
  723. }
  724. else OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  725. }
  726. private void NewBadCode_Click(object sender, EventArgs e)
  727. {
  728. if (GetSNCode.Text == "" || macode == null || macode == "")
  729. {
  730. OperatResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red);
  731. }
  732. else
  733. {
  734. Make_NewBadCode badcode = new Make_NewBadCode(GetSNCode.Text, macode);
  735. badcode.FormClosed += LoadBadInfTree;
  736. BaseUtil.SetFormCenter(badcode);
  737. badcode.ShowDialog();
  738. }
  739. }
  740. private void NewRepairInf_Click(object sender, EventArgs e)
  741. {
  742. if (bg_name.Text == "" && bc_name.Text == "")
  743. {
  744. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  745. }
  746. else
  747. {
  748. Make_NewMatainInf mataininf = new Make_NewMatainInf(bg_name.Text, bg_code.Text, bc_name.Text, bc_code.Text, GetSNCode.Text, msid, mb_id);
  749. mataininf.FormClosed += LoadBadInfTree;
  750. BaseUtil.SetFormCenter(mataininf);
  751. mataininf.ShowDialog();
  752. }
  753. }
  754. private void SaveRepairInf_Click(object sender, EventArgs e)
  755. {
  756. string ErrorMessage = "";
  757. if (bg_name.Text == "" || bc_name.Text == "")
  758. {
  759. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  760. return;
  761. }
  762. if (nrg_name.Text == "")
  763. ErrorMessage += " 不良原因组 ";
  764. if (nr_name.Text == "")
  765. ErrorMessage += " 不良原因 ";
  766. if (mbr_dutyname.Text == "")
  767. ErrorMessage += " 责任别 ";
  768. //if (mbr_dutyname.Text == "物料问题" && mbc_component.Text == "")
  769. // ErrorMessage += "责任别为物料问题时必须选择不良零件";
  770. if (ErrorMessage != "")
  771. {
  772. ErrorMessage += "不能为空";
  773. OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  774. return;
  775. }
  776. string mbr_id = dh.GetSEQ("makebadreason_seq");
  777. //存在不良组件进行提示
  778. if (dh.CheckExist("makebadreason left join makebad on mbr_mbid=mb_id and mbr_sncode=mb_sncode", "mbr_badcode='" + bc_code.Text + "' and mbr_sncode='" + ms_sncode.Text + "' and mbr_brcode='" + nr_code.Text + "' and mb_status=0"))
  779. {
  780. OperatResult.AppendText(">>不良代码【" + bc_name.Text + "】已存在不良原因【" + nr_name.Text + "】\n", Color.Red);
  781. return;
  782. }
  783. if (!dh.CheckExist("QUA_NGREASONGROUP", "nrg_name='" + nrg_name.Text + "'"))
  784. {
  785. OperatResult.AppendText(">>不良原因组不存在\n", Color.Red);
  786. return;
  787. }
  788. if (!dh.CheckExist("QUA_NGReason", "nr_name='" + nr_name.Text + "'"))
  789. {
  790. OperatResult.AppendText(">>不良原因不存在\n", Color.Red);
  791. return;
  792. }
  793. if (!dh.CheckExist("ngduty", "nd_name='" + mbr_dutyname.Text + "'"))
  794. {
  795. OperatResult.AppendText(">>责任别不存在\n", Color.Red);
  796. return;
  797. }
  798. if (!dh.CheckExist("solution", "so_name='" + so_name.Text + "'"))
  799. {
  800. OperatResult.AppendText(">>解决方案不存在\n", Color.Red);
  801. return;
  802. }
  803. //保存选择记录至后台,根据岗位资源代码记录
  804. dh.ExecuteSql("merge into DATAINPUTRECORD using (select NRG_NAME from QUA_NGREASONGROUP where NRG_NAME = '" + nrg_name.Text + "') ON (NRG_NAME = DIR_COMMENT AND DIR_GROUP = '不良原因组' and DIR_SOURCECODE = '" + User.UserSourceCode + "') when matched then update set DIR_NUMBER = DIR_NUMBER +1 when not matched then insert (DIR_COMMENT,DIR_NUMBER,DIR_SOURCECODE,DIR_GROUP) VALUES (NRG_NAME,1,'" + User.UserSourceCode + "','不良原因组')", "select");
  805. dh.ExecuteSql("merge into DATAINPUTRECORD using (select nr_name from QUA_NGReason left join QUA_NGREASONGROUPDET on nrgd_nrcode=nr_code left join QUA_NGREASONGROUP on nrgd_nrgid=nrg_id where nr_name = '" + nr_name.Text + "' and NRG_NAME = '" + nrg_name.Text + "') ON (nr_name = DIR_COMMENT AND DIR_GROUP = '不良原因' and DIR_SOURCECODE = '" + User.UserSourceCode + "') when matched then update set DIR_NUMBER = DIR_NUMBER +1 when not matched then insert (DIR_COMMENT,DIR_NUMBER,DIR_SOURCECODE,DIR_GROUP) VALUES (nr_name,1,'" + User.UserSourceCode + "','不良原因')", "select");
  806. dh.ExecuteSql("merge into DATAINPUTRECORD using (select nd_name from ngduty where nd_name = '" + mbr_dutyname.Text + "') ON (nd_name = DIR_COMMENT AND DIR_GROUP = '责任别' and DIR_SOURCECODE = '" + User.UserSourceCode + "') when matched then update set DIR_NUMBER = DIR_NUMBER +1 when not matched then insert (DIR_COMMENT,DIR_NUMBER,DIR_SOURCECODE,DIR_GROUP) VALUES (nd_name,1,'" + User.UserSourceCode + "','责任别')", "select");
  807. dh.ExecuteSql("merge into DATAINPUTRECORD using (select so_name from solution where so_name = '" + so_name.Text + "') ON (so_name = DIR_COMMENT AND DIR_GROUP = '解决方案' and DIR_SOURCECODE = '" + User.UserSourceCode + "') when matched then update set DIR_NUMBER = DIR_NUMBER +1 when not matched then insert (DIR_COMMENT,DIR_NUMBER,DIR_SOURCECODE,DIR_GROUP) VALUES (so_name,1,'" + User.UserSourceCode + "','解决方案')", "select");
  808. //保存不良原因
  809. sql.Clear();
  810. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  811. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  812. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname,mbr_remark) select '" + mb_id + "','" + mbr_id + "','" + nr_code.Text + "',");
  813. sql.Append("'" + so_code.Text + "','" + mbr_dutyname.Text + "','" + nrg_code.Text + "','" + bc_code.Text + "',");
  814. sql.Append("'" + ms_sncode.Text + "','" + ms_makecode.Text + "',sysdate,'" + User.UserCode + "','" + nr_name.Text + "','" + so_name.Text + "','" + bc_name.Text + "','" + nrg_name.Text + "','" + mbr_dutyname.Text + "','" + mb_badremark.Text + "' from dual");
  815. dh.ExecuteSql(sql.GetString(), "insert");
  816. if (mbc_component.Text != "")
  817. {
  818. sql.Clear();
  819. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  820. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  821. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbc_component.Text + "',");
  822. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + ms_sncode.Text + "','" + ms_makecode.Text + "',sysdate,'" + User.UserCode + "')");
  823. dh.ExecuteSql(sql.GetString(), "insert");
  824. }
  825. OperatResult.AppendText(">>不良原因保存成功\n", Color.Green);
  826. SaveRepairInf.Enabled = false;
  827. LoadBadInfTree(sender, e);
  828. }
  829. private void DeleteRepairInf_Click(object sender, EventArgs e)
  830. {
  831. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + GetSNCode.Text + "' and ms_status=3", "select");
  832. if (dt.Rows.Count > 0)
  833. {
  834. if (mbr_id != "")
  835. {
  836. string delete1 = "delete from makebadrsloc where mbl_mbrid='" + mbr_id + "'";
  837. string delete2 = "delete from makebadrspart where mbp_mbrid='" + mbr_id + "'";
  838. string delete3 = "delete from makebadrscom where mbc_mbrid='" + mbr_id + "'";
  839. string delete4 = "delete from makebadreason where mbr_id='" + mbr_id + "'";
  840. dh.ExecuteSQLTran(delete1, delete2, delete3, delete4);
  841. OperatResult.AppendText(">>删除成功\n", Color.Green);
  842. BaseUtil.CleanControlsText(bc_name, bc_code, bg_name, bg_code, mb_badremark, nrg_name, nrg_code, nr_name, nr_code, so_name, so_code, mbr_dutyname, mbr_dutycode, mbc_component);
  843. mbp_partdgv.DataSource = null;
  844. mbl_locdgv.DataSource = null;
  845. mbr_id = "";
  846. //删除后重新加载Tree的信息
  847. LoadBadInfTree(sender, e);
  848. }
  849. else OperatResult.AppendText(">>必须选择不良原因\n", Color.Red);
  850. }
  851. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  852. }
  853. private void SaveBadLocation_Click(object sender, EventArgs e)
  854. {
  855. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + GetSNCode.Text + "' and ms_status=3", "select");
  856. if (dt.Rows.Count > 0)
  857. {
  858. if (mbl_loc.Text != "")
  859. {
  860. if (mbr_id != "")
  861. {
  862. if (!dh.CheckExist("makebadrsloc", "mbl_mbrid='" + mbr_id + "' and mbl_sncode='" + GetSNCode.Text + "' and mbl_loc='" + mbl_loc.Text + "'"))
  863. {
  864. if (dh.CheckExist("barcode", "bar_code = '" + mbl_loc.Text + "'"))
  865. {
  866. string MBL_PRODCODE = dh.getFieldDataByCondition("barcode", "bar_prodcode", "bar_code = '" + mbl_loc.Text + "'").ToString();
  867. string orpspeccode = dh.getFieldDataByCondition("product", "pr_orispeccode", "pr_code = '" + MBL_PRODCODE + "'").ToString();
  868. string items = "";
  869. for (int i = 0; i < WaitRejectList.Items.Count; i++)
  870. {
  871. if (WaitRejectList.Items[i].Checked)
  872. {
  873. items += WaitRejectList.Items[i].SubItems[1].Text.ToString() + ",";
  874. }
  875. }
  876. if (dh.CheckExist("MAKEMATERIAL", "mm_code = '" + macode + "' and mm_prodcode||mm_repprodcode like '%" + MBL_PRODCODE + "%'"))
  877. {
  878. sql.Clear();
  879. sql.Append("insert into makebadrsloc(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,");
  880. sql.Append("mbl_sncode,mbl_makecode,mbl_indate ,mbl_inman,MBL_PRODCODE,MBL_ORISPECCODE,mbl_compents) select makebadrsloc_seq.nextval," + mbr_id);
  881. sql.Append(",'" + mbl_loc.Text + "','" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  882. sql.Append("sysdate,'" + User.UserCode + "','" + MBL_PRODCODE + "','" + orpspeccode + "','" + items + "' from dual");
  883. dh.ExecuteSql(sql.GetString(), "insert");
  884. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc,mbl_orispeccode from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  885. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  886. }
  887. else
  888. OperatResult.AppendText(">>该维修条码对应物料" + MBL_PRODCODE + "不属于此工单可用物料\n", Color.Red, mbl_loc);
  889. }
  890. else
  891. OperatResult.AppendText(">>该维修条码" + mbl_loc.Text + "系统不存在\n", Color.Red, mbl_loc);
  892. }
  893. else OperatResult.AppendText(">>已存在该维修条码\n", Color.Red, mbl_loc);
  894. }
  895. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  896. }
  897. else OperatResult.AppendText(">>维修条码不能为空\n", Color.Red);
  898. }
  899. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  900. }
  901. private void nr_name_TextChanged(object sender, EventArgs e)
  902. {
  903. if (nr_name.Text == "")
  904. SaveBadLocation.Enabled = false;
  905. else
  906. SaveBadLocation.Enabled = true;
  907. }
  908. private void mbl_loc_KeyDown(object sender, KeyEventArgs e)
  909. {
  910. if (e.KeyCode == Keys.Enter)
  911. SaveBadLocation_Click(sender, e);
  912. }
  913. private void prodcode_TextKeyDown(object sender, KeyEventArgs e)
  914. {
  915. if (e.KeyCode == Keys.Enter)
  916. {
  917. if (bd_soncode.Text != "")
  918. {
  919. if (mbr_id != "")
  920. {
  921. sql.Clear();
  922. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  923. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  924. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  925. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  926. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  927. dh.ExecuteSql(sql.GetString(), "insert");
  928. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  929. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  930. }
  931. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  932. }
  933. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  934. }
  935. }
  936. private void cr_code_UserControlTextChanged(object sender, EventArgs e)
  937. {
  938. //cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ( cd_ifburnout <>0) order by cd_stepno";
  939. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ST_IFOFFLINE = -1 order by cd_stepno";
  940. }
  941. private void Clean_Click(object sender, EventArgs e)
  942. {
  943. OperatResult.Clear();
  944. }
  945. private void mbl_locdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  946. {
  947. if (e.RowIndex >= 0)
  948. {
  949. if (mbl_locdgv.Columns[e.ColumnIndex].Name == "DeletePos")
  950. {
  951. dh.ExecuteSql("delete from makebadrsloc where mbl_id='" + mbl_locdgv.Rows[e.RowIndex].Cells["mbl_id"].Value.ToString() + "'", "insert");
  952. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc,mbl_orispeccode from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  953. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  954. }
  955. }
  956. }
  957. private void mbp_partdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  958. {
  959. if (e.RowIndex >= 0)
  960. {
  961. if (mbp_partdgv.Columns[e.ColumnIndex].Name == "DeleteCom")
  962. {
  963. dh.ExecuteSql("delete from makebadrspart where mbp_id='" + mbp_partdgv.Rows[e.RowIndex].Cells["mbp_id"].Value.ToString() + "'", "insert");
  964. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  965. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  966. }
  967. }
  968. }
  969. private void Make_Repair_FormClosing(object sender, FormClosingEventArgs e)
  970. {
  971. dh.Dispose();
  972. }
  973. private void ms_prodcode_TextChanged(object sender, EventArgs e)
  974. {
  975. if (ms_prodcode.Text != "")
  976. cr_code.Condition = "cr_prodcode='" + ms_prodcode.Text + "'";
  977. else
  978. cr_code.Condition = "";
  979. bd_soncode.Condition = "bd_mothercode='" + ms_prodcode.Text + "' and NVL(bd_usestatus,' ')<>'DISABLE'";
  980. //设置工序的条件
  981. //cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ( cd_ifburnout <>0) order by cd_stepno";
  982. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ST_IFOFFLINE = -1 order by cd_stepno";
  983. }
  984. public void RefreshData()
  985. {
  986. GetSNCode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  987. }
  988. private void nr_name_UserControlTextChanged(object sender, EventArgs e)
  989. {
  990. if (nr_name.Text != "")
  991. {
  992. SaveBadLocation.Enabled = true;
  993. if (nrg_name.Text == "")
  994. {
  995. OperatResult.AppendText(">>请先填写不良代码组\n", Color.Red);
  996. nr_name.Text = "";
  997. }
  998. else
  999. {
  1000. if (nr_code.Text == "" || (nr_code.Text != "" && nr_code.Text != nr_name.Value))
  1001. nr_code.Text = nr_name.Value;
  1002. }
  1003. }
  1004. else SaveBadLocation.Enabled = false;
  1005. }
  1006. private void nrg_name_UserControlTextChanged(object sender, EventArgs e)
  1007. {
  1008. if (nrg_code.Text == "" || (nrg_code.Text != "" && nrg_code.Text != nrg_name.Value))
  1009. nrg_code.Text = nrg_name.Value;
  1010. nr_name.Condition = "nrg_code in('" + (nrg_code.Text == "" ? "''" : nrg_code.Text) + "')";
  1011. }
  1012. private void mbr_dutyname_UserControlTextChanged(object sender, EventArgs e)
  1013. {
  1014. if (mbr_dutycode.Text == "" || (mbr_dutycode.Text != "" && mbr_dutycode.Text != mbr_dutyname.Value))
  1015. mbr_dutycode.Text = mbr_dutyname.Value;
  1016. }
  1017. private void mbc_component_UserControlTextChanged(object sender, EventArgs e)
  1018. {
  1019. }
  1020. private void so_name_UserControlTextChanged(object sender, EventArgs e)
  1021. {
  1022. if (so_code.Text == "" || (so_code.Text != "" && so_code.Text != so_name.Value))
  1023. so_code.Text = so_name.Value;
  1024. }
  1025. private void BadCodeTree_AfterSelect(object sender, TreeViewEventArgs e)
  1026. {
  1027. if (e.Node.Level == 0)
  1028. {
  1029. mb_id = e.Node.Tag.ToString();
  1030. BaseUtil.CleanControlsText(bc_name, bc_code, bg_name, bg_code, mb_badremark, nrg_name, nrg_code, nr_name, nr_code, so_name, so_code, mbr_dutyname, mbr_dutycode, mbc_component);
  1031. mbl_locdgv.DataSource = null;
  1032. mbp_partdgv.DataSource = null;
  1033. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  1034. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  1035. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  1036. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  1037. // mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  1038. mbr_id = "";
  1039. SaveRepairInf.Enabled = true;
  1040. }
  1041. if (e.Node.Level == 1)
  1042. {
  1043. //展示父节点信息
  1044. mb_id = e.Node.Parent.Tag.ToString();
  1045. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  1046. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  1047. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  1048. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  1049. //展示子节点信息
  1050. mbr_id = e.Node.Tag.ToString();
  1051. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  1052. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  1053. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  1054. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  1055. so_code.Text = BadInf_2[mbr_id]["so_code"];
  1056. so_name.Text = BadInf_2[mbr_id]["so_name"];
  1057. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  1058. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];
  1059. mb_badremark.Text = BadInf_2[mbr_id]["mbr_remark"];
  1060. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  1061. //加载两个Grid的数据源
  1062. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  1063. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  1064. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc,mbl_orispeccode from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  1065. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  1066. SaveRepairInf.Enabled = false;
  1067. }
  1068. }
  1069. private void normalButton1_Click(object sender, EventArgs e)
  1070. {
  1071. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + GetSNCode.Text + "' and ms_status=3", "select");
  1072. if (dt.Rows.Count > 0)
  1073. {
  1074. if (mb_id != "")
  1075. {
  1076. string delete1 = "delete from makebadrsloc where mbl_mbrid in (select mbr_id from makebadreason where mbr_mbid = '" + mb_id + "' )";
  1077. string delete2 = "delete from makebadrspart where mbp_mbrid in (select mbr_id from makebadreason where mbr_mbid = '" + mb_id + "' )";
  1078. string delete3 = "delete from makebadrscom where mbc_mbrid in (select mbr_id from makebadreason where mbr_mbid = '" + mb_id + "' )";
  1079. string delete4 = "delete from makebadreason where mbr_mbid='" + mb_id + "'";
  1080. string delete = "delete from makebad where mb_id = '" + mb_id + "'";
  1081. dh.ExecuteSQLTran(delete1, delete2, delete3, delete4, delete);
  1082. OperatResult.AppendText(">>删除成功\n", Color.Green);
  1083. BaseUtil.CleanControlsText(bc_name, bc_code, bg_name, bg_code, mb_badremark, nrg_name, nrg_code, nr_name, nr_code, so_name, so_code, mbr_dutyname, mbr_dutycode, mbc_component);
  1084. mbp_partdgv.DataSource = null;
  1085. mbl_locdgv.DataSource = null;
  1086. mb_id = "";
  1087. //删除后重新加载Tree的信息
  1088. LoadBadInfTree(sender, e);
  1089. }
  1090. else OperatResult.AppendText(">>必须选择不良现象\n", Color.Red);
  1091. }
  1092. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  1093. }
  1094. private void snCollectionBox1_KeyDown(object sender, KeyEventArgs e)
  1095. {
  1096. if (e.KeyCode == Keys.Enter)
  1097. {
  1098. if (retsn.Text != "")
  1099. {
  1100. if (dh.CheckExist("makeserial", "ms_sncode = '" + retsn.Text + "' and MS_IFCCLEAN is not null"))
  1101. {
  1102. dh.ExecuteSql("update makeserial set MS_IFCCLEAN ='' where ms_sncode = '" + retsn.Text + "'", "select");
  1103. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "完成清空写入信息", "完成清空写入信息", retsn.Text, "");
  1104. OperatResult.AppendText(">>" + retsn.Text + "序列号清空写入信息完成\n", Color.Green, retsn);
  1105. }
  1106. else OperatResult.AppendText(">>" + retsn.Text + "序列号不存在或不需要录入\n", Color.Red, retsn);
  1107. }
  1108. else OperatResult.AppendText(">>" + retsn.Text + "录入不可为空\n", Color.Red, retsn);
  1109. }
  1110. }
  1111. int i = 0;
  1112. private void timer1_Tick(object sender, EventArgs e)
  1113. {
  1114. if (GetSNCode.Text == "" && cd_stepcode.Text != "")
  1115. {
  1116. i = i + 1;
  1117. }
  1118. if (i > 300 && GetSNCode.Text == "" && cd_stepcode.Text != "")
  1119. {
  1120. i = 0;
  1121. cd_stepcode.Text = "";
  1122. OperatResult.AppendText(">>清空回流工序\n", Color.Black);
  1123. }
  1124. }
  1125. private void normalButton2_Click(object sender, EventArgs e)
  1126. {
  1127. if (ms_sncode.Text != "")
  1128. {
  1129. //判断是否有无法维修的记录
  1130. int ScrapNum = int.Parse(dh.getFieldDataByCondition("makebadreason left join makebad on mb_id=mbr_mbid", "count(0) cn", "mb_sncode='" + ms_sncode.Text + "' and mb_status=0").ToString());
  1131. if (ScrapNum == 0)
  1132. OperatResult.AppendText(">>" + ms_sncode.Text + "退料必须维护不良原因\n", Color.Red);
  1133. else
  1134. {
  1135. string confirm = MessageBox.Show(this.ParentForm, "此操作不可撤销,是否确认退料", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk).ToString();
  1136. if (confirm == "Yes")
  1137. {
  1138. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcode", "ms_code" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  1139. if (dt.Rows.Count > 0)
  1140. {
  1141. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  1142. string reworkcode = dt.Rows[0]["ms_reworkcode"].ToString();
  1143. string ms_code = dt.Rows[0]["ms_code"].ToString();
  1144. if (ms_ifrework == "0")
  1145. {
  1146. dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=5,ms_nextstepcode=''", "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  1147. }
  1148. else
  1149. {
  1150. sqls.Clear();
  1151. sqls.Add("update makeserial set ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=5,ms_reworkstatus= 5,ms_nextstepcode='' where ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  1152. sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_reworkcheckno.Text + "'");
  1153. sqls.Add("delete from oqcbatchdetail where obd_sncode='" + ms_sncode.Text + "' and obd_checkno='" + ms_reworkcheckno.Text + "'");
  1154. sqls.Add("update ReworkDetail set rd_rwstatus='退料' where rd_reid=(select re_id from rework where re_code='" + reworkcode + "') and rd_sncode='" + reworkcode + "'");
  1155. dh.ExecuteSQLTran(sqls.ToArray());
  1156. }
  1157. dh.ExecuteSql("update MAKESOURCESTOCK set mss_remain = mss_remain + MSS_BASEQTY,MSS_INVALIDTIME = null,mss_useqty = mss_useqty-MSS_BASEQTY where mss_barcode in (select cm_barcode from CRAFTMATERIAL where cm_mscode = '" + ms_code + "' and cm_makecode = '" + macode + "' and cm_status = 0) and mss_makecode = '" + macode + "' ", "update");
  1158. dh.ExecuteSql(" merge into barcode using (select cm_barcode,cm_inqty from CRAFTMATERIAL where cm_mscode = '" + ms_code + "' and cm_makecode = '" + macode + "' and cm_status = 0) A on (barcode.bar_code = A.cm_barcode) when matched then update set bar_remain = bar_remain + cm_inqty ", "update");
  1159. }
  1160. dh.ExecuteSql("update makebad set mb_status=-2,mb_okman ='" + User.UserName + "' where mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status = 0", "update");
  1161. dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1", "mcd_macode='" + ms_makecode.Text + "' and mcd_stepcode='" + ms_stepcode + "'");
  1162. dh.UpdateByCondition("make", "MA_NGMADEQTY=nvl(MA_NGMADEQTY,0)+1,ma_qty = ma_qty+1", "ma_code='" + macode + "'");
  1163. LogicHandler.InsertMakeProcess(ms_sncode.Text, ms_makecode.Text, User.UserSourceCode, "退料", "序列号退料", User.UserCode);
  1164. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "退料", "序列号退料", ms_sncode.Text, ms_checkno.Text);
  1165. OperatResult.AppendText(">>退料成功\n", Color.Green);
  1166. GetSNCode.Clear();
  1167. GetSNCode.Focus();
  1168. BaseUtil.CleanForm(this);
  1169. BadCodeTree.Nodes.Clear();
  1170. }
  1171. }
  1172. }
  1173. else OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  1174. }
  1175. private void badgroup_SelectedIndexChanged(object sender, EventArgs e)
  1176. {
  1177. LoadBadCodeListView();
  1178. }
  1179. }
  1180. }