Make_Repair.cs 62 KB

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