NTFBLL.cs 26 KB

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