Make_Repair.cs 62 KB

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