Esempio n. 1
0
        public List <T> Balance(T asi_info)
        {
            WORK_TIME lwt_time  = WORK_TIME.NONE;
            List <T>  llst_temp = new List <T>();

            if (asi_info == null)
            {
                return(llst_temp);
            }
            if ((asi_info.Time >= MDT_0000 && asi_info.Time <= MDT_1200))
            {
                lwt_time = WORK_TIME.MORNING;
            }
            if ((asi_info.Time > MDT_1200 && asi_info.Time <= MDT_2359))
            {
                lwt_time = WORK_TIME.AFTERNOON;
            }

            var lsi_info = asi_info.Clone <T>();

            if (lwt_time != WORK_TIME.NONE)
            {
                if (msi_info == null || msi_info.Time.Date != lsi_info.Time.Date)
                {
                    lsi_info.VolAmount = lsi_info.GVolAmount;
                    lsi_info.VolMoney  = lsi_info.GVolMoney;
                    llst_temp.Add(lsi_info.Clone <T>());
                }
                else
                {
                    lsi_info.VolAmount = lsi_info.GVolAmount - msi_info.GVolAmount;
                    lsi_info.VolMoney  = lsi_info.GVolMoney - msi_info.GVolMoney;

                    var seconds = (mwt_time != lwt_time) ? 1 : (lsi_info.Time - msi_info.Time).Seconds;
                    while (seconds > 0)
                    {
                        T lsi_temp = null;
                        if (seconds == 1)
                        {
                            lsi_temp = lsi_info.Clone <T>();
                        }
                        else
                        {
                            msi_info.Time      = msi_info.Time.AddSeconds(1);
                            lsi_temp           = msi_info.Clone <T>();
                            lsi_temp.VolAmount = decimal.Zero;
                            lsi_temp.VolMoney  = decimal.Zero;
                        }
                        llst_temp.Add(lsi_temp);
                        seconds--;
                    }
                }
            }
            msi_info = lwt_time == WORK_TIME.NONE ? null : lsi_info.Clone <T>();
            mwt_time = lwt_time;

            return(llst_temp);
        }
        public List <KeyValuePair <DateTime, decimal> > Add(KeyValuePair <DateTime, decimal> pair)
        {
            WORK_TIME lwt_time = WORK_TIME.NONE;
            List <KeyValuePair <DateTime, decimal> > lst_pairs = new List <KeyValuePair <DateTime, decimal> >();

            if ((pair.Key >= MDT_0000 && pair.Key <= MDT_1200))
            {
                lwt_time = WORK_TIME.MORNING;
            }
            if ((pair.Key > MDT_1200 && pair.Key <= MDT_2359))
            {
                lwt_time = WORK_TIME.AFTERNOON;
            }


            if (lwt_time != WORK_TIME.NONE)
            {
                if (Pair == null || Pair.Value.Key.Date != pair.Key.Date)
                {
                    lst_pairs.Add(pair);
                }
                else
                {
                    var seconds = (mwt_time != lwt_time) ? 1 : (pair.Key - Pair.Value.Key).Seconds;
                    var time    = Pair.Value.Key;
                    while (seconds > 0)
                    {
                        if (seconds == 1)
                        {
                            lst_pairs.Add(pair);
                        }
                        else
                        {
                            time = time.AddSeconds(1);
                            var value = Pair.Value.Value;
                            lst_pairs.Add(new KeyValuePair <DateTime, decimal>(time, value));
                        }
                        seconds--;
                    }
                }
            }
            Pair     = lwt_time == WORK_TIME.NONE ? null : (KeyValuePair <DateTime, decimal>?)pair;
            mwt_time = lwt_time;

            //LinearList<KeyValuePair<DateTime, decimal>> line = null;
            //List<LinearList<KeyValuePair<DateTime, decimal>>> lines = new List<LinearList<KeyValuePair<DateTime, decimal>>>();
            //lst_pairs.ForEach(p =>
            //{
            //    Averager.Add(p.Value);
            //    if (cache1.Add(new KeyValuePair<DateTime, decimal>(p.Key, Averager.Average), out line))
            //    {
            //        Lines.Add(line);
            //        lines.Add(line);
            //    }
            //});
            return(lst_pairs);
        }
