Make_Repair.cs 66 KB

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