NTFBLL.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623
  1. using MOKA_Factory_Tools.DAL;
  2. using MOKA_Factory_Tools.Models;
  3. using SXLibrary;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace MOKA_Factory_Tools.BLL
  10. {
  11. public partial class NTFBLL
  12. {
  13. /// <summary>
  14. /// ""=异常,OncePass,NTF,ReadFial
  15. /// </summary>
  16. public string ResultType = "";
  17. private string _strLastSN = "";
  18. protected readonly DAL_AMResult dalAMResult = new DAL_AMResult();
  19. protected readonly DAL_AMYields dalAMYields = new DAL_AMYields();
  20. protected readonly DAL_AMResult_TR dalAMResultTR = new DAL_AMResult_TR();
  21. protected readonly DAL_AMYields_TR dalAMYieldsTR = new DAL_AMYields_TR();
  22. /// <summary>
  23. /// 设置数据抄写结果;
  24. /// </summary>
  25. /// <param name="strLine">线体,UI输入</param>
  26. /// <param name="strStation">默认为:DataBurning</param>
  27. /// <param name="strSN"></param>
  28. /// <param name="bResult">抄写结果:成功或失败</param>
  29. /// <param name="strErrMsg">抄写失败时的描述</param>
  30. /// <returns></returns>
  31. public bool SetDataBuringResult(string strLine, string strStation, string strSN, string strDSN, bool bResult, string strLastSN, int nOrderType, string strErrMsg = "")
  32. {
  33. MaInfo maInfo;
  34. _strLastSN = strLastSN;
  35. DateTime dateNow = DateTime.Now;
  36. // 通过SN获取MES服务器中记录的ODF、Model、Dissemination信息;
  37. if (CommonMethod.GetMaInfo(strSN, out maInfo, null))
  38. {
  39. // 1.通过SN查询出订单类型;
  40. if (nOrderType == 1) // 量产;
  41. {
  42. AMResult aMResult = new AMResult();
  43. // 测试日期;
  44. string strTestDate = dateNow.ToString("yyyy-MM-dd");
  45. // 测试完成时间;
  46. string strTestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
  47. #region 赋值model
  48. aMResult.TestDate = dateNow.Date;
  49. aMResult.Line = strLine;
  50. aMResult.Station = strStation;
  51. aMResult.DSN = strDSN;
  52. aMResult.ODF = maInfo.ODF;
  53. aMResult.Model = maInfo.Model;
  54. aMResult.Dimension = maInfo.SIZE;
  55. aMResult.TestHour = dateNow.Hour;
  56. aMResult.TestTime = strTestTime;
  57. aMResult.SN = strSN;
  58. #endregion
  59. if (IsRecordExist(aMResult))
  60. {
  61. if (!UpdateAMResults(aMResult, bResult, strErrMsg))
  62. {
  63. // 更新失败;
  64. return false;
  65. }
  66. }
  67. else
  68. {
  69. if (!AddAMResult(aMResult, bResult, strErrMsg))
  70. {
  71. // 更新失败;
  72. return false;
  73. }
  74. }
  75. // 更新统计结果;
  76. if (!UpdateAMYields(aMResult, bResult, strErrMsg))
  77. {
  78. return false;
  79. }
  80. return true;
  81. }
  82. else if (nOrderType == 0) // 试产;
  83. {
  84. AMResult_TR aMResult = new AMResult_TR();
  85. // 测试日期;
  86. string strTestDate = dateNow.ToString("yyyy-MM-dd");
  87. // 测试完成时间;
  88. string strTestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
  89. #region 赋值model
  90. aMResult.TestDate = dateNow.Date;
  91. aMResult.Line = strLine;
  92. aMResult.Station = strStation;
  93. aMResult.DSN = strDSN;
  94. aMResult.ODF = maInfo.ODF;
  95. aMResult.Model = maInfo.Model;
  96. aMResult.Dimension = maInfo.SIZE;
  97. aMResult.TestHour = dateNow.Hour;
  98. aMResult.TestTime = strTestTime;
  99. aMResult.SN = strSN;
  100. #endregion
  101. if (IsRecordExist(aMResult))
  102. {
  103. if (!UpdateAMResults(aMResult, bResult, strErrMsg))
  104. {
  105. // 更新失败;
  106. return false;
  107. }
  108. }
  109. else
  110. {
  111. if (!AddAMResult(aMResult, bResult, strErrMsg))
  112. {
  113. // 更新失败;
  114. return false;
  115. }
  116. }
  117. // 更新统计结果;
  118. if (!UpdateAMYields(aMResult, bResult, strErrMsg))
  119. {
  120. return false;
  121. }
  122. return true;
  123. }
  124. }
  125. return false;
  126. }
  127. #region ------量产NTF------;
  128. public bool IsRecordExist(AMResult model)
  129. {
  130. return dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  131. }
  132. /// <summary>
  133. /// 新增记录;
  134. /// </summary>
  135. /// <param name="model"></param>
  136. /// <returns></returns>
  137. public bool AddAMResult(AMResult model, bool TestResult, string strErrMsg)
  138. {
  139. // 赋新值;
  140. model.Test01 = model.FinalTest = TestResult ? "PASS" : "FAIL";
  141. model.Test02 = "null";
  142. model.ReDo = "0";
  143. ResultType = model.ResultType = TestResult ? "OncePass" : "RealFail";
  144. if (!TestResult)
  145. model.ErrorMsg = strErrMsg;
  146. return dalAMResult.Add(model);
  147. }
  148. public bool UpdateAMResults(AMResult model, bool TestResult, string strErrMsg)
  149. {
  150. // 先获取ReDo="0"的记录;
  151. AMResult redo0Model = dalAMResult.GetModel(string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", model.Station, model.SN, "0"));
  152. if (_strLastSN == model.SN)
  153. {// 连续抄写数据,更新ReDo="0"的记录;
  154. Log.WriteInfoLog(string.Format("上一次SN={0} 与当前SN={1} 相同,只更新数据", _strLastSN, model.SN));
  155. if (!UpdateReDo0AMResult(redo0Model, TestResult, strErrMsg))
  156. {
  157. // 更新失败;
  158. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  159. return false;
  160. }
  161. }
  162. else
  163. {// 将原ReDo="0"更新为ReDo=Max(ReDo)+1,并新增ReDo="0"的记录;
  164. int maxReDo = dalAMResult.GetMaxID("convert(int,ReDo)", string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  165. redo0Model.ReDo = maxReDo.ToString();
  166. if (!dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, "0")))
  167. {
  168. // 更新失败;
  169. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  170. return false;
  171. }
  172. // 新增ReDo=0记录;
  173. if (!AddAMResult(model, TestResult, strErrMsg))
  174. {
  175. // 添加失败;
  176. Log.WriteInfoLog(string.Format("AMResult新增SN={0},Station={1},TestTime={2},ReDo={3} 失败", model.SN, model.Station, model.TestTime, model.ReDo));
  177. return false;
  178. }
  179. }
  180. return true;
  181. }
  182. public bool UpdateReDo0AMResult(AMResult redo0Model, bool TestResult, string strErrMsg)
  183. {
  184. #region 测试第2次;
  185. if (redo0Model.Test01.ToLower() == "pass" && redo0Model.Test02.ToLower() == "null" && redo0Model.FinalTest.ToLower() == "pass")
  186. {// 1.resulttype=oncepass;
  187. if (TestResult)
  188. {
  189. redo0Model.Test02 = "PASS";
  190. redo0Model.FinalTest = "PASS";
  191. redo0Model.ResultType = "OncePass";
  192. }
  193. else
  194. {
  195. redo0Model.Test02 = "FAIL";
  196. redo0Model.FinalTest = "FAIL";
  197. redo0Model.ResultType = "RealFail";
  198. }
  199. }
  200. else if (redo0Model.Test01.ToLower() == "fail" && redo0Model.Test02.ToLower() == "null" && redo0Model.FinalTest.ToLower() == "fail")
  201. {// 2.resulttype=realfail;
  202. if (TestResult)
  203. {
  204. redo0Model.Test02 = "PASS";
  205. redo0Model.FinalTest = "PASS";
  206. redo0Model.ResultType = "NTF";
  207. }
  208. else
  209. {
  210. // 连续2次Fail,锁定该SN不允许再测试.
  211. redo0Model.Test02 = "FAIL";
  212. redo0Model.FinalTest = "FAIL";
  213. redo0Model.ResultType = "RealFail";
  214. }
  215. }
  216. #endregion
  217. #region 测试第3次.
  218. else if (redo0Model.Test01.ToLower() == "pass" && redo0Model.Test02.ToLower() == "fail" && redo0Model.FinalTest.ToLower() == "fail")
  219. {// 3.resulttype=realfail;
  220. if (TestResult)
  221. {
  222. //redo0Model.Test02 = "FAIL";
  223. redo0Model.FinalTest = "PASS";
  224. redo0Model.ResultType = "NTF";
  225. }
  226. else
  227. {
  228. // 连续2次Fail,锁定该SN不允许再测试.
  229. //redo0Model.Test02 = "FAIL";
  230. redo0Model.FinalTest = "FAIL";
  231. redo0Model.ResultType = "RealFail";
  232. }
  233. }
  234. else if (redo0Model.Test01.ToLower() == "pass" && redo0Model.Test02.ToLower() == "pass" && redo0Model.FinalTest.ToLower() == "pass")
  235. {// 4.resulttype=oncepass;
  236. if (TestResult)
  237. {
  238. //redo0Model.Test02 = "PASS";
  239. redo0Model.FinalTest = "PASS";
  240. redo0Model.ResultType = "OncePass";
  241. }
  242. else
  243. {
  244. //redo0Model.Test02 = "PASS";
  245. redo0Model.FinalTest = "FAIL";
  246. redo0Model.ResultType = "RealFail";
  247. }
  248. }
  249. #region 已经累计出现2次fail了,不允许继续测试,也不允许修改记录;
  250. else if (redo0Model.Test01.ToLower() == "fail" && redo0Model.Test02.ToLower() == "fail" && redo0Model.FinalTest.ToLower() == "fail")
  251. {// 5.resulttype=realfail; 已经累计出现2次fail了,不允许继续测试,也不允许修改记录;
  252. Log.WriteInfoLog(string.Format("5.resulttype=realfail; Test01={0},Test02={1},已经累计出现2次fail了,不允许继续测试,也不允许修改记录", redo0Model.Test01, redo0Model.Test02));
  253. }
  254. #endregion
  255. else if (redo0Model.Test01.ToLower() == "fail" && redo0Model.Test02.ToLower() == "pass" && redo0Model.FinalTest.ToLower() == "pass")
  256. {// 4.resulttype=ntf;
  257. if (TestResult)
  258. {
  259. //redo0Model.Test02 = "PASS";
  260. redo0Model.FinalTest = "PASS";
  261. redo0Model.ResultType = "NTF";
  262. }
  263. else
  264. {
  265. //redo0Model.Test02 = "PASS";
  266. redo0Model.FinalTest = "FAIL";
  267. redo0Model.ResultType = "RealFail";
  268. }
  269. }
  270. #endregion
  271. if (!TestResult)
  272. redo0Model.ErrorMsg = strErrMsg;
  273. // 更新测试时间;
  274. DateTime dateNow = DateTime.Now;
  275. redo0Model.TestDate = dateNow.Date;
  276. redo0Model.TestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
  277. redo0Model.TestHour = dateNow.Hour;
  278. ResultType = redo0Model.ResultType;
  279. return dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, redo0Model.ReDo));
  280. }
  281. public bool UpdateAMYields(AMResult model, bool TestResult, string strErrMsg)
  282. {
  283. bool IsNewRecord = false;
  284. // 查询出统计的记录;
  285. AMYields yields = dalAMYields.GetModel(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  286. // 根据当前model所在的Line、Station、ODF、Model、TestDate、TestHour,统计该TestHour内的数据;
  287. List<AMResult> mResults = dalAMResult.GetModelList(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  288. // 查询每小时统计值;
  289. HourlyResultData hourlydata = dalAMResult.GetHourlyResultData(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  290. if (yields == null || yields.IsValueEmpty())
  291. {// 添加新记录;
  292. IsNewRecord = true;
  293. if (yields == null)
  294. yields = new AMYields();
  295. yields.TestDate = model.TestDate;
  296. yields.TestHour = model.TestHour;
  297. yields.Line = model.Line;
  298. yields.Station = model.Station;
  299. yields.ODF = model.ODF;
  300. yields.Dimension = model.Dimension;
  301. yields.Model = model.Model;
  302. }
  303. yields.Total = hourlydata.TotalAllCount;
  304. yields.OncePass = hourlydata.OncePassAllCount;
  305. //yields.TwiceFail = hourlydata.TwiceFailCount;
  306. yields.NTF = hourlydata.NTFAllCount;
  307. yields.RealFail = hourlydata.RealFailCount;
  308. yields.NTF_SN = hourlydata.NTFSN;
  309. yields.FailDSN = hourlydata.FailDSN;
  310. // 计算百分比;
  311. try
  312. {
  313. int totalAll = int.Parse(hourlydata.TotalAllCount);
  314. int totalZero = int.Parse(hourlydata.TotalZeroCount);
  315. int oncepassAll = int.Parse(hourlydata.OncePassAllCount);
  316. int oncepassZero = int.Parse(hourlydata.OncePassZeroCount);
  317. int ntfAll = int.Parse(hourlydata.NTFAllCount);
  318. int ntfZero = int.Parse(hourlydata.NTFZeroCount);
  319. int realfailCount = int.Parse(hourlydata.RealFailCount);
  320. // 统计合格率;
  321. yields.FPY = (oncepassAll / (double)totalAll).ToString("P");
  322. yields.SPY = ((oncepassAll + ntfAll) / (double)totalAll).ToString("P");
  323. yields.RPY = ((oncepassAll + ntfAll) / (double)totalAll).ToString("P");
  324. yields.YieldRate = ((oncepassZero + ntfZero) / (double)totalZero).ToString("P");
  325. }
  326. catch
  327. {
  328. return false;
  329. }
  330. return IsNewRecord ? dalAMYields.Add(yields) : dalAMYields.Update(yields);
  331. }
  332. #endregion
  333. #region ------试产NTF------
  334. /// <summary>
  335. /// 记录是否存在;
  336. /// </summary>
  337. /// <param name="model"></param>
  338. /// <returns></returns>
  339. public bool IsRecordExist(AMResult_TR model)
  340. {
  341. // 如果存在重流的话,可能不会在原来的Line上,可以流到其他Line。
  342. // dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}' and Line = '{2}'", model.Station, model.SN, model.Line));
  343. return dalAMResultTR.Exists(string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  344. }
  345. /// <summary>
  346. /// 新增记录;
  347. /// </summary>
  348. /// <param name="model"></param>
  349. /// <returns></returns>
  350. public bool AddAMResult(AMResult_TR model, bool TestResult, string strErrMsg)
  351. {
  352. // 赋新值;
  353. model.Test01 = model.FinalTest = TestResult ? "PASS" : "FAIL";
  354. model.Test02 = "null";
  355. model.Test03 = "null";
  356. model.ReDo = "0";
  357. ResultType = model.ResultType = TestResult ? "OncePass" : "RealFail";
  358. if (!TestResult)
  359. model.ErrorMsg = strErrMsg;
  360. return dalAMResultTR.Add(model);
  361. }
  362. public bool UpdateAMResults(AMResult_TR model, bool TestResult, string strErrMsg)
  363. {
  364. // 先获取ReDo="0"的记录;
  365. AMResult_TR redo0Model = dalAMResultTR.GetModel(string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", model.Station, model.SN, "0"));
  366. if (_strLastSN == model.SN)
  367. {// 连接抄写数据,更新ReDo="0"的记录;
  368. Log.WriteInfoLog(string.Format("上一次SN={0} 与当前SN={1} 相同,只更新数据", _strLastSN, model.SN));
  369. if (!UpdateReDo0AMResult(redo0Model, TestResult, strErrMsg))
  370. {
  371. // 更新失败;
  372. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  373. return false;
  374. }
  375. }
  376. else
  377. {// 将原ReDo="0"更新为ReDo=Max(ReDo)+1,并新增ReDo="0"的记录;
  378. int maxReDo = dalAMResultTR.GetMaxID("convert(int,ReDo)", string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  379. redo0Model.ReDo = maxReDo.ToString();
  380. if (!dalAMResultTR.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, "0")))
  381. {
  382. // 更新失败;
  383. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  384. return false;
  385. }
  386. // 新增ReDo=0记录;
  387. if (!AddAMResult(model, TestResult, strErrMsg))
  388. {
  389. // 添加失败;
  390. Log.WriteInfoLog(string.Format("AMResult新增SN={0},Station={1},TestTime={2},ReDo={3} 失败", model.SN, model.Station, model.TestTime, model.ReDo));
  391. return false;
  392. }
  393. }
  394. return true;
  395. }
  396. public bool UpdateReDo0AMResult(AMResult_TR redo0Model, bool TestResult, string strErrMsg)
  397. {
  398. #region 测试第2次
  399. if (redo0Model.Test02.ToLower() == "null" && redo0Model.Test03.ToLower() == "null")
  400. {
  401. if (redo0Model.Test01.ToLower() == "pass")
  402. {
  403. if (TestResult)
  404. {
  405. redo0Model.Test02 = "PASS";
  406. redo0Model.FinalTest = "PASS";
  407. redo0Model.ResultType = "OncePass";
  408. }
  409. else
  410. {
  411. redo0Model.Test02 = "FAIL";
  412. redo0Model.FinalTest = "FAIL";
  413. redo0Model.ResultType = "RealFail";
  414. }
  415. }
  416. else if (redo0Model.Test01.ToLower() == "fail")
  417. {
  418. if (TestResult)
  419. {
  420. redo0Model.Test02 = "PASS";
  421. redo0Model.FinalTest = "PASS";
  422. redo0Model.ResultType = "RealFail";
  423. }
  424. else
  425. {
  426. redo0Model.Test02 = "FAIL";
  427. redo0Model.FinalTest = "FAIL";
  428. redo0Model.ResultType = "RealFail";
  429. }
  430. }
  431. }
  432. #endregion
  433. #region 测试第3次
  434. else if (redo0Model.Test02.ToLower() != "null" && redo0Model.Test03.ToLower() == "null")
  435. {
  436. if (redo0Model.Test01.ToLower().Equals("pass") && redo0Model.Test02.ToLower().Equals("pass"))
  437. {
  438. if (TestResult)
  439. {
  440. redo0Model.Test03 = "PASS";
  441. redo0Model.FinalTest = "PASS";
  442. redo0Model.ResultType = "OncePass";
  443. }
  444. else
  445. {
  446. redo0Model.Test03 = "FAIL";
  447. redo0Model.FinalTest = "FAIL";
  448. redo0Model.ResultType = "RealFail";
  449. }
  450. }
  451. else if (redo0Model.Test01.ToLower().Equals("pass") && redo0Model.Test02.ToLower().Equals("fail"))
  452. {
  453. if (TestResult)
  454. {
  455. redo0Model.Test03 = "PASS";
  456. redo0Model.FinalTest = "PASS";
  457. redo0Model.ResultType = "NTF";
  458. }
  459. else
  460. {
  461. redo0Model.Test03 = "FAIL";
  462. redo0Model.FinalTest = "FAIL";
  463. redo0Model.ResultType = "RealFail";
  464. }
  465. }
  466. else if (redo0Model.Test01.ToLower().Equals("fail") && redo0Model.Test02.ToLower().Equals("pass"))
  467. {
  468. if (TestResult)
  469. {
  470. redo0Model.Test03 = "PASS";
  471. redo0Model.FinalTest = "PASS";
  472. redo0Model.ResultType = "NTF";
  473. }
  474. else
  475. {
  476. redo0Model.Test03 = "FAIL";
  477. redo0Model.FinalTest = "FAIL";
  478. redo0Model.ResultType = "RealFail";
  479. }
  480. }
  481. else if (redo0Model.Test01.ToLower().Equals("fail") && redo0Model.Test02.ToLower().Equals("fail"))
  482. {
  483. Log.WriteInfoLog("连接2次Fail,测试锁定");
  484. }
  485. }
  486. #endregion
  487. #region 测试第4次;
  488. else if (redo0Model.Test03.ToLower() != "null")
  489. {
  490. if (redo0Model.FinalTest.ToLower() == "pass" && redo0Model.ResultType.ToLower() == "ntf")
  491. {
  492. if (!TestResult)
  493. {
  494. redo0Model.FinalTest = "FAIL";
  495. redo0Model.ResultType = "RealFail";
  496. }
  497. }
  498. else if (redo0Model.FinalTest.ToLower() == "pass" && redo0Model.ResultType.ToLower() == "oncepass")
  499. {// 异常测试;
  500. if (!TestResult)
  501. {
  502. redo0Model.FinalTest = "FAIL";
  503. redo0Model.ResultType = "RealFail";
  504. }
  505. }
  506. else
  507. {
  508. Log.WriteErrorLog("异常测试,超过3次测试次数");
  509. }
  510. }
  511. #endregion
  512. if (!TestResult)
  513. redo0Model.ErrorMsg = strErrMsg;
  514. // 更新测试时间;
  515. DateTime dateNow = DateTime.Now;
  516. redo0Model.TestDate = dateNow.Date;
  517. redo0Model.TestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
  518. redo0Model.TestHour = dateNow.Hour;
  519. ResultType = redo0Model.ResultType;
  520. return dalAMResultTR.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, redo0Model.ReDo));
  521. }
  522. public bool UpdateAMYields(AMResult_TR model, bool TestResult, string strErrMsg)
  523. {
  524. bool IsNewRecord = false;
  525. // 查询出统计的记录;
  526. AMYields_TR yields = dalAMYieldsTR.GetModel(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  527. // 根据当前model所在的Line、Station、ODF、Model、TestDate、TestHour,统计该TestHour内的数据;
  528. List<AMResult_TR> mResults = dalAMResultTR.GetModelList(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  529. // 查询每小时统计值;
  530. HourlyResultTRData hourlydata = dalAMResultTR.GetHourlyResultData(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  531. if (yields == null || yields.IsValueEmpty())
  532. {// 添加新记录;
  533. IsNewRecord = true;
  534. if (yields == null)
  535. yields = new AMYields_TR();
  536. yields.TestDate = model.TestDate;
  537. yields.TestHour = model.TestHour;
  538. yields.Line = model.Line;
  539. yields.Station = model.Station;
  540. yields.ODF = model.ODF;
  541. yields.Dimension = model.Dimension;
  542. yields.Model = model.Model;
  543. }
  544. yields.Total = hourlydata.TotalAllCount;
  545. yields.OncePass = hourlydata.OncePassAllCount;
  546. //yields.TwiceFail = hourlydata.TwiceFailCount;
  547. yields.NTF = hourlydata.NTFAllCount;
  548. yields.RealFail = hourlydata.RealFailCount;
  549. yields.NTF_SN = hourlydata.NTFSN;
  550. yields.FailDSN = hourlydata.FailDSN;
  551. // 计算百分比;
  552. try
  553. {
  554. int totalAll = int.Parse(hourlydata.TotalAllCount);
  555. int totalZero = int.Parse(hourlydata.TotalZeroCount);
  556. int oncepassAll = int.Parse(hourlydata.OncePassAllCount);
  557. int oncepassZero = int.Parse(hourlydata.OncePassZeroCount);
  558. int ntfAll = int.Parse(hourlydata.NTFAllCount);
  559. int ntfZero = int.Parse(hourlydata.NTFZeroCount);
  560. int realfailCount = int.Parse(hourlydata.RealFailCount);
  561. // 统计合格率;
  562. yields.FPY = (oncepassAll / (double)totalAll).ToString("P");
  563. yields.SPY = ((oncepassAll + ntfAll) / (double)totalAll).ToString("P");
  564. yields.RPY = ((oncepassAll + ntfAll) / (double)totalAll).ToString("P");
  565. yields.YieldRate = ((oncepassZero + ntfZero) / (double)totalZero).ToString("P");
  566. }
  567. catch
  568. {
  569. return false;
  570. }
  571. return IsNewRecord ? dalAMYieldsTR.Add(yields) : dalAMYieldsTR.Update(yields);
  572. }
  573. #endregion
  574. }
  575. }