Example #1
0
        private void TrackBar_yeild_Scroll(object sender, EventArgs e)
        {
            string XDate;
            int    SelectData = 0;

            //Call CalculateYieldRetestRate()
            FileRw.ReadYieldFile(PVar.BZ_YieldMonthDataFileName, PVar.YieldOfMonth);
            SelectData = TrackBar_yeild.Value;
            for (var i = 0; i <= SelectData - 1; i++)
            {
                XDate = System.Convert.ToString(PVar.YieldOfMonth.RecordTime[i].ToString("yyyyMMdd"));
                PVar.StorXData[(int)i]         = System.Convert.ToString(PVar.YieldOfMonth.RecordTime[i].ToString("MM/dd"));
                PVar.StorYieldOverView[(int)i] = System.Convert.ToDouble((PVar.YieldOfMonth.ProductCount[(int)i] == 0) ? 0 : (Math.Round((1 - (double)PVar.YieldOfMonth.NgCount[(int)i] / PVar.YieldOfMonth.ProductCount[(int)i]) * 100, 1)));                      //当天良率
            }
            FileRw.Chart_Curve(Chart_YieldOverview, "Yield Rate(Unit:%)", "", "", "Yield", PVar.StorXData, PVar.StorYieldOverView, 0, 0, 0, false);
        }
        /// <summary>
        /// 更新生产数据
        /// </summary>
        /// <remarks></remarks>
        public void CalculateYield()
        {
            string TimeNowDate     = "";
            string TimeBeforeMonth = "";

            TimeNowDate = DateTime.Now.ToString("yyyyMMdd");
            DateTime dt = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);

            TimeBeforeMonth          = System.Convert.ToString(dt.AddDays(-30).ToString("yyyyMMdd"));
            PVar.NgCountOfDay        = int.Parse(BVar.FileRorW.ReadINI("ProductCount", "NgCountOfDay", System.Convert.ToString(0), PVar.BZ_YieldDataFileName));
            PVar.NgCountOfMonth      = int.Parse(BVar.FileRorW.ReadINI("ProductCount", "NgCountOfMonth", System.Convert.ToString(0), PVar.BZ_YieldDataFileName));
            PVar.ProductCountOfDay   = int.Parse(BVar.FileRorW.ReadINI("ProductCount", "ProductCountOfDay", System.Convert.ToString(0), PVar.BZ_YieldDataFileName));
            PVar.ProductCountOfMonth = int.Parse(BVar.FileRorW.ReadINI("ProductCount", "ProductCountOfMonth", System.Convert.ToString(0), PVar.BZ_YieldDataFileName));
            PVar.RecordTimeOfDate    = BVar.FileRorW.ReadINI("ProductTime", "RecordTimeOfDate", TimeBeforeMonth, PVar.BZ_YieldDataFileName);
            PVar.RecordTimeOfMonth   = BVar.FileRorW.ReadINI("ProductTime", "RecordTimeOfMonth", TimeNowDate, PVar.BZ_YieldDataFileName);

            FileRw.ReadYieldFile(PVar.BZ_YieldMonthDataFileName, PVar.YieldOfMonth);

            //**************************************记录当天日良率********************************************************
            if (double.Parse(TimeNowDate) - double.Parse(PVar.RecordTimeOfDate) == 0) //当前日期与记录日期相同
            {
                PVar.ProductCountOfDay++;
                PVar.NgCountOfDay                 = (BVar.ProData[4, 28] == "OK") ? PVar.NgCountOfDay : PVar.NgCountOfDay + 1;
                PVar.YieldOfMonth.NgCount[0]      = PVar.NgCountOfDay; //更新最新一天的产量
                PVar.YieldOfMonth.ProductCount[0] = PVar.ProductCountOfDay;
                PVar.YieldOfMonth.RecordTime[0]   = DateTime.Now;
            }
            else
            {
                PVar.ProductCountOfDay = 1;
                PVar.NgCountOfDay      = (BVar.ProData[4, 28] == "OK") ? 0 : 1;
                ExchangeYieldData();                                   //30天产量统计数据交换,ExchangeYieldData(0)为最新一天的产量,ExchangeYieldData(29)为30天前的产量
                PVar.YieldOfMonth.NgCount[0]      = PVar.NgCountOfDay; //更新最新一天的产量
                PVar.YieldOfMonth.ProductCount[0] = PVar.ProductCountOfDay;
                PVar.YieldOfMonth.RecordTime[0]   = DateTime.Now;
            }

            FileRw.WriteYieldFile(PVar.BZ_YieldMonthDataFileName, PVar.YieldOfMonth);
            BVar.FileRorW.WriteINI("ProductCount", "ProductCountOfDay", System.Convert.ToString(PVar.ProductCountOfDay), PVar.BZ_YieldDataFileName);
            BVar.FileRorW.WriteINI("ProductCount", "NgCountOfDay", System.Convert.ToString(PVar.NgCountOfDay), PVar.BZ_YieldDataFileName);
            BVar.FileRorW.WriteINI("ProductTime", "RecordTimeOfDate", TimeBeforeMonth, PVar.BZ_YieldDataFileName); //更新以当前向后推30天的日期
            PVar.DayYieldOfNg = Math.Round(System.Convert.ToDouble(((double)PVar.NgCountOfDay / PVar.ProductCountOfDay) * 100), 1);
            this.DRB_YieldRetest.BZ_NgRateDay = (int)PVar.DayYieldOfNg;                                            //日Ng率

            //**************************************记录当月良率********************************************************
            if (double.Parse(TimeBeforeMonth) - double.Parse(PVar.RecordTimeOfMonth) <= 0) //当前时间减30天小于记录的一个月后时间
            {
                PVar.ProductCountOfMonth++;
                PVar.NgCountOfMonth     = (BVar.ProData[4, 28] == "OK") ? PVar.NgCountOfMonth : PVar.NgCountOfMonth + 1;
                this.Lbl_StartTime.Text = System.Convert.ToString(dt.AddDays(-30).ToString("MM/dd/yy"));
                this.Lbl_EndTime.Text   = DateTime.Now.ToString("MM/dd/yy"); //结束日期为当前日期
            }
            else
            {
                PVar.ProductCountOfMonth = PVar.ProductCountOfMonth - PVar.YieldOfMonth.ProductCount[29] + 1;                                                                                 //更新月产量,总数减去30天前的产量
                PVar.NgCountOfMonth      = (BVar.ProData[4, 28] == "OK") ? (PVar.NgCountOfMonth - PVar.YieldOfMonth.NgCount[29]) : (PVar.NgCountOfMonth - PVar.YieldOfMonth.NgCount[29] + 1); //更新月NG数量,总数减去30天前的产量
                BVar.FileRorW.WriteINI("ProductTime", "RecordTimeOfMonth", DateTime.Now.ToString("yyyyMMdd"), PVar.BZ_YieldDataFileName);                                                     //更新月良率记录时间
                //Frm_Production.Lbl_StartTime.Text = YieldOfMonth.RecordTime(29).ToString("yyyyMMdd")   '开始日期为当前往前30天
                this.Lbl_StartTime.Text = System.Convert.ToString(dt.AddDays(-30).ToString("MM/dd/yy"));                                                                                      //开始日期为当前往前30天
                this.Lbl_EndTime.Text   = DateTime.Now.ToString("MM/dd/yy");                                                                                                                  //结束日期为当前日期
            }

            BVar.FileRorW.WriteINI("ProductCount", "ProductCountOfMonth", System.Convert.ToString(PVar.ProductCountOfMonth), PVar.BZ_YieldDataFileName);
            BVar.FileRorW.WriteINI("ProductCount", "NgCountOfMonth", System.Convert.ToString(PVar.NgCountOfMonth), PVar.BZ_YieldDataFileName);

            PVar.MonthYieldOfNg = Math.Round(System.Convert.ToDouble(((double)PVar.NgCountOfMonth / PVar.ProductCountOfMonth) * 100), 1);
            this.DRB_YieldRetest.BZ_NgRateMonth = (int)PVar.MonthYieldOfNg; //月Ng率
        }