NTFBLL.cs 27 KB

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