NTFBLL.cs 11 KB

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