Ejemplo n.º 1
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            #region adding validation
            if (numericNoOfDays.Value < 1 ^ numericNoOfDays.Value >= 7)
            {
                numericNoOfDays.Focus();
                errorAddWorkingDays.SetError(numericNoOfDays, "Please Enter Valid No Of Working Days");
            }
            else if (checkBoxMonday.Checked == false & checkBoxTuesday.Checked == false & checkBoxWednesday.Checked == false & checkBoxThursday.Checked == false & checkBoxFriday.Checked == false & checkBoxSaturday.Checked == false & checkBoxSunday.Checked == false)
            {
                ErrorMessage em = new ErrorMessage("Please Select One More Working Days");
                em.Show();
            }
            else if (numericTPerDayHours.Value < 0 ^ numericTPerDayHours.Value > 24)
            {
                numericTPerDayHours.Focus();
                errorAddWorkingDays.SetError(numericTPerDayHours, "Please Enter Valid No Of Working Hours");
            }
            else if (numericTPerDayMinutes.Value < 0 ^ numericTPerDayMinutes.Value >= 60)
            {
                numericTPerDayMinutes.Focus();
                errorAddWorkingDays.SetError(numericTPerDayMinutes, "Please Enter Valid No Of Working Minutes");
            }
            #endregion
            else
            {
                workingDaysHoursService = new WorkingDaysHoursService();

                #region Set Data to Object
                // Set Data to model
                workingDaysHours.NoOfWorkingDays = int.Parse(numericNoOfDays.Value.ToString());
                workingDaysHours.NoOfHours       = int.Parse(numericTPerDayHours.Value.ToString());
                workingDaysHours.NoOfMinutes     = int.Parse(numericTPerDayMinutes.Value.ToString());

                // Check Days Monday
                if (checkBoxMonday.Checked == true)
                {
                    workingDaysHours.Monday = 1;
                }
                else
                {
                    workingDaysHours.Monday = 0;
                }

                // Check Days Tuesday
                if (checkBoxTuesday.Checked == true)
                {
                    workingDaysHours.Tuesday = 1;
                }
                else
                {
                    workingDaysHours.Tuesday = 0;
                }

                // Check Days Wednesday
                if (checkBoxWednesday.Checked == true)
                {
                    workingDaysHours.Wednesday = 1;
                }
                else
                {
                    workingDaysHours.Wednesday = 0;
                }

                // Check Days Thursday
                if (checkBoxThursday.Checked == true)
                {
                    workingDaysHours.Thursday = 1;
                }
                else
                {
                    workingDaysHours.Thursday = 0;
                }

                // Check Days Friday
                if (checkBoxFriday.Checked == true)
                {
                    workingDaysHours.Friday = 1;
                }
                else
                {
                    workingDaysHours.Friday = 0;
                }

                // Check Days Saturday
                if (checkBoxSaturday.Checked == true)
                {
                    workingDaysHours.Saturday = 1;
                }
                else
                {
                    workingDaysHours.Saturday = 0;
                }

                // Check Days Sunday
                if (checkBoxSunday.Checked == true)
                {
                    workingDaysHours.Sunday = 1;
                }
                else
                {
                    workingDaysHours.Sunday = 0;
                }
                #endregion

                //Insert Data
                if (workingDaysHoursService.addWorkingDaysHours(workingDaysHours))
                {
                    SuccessMessage sc = new SuccessMessage("Working Days And Hours Added Successfully !");
                    sc.Show();
                    getData();
                    btnUpdate.Visible = true;
                    btnDelete.Visible = true;
                    btnSave.Visible   = false;
                    btnClear.Visible  = false;
                }
                else
                {
                    ErrorMessage ec = new ErrorMessage("Oops, Somthing went wrong!");
                    ec.Show();
                }
            }
        }
Ejemplo n.º 2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            #region adding validation
            if (numericNoOfDays.Value < 1 ^ numericNoOfDays.Value >= 7)
            {
                numericNoOfDays.Focus();
                errorAddWorkingDays.SetError(numericNoOfDays, "Please Enter Valid No Of Working Days");
            }
            else if (checkBoxMonday.Checked == false & checkBoxTuesday.Checked == false & checkBoxWednesday.Checked == false & checkBoxThursday.Checked == false & checkBoxFriday.Checked == false & checkBoxSaturday.Checked == false & checkBoxSunday.Checked == false)
            {
                ErrorMessage em = new ErrorMessage("Please Select One or More Working Days");
                em.Show();
            }
            else if (numericTPerDayHours.Value < 0 ^ numericTPerDayHours.Value > 24)
            {
                numericTPerDayHours.Focus();
                errorAddWorkingDays.SetError(numericTPerDayHours, "Please Enter Valid No Of Working Hours");
            }
            else if (numericTPerDayMinutes.Value < 0 ^ numericTPerDayMinutes.Value >= 60)
            {
                numericTPerDayMinutes.Focus();
                errorAddWorkingDays.SetError(numericTPerDayMinutes, "Please Enter Valid No Of Working Minutes");
            }
            #endregion
            else
            {
                workingDaysHoursService = new WorkingDaysHoursService();
                WorkingDaysHours workingDaysHoursUpdate = new WorkingDaysHours();

                #region Set Data to Object
                // Set Data to model
                workingDaysHoursUpdate.NoOfWorkingDays = int.Parse(numericNoOfDays.Value.ToString());
                workingDaysHoursUpdate.NoOfHours       = int.Parse(numericTPerDayHours.Value.ToString());
                workingDaysHoursUpdate.NoOfMinutes     = int.Parse(numericTPerDayMinutes.Value.ToString());

                // Check Days Monday
                if (checkBoxMonday.Checked == true)
                {
                    workingDaysHoursUpdate.Monday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Monday = 0;
                }

                // Check Days Tuesday
                if (checkBoxTuesday.Checked == true)
                {
                    workingDaysHoursUpdate.Tuesday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Tuesday = 0;
                }

                // Check Days Wednesday
                if (checkBoxWednesday.Checked == true)
                {
                    workingDaysHoursUpdate.Wednesday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Wednesday = 0;
                }

                // Check Days Thursday
                if (checkBoxThursday.Checked == true)
                {
                    workingDaysHoursUpdate.Thursday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Thursday = 0;
                }

                // Check Days Friday
                if (checkBoxFriday.Checked == true)
                {
                    workingDaysHoursUpdate.Friday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Friday = 0;
                }

                // Check Days Saturday
                if (checkBoxSaturday.Checked == true)
                {
                    workingDaysHoursUpdate.Saturday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Saturday = 0;
                }

                // Check Days Sunday
                if (checkBoxSunday.Checked == true)
                {
                    workingDaysHoursUpdate.Sunday = 1;
                }
                else
                {
                    workingDaysHoursUpdate.Sunday = 0;
                }
                #endregion

                if (workingDaysHoursService.deleteWorkingDaysHours())
                {
                    if (workingDaysHoursService.addWorkingDaysHours(workingDaysHoursUpdate))
                    {
                        SuccessMessage sm = new SuccessMessage("Working Days / Hours Updated Succesfully!");
                        sm.Show();
                    }
                }
                else
                {
                    ErrorMessage em = new ErrorMessage("Ooops...Something went wrong");
                    em.Show();
                }
            }
        }