Make_TestCollectionlux.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. using System;
  2. using System.Data;
  3. using System.Text;
  4. using System.Threading;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7. using UAS_MES_NEW.DataOperate;
  8. using UAS_MES_NEW.Entity;
  9. using UAS_MES_NEW.PublicMethod;
  10. using System.Collections.Generic;
  11. using UAS_MES_NEW.CustomControl.PowerControlForm;
  12. using System.Xml;
  13. using System.IO;
  14. using ExcelHelper;
  15. using NPOI.SS.UserModel;
  16. using NPOI.HSSF.UserModel;
  17. using NPOI.SS.Formula.Eval;
  18. using NPOI.HSSF.Util;
  19. using NPOI.SS.Util;
  20. namespace UAS_MES_NEW.Make
  21. {
  22. public partial class Make_TestCollectionlux : Form
  23. {
  24. DataHelper dh = null;
  25. DataTable dt = null;
  26. //当前工序的名称
  27. string ErrorMessage = "";
  28. //用于保存是否之前输入的ms_sncode
  29. string LastSncode;
  30. string oMakeCode = "";
  31. string oMSID = "";
  32. string ifrework = "";
  33. string reworkstatus = "";
  34. LogStringBuilder sql = new LogStringBuilder();
  35. AutoSizeFormClass asc = new AutoSizeFormClass();
  36. /// <summary>
  37. /// 已选的不良
  38. /// </summary>
  39. List<string> ChoosedList = new List<string>();
  40. /// <summary>
  41. /// 待选的不良
  42. /// </summary>
  43. List<string> WaitList = new List<string>();
  44. bool AutoCut = false;
  45. bool LockSn = false;
  46. DataTable Dbfind;
  47. public Make_TestCollectionlux()
  48. {
  49. InitializeComponent();
  50. }
  51. private void TestCollection_Load(object sender, EventArgs e)
  52. {
  53. GoodProduct.Checked = true;
  54. asc.controllInitializeSize(this);
  55. ms_sncode.Focus();
  56. //设置锁定工单
  57. LockMakeCode.GetMakeCodeCtl(ma_code);
  58. ma_code.SetLockCheckBox(LockMakeCode);
  59. ControlLockTimer.Tick += ControlLockTimer_Tick;
  60. ControlLockTimer.Interval = 100;
  61. //工单号放大镜配置
  62. ma_code.TableName = "make left join product on ma_prodcode=pr_code";
  63. ma_code.SelectField = "ma_code # 工单号,ma_prodcode # 产品编号,ma_qty # 工单数量,pr_spec # 产品规格,ma_softversion # 软件版本,ma_salecode # 销售单号,pr_sendchecktype # 产品送检方式";
  64. ma_code.FormName = Name;
  65. ma_code.SetValueField = new string[] { "ma_code", "ma_prodcode", "ma_qty", "pr_spec", "ma_softversion", "ma_salecode", "nvl(pr_sendchecktype,'LineCode')pr_sendchecktype" };
  66. ma_code.Condition = "ma_statuscode='STARTED'";
  67. ma_code.DbChange += Ma_code_DbChange;
  68. dh = SystemInf.dh;
  69. StepCount.StepCode = User.CurrentStepCode;
  70. StepCount.Source = User.UserSourceCode;
  71. StepCount.LineCode = User.UserLineCode;
  72. StepCount.Dh = dh;
  73. StepCount.Start();
  74. }
  75. private void ControlLockTimer_Tick(object sender, EventArgs e)
  76. {
  77. this.Activate();
  78. ms_sncode.Focus();
  79. }
  80. private void Ma_code_DbChange(object sender, EventArgs e)
  81. {
  82. Dbfind = ma_code.ReturnData;
  83. BaseUtil.SetFormValue(this.Controls, Dbfind);
  84. LoadCollectedNum();
  85. LoadCheckQTY();
  86. }
  87. private void CleanInfo_Click(object sender, EventArgs e)
  88. {
  89. OperateResult.Clear();
  90. }
  91. private void ms_code_KeyDown(object sender, KeyEventArgs e)
  92. {
  93. if (e.KeyCode == Keys.Enter)
  94. {
  95. WaitList.Clear();
  96. ChoosedList.Clear();
  97. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out ErrorMessage))
  98. {
  99. bool NoteAlready = LogicHandler.CheckDiffMakeCodeBeforeStepCheck(ms_sncode.Text, ma_code.Text, NoteForChange.Checked, out oMakeCode, out ErrorMessage);
  100. if (!NoteAlready)
  101. {
  102. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  103. return;
  104. }
  105. if (LogicHandler.CheckStepSNAndMacode(oMakeCode, User.UserSourceCode, ms_sncode.Text, User.UserCode, out oMakeCode, out oMSID, out ErrorMessage))
  106. {
  107. //是否提示过工单切换框,检测前后执行
  108. if (!LogicHandler.CheckDiffMakeCodeAfterStepCheck(ms_sncode.Text, oMakeCode, NoteForChange.Checked, NoteAlready, ma_code, out ErrorMessage))
  109. {
  110. OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  111. return;
  112. }
  113. if (ma_code.Text != oMakeCode && oMakeCode != null)
  114. {
  115. dt = (DataTable)dh.ExecuteSql("select ma_code,ma_prodcode,ma_softversion,ma_salecode,pr_spec,nvl(pr_sendchecktype,'LineCode')pr_sendchecktype,ma_qty from make left join product on ma_prodcode=pr_code where ma_code='" + oMakeCode + "'", "select");
  116. if (dt.Rows.Count > 0)
  117. {
  118. BaseUtil.SetFormValue(this.Controls, dt);
  119. LockMakeCode.Checked = true;
  120. }
  121. }
  122. dt = (DataTable)dh.ExecuteSql("select ms_nextstepcode,ms_sncode,ms_reworkstatus,nvl(ms_ifrework,0)ms_ifrework,ms_stepcode,ms_status,nvl(ms_netcode,' ') ms_netcode,nvl(st_ifrepair,0) st_ifrepair from makeserial left join step on ms_stepcode=st_code where ms_id='" + oMSID + "'", "select");
  123. string status = dt.Rows[0]["ms_status"].ToString();
  124. reworkstatus = dt.Rows[0]["ms_reworkstatus"].ToString();
  125. string stepcode = dt.Rows[0]["ms_stepcode"].ToString();
  126. string ifrepair = dt.Rows[0]["st_ifrepair"].ToString();
  127. string sncode = dt.Rows[0]["ms_sncode"].ToString();
  128. string ms_netcode = dt.Rows[0]["ms_netcode"].ToString();
  129. string ms_nextstepcode = dt.Rows[0]["ms_nextstepcode"].ToString();
  130. if (ms_netcode != " " && dh.CheckExist("makeserial", "ms_netcode = '" + ms_netcode + "' and ms_sncode <>'" + ms_sncode.Text + "'"))
  131. {
  132. string othersn = dh.getFieldDataByCondition("makeserial", "ms_sncode", "ms_netcode = '" + ms_netcode + "' and ms_sncode <>'" + ms_sncode.Text + "'").ToString();
  133. OperateResult.AppendText(">>" + ms_sncode.Text + "对应wifibox:"+ms_netcode+"已被SN:"+othersn+"使用\n", Color.Red, ms_sncode);
  134. return;
  135. }
  136. if (sncode != ms_sncode.Text)
  137. {
  138. OperateResult.AppendText(">>" + ms_sncode.Text + " 序列号已执行过转号,不允许使用TSN采集\n", Color.Red, ms_sncode);
  139. return;
  140. }
  141. ifrework = dt.Rows[0]["ms_ifrework"].ToString();
  142. DataTable dtx = (DataTable)dh.ExecuteSql("select nvl(pr_omax,0)pr_omax,nvl(pr_omin,0)pr_omin,nvl(pr_tmax,0)pr_tmax,nvl(pr_tmin,0)pr_tmin from product where pr_code = '"+ma_prodcode.Text+"'", "select");
  143. double pr_omax = double.Parse(dtx.Rows[0]["pr_omax"].ToString());
  144. double pr_omin = double.Parse(dtx.Rows[0]["pr_omin"].ToString());
  145. double pr_tmax = double.Parse(dtx.Rows[0]["pr_tmax"].ToString());
  146. double pr_tmin = double.Parse(dtx.Rows[0]["pr_tmin"].ToString());
  147. if (pr_omax == 0 || pr_omin == 0 || pr_tmax == 0 || pr_tmin == 0)
  148. {
  149. OperateResult.AppendText(">>未获取到光感校准范围值\n", Color.Red, ms_sncode);
  150. return;
  151. }
  152. OperateResult.AppendText(">>设备检测\n", Color.Black);
  153. double avg1 = 0;
  154. double avg2 = 0;
  155. double ver1 = 0;
  156. double ver2 = 0;
  157. string str = BaseUtil.GetDataAdb("devices").ToUpper().Replace("LIST OF DEVICES ATTACHED", "").Replace("DEVICE", "").Replace("\n", "");
  158. if (!str.Contains(ms_sncode.Text))
  159. {
  160. OperateResult.AppendText(">>" + ms_sncode.Text + "与获取SN:"+str+"不一致\n", Color.Red, ms_sncode);
  161. return;
  162. }
  163. OperateResult.AppendText(">>核对SN成功,关闭抽屉\n", Color.Black);
  164. BaseUtil.GetDatacmd("Close_Drawer");
  165. Thread.Sleep(7000);
  166. OperateResult.AppendText(">>关闭暗箱所有灯光\n", Color.Black);
  167. BaseUtil.GetDatacmd("Close_Light_A");
  168. BaseUtil.GetDatacmd("Close_Light_B");
  169. OperateResult.AppendText(">>关闭产品背光\n", Color.Black);
  170. BaseUtil.GetDataAdb("shell letools setBacklightState off");
  171. OperateResult.AppendText(">>读取当前光感数值\n", Color.Black);
  172. try
  173. {
  174. double nowdata = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue"));
  175. if (nowdata >= 5)
  176. {
  177. OperateResult.AppendText(">>当前光感"+nowdata+"大于5,重新测试\n", Color.Red, ms_sncode);
  178. BaseUtil.GetDatacmd("Open_Drawer");
  179. return;
  180. }
  181. }
  182. catch (Exception ex)
  183. {
  184. OperateResult.AppendText(">>"+ex.Message+"\n", Color.Red, ms_sncode);
  185. BaseUtil.GetDatacmd("Open_Drawer");
  186. return;
  187. }
  188. OperateResult.AppendText(">>读取关灯光感数值3次并求出平均值\n", Color.Black);
  189. try
  190. {
  191. for (int i = 0; i < 3; i++)
  192. {
  193. avg1 = avg1 + double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue"));
  194. }
  195. avg1 = Math.Round(avg1 / 3, 2);
  196. }
  197. catch (Exception ex)
  198. {
  199. OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode);
  200. BaseUtil.GetDatacmd("Open_Drawer");
  201. return;
  202. }
  203. OperateResult.AppendText(">>写入关灯光感值"+ avg1 + "\n", Color.Black);
  204. BaseUtil.GetDataAdb("shell letools setLightSensorZero "+avg1);
  205. dh.ExecuteSql("update makeserial set ms_avg1 = '"+avg1+"' where ms_sncode = '"+ms_sncode.Text+"'", "update");
  206. OperateResult.AppendText(">>暂打开200lux光源\n", Color.Black);
  207. BaseUtil.GetDatacmd("Open_Light_A");
  208. OperateResult.AppendText(">>读取当前光感数值\n", Color.Black);
  209. try
  210. {
  211. double nowdata = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue"));
  212. if (nowdata < 150)
  213. {
  214. OperateResult.AppendText(">>当前光感" + nowdata + "小于150,重新测试\n", Color.Red, ms_sncode);
  215. BaseUtil.GetDatacmd("Open_Drawer");
  216. return;
  217. }
  218. }
  219. catch (Exception ex)
  220. {
  221. OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode);
  222. BaseUtil.GetDatacmd("Open_Drawer");
  223. return;
  224. }
  225. OperateResult.AppendText(">>读取当前200lux光感数值3次并求出平均值\n", Color.Black);
  226. avg2 = 0;
  227. try
  228. {
  229. for (int i = 0; i < 3; i++)
  230. {
  231. avg2 = avg2 + double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValue"));
  232. }
  233. avg2 = Math.Round(avg2 / 3, 2);
  234. }
  235. catch (Exception ex)
  236. {
  237. OperateResult.AppendText(">>" + ex.Message + "\n", Color.Red, ms_sncode);
  238. BaseUtil.GetDatacmd("Open_Drawer");
  239. return;
  240. }
  241. OperateResult.AppendText(">>写入200lux光感值" + avg2 + "\n", Color.Black);
  242. BaseUtil.GetDataAdb("shell letools setLightSensorCorr " + avg2);
  243. dh.ExecuteSql("update makeserial set ms_avg2 = '" + avg2 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update");
  244. OperateResult.AppendText(">>读取校准后200lux光感\n", Color.Black);
  245. ver1 = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValueCorrected"));
  246. if (ver1 < pr_omin || ver1 > pr_omax)
  247. {
  248. OperateResult.AppendText(">>200lux校准光感为" + ver1 + ",不在预设范围内,重新测试\n", Color.Red, ms_sncode);
  249. BaseUtil.GetDatacmd("Open_Drawer");
  250. return;
  251. }
  252. OperateResult.AppendText(">>200lux光感校准值"+ ver1 + "保存\n", Color.Black);
  253. dh.ExecuteSql("update makeserial set ms_ver1 = '" + ver1 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update");
  254. OperateResult.AppendText(">>关闭200lux并打开20lux\n", Color.Black);
  255. BaseUtil.GetDatacmd("Close_Light_A");
  256. BaseUtil.GetDatacmd("Open_Light_B");
  257. OperateResult.AppendText(">>读取校准后20lux光感\n", Color.Black);
  258. ver2 = double.Parse(BaseUtil.GetDataAdb("shell letools getLSensorValueCorrected"));
  259. if (ver2 < pr_tmin || ver2 > pr_tmax)
  260. {
  261. OperateResult.AppendText(">>20lux校准光感为" + ver2 + ",不在预设范围内,重新测试\n", Color.Red, ms_sncode);
  262. BaseUtil.GetDatacmd("Open_Drawer");
  263. return;
  264. }
  265. OperateResult.AppendText(">>20lux光感校准值" + ver2 + "保存\n", Color.Black);
  266. dh.ExecuteSql("update makeserial set ms_ver2 = '" + ver2 + "' where ms_sncode = '" + ms_sncode.Text + "'", "update");
  267. OperateResult.AppendText(">>读取WIFI MAC和BT MAC\n", Color.Black);
  268. string mac = BaseUtil.GetDataAdb("shell ft.sh getmac wifi");
  269. string bt = BaseUtil.GetDataAdb("shell ft.sh getmac bt");
  270. OperateResult.AppendText(">>保存WIFI:"+mac+",BT:"+bt+"\n", Color.Black);
  271. dh.ExecuteSql("update makeserial set ms_mac = '" + mac + "',ms_bt = '"+bt+"' where ms_sncode = '" + ms_sncode.Text + "'", "update");
  272. OperateResult.AppendText(">>测试完成打开抽屉\n", Color.Black);
  273. BaseUtil.GetDatacmd("Open_Drawer");
  274. int index = LabelDataGridView.Rows.Add();
  275. LabelDataGridView.Rows[index].Cells["SN"].Value = ms_sncode.Text;
  276. LabelDataGridView.Rows[index].Cells["avg1"].Value = avg1;
  277. LabelDataGridView.Rows[index].Cells["avg2"].Value = avg2;
  278. LabelDataGridView.Rows[index].Cells["ver1"].Value = ver1;
  279. LabelDataGridView.Rows[index].Cells["ver2"].Value = ver2;
  280. LabelDataGridView.Rows[index].Cells["wifis"].Value = mac;
  281. LabelDataGridView.Rows[index].Cells["bts"].Value = bt;
  282. if (!File.Exists(SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls"))
  283. {
  284. //创建内存流
  285. MemoryStream ms = new MemoryStream();
  286. //创建一个Book,相当于一个Excel文件
  287. HSSFWorkbook book = new HSSFWorkbook();
  288. //Excel中的Sheet
  289. ISheet sheet = book.CreateSheet("sheet1");
  290. //获取行数量和列数量
  291. int rowNum = LabelDataGridView.Rows.Count;
  292. int columnNum = LabelDataGridView.Columns.Count;
  293. //设置列的宽度,根据首行的列的内容的长度来设置
  294. for (int i = 0; i < columnNum; i++)
  295. {
  296. int dataLength = LabelDataGridView.Columns[i].Width;
  297. if (dataLength == 5)
  298. {
  299. sheet.SetColumnWidth(i, 0);
  300. }
  301. else
  302. {
  303. sheet.SetColumnWidth(i, dataLength * 25);
  304. }
  305. }
  306. //首先画好第一行带颜色的,单独写出来,避免写在循环里面
  307. IRow row = sheet.CreateRow(0);
  308. //冻结第一行
  309. sheet.CreateFreezePane(0, 1, 0, 1);
  310. ICellStyle style = book.CreateCellStyle();
  311. style.FillForegroundColor = HSSFColor.PALE_BLUE.index;
  312. style.FillPattern = FillPatternType.BIG_SPOTS;
  313. style.FillBackgroundColor = HSSFColor.LIGHT_GREEN.index;
  314. //设置边框
  315. style.BorderBottom = NPOI.SS.UserModel.BorderStyle.THICK;
  316. style.BorderLeft = NPOI.SS.UserModel.BorderStyle.THICK;
  317. style.BorderRight = NPOI.SS.UserModel.BorderStyle.THICK;
  318. style.BorderTop = NPOI.SS.UserModel.BorderStyle.THICK;
  319. row.HeightInPoints = 20;
  320. //固定第一行
  321. //row.RowStyle.IsLocked=true;
  322. //给第一行的标签赋值样式和值
  323. for (int j = 0; j < columnNum; j++)
  324. {
  325. row.CreateCell(j);
  326. row.Cells[j].CellStyle = style;
  327. row.Cells[j].CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  328. row.Cells[j].CellStyle.Alignment = NPOI.SS.UserModel.HorizontalAlignment.CENTER;
  329. row.Cells[j].SetCellValue(LabelDataGridView.Columns[j].HeaderText);
  330. }
  331. //将DataTable的值循环赋值给book,Aligment设置居中
  332. //之前已经画了带颜色的第一行,所以从i=1开始画
  333. IRow row1 = sheet.CreateRow(sheet.LastRowNum + 1);
  334. row1.HeightInPoints = 20;
  335. row1.CreateCell(0);
  336. row1.Cells[0].SetCellValue(ms_sncode.Text);
  337. row1.GetCell(0).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  338. row1.CreateCell(1);
  339. row1.Cells[1].SetCellValue(avg1);
  340. row1.GetCell(1).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  341. row1.CreateCell(2);
  342. row1.Cells[2].SetCellValue(avg2);
  343. row1.GetCell(2).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  344. row1.CreateCell(3);
  345. row1.Cells[3].SetCellValue(ver1);
  346. row1.GetCell(3).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  347. row1.CreateCell(4);
  348. row1.Cells[4].SetCellValue(ver2);
  349. row1.GetCell(4).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  350. row1.CreateCell(5);
  351. row1.Cells[5].SetCellValue(mac);
  352. row1.GetCell(5).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  353. row1.CreateCell(6);
  354. row1.Cells[6].SetCellValue(bt);
  355. row1.GetCell(6).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  356. //将book的内容写入内存流中返回
  357. book.Write(ms);
  358. //以系统当前时间命名文件,FileMode.Create表示创建文件,FileAccess.Write表示拥有写的权限
  359. string filePath = SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";
  360. FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write);
  361. byte[] data = ms.ToArray();
  362. fs.Write(data, 0, data.Length);
  363. fs.Flush();
  364. //释放当前Excel文件,否则打开文件的时候会显示文件被占用
  365. ms.Dispose();
  366. fs.Dispose();
  367. }
  368. else
  369. {
  370. //创建内存流
  371. MemoryStream ms = new MemoryStream();
  372. string filePath = SystemInf.CacheFolder + DateTime.Now.ToString("yyyy-MM-dd") + ".xls";
  373. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
  374. HSSFWorkbook book = new HSSFWorkbook(fs);
  375. ISheet sheet = book.GetSheet("sheet1");
  376. IRow row1 = sheet.CreateRow(sheet.LastRowNum + 1);
  377. row1.HeightInPoints = 20;
  378. row1.CreateCell(0);
  379. row1.Cells[0].SetCellValue(ms_sncode.Text);
  380. row1.GetCell(0).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  381. row1.CreateCell(1);
  382. row1.Cells[1].SetCellValue(avg1);
  383. row1.GetCell(1).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  384. row1.CreateCell(2);
  385. row1.Cells[2].SetCellValue(avg2);
  386. row1.GetCell(2).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  387. row1.CreateCell(3);
  388. row1.Cells[3].SetCellValue(ver1);
  389. row1.GetCell(3).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  390. row1.CreateCell(4);
  391. row1.Cells[4].SetCellValue(ver2);
  392. row1.GetCell(4).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  393. row1.CreateCell(5);
  394. row1.Cells[5].SetCellValue(mac);
  395. row1.GetCell(5).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  396. row1.CreateCell(6);
  397. row1.Cells[6].SetCellValue(bt);
  398. row1.GetCell(6).CellStyle.VerticalAlignment = VerticalAlignment.CENTER;
  399. fs = new FileStream(filePath, FileMode.Open, FileAccess.ReadWrite);
  400. fs.Flush();
  401. book.Write(fs);
  402. fs.Close();
  403. }
  404. SetCollectResult();
  405. }
  406. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  407. }
  408. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  409. }
  410. }
  411. /// <summary>
  412. /// 设置良品或者不良品的采集结果
  413. /// </summary>
  414. private void SetCollectResult()
  415. {
  416. string ErrorMessage = "";
  417. //如果勾选的是不良品
  418. if (Reject.Checked)
  419. {
  420. OperateResult.AppendText(">>请采集不良代码\n", Color.Green);
  421. //勾选了自动产生代码
  422. if (AutoBadCode.Checked)
  423. Save_Click(new object(), new EventArgs());
  424. }
  425. else if (GoodProduct.Checked)
  426. {
  427. //如果不是返修的
  428. if (ifrework == "0")
  429. {
  430. 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='" + ma_code.Text + "' and mb_status=0", "select");
  431. for (int i = 0; i < dt.Rows.Count; i++)
  432. {
  433. if (dt.Rows[i]["mb_id"].ToString() != dt.Rows[i]["mbr_mbid"].ToString())
  434. ErrorMessage += "【" + dt.Rows[i]["bc_name"].ToString() + "】";
  435. }
  436. //存在不良记录
  437. if (ErrorMessage != "")
  438. {
  439. OperateResult.AppendText(">>序列号:" + ms_sncode.Text + " 已经判为不良品,不允许修改!\n", Color.Red);
  440. return;
  441. }
  442. else
  443. {
  444. //良品信息采集
  445. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  446. {
  447. //提示正确返回时传递的信息
  448. if (ErrorMessage.Contains("AFTERSUCCESS"))
  449. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  450. LastSncode = ms_sncode.Text;
  451. OperateResult.AppendText(">>" + ms_sncode.Text + "良品采集成功\n", Color.Green, ms_sncode);
  452. //记录操作日志
  453. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  454. }
  455. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  456. }
  457. }
  458. else
  459. {
  460. if (reworkstatus != "3")
  461. {
  462. if (LogicHandler.SetStepResult(ma_code.Text, User.UserSourceCode, ms_sncode.Text, "良品采集", "检测合格", User.UserCode, out ErrorMessage))
  463. {
  464. //提示正确返回时传递的信息
  465. if (ErrorMessage.Contains("AFTERSUCCESS"))
  466. OperateResult.AppendText(">>" + ErrorMessage + "\n");
  467. LastSncode = ms_sncode.Text;
  468. OperateResult.AppendText(">>" + ms_sncode.Text + "成功采集为良品\n", Color.Green, ms_sncode);
  469. //记录操作日志
  470. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "采集良品", "采集良品成功", LastSncode, ob_checkno.Text);
  471. }
  472. else OperateResult.AppendText(">>" + ErrorMessage + "\n", Color.Red, ms_sncode);
  473. }
  474. else
  475. {
  476. OperateResult.AppendText(">>返修的不良序列号必须先进行维修\n", Color.Red);
  477. }
  478. }
  479. }
  480. //加载页面信息
  481. LoadCollectedNum();
  482. LoadCheckQTY();
  483. }
  484. private void 测试采集_SizeChanged(object sender, EventArgs e)
  485. {
  486. asc.controlAutoSize(this);
  487. }
  488. private void LoadCollectedNum()
  489. {
  490. dt = (DataTable)dh.ExecuteSql("select mcd_inqty,ma_qty-mcd_inqty mcd_remainqty from make left join makecraftdetail on mcd_macode=ma_code where ma_code='" + ma_code.Text + "' and mcd_stepcode='" + User.CurrentStepCode + "'", "select");
  491. BaseUtil.SetFormValue(Controls, dt);
  492. }
  493. private void Save_Click(object sender, EventArgs e)
  494. {
  495. if (ms_sncode.Text == "")
  496. {
  497. OperateResult.AppendText(">>序列号不允许为空\n", Color.Red);
  498. return;
  499. }
  500. if (GoodProduct.Checked)
  501. ms_code_KeyDown(sender, new KeyEventArgs(Keys.Enter));
  502. }
  503. private void LoadCheckQTY()
  504. {
  505. sql.Clear();
  506. string condition = "";
  507. int nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  508. int batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  509. if (nowcheckqty + 1 == batchqty && AutoCut)
  510. {
  511. condition = "and ob_status='UNCHECK' and ob_checkno='" + ob_checkno.Text + "'";
  512. }
  513. else
  514. {
  515. condition = "and ob_status='ENTERING' ";
  516. }
  517. if (pr_sendchecktype.Text == "SaleCode")
  518. {
  519. condition += " and ob_salecode='" + ma_salecode.Text + "'";
  520. }
  521. sql.Append("select ob_batchqty,ob_nowcheckqty,ob_checkno from oqcbatch where ");
  522. sql.Append("ob_linecode='" + User.UserLineCode + "' and ob_prodcode='" + ma_prodcode.Text + "' and ");
  523. sql.Append("ob_stepcode='" + User.CurrentStepCode + "' " + condition);
  524. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  525. if (dt.Rows.Count > 0)
  526. {
  527. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  528. ob_batchqty.Text = dt.Rows[0]["ob_batchqty"].ToString();
  529. ob_nowcheckqty.Text = dt.Rows[0]["ob_nowcheckqty"].ToString();
  530. ob_checkno.Text = dt.Rows[0]["ob_checkno"].ToString();
  531. nowcheckqty = int.Parse(ob_nowcheckqty.Text == "" ? "0" : ob_nowcheckqty.Text);
  532. batchqty = int.Parse(ob_batchqty.Text == "" ? "0" : ob_batchqty.Text);
  533. if (nowcheckqty == batchqty)
  534. {
  535. ob_nowcheckqty.ForeColor = Color.Red;
  536. OperateResult.AppendText(">>当前采集数量已达到送检数量\n", Color.Red);
  537. if (AutoCut)
  538. {
  539. OperateResult.AppendText(">>批次" + ob_checkno.Text + "自动断批\n", Color.Blue);
  540. }
  541. }
  542. }
  543. else
  544. {
  545. BaseUtil.CleanControlsText(ob_batchqty, ob_nowcheckqty, ob_checkno);
  546. SendCheck.Enabled = false;
  547. }
  548. if (ob_batchqty.Text != "")
  549. {
  550. SendCheck.Enabled = true;
  551. }
  552. else
  553. {
  554. SendCheck.Enabled = false;
  555. }
  556. }
  557. private void GoodProduct_CheckedChanged(object sender, EventArgs e)
  558. {
  559. if (GoodProduct.Checked)
  560. {
  561. Save.Visible = false;
  562. }
  563. else
  564. {
  565. Save.Visible = true;
  566. }
  567. if (ms_sncode.Text == "")
  568. {
  569. ms_sncode.Focus();
  570. }
  571. }
  572. private void SendCheck_Click(object sender, EventArgs e)
  573. {
  574. sql.Clear();
  575. sql.Append("update oqcbatch set ob_status='UNCHECK' where ob_checkno ='" + ob_checkno.Text + "'");
  576. dh.ExecuteSql(sql.GetString(), "select");
  577. ob_sendqty.Text = dh.getFieldDataByCondition("oqcbatch", "sum(ob_nowcheckqty)", "ob_makecode='" + ma_code.Text + "' and ob_status<>'ENTERING'").ToString();
  578. ob_nowcheckqty.Text = "";
  579. ob_batchqty.Text = "";
  580. ob_nowcheckqty.ForeColor = Color.Black;
  581. SendCheck.Enabled = false;
  582. OperateResult.AppendText(">>批次" + ob_checkno.Text + "送检成功\n", Color.Blue);
  583. ms_sncode.Focus();
  584. LogicHandler.InsertMakeProcess(LastSncode, ma_code.Text, User.UserSourceCode, "手动送检", "手动送检成功", User.UserCode);
  585. //记录操作日志
  586. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "手动送检", "手动送检成功", "", ob_checkno.Text);
  587. ob_checkno.Text = "";
  588. }
  589. private void ob_checkno_TextChanged(object sender, EventArgs e)
  590. {
  591. if (ob_checkno.Text != "")
  592. {
  593. string Cut = dh.getFieldDataByCondition("product left join oqcbatch on ob_prodcode=pr_code", "pr_ifautocutcheckno", "ob_checkno='" + ob_checkno.Text + "'").ToString();
  594. if (Cut == "" || Cut == "0")
  595. AutoCut = false;
  596. else
  597. AutoCut = true;
  598. SendCheck.Enabled = true;
  599. }
  600. }
  601. /// <summary>
  602. /// 工单变化修改数量
  603. /// </summary>
  604. /// <param name="sender"></param>
  605. /// <param name="e"></param>
  606. private void ma_code_UserControlTextChanged(object sender, EventArgs e)
  607. {
  608. if (ma_code.Text.Length > 4)
  609. {
  610. BaseUtil.CleanControlsText(mcd_inqty, mcd_remainqty, ob_batchqty, ob_nowcheckqty, ob_sendqty);
  611. LoadCollectedNum();
  612. LoadCheckQTY();
  613. }
  614. }
  615. private void Make_TestCollection_FormClosing(object sender, FormClosingEventArgs e)
  616. {
  617. dh.Dispose();
  618. }
  619. private void ma_prodcode_TextChanged(object sender, EventArgs e)
  620. {
  621. }
  622. private void Make_TestCollection_KeyDown(object sender, KeyEventArgs e)
  623. {
  624. if (e.Modifiers == Keys.Control && e.KeyCode == Keys.Q)
  625. {
  626. if (!LockSn)
  627. {
  628. ControlLockTimer.Start();
  629. LockSn = true;
  630. Lock_label.Visible = true;
  631. }
  632. else
  633. {
  634. ControlLockTimer.Stop();
  635. LockSn = false;
  636. Lock_label.Visible = false;
  637. }
  638. }
  639. }
  640. private void button1_Click(object sender, EventArgs e)
  641. {
  642. }
  643. }
  644. }