Esempio n. 3
0
        private bool Make_Column_Query(ref FLX_COLUMN colColumn)
        {
            WORK_TIME WorkTime_tmp = new WORK_TIME();
            string    strTime      = "";

            try
            {
                strTime = CmnFunction.GetSysDateTime();

                if (dtpDateTime.Visible == true)
                {
                    strTime = dtpDateTime.Value.ToString("yyyyMMddHHmmss");
                }

                switch (colColumn.period)
                {
                case "CS1":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = "CS1_" + colColumn.column_name;
                    break;

                case "CS2":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = "CS2_" + colColumn.column_name;
                    break;

                case "CS3":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = "CS3_" + colColumn.column_name;
                    break;

                case "PS1":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 1);
                    colColumn.column_header_name = "PS1_" + colColumn.column_name;
                    break;

                case "PS2":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 1);
                    colColumn.column_header_name = "PS2_" + colColumn.column_name;
                    break;

                case "PS3":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 1);
                    colColumn.column_header_name = "PS3_" + colColumn.column_name;
                    break;

                case "CS":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = "S" + WorkTime_tmp.work_shift.ToString() + "_" + colColumn.column_name;
                    break;

                case "PS":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 1);
                    colColumn.column_header_name = "S" + WorkTime_tmp.work_shift.ToString() + "_" + colColumn.column_name;
                    break;

                case "CD":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;

                case "PD":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 1);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;

                case "CW":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;

                case "PW":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 7);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;

                case "CM":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;

                case "PM":
                    WorkTime_tmp = Get_Current_Work_Time(strTime, 0, 1);
                    colColumn.column_header_name = colColumn.period + colColumn.column_name;
                    break;
                }

                switch (colColumn.period)
                {
                case "CS1":
                case "CS2":
                case "CS3":
                case "PS1":
                case "PS2":
                case "PS3":
                case "CS":
                case "PS":
                case "CD":
                case "PD":
                    colColumn.query  = "WHERE FACTORY = '" + cdvFactory.Text + "' \n";
                    colColumn.query += "AND WORK_MONTH = '" + WorkTime_tmp.work_date.Substring(0, 4) + WorkTime_tmp.work_month.ToString("00") + "' AND WORK_WEEK = '" + WorkTime_tmp.work_date.Substring(0, 4) + WorkTime_tmp.work_week.ToString("00") + "' AND WORK_DAYS = '" + WorkTime_tmp.work_days.ToString("000") + "' \n";
                    break;

                case "CW":
                case "PW":
                    colColumn.query  = "WHERE FACTORY = '" + cdvFactory.Text + "' \n";
                    colColumn.query += "AND WORK_MONTH = '" + WorkTime_tmp.work_date.Substring(0, 4) + WorkTime_tmp.work_month.ToString("00") + "' AND WORK_WEEK = '" + WorkTime_tmp.work_date.Substring(0, 4) + WorkTime_tmp.work_week.ToString("00") + "' \n";
                    break;

                case "CM":
                case "PM":
                    colColumn.query  = "WHERE FACTORY = '" + cdvFactory.Text + "' \n";
                    colColumn.query += "AND WORK_MONTH = '" + WorkTime_tmp.work_date.Substring(0, 4) + WorkTime_tmp.work_month.ToString("00") + "' \n";
                    break;
                }

                return(true);
            }
            catch (Exception ex)
            {
                CmnFunction.ShowMsgBox(ex.ToString());
                return(false);
            }
        }
