Make_Repair_AfterSale.cs 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021
  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_Repair_AfterSale : 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. DataTable Dbfind;
  39. public Make_Repair_AfterSale()
  40. {
  41. InitializeComponent();
  42. }
  43. private void Make_Repair_Load(object sender, EventArgs e)
  44. {
  45. //为DBFind配置Call和Form的名称
  46. cr_code.FormName = Name;
  47. cr_code.TableName = "craft";
  48. cr_code.SelectField = "cr_name # 工艺名称,cr_code # 工艺编号,cr_prodcode # 物料编号";
  49. cr_code.SetValueField = new string[] { "cr_code" };
  50. cr_code.DBTitle = "回流工艺";
  51. cr_code.DbChange += Cr_code_DbChange;
  52. cd_stepcode.FormName = Name;
  53. cd_stepcode.TableName = "craftdetail left join step on st_code=cd_stepcode left join craft on cd_crid=cr_id";
  54. cd_stepcode.SetValueField = new string[] { "cd_stepcode" };
  55. cd_stepcode.SelectField = "cd_stepname # 工序名称 ,cd_stepcode # 工序编号,cd_stepno # 执行顺序";
  56. cd_stepcode.DBTitle = "回流工序";
  57. cd_stepcode.DbChange += Cd_stepcode_DbChange;
  58. bd_soncode.FormName = Name;
  59. bd_soncode.TableName = "bom left join bomdetail on bd_bomid=bo_id left join product on bd_soncode=pr_code";
  60. bd_soncode.SetValueField = new string[] { "bd_soncode" };
  61. bd_soncode.SelectField = "bd_soncode # 子件编号,pr_detail # 物料名称,pr_spec # 物料规格,bd_location # 位号";
  62. bd_soncode.DBTitle = "不良零件";
  63. bd_soncode.DbChange += Prodcode_DbChange;
  64. //nrg_name.BringToFront();
  65. 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)";
  66. nrg_name.Field = "nrg_name";
  67. nrg_name.ValueField = "nrg_code";
  68. nrg_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  69. 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 + "' ";
  70. nr_name.Field = "nr_name";
  71. nr_name.ValueField = "nr_code";
  72. 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) ";
  73. mbr_dutyname.Field = "nd_name";
  74. mbr_dutyname.ValueField = "nd_code";
  75. mbr_dutyname.Condition = " 1=1 ORDER BY ROWNUM asc";
  76. 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)";
  77. so_name.Field = "so_name";
  78. so_name.ValueField = "so_code";
  79. so_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  80. asc.controllInitializeSize(this);
  81. mbc_component.SendToBack();
  82. so_name.SendToBack();
  83. mbl_loc.SendToBack();
  84. bd_soncode.SendToBack();
  85. mbp_partdgv.SendToBack();
  86. mbp_part_label.SendToBack();
  87. dh = SystemInf.dh;
  88. GetSNCode.Focus();
  89. }
  90. private void Prodcode_DbChange(object sender, EventArgs e)
  91. {
  92. Dbfind = bd_soncode.ReturnData;
  93. BaseUtil.SetFormValue(this.Controls, Dbfind);
  94. if (bd_soncode.Text != "")
  95. {
  96. if (mbr_id != "")
  97. {
  98. if (!dh.CheckExist("makebadrspart", "mbp_sncode='" + GetSNCode.Text + "' and mbp_part='" + bd_soncode.Text + "' and mbp_badcode='" + bc_code.Text + "'"))
  99. {
  100. sql.Clear();
  101. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  102. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  103. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  104. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  105. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  106. dh.ExecuteSql(sql.GetString(), "insert");
  107. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  108. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  109. }
  110. }
  111. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  112. }
  113. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  114. }
  115. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  116. {
  117. Dbfind = cd_stepcode.ReturnData;
  118. BaseUtil.SetFormValue(this.Controls, Dbfind);
  119. }
  120. private void Cr_code_DbChange(object sender, EventArgs e)
  121. {
  122. Dbfind = cr_code.ReturnData;
  123. BaseUtil.SetFormValue(this.Controls, Dbfind);
  124. }
  125. private void GetSNCode_KeyDown(object sender, KeyEventArgs e)
  126. {
  127. if (e.KeyCode == Keys.Enter)
  128. {
  129. if (GetSNCode.Text == "")
  130. {
  131. OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  132. BaseUtil.CleanForm(this);
  133. BadCodeTree.Nodes.Clear();
  134. return;
  135. }
  136. sql.Clear();
  137. sql.Append("select ms_status,ms_outboxcode,ms_paststep,ms_reworkstatus,nvl(ms_ifrework,0)ms_ifrework from makeserial left join make ");
  138. sql.Append("on ms_makecode=ma_code where ms_sncode = '" + GetSNCode.Text + "' order by ms_id desc");
  139. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  140. string ms_paststep = "";
  141. if (dt.Rows.Count > 0)
  142. {
  143. string ms_status = dt.Rows[0]["ms_status"].ToString();
  144. ms_paststep = dt.Rows[0]["ms_paststep"].ToString();
  145. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  146. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  147. if (dt.Rows[0]["ms_outboxcode"].ToString() != "")
  148. {
  149. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已装箱,请先进行拆箱\n", Color.Red);
  150. BaseUtil.CleanForm(this);
  151. BadCodeTree.Nodes.Clear();
  152. return;
  153. }
  154. //如果不是返修序列号执行原来的步骤
  155. //if (ifrework == "0")
  156. //{
  157. // if (ms_status == "4")
  158. // {
  159. // OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已处于报废状态\n", Color.Red);
  160. // BaseUtil.CleanForm(this);
  161. // BadCodeTree.Nodes.Clear();
  162. // return;
  163. // }
  164. // if (ms_status != "3")
  165. // {
  166. // OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不处于维修状态\n", Color.Red);
  167. // BaseUtil.CleanForm(this);
  168. // BadCodeTree.Nodes.Clear();
  169. // return;
  170. // }
  171. //}
  172. //else
  173. //{
  174. // if (reworkstatus == "4")
  175. // {
  176. // OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "已处于报废状态\n", Color.Red);
  177. // BaseUtil.CleanForm(this);
  178. // BadCodeTree.Nodes.Clear();
  179. // return;
  180. // }
  181. // if (reworkstatus != "0" && reworkstatus != "3")
  182. // {
  183. // OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不处于维修状态\n", Color.Red);
  184. // BaseUtil.CleanForm(this);
  185. // BadCodeTree.Nodes.Clear();
  186. // return;
  187. // }
  188. //}
  189. }
  190. else
  191. {
  192. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不存在\n", Color.Red);
  193. BaseUtil.CleanForm(this);
  194. BadCodeTree.Nodes.Clear();
  195. return;
  196. }
  197. //dt = (DataTable)dh.ExecuteSql("select mb_stepcode from makebad where mb_sncode='" + GetSNCode.Text + "' and mb_status=0 order by mb_id desc", "select");
  198. ////打不良的资源和当前资源相等可以快速维修,无须登录维修资源
  199. //bool QuickRepair = false;
  200. //if (dt.Rows.Count > 0)
  201. //{
  202. // if (dt.Rows[0]["mb_stepcode"].ToString() == User.CurrentStepCode)
  203. // {
  204. // QuickRepair = true;
  205. // }
  206. //}
  207. string ErrorMessage = "";
  208. //验证工序是否正确
  209. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  210. {
  211. BadInf_1.Clear();
  212. string oStatus = "";
  213. if (LogicHandler.GetMakeInfo(GetSNCode.Text, out macode, out oStatus, out ErrorMessage))
  214. {
  215. //验证makeserial或者ms_firstsn表序列号是否存在
  216. sql.Clear();
  217. sql.Append("select 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 ");
  218. 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(");
  219. sql.Append("select '" + GetSNCode.Text + "' from dual union select firstsn from makesnrelation where ");
  220. 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");
  221. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  222. if (dt.Rows.Count > 0)
  223. {
  224. msid = dt.Rows[0]["ms_id"].ToString();
  225. ms_stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  226. BaseUtil.SetFormValue(this.Controls, dt);
  227. //判断是否当前工单途程的上料记录
  228. firstsn = dt.Rows[0]["ms_firstsn"].ToString();
  229. string ma_bomversion = dt.Rows[0]["ma_bomversion"].ToString();
  230. string cdstepcode = "";
  231. //sql.Clear();
  232. //sql.Append("select cm_craftcode,cm_stepcode,cm_soncode,min(cm_indate)cm_indate,sum(case when cm_status=-1 ");
  233. //sql.Append("then 0 else 1 end)qty from craftmaterial left join product on pr_code=cm_soncode where(cm_sncode ");
  234. //sql.Append("in (select sn from makesnrelation where firstsn='" + firstsn + "' union select '" + firstsn + "' from dual)) ");
  235. //sql.Append("and cm_craftcode='" + cr_code.Text + "'and nvl(cm_lastdeco,0)<>0 group by cm_craftcode,cm_stepcode,cm_soncode having ");
  236. //sql.Append("sum(case when cm_status=-1 then 0 else 1 end)=0 order by cm_indate");
  237. sql.Clear();
  238. 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 ");
  239. sql.Append("sp_craftcode='" + cr_code.Text + "' And sp_mothercode ='" + ms_prodcode.Text + "' and sp_tracekind=1 ");
  240. //sql.Append("sp_craftcode=v_v_mscraftcode and sp_stepcode='' And sp_mothercode ='"+ms_prodcode.Text+"' and sp_tracekind=1");
  241. sql.Append("and not exists(select 1 from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union ");
  242. sql.Append("select sn from makesnrelation where firstsn='" + firstsn + "') and cm_makecode='" + macode + "' and ");
  243. 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");
  244. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  245. if (dt.Rows.Count > 0)
  246. {
  247. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  248. //如果本工序包含老化则默认选择本工序,否则选择上料的后一道工序
  249. //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")
  250. // cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  251. //else
  252. //{
  253. //string nextstep = LogicHandler.GetNextStep(dt.Rows[0]["cm_craftcode"].ToString(), dt.Rows[0]["cm_stepcode"].ToString(), ms_prodcode.Text);
  254. // if (ms_paststep.Contains(nextstep))
  255. // {
  256. // cdstepcode = nextstep;
  257. // }
  258. // else
  259. // {
  260. // cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  261. // }
  262. //}
  263. }
  264. else
  265. {
  266. sql.Clear();
  267. sql.Append("select cm_craftcode,cm_stepcode,cm_soncode,min(cm_indate)cm_indate,sum(case when cm_status=-1 ");
  268. sql.Append("then 0 else 1 end)qty from craftmaterial left join product on pr_code=cm_soncode where(cm_sncode ");
  269. sql.Append("in (select sn from makesnrelation where firstsn='" + firstsn + "' union select '" + firstsn + "' from dual)) ");
  270. sql.Append("and cm_craftcode='" + cr_code.Text + "' group by cm_craftcode,cm_stepcode,cm_soncode having ");
  271. sql.Append("sum(case when cm_status=-1 then 0 else 1 end)=0 order by cm_indate");
  272. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  273. if (dt.Rows.Count > 0)
  274. {
  275. cdstepcode = dt.Rows[0]["cm_stepcode"].ToString();
  276. }
  277. }
  278. if (cdstepcode == "")
  279. {
  280. //序号小于等于当前不良的序号
  281. 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();
  282. sql.Clear();
  283. sql.Append("select cd_stepcode from craft left join craftdetail on cr_id =cd_crid where ");
  284. sql.Append("cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' and ");
  285. sql.Append("nvl(cd_ifspc,0)<>0 and cd_detno <='" + currentdetno + "' order by cd_detno desc");
  286. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  287. if (dt.Rows.Count > 0)
  288. {
  289. cdstepcode = dt.Rows[0][0].ToString();
  290. }
  291. }
  292. //如果ms_stepcode和扣料工序均没有查到返修的工序
  293. if (cdstepcode == "")
  294. {
  295. //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();
  296. //if (flowback != "")
  297. //{
  298. // cdstepcode = flowback;
  299. //}
  300. //else
  301. //{
  302. // cdstepcode = ms_stepcode;
  303. //}
  304. }
  305. cd_stepcode.Text = cdstepcode;
  306. //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")
  307. // cd_stepcode.Enabled = false;
  308. //else
  309. // cd_stepcode.Enabled = true;
  310. LoadBadInfTree(sender, e);
  311. }
  312. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  313. }
  314. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  315. }
  316. else OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  317. }
  318. }
  319. private void Make_Repair_SizeChanged(object sender, EventArgs e)
  320. {
  321. mbc_component.BringToFront();
  322. so_name.BringToFront();
  323. mbl_loc.BringToFront();
  324. bd_soncode.BringToFront();
  325. mbp_partdgv.BringToFront();
  326. mbp_part_label.BringToFront();
  327. asc.controlAutoSize(this);
  328. mbc_component.SendToBack();
  329. so_name.SendToBack();
  330. mbl_loc.SendToBack();
  331. bd_soncode.SendToBack();
  332. mbp_partdgv.SendToBack();
  333. mbp_part_label.SendToBack();
  334. }
  335. private void BadCodeTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  336. {
  337. if (e.Node.Level == 0)
  338. {
  339. mb_id = e.Node.Tag.ToString();
  340. 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);
  341. mbl_locdgv.DataSource = null;
  342. mbp_partdgv.DataSource = null;
  343. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  344. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  345. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  346. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  347. mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  348. mbr_id = "";
  349. SaveRepairInf.Enabled = true;
  350. }
  351. if (e.Node.Level == 1)
  352. {
  353. //展示父节点信息
  354. mb_id = e.Node.Parent.Tag.ToString();
  355. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  356. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  357. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  358. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  359. //展示子节点信息
  360. mbr_id = e.Node.Tag.ToString();
  361. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  362. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  363. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  364. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  365. so_code.Text = BadInf_2[mbr_id]["so_code"];
  366. so_name.Text = BadInf_2[mbr_id]["so_name"];
  367. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  368. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];
  369. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  370. //加载两个Grid的数据源
  371. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  372. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  373. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  374. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  375. SaveRepairInf.Enabled = false;
  376. }
  377. }
  378. private void LoadBadInfTree(object sender, EventArgs e)
  379. {
  380. BadCodeTree.Nodes.Clear();
  381. sql.Clear();
  382. //不是返工工单时的取当前工单
  383. 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,");
  384. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup ");
  385. sql.Append("on bg_code=mb_bgcode where (mb_sncode='" + (GetSNCode.Text == "" ? ms_sncode.Text : GetSNCode.Text) + "' or mb_mscode='" + (GetSNCode.Text == "" ? ms_sncode.Text : GetSNCode.Text) + "' ) and mb_makecode='" + macode + "' and mb_status=0");
  386. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  387. if (dt.Rows.Count == 0)
  388. {
  389. sql.Clear();
  390. 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, ");
  391. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup on bg_code=mb_bgcode ");
  392. 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");
  393. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  394. }
  395. for (int i = 0; i < dt.Rows.Count; i++)
  396. {
  397. //添加根节点
  398. TreeNode tnode_0 = new TreeNode();
  399. string bg_name = dt.Rows[i]["bg_name"].ToString();
  400. string bc_name = dt.Rows[i]["bc_name"].ToString();
  401. string mb_badcode = dt.Rows[i]["mb_badcode"].ToString();
  402. string mb_bgcode = dt.Rows[i]["mb_bgcode"].ToString();
  403. tnode_0.Text = (bg_name == "" ? mb_bgcode : bg_name) + ":" + (bc_name == "" ? mb_bgcode : bc_name);
  404. tnode_0.Name = dt.Rows[i]["mb_bgcode"].ToString();
  405. //作为Dictionary的主标识
  406. string mb_id = dt.Rows[i]["mb_id"].ToString();
  407. tnode_0.Tag = mb_id;
  408. Dictionary<string, string> dic = new Dictionary<string, string>();
  409. dic.Add("mb_id", mb_id);
  410. dic.Add("mb_sncode", dt.Rows[i]["mb_sncode"].ToString());
  411. dic.Add("mb_badcode", dt.Rows[i]["mb_badcode"].ToString());
  412. dic.Add("mb_bgcode", dt.Rows[i]["mb_bgcode"].ToString());
  413. dic.Add("bc_name", dt.Rows[i]["bc_name"].ToString());
  414. dic.Add("bg_name", dt.Rows[i]["bg_name"].ToString());
  415. dic.Add("mb_badremark", dt.Rows[i]["mb_badremark"].ToString());
  416. if (!BadInf_1.ContainsKey(tnode_0.Tag.ToString()))
  417. BadInf_1.Add(tnode_0.Tag.ToString(), dic);
  418. BadCodeTree.Nodes.Add(tnode_0);
  419. BadCodeTree.SelectedNode = BadCodeTree.Nodes[0];
  420. //添加子节点
  421. sql.Clear();
  422. sql.Append("select mbr_id,mbr_brcode,mbr_brgcode,mbr_solutioncode,so_code,so_name,mbr_dutycode,mbr_dutyname,nd_name,nrg_name");
  423. sql.Append(",nr_name,nr_code,nrg_code from makebadreason left join QUA_NGReason on nr_code=mbr_brcode left join ");
  424. sql.Append("QUA_NGREASONGROUPdet on nrgd_nrcode=nr_code left join QUA_NGREASONGROUP on nrg_id=nrgd_nrgid and ");
  425. sql.Append("mbr_brgcode=nrg_code left join solution on so_code=mbr_solutioncode left join ngduty on nd_code=mbr_dutycode ");
  426. sql.Append("where mbr_mbid=" + mb_id);
  427. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  428. for (int j = 0; j < dt1.Rows.Count; j++)
  429. {
  430. TreeNode tnode_1 = new TreeNode();
  431. //存放子节点的信息
  432. Dictionary<string, string> dic1 = new Dictionary<string, string>();
  433. string mbr_id = dt1.Rows[j]["mbr_id"].ToString();
  434. tnode_1.Tag = mbr_id;
  435. dic1.Add("mbr_id", mbr_id);
  436. dic1.Add("mbr_brcode", dt1.Rows[j]["mbr_id"].ToString());
  437. dic1.Add("mbr_brgcode", dt1.Rows[j]["mbr_brcode"].ToString());
  438. dic1.Add("mbr_solutioncode", dt1.Rows[j]["mbr_solutioncode"].ToString());
  439. dic1.Add("mbr_dutycode", dt1.Rows[j]["mbr_dutycode"].ToString());
  440. dic1.Add("mbr_dutyname", dt1.Rows[j]["mbr_dutyname"].ToString());
  441. dic1.Add("nd_name", dt1.Rows[j]["nd_name"].ToString());
  442. dic1.Add("so_name", dt1.Rows[j]["so_name"].ToString());
  443. dic1.Add("so_code", dt1.Rows[j]["so_code"].ToString());
  444. dic1.Add("nrg_name", dt1.Rows[j]["nrg_name"].ToString());
  445. dic1.Add("nrg_code", dt1.Rows[j]["nrg_code"].ToString());
  446. dic1.Add("nr_name", dt1.Rows[j]["nr_name"].ToString());
  447. dic1.Add("nr_code", dt1.Rows[j]["nr_code"].ToString());
  448. tnode_1.Text = dt1.Rows[j]["nr_name"].ToString();
  449. if (!BadInf_2.ContainsKey(mbr_id))
  450. BadInf_2.Add(mbr_id, dic1);
  451. tnode_0.Nodes.Add(tnode_1);
  452. }
  453. }
  454. try
  455. {
  456. if (bg_code.Text != "")
  457. BadCodeTree.Nodes[bg_code.Text].Expand();
  458. }
  459. catch (Exception) { }
  460. }
  461. private void RefreshTreeView_Click(object sender, EventArgs e)
  462. {
  463. LoadBadInfTree(sender, e);
  464. }
  465. private void RepairComplete_Click(object sender, EventArgs e)
  466. {
  467. if (ms_sncode.Text == "")
  468. {
  469. OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  470. return;
  471. }
  472. if (ifrework != "0" && reworkstatus == "0")
  473. {
  474. if (dh.getRowCount("Makebad", "mb_sncode='" + ms_sncode.Text + "' and mb_makecode='" + ms_makecode.Text + "' and mb_status=0") == 0)
  475. {
  476. OperatResult.AppendText(">>维修必须维护不良代码\n", Color.Red);
  477. return;
  478. }
  479. }
  480. //判断是否所有的不良信息都有维护不良原因
  481. 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");
  482. string ErrorMessage = "";
  483. for (int i = 0; i < dt.Rows.Count; i++)
  484. {
  485. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  486. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  487. }
  488. if (ErrorMessage != "")
  489. {
  490. OperatResult.AppendText(">>" + ErrorMessage + "未维护不良原因\n", Color.Red);
  491. return;
  492. }
  493. //如果岗位资源对应工序的版面不为空的时候
  494. if (dh.getFieldDataByCondition("makeserial left join step on ms_stepcode=st_code", "st_table", "ms_id='" + msid + "'").ToString() != "")
  495. {
  496. if (!dh.CheckExist("makebadrsloc", "mbl_mbrid='" + mbr_id + "' and mbl_makecode='" + ms_makecode.Text + "' and mbl_sncode='" + GetSNCode.Text + "' "))
  497. {
  498. OperatResult.AppendText(">>工序存在版面必须维护不良位置\n", Color.Red);
  499. return;
  500. }
  501. }
  502. //查询拆解的物料
  503. sql.Clear();
  504. sql.Append("select distinct cm_soncode from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union ");
  505. 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 ");
  506. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  507. //如果含有序列号物料有被拆解过
  508. if (dt.Rows.Count > 0)
  509. {
  510. string soncode = "";
  511. for (int i = 0; i < dt.Rows.Count; i++)
  512. {
  513. soncode += "'" + dt.Rows[i][0].ToString() + "',";
  514. }
  515. //查询对应的上料记录
  516. sql.Clear();
  517. sql.Append("select cm_soncode from craftmaterial where cm_sncode in (select '" + firstsn + "' from dual union select sn from ");
  518. sql.Append(" makesnrelation where firstsn='" + firstsn + "') and cm_status=0 and cm_soncode in (" + soncode.Substring(0, soncode.Length - 1) + ")");
  519. DataTable LoadSoncode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  520. //查询的结果不相等表示未完成上料
  521. if (dt.Rows.Count != LoadSoncode.Rows.Count)
  522. {
  523. for (int i = 0; i < LoadSoncode.Rows.Count; i++)
  524. {
  525. if (soncode.Contains(LoadSoncode.Rows[i][0].ToString()))
  526. {
  527. soncode = soncode.Replace(LoadSoncode.Rows[i][0].ToString(), "");
  528. }
  529. }
  530. OperatResult.AppendText(">>" + soncode.Replace("'", "") + "物料尚未备料,不允许回流\n", Color.Red);
  531. return;
  532. }
  533. }
  534. dt = (DataTable)dh.ExecuteSql("select cr_id from craft where cr_statuscode='AUDITED' and cr_code='" + cr_code.Text + "'", "select");
  535. if (dt.Rows.Count == 0)
  536. OperatResult.AppendText(">>回流工序不存在\n", Color.Red);
  537. else
  538. {
  539. string cr_id = dt.Rows[0]["cr_id"].ToString();
  540. 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");
  541. if (dt.Rows.Count == 0)
  542. OperatResult.AppendText(">>回流工序不在回流工艺中\n", Color.Red);
  543. else
  544. {
  545. dt = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0) ms_ifrework", "ms_paststep" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  546. List<string> SQLS = new List<string>();
  547. if (dt.Rows.Count > 0)
  548. {
  549. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  550. string ms_paststep = dt.Rows[0]["ms_paststep"].ToString();
  551. //如果回流的执行过的工序为空
  552. if (!ms_paststep.Contains(cd_stepcode.Text) && ms_paststep != "")
  553. {
  554. OperatResult.AppendText(">>不允许回流到未执行的工序\n", Color.Red);
  555. return;
  556. }
  557. if (ms_ifrework == "0")
  558. 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 + "'");
  559. else
  560. 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 + "'");
  561. }
  562. SQLS.Add("update makebad set mb_status=-1 where (mb_sncode='" + ms_sncode.Text + "' or mb_mscode='" + ms_sncode.Text + "') and mb_makecode='" + ms_makecode.Text + "'");
  563. //取消最近拆解部件
  564. SQLS.Add("update craftmaterial set cm_lastdeco=0 where cm_sncode='" + ms_sncode.Text + "' and cm_makecode='" + ms_makecode.Text + "' and nvl(cm_lastdeco,0)<>0");
  565. // SQLS.Add("update MakeBadCount set mbc_status=-1 where mbc_sncode='" + ms_sncode.Text + "'");
  566. dh.ExecuteSQLTran(SQLS.ToArray());
  567. LogicHandler.InsertMakeProcess(ms_sncode.Text, ms_makecode.Text, User.UserSourceCode, "回流工序", "完成维修回流", User.UserCode);
  568. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "回流工序", "完成维修回流", ms_sncode.Text, ms_checkno.Text);
  569. OperatResult.AppendText(">>序列号" + ms_sncode.Text + "回流成功\n", Color.Green);
  570. cd_stepcode.Enabled = true;
  571. BaseUtil.CleanForm(this);
  572. BadCodeTree.Nodes.Clear();
  573. GetSNCode.Clear();
  574. GetSNCode.Focus();
  575. }
  576. }
  577. }
  578. private void Scrap_Click(object sender, EventArgs e)
  579. {
  580. if (ms_sncode.Text != "")
  581. {
  582. //判断是否有无法维修的记录
  583. 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());
  584. if (ScrapNum == 0)
  585. OperatResult.AppendText(">>" + ms_sncode.Text + "报废必须维护不良原因\n", Color.Red);
  586. else
  587. {
  588. string confirm = MessageBox.Show(this.ParentForm, "此操作不可撤销,是否确认报废", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk).ToString();
  589. if (confirm == "Yes")
  590. {
  591. DataTable dt = dh.getFieldsDataByCondition("makeserial", new string[] { "nvl(ms_ifrework,0)ms_ifrework", "ms_reworkcode" }, "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  592. if (dt.Rows.Count > 0)
  593. {
  594. string ms_ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  595. string reworkcode = dt.Rows[0]["ms_reworkcode"].ToString();
  596. if (ms_ifrework == "0")
  597. {
  598. dh.UpdateByCondition("makeserial", "ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=4,ms_nextstepcode='',ms_stepcode='" + User.CurrentStepCode + "'", "ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  599. }
  600. else
  601. {
  602. sqls.Clear();
  603. sqls.Add("update makeserial set ms_paststep = ms_paststep ||'," + User.CurrentStepCode + "',ms_status=4,ms_reworkstatus= 4,ms_nextstepcode='',ms_stepcode='" + User.CurrentStepCode + "' where ms_sncode='" + ms_sncode.Text + "' and ms_makecode='" + macode + "'");
  604. sqls.Add("update oqcbatch set ob_nowcheckqty=ob_nowcheckqty-1 where ob_checkno='" + ms_reworkcheckno.Text + "'");
  605. sqls.Add("delete from oqcbatchdetail where obd_sncode='" + ms_sncode.Text + "' and obd_checkno='" + ms_reworkcheckno.Text + "'");
  606. sqls.Add("update ReworkDetail set rd_rwstatus='报废' where rd_reid=(select re_id from rework where re_code='" + reworkcode + "') and rd_sncode='" + reworkcode + "'");
  607. dh.ExecuteSQLTran(sqls.ToArray());
  608. }
  609. }
  610. dh.UpdateByCondition("makecraftdetail", "mcd_inqty=mcd_inqty-1,mcd_outqty=mcd_outqty-1", "mcd_macode='" + ms_makecode.Text + "' and mcd_stepcode='" + ms_stepcode + "'");
  611. dh.UpdateByCondition("make", "MA_NGMADEQTY=nvl(MA_NGMADEQTY,0)+1", "ma_code='" + macode + "'");
  612. LogicHandler.InsertMakeProcess(ms_sncode.Text, ms_makecode.Text, User.UserSourceCode, "报废", "序列号报废", User.UserCode);
  613. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, macode, User.UserLineCode, User.UserSourceCode, "报废", "序列号报废", ms_sncode.Text, ms_checkno.Text);
  614. OperatResult.AppendText(">>报废成功\n", Color.Green);
  615. GetSNCode.Clear();
  616. BaseUtil.CleanForm(this);
  617. BadCodeTree.Nodes.Clear();
  618. }
  619. }
  620. }
  621. else OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  622. }
  623. private void NewBadCode_Click(object sender, EventArgs e)
  624. {
  625. if (GetSNCode.Text == "" || macode == null || macode == "")
  626. {
  627. OperatResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red);
  628. }
  629. else
  630. {
  631. Make_NewBadCode badcode = new Make_NewBadCode(GetSNCode.Text, macode);
  632. badcode.FormClosed += LoadBadInfTree;
  633. BaseUtil.SetFormCenter(badcode);
  634. badcode.ShowDialog();
  635. }
  636. }
  637. private void NewRepairInf_Click(object sender, EventArgs e)
  638. {
  639. if (bg_name.Text == "" && bc_name.Text == "")
  640. {
  641. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  642. }
  643. else
  644. {
  645. Make_NewMatainInf mataininf = new Make_NewMatainInf(bg_name.Text, bg_code.Text, bc_name.Text, bc_code.Text, GetSNCode.Text, msid, mb_id);
  646. mataininf.FormClosed += LoadBadInfTree;
  647. BaseUtil.SetFormCenter(mataininf);
  648. mataininf.ShowDialog();
  649. }
  650. }
  651. private void SaveRepairInf_Click(object sender, EventArgs e)
  652. {
  653. string ErrorMessage = "";
  654. if (bg_name.Text == "" || bc_name.Text == "")
  655. {
  656. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  657. return;
  658. }
  659. if (nrg_name.Text == "")
  660. ErrorMessage += " 不良原因组 ";
  661. if (nr_name.Text == "")
  662. ErrorMessage += " 不良原因 ";
  663. if (mbr_dutyname.Text == "")
  664. ErrorMessage += " 责任别 ";
  665. if (mbr_dutyname.Text == "物料问题" && mbc_component.Text == "")
  666. ErrorMessage += "责任别为物料问题时必须选择不良零件";
  667. if (ErrorMessage != "")
  668. {
  669. ErrorMessage += "不能为空";
  670. OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  671. return;
  672. }
  673. string mbr_id = dh.GetSEQ("makebadreason_seq");
  674. //存在不良组件进行提示
  675. 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"))
  676. {
  677. OperatResult.AppendText(">>不良代码【" + bc_name.Text + "】已存在不良原因【" + nr_name.Text + "】\n", Color.Red);
  678. return;
  679. }
  680. if (!dh.CheckExist("QUA_NGREASONGROUP", "nrg_name='" + nrg_name.Text + "'"))
  681. {
  682. OperatResult.AppendText(">>不良原因组不存在\n", Color.Red);
  683. return;
  684. }
  685. if (!dh.CheckExist("QUA_NGReason", "nr_name='" + nr_name.Text + "'"))
  686. {
  687. OperatResult.AppendText(">>不良原因不存在\n", Color.Red);
  688. return;
  689. }
  690. if (!dh.CheckExist("ngduty", "nd_name='" + mbr_dutyname.Text + "'"))
  691. {
  692. OperatResult.AppendText(">>责任别不存在\n", Color.Red);
  693. return;
  694. }
  695. if (!dh.CheckExist("solution", "so_name='" + so_name.Text + "'"))
  696. {
  697. OperatResult.AppendText(">>解决方案不存在\n", Color.Red);
  698. return;
  699. }
  700. //保存选择记录至后台,根据岗位资源代码记录
  701. 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");
  702. 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");
  703. 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");
  704. 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");
  705. //保存不良原因
  706. sql.Clear();
  707. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  708. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  709. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname,mbr_remark) select '" + mb_id + "','" + mbr_id + "','" + nr_code.Text + "',");
  710. sql.Append("'" + so_code.Text + "','" + mbr_dutyname.Text + "','" + nrg_code.Text + "','" + bc_code.Text + "',");
  711. 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");
  712. dh.ExecuteSql(sql.GetString(), "insert");
  713. if (mbc_component.Text != "")
  714. {
  715. sql.Clear();
  716. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  717. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  718. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbc_component.Text + "',");
  719. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + ms_sncode.Text + "','" + ms_makecode.Text + "',sysdate,'" + User.UserCode + "')");
  720. dh.ExecuteSql(sql.GetString(), "insert");
  721. }
  722. OperatResult.AppendText(">>不良原因保存成功\n", Color.Green);
  723. SaveRepairInf.Enabled = false;
  724. LoadBadInfTree(sender, e);
  725. }
  726. private void DeleteRepairInf_Click(object sender, EventArgs e)
  727. {
  728. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + GetSNCode.Text + "' and ms_status=3", "select");
  729. if (dt.Rows.Count > 0)
  730. {
  731. if (mbr_id != "")
  732. {
  733. string delete1 = "delete from makebadrsloc where mbl_mbrid='" + mbr_id + "'";
  734. string delete2 = "delete from makebadrspart where mbp_mbrid='" + mbr_id + "'";
  735. string delete3 = "delete from makebadrscom where mbc_mbrid='" + mbr_id + "'";
  736. string delete4 = "delete from makebadreason where mbr_id='" + mbr_id + "'";
  737. dh.ExecuteSQLTran(delete1, delete2, delete3, delete4);
  738. OperatResult.AppendText(">>删除成功\n", Color.Green);
  739. 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);
  740. mbp_partdgv.DataSource = null;
  741. mbl_locdgv.DataSource = null;
  742. mbr_id = "";
  743. //删除后重新加载Tree的信息
  744. LoadBadInfTree(sender, e);
  745. }
  746. else OperatResult.AppendText(">>必须选择不良原因\n", Color.Red);
  747. }
  748. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  749. }
  750. private void SaveBadLocation_Click(object sender, EventArgs e)
  751. {
  752. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode from makeserial where ms_id='" + msid + "' and ms_sncode='" + GetSNCode.Text + "' and ms_status=3", "select");
  753. if (dt.Rows.Count > 0)
  754. {
  755. if (mbl_loc.Text != "")
  756. {
  757. if (mbr_id != "")
  758. {
  759. if (!dh.CheckExist("makebadrsloc", "mbl_mbrid='" + mbr_id + "' and mbl_sncode='" + GetSNCode.Text + "' and mbl_loc='" + mbl_loc.Text.ToUpper() + "'"))
  760. {
  761. sql.Clear();
  762. sql.Append("insert into makebadrsloc(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,");
  763. sql.Append("mbl_sncode,mbl_makecode,mbl_indate ,mbl_inman) select makebadrsloc_seq.nextval," + mbr_id);
  764. sql.Append(",'" + mbl_loc.Text.ToUpper() + "','" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  765. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  766. dh.ExecuteSql(sql.GetString(), "insert");
  767. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  768. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  769. sql.Clear();
  770. sql.Append("with temp1 as (select bd_soncode,bd_location from bomdetail,bom where bo_id=bd_bomid ");
  771. sql.Append(" start with bo_mothercode='" + ms_prodcode.Text + "' connect by bo_mothercode= prior bd_soncode) ");
  772. sql.Append("select bd_soncode from temp1 where instr(','||bd_location||',','," + mbl_loc.Text.ToUpper() + ",')>0");
  773. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  774. if (dt.Rows.Count > 0)
  775. {
  776. sql.Clear();
  777. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  778. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  779. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + dt.Rows[0][0].ToString() + "',");
  780. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  781. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  782. dh.ExecuteSql(sql.GetString(), "insert");
  783. dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  784. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  785. mbl_loc.Clear();
  786. }
  787. }
  788. else OperatResult.AppendText(">>已存在该不良位置\n", Color.Red);
  789. }
  790. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  791. }
  792. else OperatResult.AppendText(">>不良位置不能为空\n", Color.Red);
  793. }
  794. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  795. }
  796. private void nr_name_TextChanged(object sender, EventArgs e)
  797. {
  798. if (nr_name.Text == "")
  799. SaveBadLocation.Enabled = false;
  800. else
  801. SaveBadLocation.Enabled = true;
  802. }
  803. private void mbl_loc_KeyDown(object sender, KeyEventArgs e)
  804. {
  805. if (e.KeyCode == Keys.Enter)
  806. SaveBadLocation_Click(sender, e);
  807. }
  808. private void prodcode_TextKeyDown(object sender, KeyEventArgs e)
  809. {
  810. if (e.KeyCode == Keys.Enter)
  811. {
  812. if (bd_soncode.Text != "")
  813. {
  814. if (mbr_id != "")
  815. {
  816. sql.Clear();
  817. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  818. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  819. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  820. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  821. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  822. dh.ExecuteSql(sql.GetString(), "insert");
  823. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  824. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  825. }
  826. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  827. }
  828. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  829. }
  830. }
  831. private void cr_code_UserControlTextChanged(object sender, EventArgs e)
  832. {
  833. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  834. }
  835. private void Clean_Click(object sender, EventArgs e)
  836. {
  837. OperatResult.Clear();
  838. }
  839. private void mbl_locdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  840. {
  841. if (e.RowIndex >= 0)
  842. {
  843. if (mbl_locdgv.Columns[e.ColumnIndex].Name == "DeletePos")
  844. {
  845. dh.ExecuteSql("delete from makebadrsloc where mbl_id='" + mbl_locdgv.Rows[e.RowIndex].Cells["mbl_id"].Value.ToString() + "'", "insert");
  846. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  847. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  848. }
  849. }
  850. }
  851. private void mbp_partdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  852. {
  853. if (e.RowIndex >= 0)
  854. {
  855. if (mbp_partdgv.Columns[e.ColumnIndex].Name == "DeleteCom")
  856. {
  857. dh.ExecuteSql("delete from makebadrspart where mbp_id='" + mbp_partdgv.Rows[e.RowIndex].Cells["mbp_id"].Value.ToString() + "'", "insert");
  858. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  859. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  860. }
  861. }
  862. }
  863. private void Make_Repair_FormClosing(object sender, FormClosingEventArgs e)
  864. {
  865. dh.Dispose();
  866. }
  867. private void ms_prodcode_TextChanged(object sender, EventArgs e)
  868. {
  869. if (ms_prodcode.Text != "")
  870. cr_code.Condition = "cr_prodcode='" + ms_prodcode.Text + "'";
  871. else
  872. cr_code.Condition = "";
  873. bd_soncode.Condition = "bd_mothercode='" + ms_prodcode.Text + "' and NVL(bd_usestatus,' ')<>'DISABLE'";
  874. //设置工序的条件
  875. cd_stepcode.Condition = "ST_STATUSCODE='AUDITED' and cr_code='" + cr_code.Text + "' and cr_prodcode='" + ms_prodcode.Text + "' order by cd_stepno";
  876. }
  877. public void RefreshData()
  878. {
  879. GetSNCode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  880. }
  881. private void nr_name_UserControlTextChanged(object sender, EventArgs e)
  882. {
  883. if (nr_name.Text != "")
  884. {
  885. SaveBadLocation.Enabled = true;
  886. if (nrg_name.Text == "")
  887. {
  888. OperatResult.AppendText(">>请先填写不良代码组\n", Color.Red);
  889. nr_name.Text = "";
  890. }
  891. else
  892. {
  893. if (nr_code.Text == "" || (nr_code.Text != "" && nr_code.Text != nr_name.Value))
  894. nr_code.Text = nr_name.Value;
  895. }
  896. }
  897. else SaveBadLocation.Enabled = false;
  898. }
  899. private void nrg_name_UserControlTextChanged(object sender, EventArgs e)
  900. {
  901. if (nrg_code.Text == "" || (nrg_code.Text != "" && nrg_code.Text != nrg_name.Value))
  902. nrg_code.Text = nrg_name.Value;
  903. nr_name.Condition = "nrg_code in('" + (nrg_code.Text == "" ? "''" : nrg_code.Text) + "')";
  904. }
  905. private void mbr_dutyname_UserControlTextChanged(object sender, EventArgs e)
  906. {
  907. if (mbr_dutycode.Text == "" || (mbr_dutycode.Text != "" && mbr_dutycode.Text != mbr_dutyname.Value))
  908. mbr_dutycode.Text = mbr_dutyname.Value;
  909. }
  910. private void mbc_component_UserControlTextChanged(object sender, EventArgs e)
  911. {
  912. }
  913. private void so_name_UserControlTextChanged(object sender, EventArgs e)
  914. {
  915. if (so_code.Text == "" || (so_code.Text != "" && so_code.Text != so_name.Value))
  916. so_code.Text = so_name.Value;
  917. }
  918. private void BadCodeTree_AfterSelect(object sender, TreeViewEventArgs e)
  919. {
  920. if (e.Node.Level == 0)
  921. {
  922. mb_id = e.Node.Tag.ToString();
  923. 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);
  924. mbl_locdgv.DataSource = null;
  925. mbp_partdgv.DataSource = null;
  926. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  927. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  928. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  929. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  930. mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  931. mbr_id = "";
  932. SaveRepairInf.Enabled = true;
  933. }
  934. if (e.Node.Level == 1)
  935. {
  936. //展示父节点信息
  937. mb_id = e.Node.Parent.Tag.ToString();
  938. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  939. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  940. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  941. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  942. //展示子节点信息
  943. mbr_id = e.Node.Tag.ToString();
  944. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  945. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  946. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  947. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  948. so_code.Text = BadInf_2[mbr_id]["so_code"];
  949. so_name.Text = BadInf_2[mbr_id]["so_name"];
  950. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  951. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];
  952. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  953. //加载两个Grid的数据源
  954. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  955. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  956. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  957. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  958. SaveRepairInf.Enabled = false;
  959. }
  960. }
  961. }
  962. }