Make_BurnInspection.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. using NPOI.SS.Formula.Functions;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.ComponentModel;
  6. using System.Configuration.Assemblies;
  7. using System.Data;
  8. using System.Diagnostics;
  9. using System.Drawing;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Text.RegularExpressions;
  14. using System.Windows.Forms;
  15. using System.Xml;
  16. using UAS_MES_NEW.DataOperate;
  17. using UAS_MES_NEW.Entity;
  18. using UAS_MES_NEW.PublicMethod;
  19. namespace UAS_MES_NEW.Make
  20. {
  21. public partial class Make_BurnInspection : Form
  22. {
  23. StringBuilder SQL = new StringBuilder();
  24. LogStringBuilder sql = new LogStringBuilder();
  25. DataHelper dh = new DataHelper();
  26. DataTable Dbfind;
  27. DataTable dt = new DataTable();
  28. string SN,WO = "";
  29. string burnId;
  30. public Make_BurnInspection()
  31. {
  32. InitializeComponent();
  33. }
  34. private void Make_WirelessTest_Load(object sender, EventArgs e)
  35. {
  36. //设置锁定工单
  37. LockMakeCode.GetMakeCodeCtl(ma_code);
  38. ma_code.SetLockCheckBox(LockMakeCode);
  39. //工单号放大镜配置
  40. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  41. ma_code.SelectField = "ma_code # 工单号,pr_code # 产品编号,pr_detail # 产品名称";
  42. ma_code.FormName = Name;
  43. ma_code.SetValueField = new string[] { "ma_code", "pr_code", "pr_detail" };
  44. ma_code.Condition = "ma_statuscode='STARTED'";
  45. ma_code.DbChange += Ma_code_DbChange;
  46. dh = SystemInf.dh;
  47. StartDateTime.Value = EndDateTime.Value.AddDays(-1);
  48. }
  49. private void Ma_code_DbChange(object sender, EventArgs e)
  50. {
  51. Dbfind = ma_code.ReturnData;
  52. BaseUtil.SetFormValue(this.Controls, Dbfind);
  53. //获取工单的其他信息
  54. sql.Clear();
  55. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode as pr_code ,pr_detail,");
  56. sql.Append("pr_spec,ma_qty - nvl(mcd_inqty, 0) mcd_remainqty,ma_qty from make left join makecraftdetail on ");
  57. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + ma_code.Text + "'");
  58. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  59. if (dt.Rows.Count > 0)
  60. {
  61. BaseUtil.SetFormValue(this.Controls, dt);
  62. }
  63. dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select");
  64. if (dt.Rows.Count > 0)
  65. {
  66. CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString();
  67. }
  68. SQL.Clear();
  69. if (!string.IsNullOrEmpty(ma_code.Text))
  70. {
  71. SQL.Append($"AND a.work_order = '{ma_code.Text}'");
  72. }
  73. if (DateTimeCheck.Checked)
  74. {
  75. string startTime = StartDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  76. string endTime = EndDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  77. if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  78. {
  79. SQL.Append($"AND a.update_time between to_date('{startTime}','YYYY-MM-DD HH24:MI:SS') AND to_date('{endTime}','YYYY-MM-DD HH24:MI:SS')");
  80. }
  81. }
  82. //if(DataBox.Rows.Count > 0)
  83. //{
  84. // DataTable DgvDs = (DataTable)DataBox.DataSource;
  85. // DgvDs.Clear();
  86. //}
  87. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM (SELECT a.burn_id,a.burn_lotno,a.work_order,
  88. a.line,a.burn_software,a.check_code,a.dot_detail,a.burn_qty,a.ic_detail,a.update_time,
  89. b.inspect_time,b.inspect_name,b.inspect_res
  90. FROM burn_info a LEFT JOIN burn_inspect b ON a.burn_id = b.burnid
  91. WHERE 1 = 1 {SQL.ToString()}) WHERE inspect_res IS NULL", "select");
  92. DataBox.DataSource = dt;
  93. ShowMsg(1, $"工单: {ma_code.Text} 需抽检烧录 {dt.Rows.Count} 条");
  94. }
  95. private void ClearMsg_Click(object sender, EventArgs e)
  96. {
  97. OperatResult.Clear();
  98. }
  99. private void OK_Click(object sender, EventArgs e)
  100. {
  101. PassStation("OK");
  102. }
  103. private void NG_Click(object sender, EventArgs e)
  104. {
  105. PassStation("NG");
  106. }
  107. private void PassStation(string testResult)
  108. {
  109. BurnLotnoVal.Text = BurnLotnoVal.Text.Trim();
  110. if (string.IsNullOrEmpty(EmployeeVal.Text))
  111. {
  112. ShowMsg(0, $"请填写抽检人员");
  113. return;
  114. }
  115. if (!Regex.IsMatch(EmployeeVal.Text, @"^[\u4e00-\u9fa5][\u4e00-\u9fa5\s·]{0,13}[\u4e00-\u9fa5]$"))
  116. {
  117. EmployeeVal.Focus();
  118. EmployeeVal.SelectAll();
  119. ShowMsg(0, $"请填写中文抽检人员");
  120. return;
  121. }
  122. if (DataBox.Rows.Count == 0)
  123. {
  124. ShowMsg(0, $"请选择筛选出待抽检的烧录信息");
  125. return;
  126. }
  127. if (string.IsNullOrEmpty(BurnLotnoVal.Text))
  128. {
  129. ShowMsg(0, $"请扫描烧录批号");
  130. return;
  131. }
  132. if (string.IsNullOrEmpty(InspectNumVal.Text))
  133. {
  134. ShowMsg(0, $"请输入抽检数量");
  135. return;
  136. }
  137. burnId = "";
  138. foreach (DataGridViewRow item in DataBox.Rows)
  139. {
  140. string currLotNo = item.Cells["burn_lotno"].Value.ToString();
  141. if (currLotNo == BurnLotnoVal.Text.Trim())
  142. {
  143. burnId = item.Cells["BURN_ID"].Value.ToString();
  144. }
  145. }
  146. if (string.IsNullOrEmpty(burnId))
  147. {
  148. ShowMsg(0, $"请抽检筛选出的烧录批号");
  149. return;
  150. }
  151. dt = (DataTable)dh.ExecuteSql($@"select * from burn_inspect where burnlotno = '{BurnLotnoVal.Text}'", "select");
  152. if (dt.Rows.Count > 0)
  153. {
  154. ShowMsg(0, $"批号 {BurnLotnoVal.Text}已抽检");
  155. return;
  156. }
  157. SQL.Clear();
  158. SQL.Append($@"INSERT INTO burn_inspect (burn_inspect_id,BURNLOTNO,BURNID,
  159. inspect_res,inspect_time,inspect_name,inspect_num) VALUES (burn_inspect_seq.NEXTVAL, '{BurnLotnoVal.Text}',{burnId},
  160. '{testResult}',sysdate,'{EmployeeVal.Text.Trim()}','{InspectNumVal.Text.Trim()}')");
  161. dh.ExecuteSql(SQL.ToString(), "insert");
  162. ShowMsg(1, $"{BurnLotnoVal.Text} 记录抽检结果{testResult} 成功");
  163. dt = (DataTable)dh.ExecuteSql($"select nvl(sum(burn_qty),0) allqty from burn_info where work_order = '{ma_code.Text}'", "select");
  164. if (dt.Rows.Count > 0)
  165. {
  166. CurrQtyVal.Text = dt.Rows[0]["allqty"].ToString();
  167. }
  168. SQL.Clear();
  169. if (!string.IsNullOrEmpty(ma_code.Text))
  170. {
  171. SQL.Append($"AND a.work_order = '{ma_code.Text}'");
  172. }
  173. if (DateTimeCheck.Checked)
  174. {
  175. string startTime = StartDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  176. string endTime = EndDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  177. if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  178. {
  179. SQL.Append($"AND a.update_time between to_date('{startTime}','YYYY-MM-DD HH24:MI:SS') AND to_date('{endTime}','YYYY-MM-DD HH24:MI:SS')");
  180. }
  181. }
  182. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM (SELECT a.burn_id,a.burn_lotno,a.work_order,
  183. a.line,a.burn_software,a.check_code,a.dot_detail,a.burn_qty,a.ic_detail,a.update_time,
  184. b.inspect_time,b.inspect_name,b.inspect_res
  185. FROM burn_info a LEFT JOIN burn_inspect b ON a.burn_id = b.burnid
  186. WHERE 1 = 1 {SQL.ToString()}) WHERE inspect_res IS NULL", "select");
  187. DataBox.DataSource = dt;
  188. BurnLotnoVal.Focus();
  189. BurnLotnoVal.SelectAll();
  190. }
  191. private void BurnLotnoVal_KeyDown(object sender, KeyEventArgs e)
  192. {
  193. if (e.KeyCode != Keys.Enter) return;
  194. if (OkBox.Checked)
  195. {
  196. PassStation("OK");
  197. }
  198. else
  199. {
  200. PassStation("NG");
  201. }
  202. }
  203. private void OkBox_Click(object sender, EventArgs e)
  204. {
  205. NgBox.Checked = false;
  206. }
  207. private void NgBox_Click(object sender, EventArgs e)
  208. {
  209. OkBox.Checked = false;
  210. }
  211. private void StartDateTime_ValueChanged(object sender, EventArgs e)
  212. {
  213. if (StartDateTime.Value > EndDateTime.Value)
  214. {
  215. StartDateTime.Value = EndDateTime.Value.AddDays(-1);
  216. ShowMsg(0, $"不得大于最早时间");
  217. return;
  218. }
  219. StringBuilder searchSql = new StringBuilder();
  220. if (!string.IsNullOrEmpty(ma_code.Text))
  221. {
  222. searchSql.Append($"AND a.work_order = '{ma_code.Text}'");
  223. }
  224. if (DateTimeCheck.Checked)
  225. {
  226. string startTime = StartDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  227. string endTime = EndDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  228. if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  229. {
  230. searchSql.Append($"AND a.update_time between to_date('{startTime}','YYYY-MM-DD HH24:MI:SS') AND to_date('{endTime}','YYYY-MM-DD HH24:MI:SS')");
  231. }
  232. }
  233. if (!string.IsNullOrEmpty(ma_code.Text) || DateTimeCheck.Checked)
  234. {
  235. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM (SELECT a.burn_id,a.burn_lotno,a.work_order,
  236. a.line,a.burn_software,a.check_code,a.dot_detail,a.burn_qty,a.ic_detail,a.update_time,
  237. b.inspect_time,b.inspect_name,b.inspect_res
  238. FROM burn_info a LEFT JOIN burn_inspect b ON a.burn_id = b.burnid
  239. WHERE 1 = 1 {searchSql.ToString()}) WHERE inspect_res IS NULL", "select");
  240. DataBox.DataSource = dt;
  241. ShowMsg(1, $"工单: {ma_code.Text} 需抽检烧录 {dt.Rows.Count} 条");
  242. }
  243. }
  244. private void EndDateTime_ValueChanged(object sender, EventArgs e)
  245. {
  246. if (StartDateTime.Value > EndDateTime.Value)
  247. {
  248. StartDateTime.Value = EndDateTime.Value.AddDays(-1);
  249. ShowMsg(0, $"不得小于最晚时间");
  250. return;
  251. }
  252. StringBuilder searchSql = new StringBuilder();
  253. if (!string.IsNullOrEmpty(ma_code.Text))
  254. {
  255. searchSql.Append($"AND a.work_order = '{ma_code.Text}'");
  256. }
  257. if (DateTimeCheck.Checked)
  258. {
  259. string startTime = StartDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  260. string endTime = EndDateTime.Value.ToString("yyyy-MM-dd HH:mm:ss");
  261. if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(endTime))
  262. {
  263. searchSql.Append($"AND a.update_time between to_date('{startTime}','YYYY-MM-DD HH24:MI:SS') AND to_date('{endTime}','YYYY-MM-DD HH24:MI:SS')");
  264. }
  265. }
  266. if (!string.IsNullOrEmpty(ma_code.Text) || DateTimeCheck.Checked)
  267. {
  268. dt = (DataTable)dh.ExecuteSql($@"SELECT * FROM (SELECT a.burn_id,a.burn_lotno,a.work_order,
  269. a.line,a.burn_software,a.check_code,a.dot_detail,a.burn_qty,a.ic_detail,a.update_time,
  270. b.inspect_time,b.inspect_name,b.inspect_res
  271. FROM burn_info a LEFT JOIN burn_inspect b ON a.burn_id = b.burnid
  272. WHERE 1 = 1 {searchSql.ToString()}) WHERE inspect_res IS NULL", "select");
  273. DataBox.DataSource = dt;
  274. ShowMsg(1, $"工单: {ma_code.Text} 需抽检烧录 {dt.Rows.Count} 条");
  275. }
  276. }
  277. private void DateTimeCheck_Click(object sender, EventArgs e)
  278. {
  279. EndDateTime_ValueChanged(null, null);
  280. }
  281. private void ShowMsg(int type, string msg)
  282. {
  283. string fullDateTime = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  284. if (type == 0)
  285. {
  286. OperatResult.AppendText($"{fullDateTime}: {msg}\n", Color.Red);
  287. }
  288. else if (type == 1)
  289. {
  290. OperatResult.AppendText($"{fullDateTime}: {msg}\n", Color.Green);
  291. }
  292. else if (type == 1)
  293. {
  294. OperatResult.AppendText($"{fullDateTime}: {msg}\n", Color.YellowGreen);
  295. }
  296. }
  297. }
  298. }