protected void tkrsVacations_AppointmentInsert(object sender, SchedulerCancelEventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                string filterExpression = string.Format("Deleted = 0 AND StartDate = '{0}'", e.Appointment.Start);
                 DataRow[] drarray = vacationsInformationTDS.DaysInformation.Select(filterExpression, "StartDate ASC", DataViewRowState.CurrentRows);
                 bool isValidVacation = true;

                 switch (e.Appointment.Subject)
                 {
                     case "Half Vacation Day":
                         if (drarray.Length > 0)
                         {
                             if ((drarray[0]["PaymentType"].ToString() != "Half Vacation Day") && (drarray[0]["PaymentType"].ToString() != "Unpaid Leave Half Day"))
                             {
                                 isValidVacation = false;
                             }
                             else
                             {
                                 if (drarray.Length > 1)
                                 {
                                     isValidVacation = false;
                                 }
                             }
                         }
                         break;

                     case "Full Vacation Day":
                         if (drarray.Length > 0)
                         {
                             isValidVacation = false;
                         }
                         break;

                     case "Unpaid Leave Full Day":
                         if (drarray.Length > 0)
                         {
                             isValidVacation = false;
                         }
                         break;

                     case "Unpaid Leave Half Day":
                         if (drarray.Length > 0)
                         {
                             if ((drarray[0]["PaymentType"].ToString() != "Unpaid Leave Half Day") && (drarray[0]["PaymentType"].ToString() != "Half Vacation Day"))
                             {
                                 isValidVacation = false;
                             }
                             else
                             {
                                 if (drarray.Length > 1)
                                 {
                                     isValidVacation = false;
                                 }
                             }
                         }
                         break;
                 }

                 // Verify non working days
                 if (isValidVacation)
                 {
                     isValidVacation = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateIfNonWorkingDay(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                     if (!isValidVacation)
                     {
                         e.Cancel = true;
                         ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You can not take vacations on this day, this is a non working day. Please verify your data.');", true);
                     }
                     else
                     {
                         // Verify existent vacations
                         isValidVacation = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateIfExistsAVacation(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                         if (!isValidVacation)
                         {
                             e.Cancel = true;
                             ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You have a vacation planned for this day. Please verify your data.');", true);
                         }
                         else
                         {
                             VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway();
                             int amountHalfDays = vacationsInformationGateway.IsHalfVacationDay(e.Appointment.Start, Int32.Parse(hdfEmployeeId.Value), Int32.Parse(hdfCompanyId.Value));

                             if (amountHalfDays > 0)
                             {
                                 if ((e.Appointment.Subject == "Unpaid Leave Full Day") || (e.Appointment.Subject == "Full Vacation Day"))
                                 {
                                     isValidVacation = false;
                                     e.Cancel = true;
                                     ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You have a half vacation day planned for this day. Please verify your data.');", true);
                                 }
                             }
                         }
                     }
                 }
                 else
                 {
                     e.Cancel = true;
                     ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You already have a vacation request for this day please verify your data.');", true);
                 }

                 if (isValidVacation)
                 {
                     double takenDay = 0;
                     switch (e.Appointment.Subject)
                     {
                         case "Half Vacation Day":
                             takenDay = 0.5;
                             break;

                         case "Full Vacation Day":
                             takenDay = 1;
                             break;
                     }

                     VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation(vacationsInformationTDS);
                     vacationsInformationDaysInformation.Insert(Int32.Parse(hdfRequestId.Value), e.Appointment.Start, e.Appointment.Start, e.Appointment.Subject, e.Appointment.Subject, false, Int32.Parse(hdfCompanyId.Value));

                     // Store dataset
                     Session["vacationsInformationTDS"] = vacationsInformationTDS;
                     Session["vacationDaysInformation"] = vacationsInformationTDS.DaysInformation;

                     tkrsVacations.DataBind();

                     double newRemainingVacationDays = double.Parse(tbxRemaining.Text) - takenDay;
                     tbxRemaining.Text = newRemainingVacationDays.ToString();

                     if (double.Parse(tbxRemaining.Text) < 0)
                     {
                         ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You are requesting more vacation than the entitlement. If you continue this days will be discounted from next years total.');", true);
                     }
                 }
            }
            else
            {
                e.Cancel = true;
            }
        }
Example #2
0
        /// <summary>
        /// ValidateIfExistsAVacation
        /// </summary>
        /// <param name="date">date</param>
        /// <param name="employeeId">employeeId</param>
        /// <param name="companyId">companyId</param>
        public static bool ValidateIfExistsAVacation(DateTime date, int employeeId, int companyId)
        {
            bool valid = true;

            VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway();
            if (vacationsInformationGateway.IsFullVacationDay(date, employeeId, companyId))
            {
                valid = false;
            }
            else
            {
                int amountHalfDays = vacationsInformationGateway.IsHalfVacationDay(date, employeeId, companyId);
                if (amountHalfDays == 2)
                {
                    valid = false;
                }
                else
                {
                    if ((amountHalfDays == 0) || (amountHalfDays == 1))
                    {
                        valid = true;
                    }
                }
            }

            return valid;
        }