Beispiel #1
0
        private void GenWorkingCalendarToDB()
        {
            ValidateException.ThrowErrorItem(WorkingCalendarValidation.CheckEmptyDemandMonth((NZInt)Convert.ToInt32(txtNoOfMonth.Text)));

            switch (ShowConfirmMessage(Messages.eConfirm.CFM9012))
            {
            case MessageDialogResult.Cancel:
                return;

            case MessageDialogResult.No:
                return;

            case MessageDialogResult.Yes:
                break;
            }

            // เตรียมข้อมูลสำหรับ gen
            bool[] bStopingDay =
            {
                evoCheckBoxDay1.Checked,
                evoCheckBoxDay2.Checked,
                evoCheckBoxDay3.Checked,
                evoCheckBoxDay4.Checked,
                evoCheckBoxDay5.Checked,
                evoCheckBoxDay6.Checked,
                evoCheckBoxDay7.Checked
            };
            int iNoOfMonth = Convert.ToInt32(txtNoOfMonth.Text);

            //DateTime dateTime = Convert.ToDateTime(Convert.ToDateTime(evoDateTextBoxStartMY.DateValue).ToString("MM-01-yyyy"));
            DateTime dtmSelectedMonth = (DateTime)evoDateTextBoxStartMY.DateValue;

            dtmSelectedMonth = dtmSelectedMonth.AddDays(0 - dtmSelectedMonth.Day);
            dtmSelectedMonth = dtmSelectedMonth.AddDays(1);

            m_BIZWorkingCalendar.CreateWorkingCalendar(iNoOfMonth, dtmSelectedMonth, bStopingDay);
            UpdateDateTextBox();
            MessageDialog.ShowInformation(this, "Information", new EVOFramework.Message(Messages.eInformation.INF9003.ToString()).MessageDescription);
            GenerateCalendar();
        }
Beispiel #2
0
        /// <summary>
        /// สร้างปฏิทินของเดือนที่ปรากฏจาก EVODateTimeWithCalendar
        /// </summary>
        private void GenerateCalendar()
        {
            try
            {
                DateTime dateTime;
                if (evoDateTextBoxWithCalendar.Value == null)
                {
                    evoDateTextBoxWithCalendar.Value = Convert.ToDateTime(evoDateTextBoxLastGen.DateValue);
                }

                // เปรียบเทียบว่า DateTime ปัจจุบันมีอยู่ใน database หรือไม่ ถ้าไม่มีจะหา DateTime ที่ใกล้ที่สุด
                dateTime = Convert.ToDateTime(evoDateTextBoxWithCalendar.Value);
                DateTime dtmGenFirst = (m_BIZWorkingCalendar.GetFirstGeneratedCalendar()).PERIOD.StrongValue;;
                DateTime dtmGenLast  = Convert.ToDateTime(evoDateTextBoxLastGen.DateValue);

                ErrorItem errItem = WorkingCalendarValidation.CheckDateTimeIsGen((NZDateTime)dateTime, dtmGenFirst, dtmGenLast);
                if (errItem != null)
                {
                    if (dateTime < dtmGenFirst)
                    {
                        dateTime = dtmGenFirst;
                    }
                    else if (dateTime > dtmGenLast)
                    {
                        dateTime = dtmGenLast;
                    }
                    evoDateTextBoxWithCalendar.Value = dateTime;
                }

                dateTime = dateTime.AddDays(0 - dateTime.Day);
                dateTime = dateTime.AddDays(1);
                // นำ DateTime ที่ได้ไปสร้าง dto
                WorkingCalendarDTO wkDTO = GetDTOfromCurrentCalendar();

                // เตรียม TextBox ไว้สร้างปฏิทิน
                for (int j = 0; j < 7; j++)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        m_BtnDayInCalendarList[i, j].BackColor = Color.White;
                        m_BtnDayInCalendarList[i, j].Text      = string.Empty;
                        m_BtnDayInCalendarList[i, j].Enabled   = false;
                    }
                }

                // หาว่าวันแรกของเดือนเป็นวันอะไร?
                DayOfWeek dayOfWeekEnum = dateTime.DayOfWeek;

                // ทำการใส่ค่าวันลงไปใน textbox + กำหนดสี
                int    week           = 0;
                string calendarString = wkDTO.CALENDAR_STRING.ToString();
                for (int i = 0; i < calendarString.Length; i++, dayOfWeekEnum++)
                {
                    // กำหนดค่าวันที่
                    m_BtnDayInCalendarList[week, (int)dayOfWeekEnum].Text    = (i + 1).ToString();
                    m_BtnDayInCalendarList[week, (int)dayOfWeekEnum].Enabled = true;
                    // กำหนดสี
                    if (calendarString[i] == '0')
                    {
                        m_BtnDayInCalendarList[week, (int)dayOfWeekEnum].BackColor = Color.Red;
                    }
                    else
                    {
                        m_BtnDayInCalendarList[week, (int)dayOfWeekEnum].BackColor = Color.White;
                    }

                    // เลื่อนไปวันต่อไป
                    if ((int)dayOfWeekEnum + 1 >= 7)
                    {
                        dayOfWeekEnum -= 7;
                        week++;
                    }
                }
                ValidateException.ThrowErrorItem(errItem);
            }
            catch (BusinessException err)
            {
                MessageDialog.ShowBusiness(this, err.Error.Message);
                err.Error.FocusOnControl();
            }
            catch (ValidateException err)
            {
                MessageDialog.ShowBusiness(this, err.ErrorResults[0].Message);
                err.ErrorResults[0].FocusOnControl();
            }
        }