Make_GetTestFileData.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. using HslCommunication;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Windows.Forms;
  11. using UAS_MES_NEW.DataOperate;
  12. using UAS_MES_NEW.Entity;
  13. using UAS_MES_NEW.PublicForm;
  14. using UAS_MES_NEW.PublicMethod;
  15. namespace UAS_MES_NEW.Make
  16. {
  17. public partial class Make_GetTestFileData : Form
  18. {
  19. AutoSizeFormClass asc = new AutoSizeFormClass();
  20. DataHelper dh;
  21. LogStringBuilder sql;
  22. string oErrorMessage = "";
  23. string omakeCode = "";
  24. string oMsid = "";
  25. ftpOperater ftp = new ftpOperater();
  26. public Make_GetTestFileData()
  27. {
  28. InitializeComponent();
  29. }
  30. private void Make_LabelCheck_Load(object sender, EventArgs e)
  31. {
  32. asc.controllInitializeSize(this);
  33. //聚焦SN号
  34. sncode.Focus();
  35. //打开界面提示用户:请输入SN
  36. sql = new LogStringBuilder();
  37. dh = SystemInf.dh;
  38. StepCount.StepCode = User.CurrentStepCode;
  39. StepCount.Source = User.UserSourceCode;
  40. StepCount.LineCode = User.UserLineCode;
  41. StepCount.Dh = dh;
  42. StepCount.Start();
  43. sql.Clear();
  44. sql.Append("select bg_code,bg_code||':'||bg_name bg_name from PRODUCTBADGROUP left join productkind on ");
  45. sql.Append("pk_code= pb_kindcode left join product on pr_kind=pk_name left join ");
  46. sql.Append("badgroup on bg_code=pb_badgroup where pr_code='" + ma_prodcode.Text + "'");
  47. DataTable BadCode = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  48. if (BadCode.Rows.Count > 0)
  49. {
  50. BadGroupCode.DisplayMember = "bg_name";
  51. BadGroupCode.ValueMember = "bg_code";
  52. BadGroupCode.DataSource = BadCode;
  53. }
  54. else
  55. {
  56. BadCode = (DataTable)dh.ExecuteSql("select bg_code,bg_name from badgroup where bg_statuscode='AUDITED'", "select");
  57. BadGroupCode.DisplayMember = "bg_name";
  58. BadGroupCode.ValueMember = "bg_code";
  59. BadGroupCode.DataSource = BadCode;
  60. }
  61. DataTable dt = (DataTable)dh.ExecuteSql("select or_badcode bc_code,or_description bc_name,or_bgcode bg_code,bg_name from OQCNGReason left join badgroup on or_bgcode=bg_code where or_sncode='" + sncode.Text + "'", "select");
  62. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  63. }
  64. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  65. {
  66. asc.controlAutoSize(this);
  67. }
  68. private void LoadCollectedNum()
  69. {
  70. //sql.Clear();
  71. //sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  72. //sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  73. //sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  74. //DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  75. //BaseUtil.SetFormValue(Controls, dt);
  76. }
  77. private void sncode_KeyDown(object sender, KeyEventArgs e)
  78. {
  79. //判断是enter事件
  80. if (e.KeyCode == Keys.Enter)
  81. {
  82. if (sncode.Text == "")
  83. {
  84. OperateResult.AppendText("SN不允许为空");
  85. return;
  86. }
  87. DataTable dt = (DataTable)dh.ExecuteSql("select ms_makecode,ms_prodcode,pr_detail from makeserial left join product on pr_code=ms_prodcode where ms_sncode='" + sncode.Text + "' order by ms_id desc", "select");
  88. if (dt.Rows.Count == 0)
  89. {
  90. OperateResult.AppendText("SN【" + sncode.Text + "】不存在\n", Color.Red);
  91. return;
  92. }
  93. ma_code.Text = dt.Rows[0]["ms_makecode"].ToString();
  94. ma_prodcode.Text = dt.Rows[0]["ms_prodcode"].ToString();
  95. pr_detail.Text = dt.Rows[0]["pr_detail"].ToString();
  96. dt = (DataTable)dh.ExecuteSql("select msi_result from makeserial_inspect where msi_sncode='" + sncode.Text + "'", "select");
  97. if (dt.Rows.Count > 0)
  98. {
  99. OperateResult.AppendText("SN【" + sncode.Text + "】已抽检,检验结果为'" + dt.Rows[0]["msi_result"].ToString() + "'\n");
  100. return;
  101. }
  102. if (OK.Checked)
  103. {
  104. dh.ExecuteSql("insert into makeserial_inspect(msi_id,msi_sncode,msi_makecode,msi_indate,msi_result,msi_inman,msi_source)values(makeserial_inspect_seq.nextval,'" + sncode.Text + "','" + ma_code.Text + "',sysdate,'OK','" + User.UserName + "','" + User.UserSourceCode + "')", "insert");
  105. sncode.Text = "";
  106. }
  107. else
  108. {
  109. List<string> bc_code = new List<string>();
  110. List<string> bc_name = new List<string>();
  111. List<string> bg_code = new List<string>();
  112. List<string> bg_name = new List<string>();
  113. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  114. {
  115. bc_code.Add(ChoosedDGV.Rows[i].Cells["bc_code1"].Value.ToString());
  116. bc_name.Add(ChoosedDGV.Rows[i].Cells["bc_name1"].Value.ToString());
  117. bg_code.Add(ChoosedDGV.Rows[i].Cells["bg_code1"].Value.ToString());
  118. bg_name.Add(ChoosedDGV.Rows[i].Cells["bg_name1"].Value.ToString());
  119. }
  120. if (bc_code.ToArray().Length == 0)
  121. {
  122. OperateResult.AppendText(">>不良品请勾选不良明细\n", Color.Red);
  123. return;
  124. }
  125. sql.Clear();
  126. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  127. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_soncode,mb_badname,mb_status,mb_bgname,mb_type)");
  128. sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "',ms_sourcecode,:bc_code,:bg_code,'',");
  129. sql.Append("sp_soncode,:bc_name,'0',:bg_name,'Client' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  130. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + sncode.Text + "' and ms_makecode='" + ma_code.Text + "'");
  131. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_name", "bg_name" }, bc_code.ToArray(), bg_code.ToArray(), bc_name.ToArray(), bg_name.ToArray());
  132. dh.ExecuteSql("insert into makeserial_inspect(msi_id,msi_sncode,msi_makecode,msi_indate,msi_result,msi_inman,msi_source)values(makeserial_inspect_seq.nextval,'" + sncode.Text + "','" + ma_code.Text + "',sysdate,'NG','" + User.UserName + "','" + User.UserSourceCode + "')", "insert");
  133. sncode.Text = "";
  134. }
  135. LoadGridData();
  136. }
  137. }
  138. private void StepCount_Load(object sender, EventArgs e)
  139. {
  140. }
  141. private void LoadGridData()
  142. {
  143. DataTable dt = (DataTable)dh.ExecuteSql("select MSI_ID, MSI_SNCODE, MSI_MAKECODE, MSI_INDATE, MSI_RESULT from makeserial_inspect where msi_makecode='" + ma_code.Text + "'", "select");
  144. CheckItemDGV.DataSource = dt;
  145. }
  146. private void CheckItemDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  147. {
  148. //系统值和
  149. if (e.ColumnIndex >= 0)
  150. {
  151. if (CheckItemDGV.Columns[e.ColumnIndex].Name == "std_testresult")
  152. {
  153. if (e.RowIndex >= 0)
  154. {
  155. if (CheckItemDGV.Rows[e.RowIndex].Cells["std_testresult"].Value != null && (CheckItemDGV.Rows[e.RowIndex].Cells["std_testresult"].Value.ToString() == "OK"))
  156. {
  157. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  158. Rectangle border = e.CellBounds;
  159. border.Width -= 1;
  160. e.Graphics.DrawRectangle(Pens.Black, border);
  161. e.PaintContent(e.CellBounds);
  162. e.Handled = true;
  163. }
  164. else
  165. {
  166. e.Graphics.FillRectangle(Brushes.OrangeRed, e.CellBounds);
  167. Rectangle border = e.CellBounds;
  168. border.Width -= 1;
  169. e.Graphics.DrawRectangle(Pens.Black, border);
  170. e.PaintContent(e.CellBounds);
  171. e.Handled = true;
  172. }
  173. }
  174. }
  175. }
  176. }
  177. private void BadGroupCode_SelectedIndexChanged(object sender, EventArgs e)
  178. {
  179. string bg_code = BadGroupCode.SelectedValue.ToString();
  180. sql.Clear();
  181. sql.Append("select 0 ChooseAll,bc_code,bc_name,bg_name,bg_code from badgroupdetail left join badgroup on bg_id=bgd_bgid ");
  182. sql.Append("left join badcode on bgd_badcode=bc_code where bg_code='" + ((bg_code != "" && bg_code != "System.Data.DataRowView") ? bg_code.ToString() : "") + "' and bg_code is not null ");
  183. sql.Append(" order by bc_code");
  184. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  185. BadInfoSource.DataSource = dt;
  186. BaseUtil.FillDgvWithDataTable(WaitChooseDGV, dt);
  187. }
  188. private void ChooseedReject_Click(object sender, EventArgs e)
  189. {
  190. DataTable wait = BaseUtil.filterDataTable((DataTable)WaitChooseDGV.DataSource, "ChooseAll<>0");
  191. DataTable choose = (ChoosedDGV.DataSource as DataTable);
  192. List<string> Chooseed = new List<string>();
  193. for (int i = 0; i < choose.Rows.Count; i++)
  194. {
  195. Chooseed.Add(choose.Rows[i]["bc_code"].ToString());
  196. }
  197. if (wait.Rows.Count > 0)
  198. {
  199. for (int i = 0; i < wait.Rows.Count; i++)
  200. {
  201. if (!Chooseed.Contains(wait.Rows[i]["bc_code"].ToString()))
  202. {
  203. DataRow dr1 = choose.NewRow();
  204. dr1["bc_code"] = wait.Rows[i]["bc_code"];
  205. dr1["bc_name"] = wait.Rows[i]["bc_name"];
  206. dr1["bg_code"] = wait.Rows[i]["bg_code"];
  207. dr1["bg_name"] = wait.Rows[i]["bg_name"];
  208. choose.Rows.Add(dr1);
  209. }
  210. }
  211. for (int i = 0; i < WaitChooseDGV.Rows.Count; i++)
  212. {
  213. ((DataTable)WaitChooseDGV.DataSource).Rows[i]["ChooseAll"] = 0;
  214. }
  215. }
  216. else OperateResult.AppendText(">>请勾选不良明细\n", Color.Red);
  217. }
  218. private void WaitReject_Click(object sender, EventArgs e)
  219. {
  220. for (int i = ChoosedDGV.Rows.Count - 1; i >= 0; i--)
  221. {
  222. if (ChoosedDGV.Rows[i].Cells["choose1"].FormattedValue.ToString() == "True")
  223. {
  224. ChoosedDGV.Rows.RemoveAt(i);
  225. }
  226. }
  227. (ChoosedDGV.DataSource as DataTable).AcceptChanges();
  228. }
  229. private void StepCount_Load_1(object sender, EventArgs e)
  230. {
  231. }
  232. private void bccode_KeyDown(object sender, KeyEventArgs e)
  233. {
  234. if (e.KeyCode == Keys.Enter)
  235. {
  236. DataTable dt = (DataTable)dh.ExecuteSql("select bc_code bg_code,bc_name bg_name from badcode where bc_code='" + bccode.Text + "'", "select");
  237. if (dt.Rows.Count > 0)
  238. {
  239. try
  240. {
  241. for (int i = 0; i < ChoosedDGV.Rows.Count; i++)
  242. {
  243. if (ChoosedDGV.Rows[i].Cells[1].Value.ToString() == dt.Rows[0][0].ToString())
  244. {
  245. OperateResult.AppendText(">>已添加过不良代码" + bccode.Text + "\n", Color.Red);
  246. bccode.Clear();
  247. return;
  248. }
  249. }
  250. dt.Merge(ChoosedDGV.DataSource as DataTable);
  251. BaseUtil.FillDgvWithDataTable(ChoosedDGV, dt);
  252. bccode.Clear();
  253. }
  254. catch (Exception) { }
  255. }
  256. else OperateResult.AppendText(">>不良代码不存在\n", Color.Red);
  257. }
  258. }
  259. private void Confirm_Click(object sender, EventArgs e)
  260. {
  261. if (OK.Checked)
  262. {
  263. dh.ExecuteSql("insert into makeserial_inspect(msi_id,msi_sncode,msi_makecode,msi_indate,msi_result,msi_inman,msi_source)values(makeserial_inspect_seq.nextval,'" + sncode.Text + "','" + ma_code.Text + "',sysdate,'OK','" + User.UserName + "','" + User.UserSourceCode + "')", "insert");
  264. }
  265. else
  266. {
  267. List<string> bc_code = new List<string>();
  268. List<string> bc_name = new List<string>();
  269. List<string> bg_code = new List<string>();
  270. List<string> bg_name = new List<string>();
  271. for (int i = 0; i < ChoosedDGV.RowCount; i++)
  272. {
  273. bc_code.Add(ChoosedDGV.Rows[i].Cells["bc_code1"].Value.ToString());
  274. bc_name.Add(ChoosedDGV.Rows[i].Cells["bc_name1"].Value.ToString());
  275. bg_code.Add(ChoosedDGV.Rows[i].Cells["bg_code1"].Value.ToString());
  276. bg_name.Add(ChoosedDGV.Rows[i].Cells["bg_name1"].Value.ToString());
  277. }
  278. if (bc_code.ToArray().Length == 0)
  279. {
  280. OperateResult.AppendText(">>不良品请勾选不良明细\n", Color.Red);
  281. }
  282. sql.Clear();
  283. sql.Append("insert into makebad(mb_id,mb_makecode,mb_mscode,mb_sncode,mb_inman,mb_indate,mb_stepcode");
  284. sql.Append(",mb_sourcecode,mb_badcode,mb_bgcode,mb_badtable,mb_soncode,mb_badname,mb_status,mb_bgname,mb_type)");
  285. sql.Append("select makebad_seq.nextval,ma_code,ms_code,ms_sncode,'" + User.UserCode + "',sysdate,'" + User.CurrentStepCode + "',ms_sourcecode,:bc_code,:bg_code,'',");
  286. sql.Append("sp_soncode,:bc_name,'0',:bg_name,'Client' from make left join makeSerial on ms_makecode=ma_code left join stepProduct on ");
  287. sql.Append("sp_mothercode=ma_prodcode and sp_stepcode=ms_nextstepcode where ms_sncode='" + sncode.Text + "' and ms_makecode='" + ma_code.Text + "'");
  288. dh.BatchInsert(sql.GetString(), new string[] { "bc_code", "bg_code", "bc_name", "bg_name" }, bc_code.ToArray(), bg_code.ToArray(), bc_name.ToArray(), bg_name.ToArray());
  289. dh.ExecuteSql("insert into makeserial_inspect(msi_id,msi_sncode,msi_makecode,msi_indate,msi_result,msi_inman,msi_source)values(makeserial_inspect_seq.nextval,'" + sncode.Text + "','" + ma_code.Text + "',sysdate,'NG','" + User.UserName + "','" + User.UserSourceCode + "')", "insert");
  290. }
  291. LoadGridData();
  292. }
  293. }
  294. }