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 = vacationsAddTDS.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; } VacationsAddDaysInformation vacationsAddDaysInformation = new VacationsAddDaysInformation(vacationsAddTDS); vacationsAddDaysInformation.Insert(1, e.Appointment.Start, e.Appointment.Start, e.Appointment.Subject, e.Appointment.Subject, false, Int32.Parse(hdfCompanyId.Value)); // Store dataset Session["vacationsAddTDS"] = vacationsAddTDS; Session["vacationDaysInformation"] = vacationsAddTDS.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 these days will be discounted from next years total.');", true); } } } else { e.Cancel = true; } }