Make_GetTestFileData.cs 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Windows.Forms;
  10. using UAS_MES_NEW.DataOperate;
  11. using UAS_MES_NEW.Entity;
  12. using UAS_MES_NEW.PublicForm;
  13. using UAS_MES_NEW.PublicMethod;
  14. namespace UAS_MES_NEW.Make
  15. {
  16. public partial class Make_GetTestFileData : Form
  17. {
  18. AutoSizeFormClass asc = new AutoSizeFormClass();
  19. DataHelper dh;
  20. LogStringBuilder sql;
  21. string oErrorMessage = "";
  22. string omakeCode = "";
  23. string oMsid = "";
  24. ftpOperater ftp = new ftpOperater();
  25. public Make_GetTestFileData()
  26. {
  27. InitializeComponent();
  28. }
  29. private void Make_LabelCheck_Load(object sender, EventArgs e)
  30. {
  31. asc.controllInitializeSize(this);
  32. //聚焦SN号
  33. sncode.Focus();
  34. //打开界面提示用户:请输入SN
  35. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  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. }
  44. private void Make_LabelCheck_SizeChanged(object sender, EventArgs e)
  45. {
  46. asc.controlAutoSize(this);
  47. }
  48. private void LoadCollectedNum()
  49. {
  50. sql.Clear();
  51. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  52. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  53. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  54. DataTable dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  55. BaseUtil.SetFormValue(Controls, dt);
  56. }
  57. private void sncode_KeyDown(object sender, KeyEventArgs e)
  58. {
  59. //判断是enter事件
  60. if (e.KeyCode == Keys.Enter)
  61. {
  62. if (sncode.Text == "")
  63. {
  64. OperateResult.AppendText("<<输入不能为空\n", Color.Red);
  65. return;
  66. }
  67. if (LogicHandler.CheckStepAttribute(Tag.ToString(), User.UserSourceCode, out oErrorMessage))
  68. {
  69. DataTable dt1 = new DataTable();
  70. dt1 = (DataTable)dh.ExecuteSql("select 1 from makeserial where ms_sncode='" + sncode.Text + "'", "select");
  71. if (dt1.Rows.Count == 0)
  72. {
  73. OperateResult.AppendText("序列号" + sncode.Text + "不存在\n", Color.Red);
  74. return;
  75. }
  76. //if (LogicHandler.CheckStepSNAndMacode("", User.UserSourceCode, sncode.Text, User.UserCode, out omakeCode, out oMsid, out oErrorMessage))
  77. //{
  78. ma_code.Text = omakeCode;
  79. LoadCollectedNum();
  80. //发送对应平台的指令
  81. if (MTK.Checked)
  82. {
  83. BaseUtil.GetDataFromDevice("MTK");
  84. }
  85. else
  86. {
  87. BaseUtil.GetDataFromDevice("ZHANXUN");
  88. }
  89. string ms_prodcode = dh.getFieldDataByCondition("makeserial", "ms_prodcode", "ms_id='" + oMsid + "'").ToString();
  90. DataTable dt = new DataTable();
  91. if (Directory.Exists(Application.StartupPath + "/" + DateTime.Now.ToString("yyyy-MM-dd") + @"/" + sncode.Text))
  92. {
  93. DirectoryInfo di = new DirectoryInfo(Application.StartupPath + "/" + DateTime.Now.ToString("yyyy-MM-dd") + @"/" + sncode.Text);
  94. FileInfo[] file = di.GetFiles();
  95. for (int i = 0; i < file.Length; i++)
  96. {
  97. File.Delete(file[i].FullName);
  98. }
  99. }
  100. BaseUtil.GetDataFromDevice("GETFILE", WatchPath.Text + " ./" + DateTime.Now.ToString("yyyy-MM-dd") + @"/" + sncode.Text);
  101. string[] files = Directory.GetFiles(Application.StartupPath + "/" + DateTime.Now.ToString("yyyy-MM-dd") + @"/" + sncode.Text + "", "*.csv");
  102. if (files.Length == 0)
  103. {
  104. files = Directory.GetFiles(Application.StartupPath + "/" + DateTime.Now.ToString("yyyy-MM-dd") + @"/" + sncode.Text + "/factory", "*.csv");
  105. }
  106. if (!BaseUtil.OpenCSVFile(ref dt, files[0]))
  107. {
  108. if (files.Length > 1)
  109. {
  110. dt = new DataTable();
  111. BaseUtil.OpenCSVFile(ref dt, files[1]);
  112. }
  113. }
  114. //移除标题行
  115. dt.Rows.RemoveAt(0);
  116. if (dt.Columns.Count == 12 || dt.Columns.Count == 13)
  117. {
  118. //设置列名绑定数据
  119. dt.Columns[0].ColumnName = "std_class";
  120. dt.Columns[1].ColumnName = "std_testresult";
  121. dt.Columns[2].ColumnName = "std_sn";
  122. dt.Columns[3].ColumnName = "std_mac";
  123. dt.Columns[4].ColumnName = "std_bt";
  124. dt.Columns[5].ColumnName = "std_imei1";
  125. dt.Columns[6].ColumnName = "std_imei2";
  126. dt.Columns[7].ColumnName = "std_googlekey";
  127. dt.Columns[8].ColumnName = "std_videotest";
  128. dt.Columns[9].ColumnName = "std_version";
  129. dt.Columns[10].ColumnName = "std_rom";
  130. dt.Columns[11].ColumnName = "std_ram";
  131. if (dt.Rows.Count > 0)
  132. {
  133. PSN.Text = dt.Rows[0]["std_sn"].ToString();
  134. if (sncode.Text != PSN.Text)
  135. {
  136. OperateResult.AppendText("扫描SN【" + sncode.Text + "】和设备读取SN【" + PSN.Text + "不相符】\n", Color.Red);
  137. BaseUtil.CleanControls(this.Controls);
  138. WatchPath.Text = "/sdcard/factory";
  139. return;
  140. }
  141. MAC.Text = dt.Rows[0]["std_mac"].ToString().Replace(":", "").ToUpper();
  142. BT.Text = dt.Rows[0]["std_bt"].ToString().Replace(":", "").ToUpper();
  143. IMEI1.Text = dt.Rows[0]["std_imei1"].ToString().Replace("null", "").Replace("unknow", "");
  144. IMEI2.Text = dt.Rows[0]["std_imei2"].ToString().Replace("null", "").Replace("unknow", "");
  145. GoogleKey.Text = dt.Rows[0]["std_googlekey"].ToString().Replace("null", "").Replace("unknow", "").ToUpper();
  146. Aging.Text = dt.Rows[0]["std_videotest"].ToString().Replace("null", "").Replace("unknow", "").ToUpper();
  147. Version.Text = dt.Rows[0]["std_version"].ToString().Replace("null", "").Replace("unknow", "");
  148. ram.Text = dt.Rows[0]["std_ram"].ToString().Replace("null", "").Replace("unknow", "");
  149. rom.Text = dt.Rows[0]["std_rom"].ToString().Replace("null", "").Replace("unknow", "");
  150. }
  151. }
  152. if (dt.Columns.Count == 9 || dt.Columns.Count == 8)
  153. {
  154. //设置列名绑定数据
  155. dt.Columns[0].ColumnName = "std_class";
  156. dt.Columns[1].ColumnName = "std_testresult";
  157. dt.Columns[2].ColumnName = "std_sn";
  158. dt.Columns[3].ColumnName = "std_mac";
  159. dt.Columns[4].ColumnName = "std_bt";
  160. dt.Columns[5].ColumnName = "std_version";
  161. dt.Columns[6].ColumnName = "std_rom";
  162. dt.Columns[7].ColumnName = "std_ram";
  163. if (dt.Rows.Count > 0)
  164. {
  165. PSN.Text = dt.Rows[0]["std_sn"].ToString();
  166. if (sncode.Text != PSN.Text)
  167. {
  168. OperateResult.AppendText("扫描SN【" + sncode.Text + "】和设备读取SN【" + PSN.Text + "不相符】\n", Color.Red);
  169. BaseUtil.CleanControls(this.Controls);
  170. WatchPath.Text = "/sdcard/factory";
  171. return;
  172. }
  173. MAC.Text = dt.Rows[0]["std_mac"].ToString().Replace(":", "").ToUpper();
  174. BT.Text = dt.Rows[0]["std_bt"].ToString().Replace(":", "").ToUpper();
  175. Version.Text = dt.Rows[0]["std_version"].ToString().Replace("null", "").Replace("unknow", "");
  176. ram.Text = dt.Rows[0]["std_ram"].ToString().Replace("null", "").Replace("unknow", "");
  177. rom.Text = dt.Rows[0]["std_rom"].ToString().Replace("null", "").Replace("unknow", "");
  178. }
  179. }
  180. DataView dv = dt.DefaultView;
  181. dv.Sort = "std_testresult Asc";
  182. dt = dv.ToTable();
  183. CheckItemDGV.DataSource = dt;
  184. bool Result = true;
  185. for (int i = 0; i < dt.Rows.Count; i++)
  186. {
  187. if (dt.Rows[i]["std_testresult"].ToString() != "OK" || dt.Rows[i]["std_testresult"].ToString() == "NOTEST")
  188. {
  189. Result = false;
  190. }
  191. dh.ExecuteSql("insert into STEPTESTDETAIL(std_id,std_sn,std_indate,std_class,std_testtimes,std_testresult,std_badcode) values(STEPTESTDETAIL_seq.nextval,'" + sncode.Text + "',sysdate,'" + dt.Rows[i]["std_class"].ToString() + "','','" + dt.Rows[i]["std_testresult"].ToString() + "','')", "insert");
  192. }
  193. //IMEI核对
  194. dt = (DataTable)dh.ExecuteSql("select mil_imei1,mil_imei2 from makeimeilist where mil_psn='" + PSN.Text + "'", "select");
  195. if (dt.Rows.Count > 0)
  196. {
  197. string imei1 = dt.Rows[0]["mil_imei1"].ToString();
  198. string imei2 = dt.Rows[0]["mil_imei2"].ToString();
  199. if (IMEI1.Text == imei1 && IMEI1.Text != "")
  200. {
  201. OperateResult.AppendText(PSN.Text + "【IMEI1】比对成功\n", Color.Green);
  202. }
  203. else
  204. {
  205. OperateResult.AppendText(PSN.Text + "读取【IMEI1】:" + IMEI1.Text + ",系统导入:" + imei1 + ",比对失败\n", Color.Red);
  206. }
  207. if (IMEI2.Text == imei2 && IMEI2.Text != "")
  208. {
  209. OperateResult.AppendText(PSN.Text + "【IMEI2】比对成功\n", Color.Green);
  210. }
  211. else
  212. {
  213. OperateResult.AppendText(PSN.Text + "读取【IMEI2】:" + IMEI2.Text + ",系统导入:" + imei2 + ",比对失败\n", Color.Red);
  214. }
  215. }
  216. else
  217. {
  218. OperateResult.AppendText(PSN.Text + "未导入IMEI\n", Color.Red);
  219. }
  220. //MAC核对
  221. dt = (DataTable)dh.ExecuteSql("select mal_mac,mal_bt from makeaddresslist where mal_sncode='" + PSN.Text + "'", "select");
  222. if (dt.Rows.Count > 0)
  223. {
  224. string mac = dt.Rows[0]["mal_mac"].ToString();
  225. string bt = dt.Rows[0]["mal_bt"].ToString();
  226. if (MAC.Text == mac && MAC.Text != "")
  227. {
  228. OperateResult.AppendText(PSN.Text + "【MAC】比对成功\n", Color.Green);
  229. }
  230. else
  231. {
  232. OperateResult.AppendText(PSN.Text + "读取【MAC】:" + MAC.Text + ",系统导入:" + mac + ",比对失败\n", Color.Red);
  233. }
  234. if (BT.Text == bt && BT.Text != "")
  235. {
  236. OperateResult.AppendText(PSN.Text + "【BT】比对成功\n", Color.Green);
  237. }
  238. else
  239. {
  240. OperateResult.AppendText(PSN.Text + "读取【BT】:" + BT.Text + ",系统导入:" + bt + ",比对失败\n", Color.Red);
  241. }
  242. }
  243. else
  244. {
  245. OperateResult.AppendText(PSN.Text + "未导入MAC/BT\n", Color.Red);
  246. }
  247. //if (Aging.Text == "")
  248. //{
  249. // OperateResult.AppendText(">>" + sncode.Text + "设备未进行老化测试\n");
  250. // return;
  251. //}
  252. if (true)
  253. {
  254. //提示正确返回时传递的信息
  255. if (oErrorMessage.Contains("AFTERSUCCESS"))
  256. OperateResult.AppendText(">>" + oErrorMessage + "\n");
  257. //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  258. sql.Clear();
  259. sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  260. sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  261. sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  262. dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  263. BaseUtil.SetFormValue(Controls, dt);
  264. //将SN,时间,结果记录在页面1
  265. //记录日志
  266. //ftp.UpLoadFile(Application.StartupPath, sncode.Text + ".csv", "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + ms_prodcode + "/");
  267. LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "参数核对成功", sncode.Text, "");
  268. //SN核对成功
  269. //>> 请输入SN
  270. OperateResult.AppendText("<<" + sncode.Text + "信息核对完成\n", Color.Green, sncode);
  271. OperateResult.AppendText(">>请输入SN\n", Color.Black);
  272. SetCheck set = new SetCheck("OK", Color.Green);
  273. BaseUtil.SetFormCenter(set);
  274. set.ShowDialog();
  275. if (ReSet.Checked)
  276. {
  277. BaseUtil.GetDataFromDevice("RESET");
  278. }
  279. //if (LogicHandler.snChangeAndBurn(sncode.Text, PSN.Text, User.UserSourceCode, User.UserCode, omakeCode, 0, IMEI1.Text, IMEI2.Text, "", "", "", "", "", "", "", MAC.Text, BT.Text, "", "", "", out oErrorMessage))
  280. //{
  281. //}
  282. //else
  283. //{
  284. // OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  285. //}
  286. //if (LogicHandler.SetStepResult(omakeCode, User.UserSourceCode, sncode.Text, "", "OK", User.UserCode, out oErrorMessage))
  287. //{
  288. // //提示正确返回时传递的信息
  289. // if (oErrorMessage.Contains("AFTERSUCCESS"))
  290. // OperateResult.AppendText(">>" + oErrorMessage + "\n");
  291. // //根据工单号查询makecraftdetail 表中的 mcd_okqty 计数,剩余数为ma_qty - nvl(mcd_inqty,0),刷新页面中工单信息的显示
  292. // sql.Clear();
  293. // sql.Append("select ma_code,nvl(mcd_okqty,0) mcd_okqty,ma_prodcode,pr_detail,");
  294. // sql.Append("ma_qty - nvl(mcd_okqty, 0) remain_qty from make left join makecraftdetail on ");
  295. // sql.Append("mcd_maid=ma_id left join product on pr_code=ma_prodcode where ma_code='" + omakeCode + "' and mcd_stepcode='" + User.CurrentStepCode + "'");
  296. // dt = (DataTable)dh.ExecuteSql(sql.GetString(), "select");
  297. // BaseUtil.SetFormValue(Controls, dt);
  298. // //将SN,时间,结果记录在页面
  299. // //记录日志
  300. // //ftp.UpLoadFile(Application.StartupPath, sncode.Text + ".csv", "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + ms_prodcode + "/");
  301. // LogicHandler.DoCommandLog(Tag.ToString(), User.UserCode, ma_code.Text, User.UserLineCode, User.UserSourceCode, "标签核对", "参数核对成功", sncode.Text, "");
  302. // //SN核对成功
  303. // //>> 请输入SN
  304. // OperateResult.AppendText("<<" + sncode.Text + "信息核对成功\n", Color.Green, sncode);
  305. // OperateResult.AppendText(">>请输入SN\n", Color.Black);
  306. // SetCheck set = new SetCheck("OK", Color.Green);
  307. // BaseUtil.SetFormCenter(set);
  308. // set.ShowDialog();
  309. // if (ReSet.Checked)
  310. // {
  311. // BaseUtil.GetDataFromDevice("RESET");
  312. // }
  313. //}
  314. //else
  315. //{
  316. // OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  317. //}
  318. }
  319. else
  320. {
  321. //ftp.UpLoadFile(Application.StartupPath, sncode.Text + ".csv", "/" + DateTime.Now.ToString("yyyy-MM-dd") + "/" + ms_prodcode + "/");
  322. OperateResult.AppendText(">>序列号" + sncode.Text + "测试不通过\n", Color.Red, sncode);
  323. }
  324. }
  325. //else
  326. //{
  327. // OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  328. //}
  329. //}
  330. else
  331. {
  332. OperateResult.AppendText(">>" + oErrorMessage + "\n", Color.Red, sncode);
  333. }
  334. }
  335. }
  336. private void StepCount_Load(object sender, EventArgs e)
  337. {
  338. }
  339. private void CheckItemDGV_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
  340. {
  341. //系统值和
  342. if (e.ColumnIndex >= 0)
  343. {
  344. if (CheckItemDGV.Columns[e.ColumnIndex].Name == "std_testresult")
  345. {
  346. if (e.RowIndex >= 0)
  347. {
  348. if (CheckItemDGV.Rows[e.RowIndex].Cells["std_testresult"].Value != null && (CheckItemDGV.Rows[e.RowIndex].Cells["std_testresult"].Value.ToString() == "OK"))
  349. {
  350. e.Graphics.FillRectangle(Brushes.ForestGreen, e.CellBounds);
  351. Rectangle border = e.CellBounds;
  352. border.Width -= 1;
  353. e.Graphics.DrawRectangle(Pens.Black, border);
  354. e.PaintContent(e.CellBounds);
  355. e.Handled = true;
  356. }
  357. else
  358. {
  359. e.Graphics.FillRectangle(Brushes.OrangeRed, e.CellBounds);
  360. Rectangle border = e.CellBounds;
  361. border.Width -= 1;
  362. e.Graphics.DrawRectangle(Pens.Black, border);
  363. e.PaintContent(e.CellBounds);
  364. e.Handled = true;
  365. }
  366. }
  367. }
  368. }
  369. }
  370. }
  371. }