Răsfoiți Sursa

【软件版本】
V 3.0.6.3 状态:未发布
【模块名称】
G客户NTF统计功能
【问题原因】

【修改描述】
G客户NTF统计功能,完成NTFBLL类功能,同时完善其他DAL类功能。
【测试结果】

sat23 3 ani în urmă
părinte
comite
d944b60ad3

+ 266 - 0
SCBC Factory Tools/BLL/NTFBLL.cs

@@ -0,0 +1,266 @@
+using MOKA_Factory_Tools.DAL;
+using MOKA_Factory_Tools.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MOKA_Factory_Tools.BLL
+{
+    public partial class NTFBLL
+    {
+        private static string strLastSN = CommonMethod.ReadProfileString("MOKAFactoryTools", "LastGSN", "");
+        protected readonly DAL_AMResult dalAMResult = new DAL_AMResult();
+        protected readonly DAL_AMYields dalAMYields = new DAL_AMYields();
+
+        /// <summary>
+        /// 设置数据抄写结果;
+        /// </summary>
+        /// <param name="strLine">线体,UI输入</param>
+        /// <param name="strStation">默认为:DataBurning</param>
+        /// <param name="strSN"></param>
+        /// <param name="bResult">抄写结果:成功或失败</param>
+        /// <param name="strErrMsg">抄写失败时的描述</param>
+        /// <returns></returns>
+        public bool SetDataBuringResult(string strLine, string strStation, string strSN, string strDSN, bool bResult, string strErrMsg)
+        {
+            MaInfo maInfo;
+            DateTime dateNow = DateTime.Now;
+            AMResult aMResult = new AMResult();            
+            // 通过SN获取MES服务器中记录的ODF、Model、Dissemination信息;            
+            if ( CommonMethod.GetMaInfo(strSN, out maInfo, null) )
+            {
+                // 测试日期;
+                string strTestDate = dateNow.ToString("yyyy-MM-dd");
+                // 测试完成时间;
+                string strTestTime = dateNow.ToString("yyyy-MM-dd HH:mm:ss");
+
+                #region 赋值model
+                aMResult.TestDate = dateNow.Date;
+                aMResult.Line = strLine;
+                aMResult.Station = strStation;
+                aMResult.DSN = strDSN;
+                aMResult.ODF = maInfo.ODF;
+                aMResult.Model = maInfo.Model;
+                aMResult.Dimension = maInfo.SIZE;
+                aMResult.TestHour = dateNow.Hour;
+                aMResult.TestTime = strTestTime;
+                aMResult.SN = strSN;
+                #endregion
+
+                if (IsRecordExist(aMResult))
+                {
+                    if ( !UpdateAMResults(aMResult, bResult, strErrMsg) )
+                    {
+                        // 更新失败;
+                        return false;
+                    }
+                }
+                else
+                {
+                    if (!AddAMResult(aMResult, bResult, strErrMsg))
+                    {
+                        // 更新失败;
+                        return false;
+                    }
+                }
+
+                // 更新统计结果;
+                if (!UpdateAMYields(aMResult, bResult, strErrMsg))
+                {
+                    return false;
+                }
+
+                strLastSN = strSN;
+                CommonMethod.WriteProfileString("MOKAFactoryTools", "LastGSN", strSN);
+            }
+
+            return false;
+        }
+
+        /// <summary>
+        /// 记录是否存在;
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public bool IsRecordExist(AMResult model)
+        {
+            // 如果存在重流的话,可能不会在原来的Line上,可以流到其他Line。
+            // dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}' and Line = '{2}'", model.Station, model.SN, model.Line));
+            return dalAMResult.Exists(string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
+        }
+
+        /// <summary>
+        /// 新增记录;
+        /// </summary>
+        /// <param name="model"></param>
+        /// <returns></returns>
+        public bool AddAMResult(AMResult model, bool TestResult, string strErrMsg)
+        {
+            // 赋新值;
+            model.Test01 = model.FinalTest = TestResult ? "PASS" : "FAIL";
+            model.Test02 = "NULL";
+            model.ReDo = "0";
+            model.ResultType = TestResult ? "OncePass" : "OnceFail";
+            if (!TestResult)
+                model.ErrorMsg = strErrMsg;
+            return dalAMResult.Add(model);
+        }
+
+        public bool UpdateAMResults(AMResult model, bool TestResult, string strErrMsg)
+        {
+            // 先获取ReDo="0"的记录;
+            AMResult redo0Model = dalAMResult.GetModel(string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", model.Station, model.SN, "0"));
+            if ( strLastSN == model.SN )
+            {// 连接抄写数据,更新ReDo="0"的记录;
+                if ( !UpdateReDo0AMResult(redo0Model, TestResult, strErrMsg) )
+                {
+                    // 更新失败;
+                    return false;
+                }
+            }
+            else
+            {// 将原ReDo="0"更新为ReDo=Max(ReDo)+1,并新增ReDo="0"的记录;
+                int maxReDo = dalAMResult.GetMaxID("ReDo", string.Format("Station='{0}' and SN='{1}'", model.Station, model.SN));
+                redo0Model.ReDo = maxReDo.ToString();
+                if ( !dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, "0")) )
+                {
+                    // 更新失败;
+                    return false;
+                }
+
+                // 新增ReDo=0记录;
+                if ( !AddAMResult(model, TestResult, strErrMsg) )
+                {
+                    // 添加失败;
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+        public bool UpdateReDo0AMResult(AMResult redo0Model, bool TestResult, string strErrMsg)
+        {
+            if (redo0Model.Test01 == "PASS" && redo0Model.Test02 == "NULL" && redo0Model.FinalTest == "PASS")
+            {// OncePass 的情况;
+                if (TestResult)
+                {
+                    redo0Model.Test02 = "PASS";
+                    redo0Model.ResultType = "FinalPass";
+                }
+                else
+                {
+                    redo0Model.Test02 = "FAIL";
+                    redo0Model.FinalTest = "FAIL";
+                    redo0Model.ResultType = "FinalFail";
+                }
+            }
+            else if (redo0Model.Test01 == "FAIL" && redo0Model.Test02 == "NULL" && redo0Model.FinalTest == "FAIL")
+            {// OnceFail 的情况;
+                if (TestResult)
+                {
+                    redo0Model.Test02 = "PASS";
+                    redo0Model.FinalTest = "PASS";
+                    redo0Model.ResultType = "NTF";
+                }
+                else
+                {
+                    redo0Model.Test02 = "FAIL";
+                    redo0Model.FinalTest = "FAIL";
+                    redo0Model.ResultType = "TwiceFail";
+                }
+            }
+            else if (redo0Model.Test01 == "FAIL" && redo0Model.Test02 == "PASS" && redo0Model.FinalTest == "PASS")
+            {// NTF 的情况;
+                if (TestResult)
+                {
+                    redo0Model.FinalTest = "PASS";
+                    redo0Model.ResultType = "NTF";
+                }
+                else
+                {
+                    redo0Model.FinalTest = "FAIL";
+                    redo0Model.ResultType = "FinalFail";
+                }
+            }
+            else 
+            {
+                if (TestResult)
+                {
+                    redo0Model.FinalTest = "PASS";
+                    redo0Model.ResultType = "FinalPass";
+                }
+                else
+                {
+                    redo0Model.FinalTest = "FAIL";
+                    redo0Model.ResultType = "FinalFail";
+                }
+            }
+
+            if (!TestResult)
+                redo0Model.ErrorMsg = strErrMsg;
+
+            return dalAMResult.Update(redo0Model, string.Format("Station='{0}' and SN='{1}' and ReDo='{2}'", redo0Model.Station, redo0Model.SN, redo0Model.ReDo));
+        }
+
+        public bool UpdateAMYields(AMResult model, bool TestResult, string strErrMsg)
+        {
+            bool IsNewRecord = false;
+            // 查询出统计的记录;
+            AMYields yields = dalAMYields.GetModel(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
+            // 根据当前model所在的Line、Station、ODF、Model、TestDate、TestHour,统计该TestHour内的数据;
+            List<AMResult> mResults = dalAMResult.GetModelList(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
+            // 查询每小时统计值;
+            HourlyResultData hourlydata = dalAMResult.GetHourlyResultData(model.Line, model.Station, model.ODF, model.TestDate, model.TestHour);
+
+            if ( yields == null || yields.IsValueEmpty() )
+            {// 添加新记录;
+                IsNewRecord = true;
+                if (yields == null)
+                    yields = new AMYields();
+
+                yields.TestDate = model.TestDate;
+                yields.TestHour = model.TestHour;
+                yields.Line = model.Line;
+                yields.Station = model.Station;
+                yields.ODF = model.ODF;
+                yields.Dimension = model.Dimension;
+                yields.Model = model.Model;
+            }
+
+            yields.Total = hourlydata.TotalCount;
+            yields.OncePass = hourlydata.OncePassCount;
+            yields.TwiceFail = hourlydata.TwiceFailCount;
+            yields.NTF = hourlydata.NTFCount;
+            yields.RealFail = hourlydata.FinalFailCount;    // hourlydata.RealFailCount;
+            yields.NTF_SN = hourlydata.NTFSN;
+            yields.FailDSN = hourlydata.FailDSN;
+            // 计算百分比;
+            try
+            {
+                int total = int.Parse(yields.Total);
+                int realtotal = int.Parse(hourlydata.RealTotalCount);
+                int oncepassCount = int.Parse(yields.OncePass);
+                int twicefailCount = int.Parse(yields.TwiceFail);
+                int ntfCount = int.Parse(yields.NTF);
+                int realfailCount = int.Parse(yields.RealFail);
+                int realpassCount = int.Parse(hourlydata.RealPassCount);
+                int finalpassCount = int.Parse(hourlydata.FinalPassCount);
+                int finalfailCount = int.Parse(hourlydata.FinalFailCount);
+                // 统计合格率;
+                yields.FPY = (oncepassCount / (double)total).ToString("P");
+                yields.SPY = (oncepassCount + ntfCount / (double)total).ToString("P");
+                yields.RPY = (finalpassCount / (double)total).ToString("P");
+                yields.YieldRate = (realpassCount / (double)realtotal).ToString("P");
+            }
+            catch
+            {
+                return false;
+            }
+
+            return IsNewRecord ? dalAMYields.Add(yields) : dalAMYields.Update(yields);
+        }
+    }
+}

+ 6 - 0
SCBC Factory Tools/Business/CommonMethod.cs

@@ -37,6 +37,12 @@ namespace MOKA_Factory_Tools
         private static string lastOrder = "";
         private static List<string> ListACASSN = new List<string>();
 
+        public static string ReadProfileString(string lpApplicationName, string lpKeyName, string lpDefault)
+        {
+            StringBuilder MyString = new StringBuilder(256);
+            GetProfileString(lpApplicationName, lpKeyName, lpDefault, MyString, 256);
+            return MyString.ToString();
+        }
         //public static string LocalMacAddress = GetMacAddress();
         /// <summary>
         /// 获取活动网卡硬件地址

+ 73 - 1
SCBC Factory Tools/DAL/DAL_AMResult.cs

@@ -1,4 +1,5 @@
-using MOKA_Factory_Tools.Models;
+using MOKA_Factory_Tools.Database;
+using MOKA_Factory_Tools.Models;
 using System;
 using System.Collections.Generic;
 using System.Data;
@@ -143,6 +144,62 @@ namespace MOKA_Factory_Tools.DAL
             return DataRowToModel(GetDataRow(string.Format("Station = '{0}' and SN = '{1}'", strStation, strSN)));
         }
 
+        public HourlyResultData GetHourlyResultData(string Line, string Station, string ODF, DateTime TestDate, int TestHour)
+        {
+            DataRow row = GetHourlyDataRow(string.Format("Line='{0}' and Station='{1}' and ODF='{2}' and TestDate='{3}' and TestHour='{4}'", Line, Station, ODF, TestDate, TestHour));
+            if ( row != null )
+            {
+                HourlyResultData model = new HourlyResultData();
+                model.TotalCount = row["Total"].ToString();
+                model.RealTotalCount = row["RealTotal"].ToString();
+                model.OncePassCount = row["OncePass"].ToString();
+                model.OnceFailCount = row["OnceFail"].ToString();
+                model.NTFCount = row["NTF"].ToString();
+                model.TwiceFailCount = row["TwiceFail"].ToString();
+                model.FinalFailCount = row["FinalFail"].ToString();
+                model.FinalPassCount = row["FinalPass"].ToString();
+                model.RealFailCount = row["RealFail"].ToString();
+                model.RealPassCount = row["RealPass"].ToString();
+                model.NTFSN = row["NTFSN"].ToString();
+                model.FailDSN = row["FailDSN"].ToString();
+
+                return model;
+            }
+
+            return null;
+        }
+
+        public DataRow GetHourlyDataRow(string whereString)
+        {
+            if (whereString.Trim().Length > 0)
+            {
+                StringBuilder strSql = new StringBuilder();
+                strSql.Append("select ");
+                strSql.Append("count(1) as 'Total',");
+                strSql.Append("count(case when ReDo = '0' then 1 else null end) as 'RealTotal',");
+                strSql.Append("count(case when ResultType = 'OncePass' then 1 else null end) as 'OncePass',");
+                strSql.Append("count(case when ResultType = 'OnceFail' then 1 else null end) as 'OnceFail',");
+                strSql.Append("count(case when ResultType = 'NTF' then 1 else null end) as 'NTF',");
+                strSql.Append("count(case when ResultType = 'TwiceFail' then 1 else null end) as 'TwiceFail',");
+                strSql.Append("count(case when ResultType = 'FinalFail' then 1 else null end) as 'FinalFail',");
+                strSql.Append("count(case when ResultType = 'FinalPass' then 1 else null end) as 'FinalPass',");
+                strSql.Append("count(case when FinalTest = 'PASS' and ReDo = '0' then 1 else null end) as 'RealPass',");
+                strSql.Append("count(case when FinalTest = 'FAIL' and ReDo = '0' then 1 else null end) as 'RealFail',");
+                strSql.Append(string.Format("stuff((select ',' + SN from {0} where {1} and ResultType='NTF' for XML PATH('')),1,1,'') as 'NTFSN',", this.TableName, whereString));
+                strSql.Append(string.Format("stuff((select ',' + DSN from {0} where {1} and FinalTest='FAIL' for XML PATH('')),1,1,'') as 'FailDSN' ", this.TableName, whereString));
+                strSql.Append("from " + this.TableName);
+                strSql.Append(" where  " + whereString);
+
+                DataSet ds = DbHelper.Query(cps.ConnectionString, strSql.ToString());
+                if (ds.Tables[0].Rows.Count > 0)
+                {
+                    return ds.Tables[0].Rows[0];
+                }
+            }
+
+            return null;            
+        }
+
         /// <summary>
         /// 得到一个对象实体
         /// </summary>
@@ -163,6 +220,21 @@ namespace MOKA_Factory_Tools.DAL
             return DataTableToList(ds.Tables[0]);
         }
 
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="strLine"></param>
+        /// <param name="strStation"></param>
+        /// <param name="ODF"></param>
+        /// <param name="TestDate"></param>
+        /// <param name="TestHour"></param>
+        /// <returns></returns>
+        public List<AMResult> GetModelList(string strLine, string strStation, string ODF, DateTime TestDate, int TestHour)
+        {
+            DataSet ds = base.GetList(string.Format("Line = '{0}' and Station = '{1}' and ODF='{2}' and TestDate='{3}' and TestHour='{4}'", strLine, strStation, ODF, TestDate, TestHour));
+            return DataTableToList(ds.Tables[0]);
+        }
+
         /// <summary>
         /// 获得数据列表
         /// </summary>

+ 11 - 3
SCBC Factory Tools/DAL/DAL_AMYields.cs

@@ -18,7 +18,7 @@ namespace MOKA_Factory_Tools.DAL
 
         #region 属性和字段
 
-        string _tableName = "AMResult";
+        string _tableName = "AMYields";
 
         /// <summary>
         /// 获取数据表名
@@ -128,9 +128,17 @@ namespace MOKA_Factory_Tools.DAL
         /// <summary>
         /// 得到一个对象实体
         /// </summary>
-        public AMYields GetModel(int ID)
+        public AMYields GetModel(string strWhere)
         {
-            return DataRowToModel(GetDataRow(ID));
+            return DataRowToModel(GetDataRow(strWhere));
+        }
+
+        /// <summary>
+        /// 得到一个对象实体
+        /// </summary>
+        public AMYields GetModel(string strLine, string strStation, string ODF, DateTime TestDate, int TestHour)
+        {
+            return DataRowToModel(GetDataRow(string.Format("Line = '{0}' and Station = '{1}' and ODF='{2}' and TestDate='{3}' and TestHour='{4}'", strLine, strStation, ODF, TestDate, TestHour)));
         }
 
         /// <summary>

+ 1 - 1
SCBC Factory Tools/Database/DbHelper.cs

@@ -143,7 +143,7 @@ namespace MOKA_Factory_Tools.Database
         public static bool Exists(string connectionString, string strSQL)
         {
             int cmdresult;
-            object obj = GetSingle(strSQL, connectionString);
+            object obj = GetSingle(connectionString, strSQL);
             if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
             {
                 cmdresult = 0;

+ 44 - 17
SCBC Factory Tools/Models/AMResult.cs

@@ -8,22 +8,49 @@ namespace MOKA_Factory_Tools.Models
 {
     public class AMResult
     {
-        public DateTime TestDate { get; set; }   /* 日期班次 */
-        public int TestHour { get; set; }        /* 小时 */
-        public string Line { get; set; }         /* 线体:UI界面或配置文件提供 */
-        public string Station { get; set; }      /* 工站:UI界面或配置文件提供 */
-        public string Model { get; set; }        /* 机型:HTTP接口获取 */
-        public string Dimension { get; set; }    /* 尺寸:HTTP接口获取 */
-        public string TestTime { get; set; }     /* 测试时间 */
-        public string ODF { get; set; }          /* 批次:HTTP接口获取 */
-        public string SN { get; set; }           /* 本次抄写SN */
-        public string ReDo { get; set; }         /* 重流标识 */
-        public string Test01 { get; set; }       /* 首次测试结果 */
-        public string Test02 { get; set; }       /* 第二次测试结果 */
-        public string FinalTest { get; set; }    /* 最终测试结果 */
-        public string ResultType { get; set; }   /* 结果类型:OncePass、NTF、FinalPass、TwiceFail、FinalPass、OnceFail、FinalFail */
-        public string DSN { get; set; }          /* 本次抄写DSN */
-        public string ErrorMsg { get; set; }     /* 抄写失败描述 */
-        public string Remark { get; set; }       /* 备注:一般用于重流标记 */
+        public DateTime TestDate { get; set; }      /* 日期班次 */
+        public int TestHour { get; set; } = -1;     /* 小时 */
+        public string Line { get; set; }            /* 线体:UI界面或配置文件提供 */
+        public string Station { get; set; } = "";   /* 工站:UI界面或配置文件提供 */
+        public string Model { get; set; }           /* 机型:HTTP接口获取 */
+        public string Dimension { get; set; }       /* 尺寸:HTTP接口获取 */
+        public string TestTime { get; set; }        /* 测试时间 */
+        public string ODF { get; set; }             /* 批次:HTTP接口获取 */
+        public string SN { get; set; } = "";        /* 本次抄写SN */
+        public string ReDo { get; set; }            /* 重流标识 */
+        public string Test01 { get; set; }          /* 首次测试结果 */
+        public string Test02 { get; set; }          /* 第二次测试结果 */
+        public string FinalTest { get; set; }       /* 最终测试结果 */
+        public string ResultType { get; set; }      /* 结果类型:OncePass、NTF、FinalPass、TwiceFail、FinalPass、OnceFail、FinalFail */
+        public string DSN { get; set; }             /* 本次抄写DSN */
+        public string ErrorMsg { get; set; }        /* 抄写失败描述 */
+        public string Remark { get; set; }          /* 备注:一般用于重流标记 */
+
+        /// <summary>
+        /// 判断对象的值是否空;
+        /// </summary>
+        /// <returns></returns>
+        public bool IsValueEmpty()
+        {
+            if (TestHour == -1 || SN == "")
+                return true;
+            return false;
+        }
+    }
+
+    public class HourlyResultData
+    {
+        public string TotalCount { get; set; } = "0";
+        public string RealTotalCount { get; set; } = "0";
+        public string OncePassCount { get; set; } = "0";
+        public string OnceFailCount { get; set; } = "0";
+        public string NTFCount { get; set; } = "0";
+        public string TwiceFailCount { get; set; } = "0";
+        public string FinalFailCount { get; set; } = "0";
+        public string FinalPassCount { get; set; } = "0";
+        public string RealFailCount { get; set; } = "0";        // 只查询ReDo=0的记录;
+        public string RealPassCount { get; set; } = "0";        // 只查询ReDo=0的记录;
+        public string NTFSN { get; set; }
+        public string FailDSN { get; set; }
     }
 }

+ 12 - 1
SCBC Factory Tools/Models/AMYields.cs

@@ -8,7 +8,7 @@ namespace MOKA_Factory_Tools.Models
 {
     public class AMYields
     {
-        public int ID { get; set; }                     /* 自增ID */
+        public int ID { get; set; } = -1;               /* 自增ID */
         public DateTime TestDate { get; set; }          /* 日期班次 */
         public int TestHour{ get; set; }                /* 小时 */
         public string Line{ get; set; }                 /* 线体:UI界面或配置文件提供 */
@@ -29,5 +29,16 @@ namespace MOKA_Factory_Tools.Models
         public string NTF_SN{ get; set; }               /* 记录NTF的FSN号,使用分号分隔 */
         public string FailDSN{ get; set; }              /* 记录实际Fail的FSN号 */
         public string Remark{ get; set; }               /* 备注 */
+
+        /// <summary>
+        /// 判断对象的值是否空;
+        /// </summary>
+        /// <returns></returns>
+        public bool IsValueEmpty()
+        {
+            if (ID == -1)
+                return true;
+            return false;
+        }
     }
 }