Make_Repair.cs 53 KB

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