Make_Repair_AfterSale.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using UAS_MES_NEW.CustomControl.DataGrid_View;
  9. using UAS_MES_NEW.CustomControl.TextBoxWithIcon;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicMethod;
  13. namespace UAS_MES_NEW.Make
  14. {
  15. public partial class Make_Repair_AfterSale : Form
  16. {
  17. string mb_id = "";
  18. string mbr_id = "";
  19. /// <summary>
  20. /// 存放父节点信息
  21. /// </summary>
  22. Dictionary<string, Dictionary<string, string>> BadInf_1 = new Dictionary<string, Dictionary<string, string>>();
  23. /// <summary>
  24. /// 存放子节点信息
  25. /// </summary>
  26. Dictionary<string, Dictionary<string, string>> BadInf_2 = new Dictionary<string, Dictionary<string, string>>();
  27. DataHelper dh = null;
  28. LogStringBuilder sql = new LogStringBuilder();
  29. List<string> sqls = new List<string>();
  30. DataTable dt = null;
  31. AutoSizeFormClass asc = new AutoSizeFormClass();
  32. string macode;
  33. string msid = "";
  34. string ifrework = "";
  35. string reworkstatus = "";
  36. string firstsn = "";
  37. string ms_stepcode = "";
  38. DataTable Dbfind;
  39. public Make_Repair_AfterSale()
  40. {
  41. InitializeComponent();
  42. }
  43. private void Make_Repair_Load(object sender, EventArgs e)
  44. {
  45. //为DBFind配置Call和Form的名称
  46. bd_soncode.FormName = Name;
  47. bd_soncode.TableName = "bom left join bomdetail on bd_bomid=bo_id left join product on bd_soncode=pr_code";
  48. bd_soncode.SetValueField = new string[] { "bd_soncode" };
  49. bd_soncode.SelectField = "bd_soncode # 子件编号,pr_detail # 物料名称,pr_spec # 物料规格,bd_location # 位号";
  50. bd_soncode.DBTitle = "不良零件";
  51. bd_soncode.DbChange += Prodcode_DbChange;
  52. //nrg_name.BringToFront();
  53. 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)";
  54. nrg_name.Field = "nrg_name";
  55. nrg_name.ValueField = "nrg_code";
  56. nrg_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  57. 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 + "' ";
  58. nr_name.Field = "nr_name";
  59. nr_name.ValueField = "nr_code";
  60. 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) ";
  61. mbr_dutyname.Field = "nd_name";
  62. mbr_dutyname.ValueField = "nd_code";
  63. mbr_dutyname.Condition = " 1=1 ORDER BY ROWNUM asc";
  64. 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)";
  65. so_name.Field = "so_name";
  66. so_name.ValueField = "so_code";
  67. so_name.Condition = " 1=1 ORDER BY ROWNUM asc";
  68. asc.controllInitializeSize(this);
  69. mbc_component.SendToBack();
  70. so_name.SendToBack();
  71. mbl_loc.SendToBack();
  72. bd_soncode.SendToBack();
  73. mbp_partdgv.SendToBack();
  74. mbp_part_label.SendToBack();
  75. dh = SystemInf.dh;
  76. GetSNCode.Focus();
  77. }
  78. private void Prodcode_DbChange(object sender, EventArgs e)
  79. {
  80. Dbfind = bd_soncode.ReturnData;
  81. BaseUtil.SetFormValue(this.Controls, Dbfind);
  82. if (bd_soncode.Text != "")
  83. {
  84. if (mbr_id != "")
  85. {
  86. if (!dh.CheckExist("makebadrspart", "mbp_sncode='" + GetSNCode.Text + "' and mbp_part='" + bd_soncode.Text + "' and mbp_badcode='" + bc_code.Text + "'"))
  87. {
  88. sql.Clear();
  89. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  90. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  91. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  92. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  93. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  94. dh.ExecuteSql(sql.GetString(), "insert");
  95. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  96. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  97. }
  98. }
  99. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  100. }
  101. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  102. }
  103. private void Cd_stepcode_DbChange(object sender, EventArgs e)
  104. {
  105. BaseUtil.SetFormValue(this.Controls, Dbfind);
  106. }
  107. private void Cr_code_DbChange(object sender, EventArgs e)
  108. {
  109. BaseUtil.SetFormValue(this.Controls, Dbfind);
  110. }
  111. private void GetSNCode_KeyDown(object sender, KeyEventArgs e)
  112. {
  113. if (e.KeyCode == Keys.Enter)
  114. {
  115. if (GetSNCode.Text == "")
  116. {
  117. OperatResult.AppendText(">>序列号不允许为空\n", Color.Red);
  118. BaseUtil.CleanForm(this);
  119. BadCodeTree.Nodes.Clear();
  120. return;
  121. }
  122. sql.Clear();
  123. sql.Append("select sb_status,sb_makecode,pr_detail,pr_spec,sb_sncode from SINGLEBOARD left join make ");
  124. sql.Append("on SB_MAKECODE=ma_code left join product on ma_prodcode=pr_code where SB_SNCODE = '" + GetSNCode.Text + "'");
  125. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  126. if (dt.Rows.Count > 0)
  127. {
  128. if (dt.Rows[0]["sb_status"].ToString() != "3")
  129. {
  130. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不处于维修状态\n", Color.Red);
  131. BaseUtil.CleanForm(this);
  132. BadCodeTree.Nodes.Clear();
  133. return;
  134. }
  135. else
  136. {
  137. BaseUtil.SetFormValue(this.Controls, dt);
  138. }
  139. }
  140. else
  141. {
  142. OperatResult.AppendText(">>序列号:" + GetSNCode.Text + "不存在\n", Color.Red);
  143. BaseUtil.CleanForm(this);
  144. BadCodeTree.Nodes.Clear();
  145. return;
  146. }
  147. LoadBadInfTree(sender, e);
  148. }
  149. }
  150. private void Make_Repair_SizeChanged(object sender, EventArgs e)
  151. {
  152. mbc_component.BringToFront();
  153. so_name.BringToFront();
  154. mbl_loc.BringToFront();
  155. bd_soncode.BringToFront();
  156. mbp_partdgv.BringToFront();
  157. mbp_part_label.BringToFront();
  158. asc.controlAutoSize(this);
  159. mbc_component.SendToBack();
  160. so_name.SendToBack();
  161. mbl_loc.SendToBack();
  162. bd_soncode.SendToBack();
  163. mbp_partdgv.SendToBack();
  164. mbp_part_label.SendToBack();
  165. }
  166. private void BadCodeTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
  167. {
  168. if (e.Node.Level == 0)
  169. {
  170. mb_id = e.Node.Tag.ToString();
  171. 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);
  172. mbl_locdgv.DataSource = null;
  173. mbp_partdgv.DataSource = null;
  174. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  175. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  176. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  177. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  178. mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  179. mbr_id = "";
  180. SaveRepairInf.Enabled = true;
  181. }
  182. if (e.Node.Level == 1)
  183. {
  184. //展示父节点信息
  185. mb_id = e.Node.Parent.Tag.ToString();
  186. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  187. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  188. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  189. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  190. //展示子节点信息
  191. mbr_id = e.Node.Tag.ToString();
  192. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  193. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  194. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  195. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  196. so_code.Text = BadInf_2[mbr_id]["so_code"];
  197. so_name.Text = BadInf_2[mbr_id]["so_name"];
  198. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  199. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];
  200. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  201. //加载两个Grid的数据源
  202. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  203. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  204. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  205. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  206. SaveRepairInf.Enabled = false;
  207. }
  208. }
  209. private void LoadBadInfTree(object sender, EventArgs e)
  210. {
  211. BadCodeTree.Nodes.Clear();
  212. sql.Clear();
  213. //不是返工工单时的取当前工单
  214. 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,");
  215. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup ");
  216. sql.Append("on bg_code=mb_bgcode where (mb_sncode='" + (GetSNCode.Text == "" ? sb_sncode.Text : GetSNCode.Text) + "' or mb_mscode='" + (GetSNCode.Text == "" ? sb_sncode.Text : GetSNCode.Text) + "' ) and mb_makecode='" + sb_makecode.Text + "' and mb_status=0");
  217. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  218. if (dt.Rows.Count == 0)
  219. {
  220. sql.Clear();
  221. 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, ");
  222. sql.Append("mb_badremark from makebad left join badcode on bc_code=mb_badcode left join badgroup on bg_code=mb_bgcode ");
  223. sql.Append("left join make on ma_code=mb_makecode where mb_sncode='" + (GetSNCode.Text == "" ? sb_sncode.Text : GetSNCode.Text) + "' and mb_makecode<>'" + sb_makecode.Text + "' and mb_status=0");
  224. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  225. }
  226. for (int i = 0; i < dt.Rows.Count; i++)
  227. {
  228. //添加根节点
  229. TreeNode tnode_0 = new TreeNode();
  230. string bg_name = dt.Rows[i]["bg_name"].ToString();
  231. string bc_name = dt.Rows[i]["bc_name"].ToString();
  232. string mb_badcode = dt.Rows[i]["mb_badcode"].ToString();
  233. string mb_bgcode = dt.Rows[i]["mb_bgcode"].ToString();
  234. tnode_0.Text = (bg_name == "" ? mb_bgcode : bg_name) + ":" + (bc_name == "" ? mb_bgcode : bc_name);
  235. tnode_0.Name = dt.Rows[i]["mb_bgcode"].ToString();
  236. //作为Dictionary的主标识
  237. string mb_id = dt.Rows[i]["mb_id"].ToString();
  238. tnode_0.Tag = mb_id;
  239. Dictionary<string, string> dic = new Dictionary<string, string>();
  240. dic.Add("mb_id", mb_id);
  241. dic.Add("mb_sncode", dt.Rows[i]["mb_sncode"].ToString());
  242. dic.Add("mb_badcode", dt.Rows[i]["mb_badcode"].ToString());
  243. dic.Add("mb_bgcode", dt.Rows[i]["mb_bgcode"].ToString());
  244. dic.Add("bc_name", dt.Rows[i]["bc_name"].ToString());
  245. dic.Add("bg_name", dt.Rows[i]["bg_name"].ToString());
  246. dic.Add("mb_badremark", dt.Rows[i]["mb_badremark"].ToString());
  247. if (!BadInf_1.ContainsKey(tnode_0.Tag.ToString()))
  248. BadInf_1.Add(tnode_0.Tag.ToString(), dic);
  249. BadCodeTree.Nodes.Add(tnode_0);
  250. BadCodeTree.SelectedNode = BadCodeTree.Nodes[0];
  251. //添加子节点
  252. sql.Clear();
  253. sql.Append("select mbr_id,mbr_brcode,mbr_brgcode,mbr_solutioncode,so_code,so_name,mbr_dutycode,mbr_dutyname,nd_name,nrg_name");
  254. sql.Append(",nr_name,nr_code,nrg_code from makebadreason left join QUA_NGReason on nr_code=mbr_brcode left join ");
  255. sql.Append("QUA_NGREASONGROUPdet on nrgd_nrcode=nr_code left join QUA_NGREASONGROUP on nrg_id=nrgd_nrgid and ");
  256. sql.Append("mbr_brgcode=nrg_code left join solution on so_code=mbr_solutioncode left join ngduty on nd_code=mbr_dutycode ");
  257. sql.Append("where mbr_mbid=" + mb_id);
  258. DataTable dt1 = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  259. for (int j = 0; j < dt1.Rows.Count; j++)
  260. {
  261. TreeNode tnode_1 = new TreeNode();
  262. //存放子节点的信息
  263. Dictionary<string, string> dic1 = new Dictionary<string, string>();
  264. string mbr_id = dt1.Rows[j]["mbr_id"].ToString();
  265. tnode_1.Tag = mbr_id;
  266. dic1.Add("mbr_id", mbr_id);
  267. dic1.Add("mbr_brcode", dt1.Rows[j]["mbr_id"].ToString());
  268. dic1.Add("mbr_brgcode", dt1.Rows[j]["mbr_brcode"].ToString());
  269. dic1.Add("mbr_solutioncode", dt1.Rows[j]["mbr_solutioncode"].ToString());
  270. dic1.Add("mbr_dutycode", dt1.Rows[j]["mbr_dutycode"].ToString());
  271. dic1.Add("mbr_dutyname", dt1.Rows[j]["mbr_dutyname"].ToString());
  272. dic1.Add("nd_name", dt1.Rows[j]["nd_name"].ToString());
  273. dic1.Add("so_name", dt1.Rows[j]["so_name"].ToString());
  274. dic1.Add("so_code", dt1.Rows[j]["so_code"].ToString());
  275. dic1.Add("nrg_name", dt1.Rows[j]["nrg_name"].ToString());
  276. dic1.Add("nrg_code", dt1.Rows[j]["nrg_code"].ToString());
  277. dic1.Add("nr_name", dt1.Rows[j]["nr_name"].ToString());
  278. dic1.Add("nr_code", dt1.Rows[j]["nr_code"].ToString());
  279. tnode_1.Text = dt1.Rows[j]["nr_name"].ToString();
  280. if (!BadInf_2.ContainsKey(mbr_id))
  281. BadInf_2.Add(mbr_id, dic1);
  282. tnode_0.Nodes.Add(tnode_1);
  283. }
  284. }
  285. try
  286. {
  287. if (bg_code.Text != "")
  288. BadCodeTree.Nodes[bg_code.Text].Expand();
  289. }
  290. catch (Exception) { }
  291. }
  292. private void RefreshTreeView_Click(object sender, EventArgs e)
  293. {
  294. LoadBadInfTree(sender, e);
  295. }
  296. private void RepairComplete_Click(object sender, EventArgs e)
  297. {
  298. dh.ExecuteSql("update SINGLEBOARD set SB_STATUS=1,sb_nextstepcode=sb_stepcode where sb_sncode='" + sb_sncode.Text + "'", "update");
  299. OperatResult.AppendText(">>序列号" + sb_sncode.Text + "完成维修\n", Color.Green);
  300. BaseUtil.CleanForm(this);
  301. BadCodeTree.Nodes.Clear();
  302. GetSNCode.Clear();
  303. GetSNCode.Focus();
  304. }
  305. private void NewBadCode_Click(object sender, EventArgs e)
  306. {
  307. if (GetSNCode.Text == "" || macode == null || macode == "")
  308. {
  309. OperatResult.AppendText(">>序列号和工单号不允许为空\n", Color.Red);
  310. }
  311. else
  312. {
  313. Make_NewBadCode badcode = new Make_NewBadCode(GetSNCode.Text, macode);
  314. badcode.FormClosed += LoadBadInfTree;
  315. BaseUtil.SetFormCenter(badcode);
  316. badcode.ShowDialog();
  317. }
  318. }
  319. private void NewRepairInf_Click(object sender, EventArgs e)
  320. {
  321. if (bg_name.Text == "" && bc_name.Text == "")
  322. {
  323. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  324. }
  325. else
  326. {
  327. Make_NewMatainInf mataininf = new Make_NewMatainInf(bg_name.Text, bg_code.Text, bc_name.Text, bc_code.Text, GetSNCode.Text, msid, mb_id);
  328. mataininf.FormClosed += LoadBadInfTree;
  329. BaseUtil.SetFormCenter(mataininf);
  330. mataininf.ShowDialog();
  331. }
  332. }
  333. private void SaveRepairInf_Click(object sender, EventArgs e)
  334. {
  335. string ErrorMessage = "";
  336. if (bg_name.Text == "" || bc_name.Text == "")
  337. {
  338. OperatResult.AppendText(">>不良代码组和不良代码不能为空\n", Color.Red);
  339. return;
  340. }
  341. if (nrg_name.Text == "")
  342. ErrorMessage += " 不良原因组 ";
  343. if (nr_name.Text == "")
  344. ErrorMessage += " 不良原因 ";
  345. if (mbr_dutyname.Text == "")
  346. ErrorMessage += " 责任别 ";
  347. if (mbr_dutyname.Text == "物料问题" && mbc_component.Text == "")
  348. ErrorMessage += "责任别为物料问题时必须选择不良零件";
  349. if (ErrorMessage != "")
  350. {
  351. ErrorMessage += "不能为空";
  352. OperatResult.AppendText(">>" + ErrorMessage + "\n", Color.Red);
  353. return;
  354. }
  355. string mbr_id = dh.GetSEQ("makebadreason_seq");
  356. //存在不良组件进行提示
  357. 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='" + sb_sncode.Text + "' and mbr_brcode='" + nr_code.Text + "' and mb_status=0"))
  358. {
  359. OperatResult.AppendText(">>不良代码【" + bc_name.Text + "】已存在不良原因【" + nr_name.Text + "】\n", Color.Red);
  360. return;
  361. }
  362. if (!dh.CheckExist("QUA_NGREASONGROUP", "nrg_name='" + nrg_name.Text + "'"))
  363. {
  364. OperatResult.AppendText(">>不良原因组不存在\n", Color.Red);
  365. return;
  366. }
  367. if (!dh.CheckExist("QUA_NGReason", "nr_name='" + nr_name.Text + "'"))
  368. {
  369. OperatResult.AppendText(">>不良原因不存在\n", Color.Red);
  370. return;
  371. }
  372. if (!dh.CheckExist("ngduty", "nd_name='" + mbr_dutyname.Text + "'"))
  373. {
  374. OperatResult.AppendText(">>责任别不存在\n", Color.Red);
  375. return;
  376. }
  377. if (!dh.CheckExist("solution", "so_name='" + so_name.Text + "'"))
  378. {
  379. OperatResult.AppendText(">>解决方案不存在\n", Color.Red);
  380. return;
  381. }
  382. //保存选择记录至后台,根据岗位资源代码记录
  383. 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");
  384. 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");
  385. 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");
  386. 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");
  387. //保存不良原因
  388. sql.Clear();
  389. sql.Append("insert into makebadreason (mbr_mbid,mbr_id,mbr_brcode,mbr_solutioncode,");
  390. sql.Append("mbr_dutycode,mbr_brgcode,mbr_badcode,mbr_sncode,mbr_makecode,mbr_indate,");
  391. sql.Append("mbr_inman,mbr_brname,mbr_solutionname,mbr_badname,mbr_brgname,mbr_dutyname,mbr_remark) select '" + mb_id + "','" + mbr_id + "','" + nr_code.Text + "',");
  392. sql.Append("'" + so_code.Text + "','" + mbr_dutyname.Text + "','" + nrg_code.Text + "','" + bc_code.Text + "',");
  393. sql.Append("'" + sb_sncode.Text + "','" + sb_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");
  394. dh.ExecuteSql(sql.GetString(), "insert");
  395. if (mbc_component.Text != "")
  396. {
  397. sql.Clear();
  398. sql.Append("insert into makebadrscom (mbc_id,mbc_mbrid,mbc_component,mbc_badcode,");
  399. sql.Append("mbc_brcode,mbc_sncode,mbc_makecode,mbc_indate,mbc_inman ) values ");
  400. sql.Append("(makebadrscom_seq.nextval,'" + mbr_id + "' ,'" + mbc_component.Text + "',");
  401. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + sb_sncode.Text + "','" + sb_makecode.Text + "',sysdate,'" + User.UserCode + "')");
  402. dh.ExecuteSql(sql.GetString(), "insert");
  403. }
  404. OperatResult.AppendText(">>不良原因保存成功\n", Color.Green);
  405. SaveRepairInf.Enabled = false;
  406. LoadBadInfTree(sender, e);
  407. }
  408. private void DeleteRepairInf_Click(object sender, EventArgs e)
  409. {
  410. DataTable dt = (DataTable)dh.ExecuteSql("select sb_makecode from SINGLEBOARD where sb_sncode='" + GetSNCode.Text + "' and sb_status=3", "select");
  411. if (dt.Rows.Count > 0)
  412. {
  413. if (mbr_id != "")
  414. {
  415. string delete1 = "delete from makebadrsloc where mbl_mbrid='" + mbr_id + "'";
  416. string delete2 = "delete from makebadrspart where mbp_mbrid='" + mbr_id + "'";
  417. string delete3 = "delete from makebadrscom where mbc_mbrid='" + mbr_id + "'";
  418. string delete4 = "delete from makebadreason where mbr_id='" + mbr_id + "'";
  419. dh.ExecuteSQLTran(delete1, delete2, delete3, delete4);
  420. OperatResult.AppendText(">>删除成功\n", Color.Green);
  421. 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);
  422. mbp_partdgv.DataSource = null;
  423. mbl_locdgv.DataSource = null;
  424. mbr_id = "";
  425. //删除后重新加载Tree的信息
  426. LoadBadInfTree(sender, e);
  427. }
  428. else OperatResult.AppendText(">>必须选择不良原因\n", Color.Red);
  429. }
  430. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  431. }
  432. private void SaveBadLocation_Click(object sender, EventArgs e)
  433. {
  434. DataTable dt = (DataTable)dh.ExecuteSql("select sb_makecode from SINGLEBOARD where sb_sncode='" + GetSNCode.Text + "' and sb_status=3", "select");
  435. if (dt.Rows.Count > 0)
  436. {
  437. if (mbl_loc.Text != "")
  438. {
  439. if (mbr_id != "")
  440. {
  441. if (!dh.CheckExist("makebadrsloc", "mbl_mbrid='" + mbr_id + "' and mbl_sncode='" + GetSNCode.Text + "' and mbl_loc='" + mbl_loc.Text.ToUpper() + "'"))
  442. {
  443. sql.Clear();
  444. sql.Append("insert into makebadrsloc(mbl_id,mbl_mbrid,mbl_loc,mbl_badcode,mbl_brcode,");
  445. sql.Append("mbl_sncode,mbl_makecode,mbl_indate ,mbl_inman) select makebadrsloc_seq.nextval," + mbr_id);
  446. sql.Append(",'" + mbl_loc.Text.ToUpper() + "','" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  447. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  448. dh.ExecuteSql(sql.GetString(), "insert");
  449. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  450. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  451. sql.Clear();
  452. sql.Append("with temp1 as (select bd_soncode,bd_location from bomdetail,bom where bo_id=bd_bomid ");
  453. sql.Append(" start with bo_mothercode='" + pr_code.Text + "' connect by bo_mothercode= prior bd_soncode) ");
  454. sql.Append("select bd_soncode from temp1 where instr(','||bd_location||',','," + mbl_loc.Text.ToUpper() + ",')>0");
  455. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  456. if (dt.Rows.Count > 0)
  457. {
  458. sql.Clear();
  459. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  460. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  461. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + dt.Rows[0][0].ToString() + "',");
  462. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  463. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  464. dh.ExecuteSql(sql.GetString(), "insert");
  465. dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  466. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  467. mbl_loc.Clear();
  468. }
  469. }
  470. else OperatResult.AppendText(">>已存在该不良位置\n", Color.Red);
  471. }
  472. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  473. }
  474. else OperatResult.AppendText(">>不良位置不能为空\n", Color.Red);
  475. }
  476. else OperatResult.AppendText(">>" + GetSNCode.Text + "序列号错误,不存在或者不处于维修状态\n", Color.Red);
  477. }
  478. private void nr_name_TextChanged(object sender, EventArgs e)
  479. {
  480. if (nr_name.Text == "")
  481. SaveBadLocation.Enabled = false;
  482. else
  483. SaveBadLocation.Enabled = true;
  484. }
  485. private void mbl_loc_KeyDown(object sender, KeyEventArgs e)
  486. {
  487. if (e.KeyCode == Keys.Enter)
  488. SaveBadLocation_Click(sender, e);
  489. }
  490. private void prodcode_TextKeyDown(object sender, KeyEventArgs e)
  491. {
  492. if (e.KeyCode == Keys.Enter)
  493. {
  494. if (bd_soncode.Text != "")
  495. {
  496. if (mbr_id != "")
  497. {
  498. sql.Clear();
  499. sql.Append("insert into makebadrspart(mbp_id,mbp_mbrid,mbp_part,mbp_badcode,");
  500. sql.Append("mbp_brcode,mbp_sncode,mbp_makecode,mbp_indate,mbp_inman)");
  501. sql.Append("select makebadrspart_seq.nextval," + mbr_id + ",'" + bd_soncode.Text + "',");
  502. sql.Append("'" + bc_code.Text + "','" + nr_code.Text + "','" + GetSNCode.Text + "','" + macode + "',");
  503. sql.Append("sysdate,'" + User.UserCode + "' from dual");
  504. dh.ExecuteSql(sql.GetString(), "insert");
  505. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  506. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  507. }
  508. else OperatResult.AppendText(">>请先选择不良原因\n", Color.Red);
  509. }
  510. else OperatResult.AppendText(">>不良零件不能为空\n", Color.Red);
  511. }
  512. }
  513. private void Clean_Click(object sender, EventArgs e)
  514. {
  515. OperatResult.Clear();
  516. }
  517. private void mbl_locdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  518. {
  519. if (e.RowIndex >= 0)
  520. {
  521. if (mbl_locdgv.Columns[e.ColumnIndex].Name == "DeletePos")
  522. {
  523. dh.ExecuteSql("delete from makebadrsloc where mbl_id='" + mbl_locdgv.Rows[e.RowIndex].Cells["mbl_id"].Value.ToString() + "'", "insert");
  524. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  525. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  526. }
  527. }
  528. }
  529. private void mbp_partdgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
  530. {
  531. if (e.RowIndex >= 0)
  532. {
  533. if (mbp_partdgv.Columns[e.ColumnIndex].Name == "DeleteCom")
  534. {
  535. dh.ExecuteSql("delete from makebadrspart where mbp_id='" + mbp_partdgv.Rows[e.RowIndex].Cells["mbp_id"].Value.ToString() + "'", "insert");
  536. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  537. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  538. }
  539. }
  540. }
  541. private void Make_Repair_FormClosing(object sender, FormClosingEventArgs e)
  542. {
  543. dh.Dispose();
  544. }
  545. public void RefreshData()
  546. {
  547. GetSNCode_KeyDown(new object(), new KeyEventArgs(Keys.Enter));
  548. }
  549. private void nr_name_UserControlTextChanged(object sender, EventArgs e)
  550. {
  551. if (nr_name.Text != "")
  552. {
  553. SaveBadLocation.Enabled = true;
  554. if (nrg_name.Text == "")
  555. {
  556. OperatResult.AppendText(">>请先填写不良代码组\n", Color.Red);
  557. nr_name.Text = "";
  558. }
  559. else
  560. {
  561. if (nr_code.Text == "" || (nr_code.Text != "" && nr_code.Text != nr_name.Value))
  562. nr_code.Text = nr_name.Value;
  563. }
  564. }
  565. else SaveBadLocation.Enabled = false;
  566. }
  567. private void nrg_name_UserControlTextChanged(object sender, EventArgs e)
  568. {
  569. if (nrg_code.Text == "" || (nrg_code.Text != "" && nrg_code.Text != nrg_name.Value))
  570. nrg_code.Text = nrg_name.Value;
  571. nr_name.Condition = "nrg_code in('" + (nrg_code.Text == "" ? "''" : nrg_code.Text) + "')";
  572. }
  573. private void mbr_dutyname_UserControlTextChanged(object sender, EventArgs e)
  574. {
  575. if (mbr_dutycode.Text == "" || (mbr_dutycode.Text != "" && mbr_dutycode.Text != mbr_dutyname.Value))
  576. mbr_dutycode.Text = mbr_dutyname.Value;
  577. }
  578. private void mbc_component_UserControlTextChanged(object sender, EventArgs e)
  579. {
  580. }
  581. private void so_name_UserControlTextChanged(object sender, EventArgs e)
  582. {
  583. if (so_code.Text == "" || (so_code.Text != "" && so_code.Text != so_name.Value))
  584. so_code.Text = so_name.Value;
  585. }
  586. private void BadCodeTree_AfterSelect(object sender, TreeViewEventArgs e)
  587. {
  588. if (e.Node.Level == 0)
  589. {
  590. mb_id = e.Node.Tag.ToString();
  591. 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);
  592. mbl_locdgv.DataSource = null;
  593. mbp_partdgv.DataSource = null;
  594. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  595. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  596. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  597. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  598. mb_badremark.Text = BadInf_1[mb_id]["mb_badremark"];
  599. mbr_id = "";
  600. SaveRepairInf.Enabled = true;
  601. }
  602. if (e.Node.Level == 1)
  603. {
  604. //展示父节点信息
  605. mb_id = e.Node.Parent.Tag.ToString();
  606. bc_code.Text = BadInf_1[mb_id]["mb_badcode"];
  607. bc_name.Text = BadInf_1[mb_id]["bc_name"];
  608. bg_code.Text = BadInf_1[mb_id]["mb_bgcode"];
  609. bg_name.Text = BadInf_1[mb_id]["bg_name"];
  610. //展示子节点信息
  611. mbr_id = e.Node.Tag.ToString();
  612. nrg_code.Text = BadInf_2[mbr_id]["nrg_code"];
  613. nrg_name.Text = BadInf_2[mbr_id]["nrg_name"];
  614. nr_code.Text = BadInf_2[mbr_id]["nr_code"];
  615. nr_name.Text = BadInf_2[mbr_id]["nr_name"];
  616. so_code.Text = BadInf_2[mbr_id]["so_code"];
  617. so_name.Text = BadInf_2[mbr_id]["so_name"];
  618. mbr_dutycode.Text = BadInf_2[mbr_id]["mbr_dutycode"];
  619. mbr_dutyname.Text = BadInf_2[mbr_id]["mbr_dutyname"];
  620. mbc_component.Text = dh.getFieldDataByCondition("makebadrscom", "mbc_component", "mbc_mbrid=" + mbr_id).ToString();
  621. //加载两个Grid的数据源
  622. DataTable dt = (DataTable)dh.ExecuteSql("select mbp_id,mbp_part from makebadrspart where mbp_mbrid=" + mbr_id, "select");
  623. BaseUtil.FillDgvWithDataTable(mbp_partdgv, dt);
  624. dt = (DataTable)dh.ExecuteSql("select mbl_id,mbl_loc from makebadrsloc where mbl_mbrid=" + mbr_id, "select");
  625. BaseUtil.FillDgvWithDataTable(mbl_locdgv, dt);
  626. SaveRepairInf.Enabled = false;
  627. }
  628. }
  629. }
  630. }