示例#1
0
        /// <summary>
        /// C2样本数据计算
        /// </summary>
        /// <returns></returns>
        public string C2DataStatistics()
        {
            String message = "";

            LogStr.Clear();

            DateTime    startTime;
            DateTime    endTime;
            String      wo;
            String      machine;
            int         orderNo;
            String      mat_Ctrl;
            double      UCL;
            double      LCL;
            DataSet     dsC2Data = GetC2DataStatTime();
            CDataResult res      = new CDataResult();

            if (dsC2Data.Tables[0].Rows.Count > 0 || dsC2Data.Tables[1].Rows.Count > 0 || dsC2Data.Tables[2].Rows.Count > 0)
            {
                for (int i = 0; i < dsC2Data.Tables.Count; i++)
                {
                    startTime = Convert.ToDateTime(dsC2Data.Tables[i].Rows[0]["CHECKTIME"]);
                    wo        = dsC2Data.Tables[i].Rows[0]["WO"].ToString();
                    machine   = dsC2Data.Tables[i].Rows[0]["MACHINE"].ToString();
                    orderNo   = Convert.ToInt32(dsC2Data.Tables[i].Rows[0]["ORDERNUM"]);
                    DataSet dsEndTime = GetC2DataEndTime(startTime, machine);
                    if (dsEndTime.Tables[0].Rows.Count > 0)
                    {
                        endTime = Convert.ToDateTime(dsEndTime.Tables[0].Rows[0]["ROWTIME"]);
                        DataSet ds = GetC2DataFromMes(startTime, endTime, machine);

                        if (ds.Tables[0].Rows.Count > 19)
                        {
                            IList <CData> list = ConvetToObjList(ds.Tables[0]);
                            //计算平均值
                            res.WG_AVG   = list.Average(c => c.Wg);
                            res.CIRC_AVG = list.Average(c => c.CIRC);
                            res.LEN_AVG  = list.Average(c => c.Len);
                            res.PD_AVG   = list.Average(c => c.Pd);
                            res.TV_AVG   = list.Average(c => c.TV);
                            //计算标准偏差
                            IList <double> wgData = mu.InitDoubleData(list, "WG");
                            res.WG_STDV = Convert.ToDecimal(mu.ComputSD(wgData));
                            IList <double> lenData = mu.InitDoubleData(list, "LEN");
                            res.LEN_STDV = Convert.ToDecimal(mu.ComputSD(lenData));
                            IList <double> pdData = mu.InitDoubleData(list, "PD");
                            res.PD_STDV = Convert.ToDecimal(mu.ComputSD(pdData));
                            IList <double> circData = mu.InitDoubleData(list, "CIRC");
                            res.CIRC_STDV = Convert.ToDecimal(mu.ComputSD(circData));
                            IList <double> tvData = mu.InitDoubleData(list, "TV");
                            res.TV_STDV = Convert.ToDecimal(mu.ComputSD(tvData));
                            //其他结果值
                            mat_Ctrl      = list[list.Count - 1].mat_Ctrl;
                            res.checkTime = list[list.Count - 1].testdate;
                            res.wo        = list[list.Count - 1].Wo;
                            res.machine   = machine;
                            if (wo.Equals(res.wo))
                            {
                                res.ordernum = orderNo + 1;
                            }
                            else
                            {
                                res.ordernum = 1;
                            }
                            //取标准 计算CPK
                            DataSet dsStandard = GetStandard(machine, mat_Ctrl);
                            if (dsStandard.Tables[0].Rows.Count > 0)
                            {
                                foreach (DataRow dr in dsStandard.Tables[0].Rows)
                                {
                                    UCL = Convert.ToDouble(dr["LCL"]);
                                    LCL = Convert.ToDouble(dr["UCL"]);
                                    switch (dr["TEST"].ToString())
                                    {
                                    case "WG":
                                        res.WG_CPK = Convert.ToDecimal(mu.ComputCPK(wgData, UCL, Convert.ToDouble(res.WG_AVG), LCL));
                                        break;

                                    case "LEN_":
                                        res.LEN_CPK = Convert.ToDecimal(mu.ComputCPK(lenData, UCL, Convert.ToDouble(res.LEN_AVG), LCL));
                                        break;

                                    case "CIRC":
                                        res.CIRC_CPK = Convert.ToDecimal(mu.ComputCPK(circData, UCL, Convert.ToDouble(res.CIRC_AVG), LCL));
                                        break;

                                    case "PD":
                                        res.PD_CPK = Convert.ToDecimal(mu.ComputCPK(pdData, UCL, Convert.ToDouble(res.PD_AVG), LCL));
                                        break;

                                    case "TV":
                                        res.TV_CPK = Convert.ToDecimal(mu.ComputCPK(tvData, UCL, Convert.ToDouble(res.TV_AVG), LCL));
                                        break;

                                    default:
                                        break;
                                    }
                                }
                            }
                            dsSql.BeginTransaction();
                            message = SaveC2StatisticsData(res);
                            dsSql.CommitTransaction();
                        }
                    }
                    //else
                    //{
                    //    res.checkTime = endTime;
                    //    res.machine = machine;
                    //    res.wo = wo;
                    //}
                }
            }
            if (!String.IsNullOrEmpty(message))
            {
                string tempStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss    ") + "C2" + message + "\r\n";
                LogStr.Append(tempStr);
                String savePath = "D:\\GetC2RowNum_Log";
                String fileName = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                String fileMsg  = LogStr.ToString() + "\r\n";
                LogHelper.SaveMsgToFile(savePath, fileName, fileMsg);
            }
            return(message);
        }
