Beispiel #1
0
        private m_factory_shift Get_Factory_Shift()
        {
            m_factory_shift FactoryShift_tmp = new m_factory_shift();

            DataTable rtDataTable = new DataTable();
            string    QueryCond   = null;

            try
            {
                CmnFunction.oComm.SetUrl();

                QueryCond = FwxCmnFunction.PackCondition(QueryCond, Factory);

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

                if (rtDataTable.Rows.Count == 0)
                {
                    QueryCond = null;
                    QueryCond = FwxCmnFunction.PackCondition(QueryCond, "SYSTEM");

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

                if (rtDataTable.Rows.Count > 0)
                {
                    int i = 0;

                    FactoryShift_tmp.shift    = new m_factory_shift_shift[4];
                    FactoryShift_tmp.shift[0] = new m_factory_shift_shift();
                    FactoryShift_tmp.shift[1] = new m_factory_shift_shift();
                    FactoryShift_tmp.shift[2] = new m_factory_shift_shift();
                    FactoryShift_tmp.shift[3] = new m_factory_shift_shift();

                    FactoryShift_tmp.shift[0].shift_day_flag = rtDataTable.Rows[i]["SHIFT_1_DAY_FLAG"].ToString();
                    FactoryShift_tmp.shift[0].shift_start    = rtDataTable.Rows[i]["SHIFT_1_START"].ToString();

                    FactoryShift_tmp.shift[1].shift_day_flag = rtDataTable.Rows[i]["SHIFT_2_DAY_FLAG"].ToString();
                    FactoryShift_tmp.shift[1].shift_start    = rtDataTable.Rows[i]["SHIFT_2_START"].ToString();

                    FactoryShift_tmp.shift[2].shift_day_flag = rtDataTable.Rows[i]["SHIFT_3_DAY_FLAG"].ToString();
                    FactoryShift_tmp.shift[2].shift_start    = rtDataTable.Rows[i]["SHIFT_3_START"].ToString();

                    FactoryShift_tmp.shift[3].shift_day_flag = rtDataTable.Rows[i]["SHIFT_4_DAY_FLAG"].ToString();
                    FactoryShift_tmp.shift[3].shift_start    = rtDataTable.Rows[i]["SHIFT_4_START"].ToString();
                }

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

                return(FactoryShift_tmp);
            }
            catch (Exception ex)
            {
                CmnFunction.ShowMsgBox(ex.ToString());
                return(FactoryShift_tmp);
            }
        }
Beispiel #2
0
        private m_work_time Get_Current_Work_Time(string strDateTime, int iDay, int iMonth)
        {
            DataTable   rtDataTable  = new DataTable();
            m_work_time WorkTime_tmp = new m_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 = CurrentDateTime.AddDays(-iDay);
                }

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

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

                CmnFunction.oComm.SetUrl();

                QueryCond = FwxCmnFunction.PackCondition(QueryCond, Factory);
                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);
            }
        }