Ejemplo n.º 1
0
        private void cboPeriod_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_PERIOD)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = true;
                dtpToDate.Enabled   = true;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_DATE)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = false;
                dtpFromDate.Enabled = true;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_WEEK)
            {
                dtpToDate.Visible   = false;
                dtpFromDate.Visible = false;

                dtpFromYear.Visible = true;
                numFromWeek.Visible = true;

                WorkTime_tmp      = Get_Current_Work_Time(DateTime.Now.ToString("yyyyMMddHHmmss"), 0);
                dtpFromYear.Text  = CmnFunction.ChangeDateTimeString(WorkTime_tmp.work_date, "yyyyMMdd", "yyyy-MM-dd");
                numFromWeek.Value = WorkTime_tmp.work_week;
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_CURRENT_DAY)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                dtpFromDate.Value = DateTime.Now;
                dtpToDate.Value   = DateTime.Now;
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_PREVIOUS_DAY)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                dtpFromDate.Value = DateTime.Now.AddDays(-1);
                dtpToDate.Value   = DateTime.Now.AddDays(-1);
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_CURRENT_WEEK)
            {
                int iCurrentDayOfWeek;

                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                iCurrentDayOfWeek = (int)DateTime.Now.DayOfWeek;
                dtpFromDate.Value = DateTime.Now.AddDays(-iCurrentDayOfWeek + 1);
                dtpToDate.Value   = DateTime.Now.AddDays(-iCurrentDayOfWeek + 1 + 6);
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_PREVIOUS_WEEK)
            {
                int iCurrentDayOfWeek;

                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                iCurrentDayOfWeek = (int)DateTime.Now.DayOfWeek;
                dtpFromDate.Value = DateTime.Now.AddDays(-iCurrentDayOfWeek + 1 - 6 - 1);
                dtpToDate.Value   = DateTime.Now.AddDays(-iCurrentDayOfWeek + 1 + 6 - 6 - 1);
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_CURRENT_MONTH)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                string sCurrentDate = DateTime.Now.ToString("yyyyMMdd");
                sCurrentDate = sCurrentDate.Substring(0, 6) + "01";
                DateTime dtTemp;
                if (CmnFunction.StringToDateTime(sCurrentDate, "yyyyMMdd", out dtTemp))
                {
                    dtpFromDate.Text = dtTemp.ToString();
                }

                sCurrentDate = DateTime.Now.AddMonths(1).ToString("yyyyMMdd");
                sCurrentDate = sCurrentDate.Substring(0, 6) + "01";
                if (CmnFunction.StringToDateTime(sCurrentDate, "yyyyMMdd", out dtTemp))
                {
                    dtpToDate.Text = dtTemp.AddDays(-1).ToString();
                }
            }
            else if (cboPeriod.SelectedIndex == (int)udcPeriod.ePeriod.PERIOD_PREVIOUS_MONTH)
            {
                dtpFromDate.Visible = true;
                dtpToDate.Visible   = true;
                dtpFromDate.Enabled = false;
                dtpToDate.Enabled   = false;

                dtpFromYear.Visible = false;
                numFromWeek.Visible = false;

                string sCurrentDate = DateTime.Now.AddMonths(-1).ToString("yyyyMMdd");
                sCurrentDate = sCurrentDate.Substring(0, 6) + "01";
                DateTime dtTemp;
                if (CmnFunction.StringToDateTime(sCurrentDate, "yyyyMMdd", out dtTemp))
                {
                    dtpFromDate.Text = dtTemp.ToString();
                }

                sCurrentDate = DateTime.Now.ToString("yyyyMMdd");
                sCurrentDate = sCurrentDate.Substring(0, 6) + "01";
                if (CmnFunction.StringToDateTime(sCurrentDate, "yyyyMMdd", out dtTemp))
                {
                    dtpToDate.Text = dtTemp.AddDays(-1).ToString();
                }
            }

            if (SelectedItemChangedEvent != null)
            {
                SelectedItemChangedEvent(this, e);
            }
        }
Ejemplo n.º 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);
            }
        }