NTFBLL.cs 27 KB

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