コード例 #1
0
    public List <MDataGraph> GetPlan(decimal CycleTime, string Fac, string Line, string Mac, string ModelCode, string strDate, string endDate)
    {
        bool     shipDay = true;
        DateTime DateNow = DateTime.Now;

        if (Fac == "old")
        {
            DateNow = Convert.ToDateTime(Mac) + new TimeSpan(8, 20, 0);
        }
        TimeSpan strTime = new TimeSpan(0, 0, 0);//---- Data Test ---------
        TimeSpan endTime = new TimeSpan(12, 0, 0);
        DateTime stDate  = DateTime.Now.Date + strTime;
        DateTime edDate  = DateTime.Now.Date + endTime;

        if (DateTime.Now.Hour >= 8 && DateTime.Now.Hour <= 19)
        {
            stDate  = DateNow.Date + new TimeSpan(8, 5, 0);//---- Data Test ---------
            edDate  = DateNow.Date + new TimeSpan(19, 59, 59);
            shipDay = true;
        }
        else if (DateTime.Now.Hour >= 20 && DateTime.Now.Hour <= 23)
        {
            stDate  = DateNow.Date + new TimeSpan(20, 0, 0);//---- Data Test ---------
            edDate  = DateNow.Date.AddDays(1) + new TimeSpan(7, 59, 59);
            shipDay = false;
        }
        else if (DateTime.Now.Hour >= 0 && DateTime.Now.Hour <= 7)
        {
            stDate  = DateNow.Date.AddDays(-1) + new TimeSpan(20, 0, 0);//---- Data Test ---------
            edDate  = DateNow.Date + new TimeSpan(7, 59, 59);
            shipDay = false;
        }

        TimeSpan difference = edDate - stDate;

        strDate = stDate.ToString("yyyy-MM-dd HH:mm:ss");
        endDate = edDate.ToString("yyyy-MM-dd HH:mm:ss");

        DateTime          CurrDate  = stDate;
        List <MDataGraph> oListPlan = new List <MDataGraph>();
        MDataGraph        oPlan     = new MDataGraph();

        //---------- Get Actual -----------
        DataTable dtActual = GetDataActual(Fac, Line, Mac, ModelCode, strDate, endDate);

        //--------- Get Plan from Andon board Line Main Fac 3 Board ID is 301 --------------
        #region Set Board id
        SqlCommand sql   = new SqlCommand();
        string     Board = "";
        if (Line == "mecha")
        {
            Board = "302";
        }
        else if (Line == "casing")
        {
            Board = "312";
        }
        else if (Line == "motor")
        {
            Board = "310";
        }
        else if (Line == "piston")
        {
            Board = "308";
        }
        else if (Line == "fh")
        {
            Board = "307";
        }
        else if (Line == "cs" || Line == "ct")
        {
            Board = "306";
        }
        else if (Line == "cd")
        {
            Board = "305";
        }
        else if (Line == "rh")
        {
            Board = "304";
        }
        else if (Line == "fn")
        {
            Board = "303";
        }
        else
        {
            Board = "301";
        }
        #endregion
        sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                          " FROM [DataLog] WHERE BoardId = @Board AND LogTime >= @strDate" +
                          " AND LogTime <= @endDate" +
                          " ORDER BY LogTime ASC";
        sql.Parameters.Add(new SqlParameter("@Board", Board));
        sql.Parameters.Add(new SqlParameter("@strDate", strDate));
        sql.Parameters.Add(new SqlParameter("@endDate", endDate));
        DataTable dtPlan = new DataTable();
        dtPlan = oConnPDB.Query(sql);
        int    DailyPlan = 500;
        double PlanHour  = 0;
        double PlanMin   = 0;
        if (dtPlan.Rows.Count > 0)
        {
            DailyPlan = Convert.ToInt32(dtPlan.Rows[dtPlan.Rows.Count - 1]["DailyPlan"].ToString());
        }
        PlanHour = (DailyPlan / 12);
        PlanMin  = 60 / PlanHour;

        double TotalMinWork = 589;
        double ComPerMin    = 0;
        ComPerMin = Convert.ToDouble(DailyPlan) / TotalMinWork;
        double PlanPerMin   = ComPerMin;
        int    CurrPlan     = 0;
        int    SumPlanBreak = 0;

        DateTime ChDate = stDate;
        for (int i = 1; i <= 700; i++)//---------- Loop for 1 Min - 701 Min Is 8:20 - 20:00 ------------
        {
            MDataGraph oMDPlan = new MDataGraph();
            int        plan    = 0;

            oMDPlan.Target = DailyPlan;
            if (CurrDate > DateNow)
            {
                oMDPlan.PlanAccu   = null;// Convert.ToInt32(ComPerMin);
                oMDPlan.ActualAccu = null;
                oMDPlan.EffiAccu   = null;
                oMDPlan.DatePlan   = CurrDate.ToString("HH:mm:ss");
                oMDPlan.Totalmilli = ConvertDateTimeToMilliSeconde(Convert.ToDateTime(CurrDate.ToString("yyyy-MM-dd HH:mm:ss")));
            }
            else
            {
                //-------- Get Data Plan Form Andon Board Table DataLog -----------
                if (dtPlan.Rows.Count > 0)
                {
                    DataRow[] _rowPlan = dtPlan.Select("LogTime >= '" + stDate.ToString("yyyy-MM-dd HH:mm:ss") + "' AND LogTime <= '" + CurrDate.ToString("yyyy-MM-dd HH:mm:ss") + "'");
                    if (_rowPlan.Length > 0)
                    {
                        try
                        {
                            plan = Convert.ToInt32(_rowPlan[_rowPlan.Length - 1]["Plan_"].ToString());
                        }
                        catch
                        {
                            plan = 0;
                        }
                    }
                }
                //-------- Get Data Plan Form Andon Board Table DataLog -----------

                oMDPlan.PlanAccu = plan;// Convert.ToInt32(Math.Floor(ComPerMin));
                string CurrTimeOfCycle = stDate.TimeOfDay.ToString().Replace(":", "");
                string NextTimeOfCycle = CurrDate.TimeOfDay.ToString().Replace(":", "");

                //----------- Get Actual By Count Rows ------------
                int      Actual      = 0;
                DataView dViewActual = dtActual.DefaultView;
                dViewActual.RowFilter = "LogTime >= '" + stDate.ToString("yyyy-MM-dd HH:mm:ss") + "' AND LogTime <= '" + CurrDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                dViewActual.Sort      = "LogTime DESC";
                DataTable dtViewActual = dViewActual.ToTable();

                if (dtViewActual.Rows.Count > 0)
                {
                    Actual = Convert.ToInt32(dtViewActual.Rows[0]["Actual"].ToString());
                }
                oMDPlan.ActualAccu = Actual;

                if (oMDPlan.PlanAccu == 0)
                {
                    oMDPlan.EffiAccu = null;
                }
                else
                {
                    decimal eff    = (Convert.ToDecimal(oMDPlan.ActualAccu * 100) / Convert.ToDecimal(oMDPlan.PlanAccu));
                    decimal?effSet = Math.Round(eff, 3);
                    oMDPlan.EffiAccu = effSet > 100 ? 100 : effSet;
                }
                oMDPlan.DatePlan   = CurrDate.ToString("HH:mm:ss");
                oMDPlan.Totalmilli = ConvertDateTimeToMilliSeconde(Convert.ToDateTime(CurrDate.ToString("yyyy-MM-dd HH:mm:ss")));
            }

            //--------- Check Not Cal Plan Per Min -----------
            if (((CurrDate.TimeOfDay >= new TimeSpan(10, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(10, 10, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(12, 0, 0) && CurrDate.TimeOfDay <= new TimeSpan(13, 0, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(15, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(15, 10, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(17, 45, 0) && CurrDate.TimeOfDay <= new TimeSpan(18, 15, 0))) && shipDay)
            {
                //------ Plan Per Min ---------
                ComPerMin += 0;
            }
            else if (((CurrDate.TimeOfDay >= new TimeSpan(22, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(22, 10, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(0, 0, 0) && CurrDate.TimeOfDay <= new TimeSpan(0, 0, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(3, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(3, 10, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(5, 45, 0) && CurrDate.TimeOfDay <= new TimeSpan(6, 15, 0))) && !shipDay)
            {
                //------ Plan Per Min ---------
                ComPerMin += 0;
            }
            else
            {
                //------ Plan Per Min ---------
                ComPerMin += PlanPerMin;
            }

            oListPlan.Add(oMDPlan);
            CurrDate = CurrDate.AddMinutes(1);
        }

        return(oListPlan);
    }
コード例 #2
0
    public List <MDataGraph> GetPlan(decimal CycleTime, string Fac, string Line, string Mac, string ModelCode, string strDate, string endDate)
    {
        bool     shipDay = true;
        DateTime DateNow = DateTime.Now;

        if (Mac == "last")
        {
            DateNow = DateNow.AddDays(-1) + new TimeSpan(8, 20, 0);
            DateTime DateNew = new DateTime(DateNow.Year, DateNow.Month, DateNow.Day - 1) + new TimeSpan(8, 20, 0);
            DateNow = DateTime.Now;
        }

        TimeSpan strTime = new TimeSpan(0, 0, 0);//---- Data Test ---------
        TimeSpan endTime = new TimeSpan(12, 0, 0);
        DateTime stDate  = DateTime.Now.Date.AddDays(-1) + strTime;
        DateTime edDate  = DateTime.Now.Date.AddDays(-1) + endTime;

        if ((DateNow.TimeOfDay >= new TimeSpan(20, 0, 0) || DateNow.TimeOfDay < new TimeSpan(8, 0, 0)))
        {
            stDate  = stDate.Date + new TimeSpan(20, 0, 0);//---- Data Test ---------
            edDate  = edDate.AddDays(1) + new TimeSpan(8, 20, 0);
            shipDay = false;
        }
        else
        {
            stDate = stDate.Date + new TimeSpan(8, 20, 0);//---- Data Test ---------
            edDate = edDate.Date + new TimeSpan(20, 0, 0);
        }

        TimeSpan difference = edDate - stDate;

        strDate = stDate.ToString("yyyy-MM-dd HH:mm:ss");
        endDate = edDate.ToString("yyyy-MM-dd HH:mm:ss");

        DateTime          CurrDate  = stDate;
        List <MDataGraph> oListPlan = new List <MDataGraph>();
        MDataGraph        oPlan     = new MDataGraph();

        //---------- Get Actual -----------
        DataTable dtActual = GetDataActual(Fac, Line, Mac, ModelCode, strDate, endDate);

        //--------- Get Plan from Andon board Line Main Fac 3 Board ID is 301 --------------
        #region
        SqlCommand sql = new SqlCommand();
        if (Line == "mecha")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '302' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate AND DailyPlan != '0' " +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "casing")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '312' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "motor")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '310' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "piston")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '308' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "fh")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '307' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate " +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "cs")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '306' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "cd")
        {
            //------------ Line Cylinder don,t have andon board ----------------
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '305' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate " +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "rh")
        {
            //------------ Line Rear head don,t have andon board ----------------
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '304' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else if (Line == "fn")
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '303' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate" +
                              " ORDER BY LogTime DESC";
        }
        else
        {
            sql.CommandText = "SELECT [LogTime],[BoardId],[DailyPlan],[Plan_],[Actual],[Diff],[Shift],[Status],[BreakDown]" +
                              " FROM [DataLog] WHERE BoardId = '301' AND LogTime >= @strDate" +
                              " AND LogTime <= @endDate AND DailyPlan != '0' " +
                              " ORDER BY LogTime DESC";
        }
        #endregion

        sql.Parameters.Add(new SqlParameter("@strDate", strDate));
        sql.Parameters.Add(new SqlParameter("@endDate", endDate));
        DataTable dtPlan = new DataTable();
        dtPlan = oConnPDB.Query(sql);
        double DailyPlan = 0;
        double PlanHour  = 0;
        double PlanMin   = 0;
        if (dtPlan.Rows.Count > 0)
        {
            DailyPlan = Convert.ToInt32(dtPlan.Rows[0]["DailyPlan"].ToString());
        }
        PlanHour = (DailyPlan / 12);
        PlanMin  = (60 / PlanHour);

        double TotalMinWork = 589;
        double ComPerMin    = 0;
        ComPerMin = Convert.ToDouble(DailyPlan) / TotalMinWork;
        double PlanPerMin = ComPerMin;

        int CurrPlan     = 0;
        int SumPlanBreak = 0;

        DateTime ChDate = stDate;
        for (int i = 1; i <= 701; i++)
        {
            MDataGraph oMDPlan = new MDataGraph();

            //----------- Set Now -------------
            #region

            //oMDPlan.PlanAccu = CurrPlan;
            oMDPlan.PlanAccu = Convert.ToInt32(ComPerMin);
            oMDPlan.Target   = Convert.ToInt32(DailyPlan);
            string CurrTimeOfCycle = stDate.TimeOfDay.ToString().Replace(":", "");
            string NextTimeOfCycle = CurrDate.TimeOfDay.ToString().Replace(":", "");

            int      Actual      = 0;
            DataView dViewActual = dtActual.DefaultView;
            dViewActual.RowFilter = "LogTime >= '" + stDate.ToString("yyyy-MM-dd HH:mm:ss") + "' AND LogTime <= '" + CurrDate.ToString("yyyy-MM-dd HH:mm:ss") + "'";
            DataTable newDtPlan = dViewActual.ToTable();

            if (newDtPlan.Rows.Count > 0)
            {
                Actual = Convert.ToInt32(newDtPlan.Rows[0]["Actual"].ToString());
            }

            oMDPlan.ActualAccu = Convert.ToInt32(Actual);
            if (oMDPlan.PlanAccu == 0)
            {
                oMDPlan.EffiAccu = null;
            }
            else
            {
                decimal eff    = (Convert.ToDecimal(oMDPlan.ActualAccu * 100) / Convert.ToDecimal(oMDPlan.PlanAccu));
                decimal?effSet = Math.Round(eff, 3);
                oMDPlan.EffiAccu = effSet > 100 ? 100 : effSet;
            }
            #endregion

            oMDPlan.DatePlan   = CurrDate.ToString("HH:mm:ss");
            oMDPlan.Totalmilli = ConvertDateTimeToMilliSeconde(Convert.ToDateTime(CurrDate.ToString("yyyy-MM-dd HH:mm:ss")));

            //--------- Check Not Cal Plan Per Min -----------
            if (((CurrDate.TimeOfDay >= new TimeSpan(10, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(10, 10, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(12, 0, 0) && CurrDate.TimeOfDay <= new TimeSpan(13, 0, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(15, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(15, 10, 0)) ||
                 (CurrDate.TimeOfDay >= new TimeSpan(17, 45, 0) && CurrDate.TimeOfDay <= new TimeSpan(18, 15, 0))) && shipDay)
            {
                CurrPlan += 0;
                SumPlanBreak++;

                //------ Plan Per Min ---------
                ComPerMin += 0;
            }
            else if (((CurrDate.TimeOfDay >= new TimeSpan(22, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(22, 10, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(0, 0, 0) && CurrDate.TimeOfDay <= new TimeSpan(0, 0, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(3, 00, 0) && CurrDate.TimeOfDay <= new TimeSpan(3, 10, 0)) ||
                      (CurrDate.TimeOfDay >= new TimeSpan(5, 45, 0) && CurrDate.TimeOfDay <= new TimeSpan(6, 15, 0))) && !shipDay)
            {
                CurrPlan += 0;
                SumPlanBreak++;

                //------ Plan Per Min ---------
                ComPerMin += 0;
            }
            else
            {
                CurrPlan++;
                CurrPlan    += SumPlanBreak;
                SumPlanBreak = 0;

                //------ Plan Per Min ---------
                ComPerMin += PlanPerMin;
            }
            //--------- Check Not Cal Plan Per Min -----------

            oListPlan.Add(oMDPlan);
            CurrDate = CurrDate.AddSeconds(60);
        }

        return(oListPlan);
    }