Esempio n. 4
0
        private WORK_TIME Get_Current_Work_Time(string strDateTime, int iDay, int iMonth)
        {
            DataTable rtDataTable  = new DataTable();
            WORK_TIME WorkTime_tmp = new WORK_TIME();
            DateTime  CurrentDateTime;

            string QueryCond = null;
            int    i;

            try
            {
                Factory_Shift = Get_Factory_Shift();

                for (i = 0; i < 4; i++)
                {
                    if (Factory_Shift.shift[i].shift_day_flag == Factory_Shift.shift[i + 1].shift_day_flag)
                    {
                        if (System.Convert.ToInt32(strDateTime.Substring(8, 4)) >= System.Convert.ToInt32(Factory_Shift.shift[i].shift_start) && System.Convert.ToInt32(strDateTime.Substring(8, 4)) < System.Convert.ToInt32(Factory_Shift.shift[i + 1].shift_start))
                        {
                            WorkTime_tmp.work_shift = i + 1;
                            break;
                        }
                    }
                    else if (Factory_Shift.shift[i].shift_day_flag != Factory_Shift.shift[i + 1].shift_day_flag && Factory_Shift.shift[i + 1].shift_day_flag != " ")
                    {
                        if (System.Convert.ToInt32(strDateTime.Substring(8, 4)) >= System.Convert.ToInt32(Factory_Shift.shift[i].shift_start) || System.Convert.ToInt32(strDateTime.Substring(8, 4)) < System.Convert.ToInt32(Factory_Shift.shift[i + 1].shift_start))
                        {
                            WorkTime_tmp.work_shift = i + 1;
                            break;
                        }
                    }
                    else if (Factory_Shift.shift[i + 1].shift_day_flag == " ")
                    {
                        WorkTime_tmp.work_shift = i + 1;
                        break;
                    }
                }

                if (Factory_Shift.shift[0].shift_day_flag == "T")
                {
                    WorkTime_tmp.last_shift = 1;
                }
                else
                {
                    WorkTime_tmp.last_shift = 0;
                }
                if (Factory_Shift.shift[1].shift_day_flag == "T")
                {
                    WorkTime_tmp.last_shift = 2;
                }
                if (Factory_Shift.shift[2].shift_day_flag == "T")
                {
                    WorkTime_tmp.last_shift = 3;
                }
                if (Factory_Shift.shift[3].shift_day_flag == "T")
                {
                    WorkTime_tmp.last_shift = 4;
                }

                CurrentDateTime = new DateTime(System.Convert.ToInt32(strDateTime.Substring(0, 4)),
                                               System.Convert.ToInt32(strDateTime.Substring(4, 2)),
                                               System.Convert.ToInt32(strDateTime.Substring(6, 2)),
                                               System.Convert.ToInt32(strDateTime.Substring(8, 2)),
                                               System.Convert.ToInt32(strDateTime.Substring(10, 2)),
                                               System.Convert.ToInt32(strDateTime.Substring(12, 2)));

                if (iDay != 0)
                {
                    CurrentDateTime.AddDays(-iDay);
                }

                if (iMonth != 0)
                {
                    CurrentDateTime.AddMonths(-iMonth);
                }

                if (System.Convert.ToInt32(strDateTime.Substring(8, 4)) < System.Convert.ToInt32(Factory_Shift.shift[0].shift_start))
                {
                    CurrentDateTime.AddDays(-1);
                }

                CmnFunction.oComm.SetUrl();

                QueryCond = FwxCmnFunction.PackCondition(QueryCond, cdvFactory.Text);
                QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Year.ToString());
                QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Month.ToString());
                QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Day.ToString());

                rtDataTable = CmnFunction.oComm.SelectData("MWIPCALDEF", "1", QueryCond);

                if (rtDataTable.Rows.Count == 0)
                {
                    QueryCond = null;
                    QueryCond = FwxCmnFunction.PackCondition(QueryCond, "SYSTEM");
                    QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Year.ToString());
                    QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Month.ToString());
                    QueryCond = FwxCmnFunction.PackCondition(QueryCond, CurrentDateTime.Day.ToString());

                    rtDataTable = CmnFunction.oComm.SelectData("MWIPCALDEF", "1", QueryCond);
                }

                if (rtDataTable.Rows.Count == 0)
                {
                    //default
                }
                if (rtDataTable.Rows.Count > 0)
                {
                    i = 0;

                    WorkTime_tmp.work_year  = System.Convert.ToInt32(rtDataTable.Rows[i]["PLAN_YEAR"]);
                    WorkTime_tmp.work_month = System.Convert.ToInt32(rtDataTable.Rows[i]["PLAN_MONTH"]);
                    WorkTime_tmp.work_week  = System.Convert.ToInt32(rtDataTable.Rows[i]["PLAN_WEEK"]);
                    WorkTime_tmp.work_days  = System.Convert.ToInt32(rtDataTable.Rows[i]["JULIAN_DAY"]);

                    int iTime;
                    iTime = CurrentDateTime.Hour * 100 + CurrentDateTime.Minute;

                    if (rtDataTable.Rows[i]["PREV_DAY_FG"].ToString() == "Y")
                    {
                        if (System.Convert.ToInt32(rtDataTable.Rows[i]["START_TIME"]) <= iTime)
                        {
                            CurrentDateTime.AddDays(-1);
                        }
                    }
                    else
                    {
                        if (System.Convert.ToInt32(rtDataTable.Rows[i]["START_TIME"]) > iTime)
                        {
                            CurrentDateTime.AddDays(-1);
                        }
                    }

                    WorkTime_tmp.work_date = CurrentDateTime.ToString("yyyyMMdd");
                }

                if (rtDataTable.Rows.Count > 0)
                {
                    rtDataTable.Dispose();
                }

                return(WorkTime_tmp);
            }
            catch (Exception ex)
            {
                CmnFunction.ShowMsgBox(ex.ToString());
                return(WorkTime_tmp);
            }
        }
 public void Reset()
 {
     Pair     = null;
     mwt_time = WORK_TIME.NONE;
 }