NTFBLL.cs 29 KB

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