Make_TestCollectionlux.cs 35 KB

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