NTFBLL.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. private static string strLastSN = CommonMethod.ReadProfileString("MOKAFactoryTools", "LastGSN", "");
  14. protected readonly DAL_AMResult dalAMResult = new DAL_AMResult();
  15. protected readonly DAL_AMYields dalAMYields = new DAL_AMYields();
  16. /// <summary>
  17. /// 设置数据抄写结果;
  18. /// </summary>
  19. /// <param name="strLine">线体,UI输入</param>
  20. /// <param name="strStation">默认为:DataBurning</param>
  21. /// <param name="strSN"></param>
  22. /// <param name="bResult">抄写结果:成功或失败</param>
  23. /// <param name="strErrMsg">抄写失败时的描述</param>
  24. /// <returns></returns>
  25. public bool SetDataBuringResult(string strLine, string strStation, string strSN, string strDSN, bool bResult, string strErrMsg = "")
  26. {
  27. return false;
  28. MaInfo maInfo;
  29. DateTime dateNow = DateTime.Now;
  30. AMResult aMResult = new AMResult();
  31. // 通过SN获取MES服务器中记录的ODF、Model、Dissemination信息;
  32. if ( CommonMethod.GetMaInfo(strSN, out maInfo, null) )
  33. {
  34. // 测试日期;
  35. string strTestDate = dateNow.ToString("yyyy-MM-dd");
  36. // 测试完成时间;
  37. string strTestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
  38. #region 赋值model
  39. aMResult.TestDate = dateNow.Date;
  40. aMResult.Line = strLine;
  41. aMResult.Station = strStation;
  42. aMResult.DSN = strDSN;
  43. aMResult.ODF = maInfo.ODF;
  44. aMResult.Model = maInfo.Model;
  45. aMResult.Dimension = maInfo.SIZE;
  46. aMResult.TestHour = dateNow.Hour;
  47. aMResult.TestTime = strTestTime;
  48. aMResult.SN = strSN;
  49. #endregion
  50. Log.WriteInfoLog(string.Format("上一次SN={0},当前SN={1}", strLastSN, aMResult.SN));
  51. if (IsRecordExist(aMResult))
  52. {
  53. if ( !UpdateAMResults(aMResult, bResult, strErrMsg) )
  54. {
  55. // 更新失败;
  56. return false;
  57. }
  58. }
  59. else
  60. {
  61. if (!AddAMResult(aMResult, bResult, strErrMsg))
  62. {
  63. // 更新失败;
  64. return false;
  65. }
  66. }
  67. // 更新统计结果;
  68. if (!UpdateAMYields(aMResult, bResult, strErrMsg))
  69. {
  70. return false;
  71. }
  72. strLastSN = strSN;
  73. CommonMethod.WriteProfileString("MOKAFactoryTools", "LastGSN", strSN);
  74. }
  75. return false;
  76. }
  77. /// <summary>
  78. /// 记录是否存在;
  79. /// </summary>
  80. /// <param name="model"></param>
  81. /// <returns></returns>
  82. public bool IsRecordExist(AMResult model)
  83. {
  84. // 如果存在重流的话,可能不会在原来的Line上,可以流到其他Line。
  85. // dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}' and Line = '{2}'", model.Station, model.SN, model.Line));
  86. return dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  87. }
  88. /// <summary>
  89. /// 新增记录;
  90. /// </summary>
  91. /// <param name="model"></param>
  92. /// <returns></returns>
  93. public bool AddAMResult(AMResult model, bool TestResult, string strErrMsg)
  94. {
  95. // 赋新值;
  96. model.Test01 = model.FinalTest = TestResult ? "PASS" : "FAIL";
  97. model.Test02 = "NULL";
  98. model.ReDo = "0";
  99. model.ResultType = TestResult ? "OncePass" : "OnceFail";
  100. if (!TestResult)
  101. model.ErrorMsg = strErrMsg;
  102. return dalAMResult.Add(model);
  103. }
  104. public bool UpdateAMResults(AMResult model, bool TestResult, string strErrMsg)
  105. {
  106. // 先获取ReDo="0"的记录;
  107. AMResult redo0Model = dalAMResult.GetModel(string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", model.Station, model.SN, "0"));
  108. if ( strLastSN == model.SN )
  109. {// 连接抄写数据,更新ReDo="0"的记录;
  110. Log.WriteInfoLog(string.Format("上一次SN={0} 与当前SN={1} 相同,只更新数据", strLastSN, model.SN));
  111. if ( !UpdateReDo0AMResult(redo0Model, TestResult, strErrMsg) )
  112. {
  113. // 更新失败;
  114. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  115. return false;
  116. }
  117. }
  118. else
  119. {// 将原ReDo="0"更新为ReDo=Max(ReDo)+1,并新增ReDo="0"的记录;
  120. int maxReDo = dalAMResult.GetMaxID("ReDo", string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
  121. redo0Model.ReDo = maxReDo.ToString();
  122. if ( !dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, "0")) )
  123. {
  124. // 更新失败;
  125. Log.WriteInfoLog(string.Format("AMResult更新SN={0},Station={1},TestTime={2},ReDo={3} 失败", redo0Model.SN, redo0Model.Station, redo0Model.TestTime, redo0Model.ReDo));
  126. return false;
  127. }
  128. // 新增ReDo=0记录;
  129. if ( !AddAMResult(model, TestResult, strErrMsg) )
  130. {
  131. // 添加失败;
  132. Log.WriteInfoLog(string.Format("AMResult新增SN={0},Station={1},TestTime={2},ReDo={3} 失败", model.SN, model.Station, model.TestTime, model.ReDo));
  133. return false;
  134. }
  135. }
  136. return true;
  137. }
  138. public bool UpdateReDo0AMResult(AMResult redo0Model, bool TestResult, string strErrMsg)
  139. {
  140. if (redo0Model.Test01 == "PASS" && redo0Model.Test02 == "NULL" && redo0Model.FinalTest == "PASS")
  141. {// OncePass 的情况;
  142. if (TestResult)
  143. {
  144. redo0Model.Test02 = "PASS";
  145. redo0Model.ResultType = "FinalPass";
  146. }
  147. else
  148. {
  149. redo0Model.Test02 = "FAIL";
  150. redo0Model.FinalTest = "FAIL";
  151. redo0Model.ResultType = "FinalFail";
  152. }
  153. }
  154. else if (redo0Model.Test01 == "FAIL" && redo0Model.Test02 == "NULL" && redo0Model.FinalTest == "FAIL")
  155. {// OnceFail 的情况;
  156. if (TestResult)
  157. {
  158. redo0Model.Test02 = "PASS";
  159. redo0Model.FinalTest = "PASS";
  160. redo0Model.ResultType = "NTF";
  161. }
  162. else
  163. {
  164. redo0Model.Test02 = "FAIL";
  165. redo0Model.FinalTest = "FAIL";
  166. redo0Model.ResultType = "TwiceFail";
  167. }
  168. }
  169. else if (redo0Model.Test01 == "FAIL" && redo0Model.Test02 == "PASS" && (redo0Model.FinalTest == "PASS" || redo0Model.FinalTest == "FAIL"))
  170. {// NTF + FinalFail 的情况;
  171. if (TestResult)
  172. {
  173. redo0Model.FinalTest = "PASS";
  174. redo0Model.ResultType = "NTF";
  175. }
  176. else
  177. {
  178. redo0Model.FinalTest = "FAIL";
  179. redo0Model.ResultType = "FinalFail";
  180. }
  181. }
  182. else
  183. {
  184. if (TestResult)
  185. {
  186. redo0Model.FinalTest = "PASS";
  187. redo0Model.ResultType = "FinalPass";
  188. }
  189. else
  190. {
  191. redo0Model.FinalTest = "FAIL";
  192. redo0Model.ResultType = "FinalFail";
  193. }
  194. }
  195. if (!TestResult)
  196. redo0Model.ErrorMsg = strErrMsg;
  197. return dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, redo0Model.ReDo));
  198. }
  199. public bool UpdateAMYields(AMResult model, bool TestResult, string strErrMsg)
  200. {
  201. bool IsNewRecord = false;
  202. // 查询出统计的记录;
  203. AMYields yields = dalAMYields.GetModel(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  204. // 根据当前model所在的Line、Station、ODF、Model、TestDate、TestHour,统计该TestHour内的数据;
  205. List<AMResult> mResults = dalAMResult.GetModelList(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  206. // 查询每小时统计值;
  207. HourlyResultData hourlydata = dalAMResult.GetHourlyResultData(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
  208. if ( yields == null || yields.IsValueEmpty() )
  209. {// 添加新记录;
  210. IsNewRecord = true;
  211. if (yields == null)
  212. yields = new AMYields();
  213. yields.TestDate = model.TestDate;
  214. yields.TestHour = model.TestHour;
  215. yields.Line = model.Line;
  216. yields.Station = model.Station;
  217. yields.ODF = model.ODF;
  218. yields.Dimension = model.Dimension;
  219. yields.Model = model.Model;
  220. }
  221. yields.Total = hourlydata.TotalCount;
  222. yields.OncePass = hourlydata.OncePassCount;
  223. yields.TwiceFail = hourlydata.TwiceFailCount;
  224. yields.NTF = hourlydata.NTFCount;
  225. yields.RealFail = hourlydata.FinalFailCount; // hourlydata.RealFailCount;
  226. yields.NTF_SN = hourlydata.NTFSN;
  227. yields.FailDSN = hourlydata.FailDSN;
  228. // 计算百分比;
  229. try
  230. {
  231. int total = int.Parse(yields.Total);
  232. int realtotal = int.Parse(hourlydata.RealTotalCount);
  233. int oncepassCount = int.Parse(yields.OncePass);
  234. int twicefailCount = int.Parse(yields.TwiceFail);
  235. int ntfCount = int.Parse(yields.NTF);
  236. int realfailCount = int.Parse(yields.RealFail);
  237. int realpassCount = int.Parse(hourlydata.RealPassCount);
  238. int finalpassCount = int.Parse(hourlydata.FinalPassCount);
  239. int finalfailCount = int.Parse(hourlydata.FinalFailCount);
  240. // 统计合格率;
  241. yields.FPY = (oncepassCount / (double)total).ToString("P");
  242. yields.SPY = (oncepassCount + ntfCount / (double)total).ToString("P");
  243. yields.RPY = (finalpassCount / (double)total).ToString("P");
  244. yields.YieldRate = (realpassCount / (double)realtotal).ToString("P");
  245. }
  246. catch
  247. {
  248. return false;
  249. }
  250. return IsNewRecord ? dalAMYields.Add(yields) : dalAMYields.Update(yields);
  251. }
  252. }
  253. }