示例#2
0
        /// <summary>
        /// C2样本编号
        /// </summary>
        /// <returns></returns>
        public string GetC2RowNum()
        {
            String message = "";

            LogStr.Clear();

            DateTime timeFlag;
            String   mat;
            String   machine;
            int      rowNum     = 1;
            String   rowGuid    = "";
            DataSet  dsTimeFlag = this.GetStartTime();

            if (dsTimeFlag.Tables[0].Rows.Count > 0 || dsTimeFlag.Tables[1].Rows.Count > 0 || dsTimeFlag.Tables[2].Rows.Count > 0)
            {
                for (int i = 0; i < dsTimeFlag.Tables.Count; i++)
                {
                    timeFlag = Convert.ToDateTime(dsTimeFlag.Tables[i].Rows[0]["TIMEFLAG"]);
                    mat      = dsTimeFlag.Tables[i].Rows[0]["MAT"].ToString();
                    machine  = dsTimeFlag.Tables[i].Rows[0]["MACHINE"].ToString();
                    DataSet ds = this.GetC2Data(timeFlag, machine);
                    if (ds.Tables[0].Rows.Count > 5)
                    {
                        if (ds.Tables[0].Rows[0]["BATCH_BRAND"].ToString().Equals(mat))
                        {
                            rowNum = GetContinueRowNum(timeFlag, machine) + 1;
                        }
                        dsSql.BeginTransaction();
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (!dr["BATCH_BRAND"].ToString().Equals(mat))
                            {
                                rowNum = 1;
                            }
                            if (rowNum > 20)
                            {
                                rowNum = 1;
                            }
                            TimeSpan timeSpan = Convert.ToDateTime(dr["GMT_Date_Time"]) - timeFlag;
                            timeFlag = Convert.ToDateTime(dr["GMT_Date_Time"]);
                            if (timeSpan.Hours > 4)
                            {
                                rowNum = 1;
                            }
                            mat      = dr["BATCH_BRAND"].ToString();
                            rowGuid  = dr["rowguid"].ToString();
                            message += SaveC2Data(timeFlag, machine, rowNum);
                            rowNum++;
                        }
                        message += SaveC2TimeFlag(timeFlag, mat, machine);
                        dsSql.CommitTransaction();
                    }
                }
            }
            if (!String.IsNullOrEmpty(message))
            {
                string tempStr = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss    ") + message + "\r\n";
                LogStr.Append(tempStr);
                String savePath = "D:\\GetC2RowNum_Log";
                String fileName = DateTime.Now.ToString("yyyy-MM-dd") + ".log";
                String fileMsg  = LogStr.ToString() + "\r\n";
                LogHelper.SaveMsgToFile(savePath, fileName, fileMsg);
            }
            return(message);
        }