NTFBLL.cs 29 KB

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