private void UpdateDatabase()
        {
            DB.Open();
            DB.BeginTransaction();
            try
            {
                double newTakenDays = double.Parse(tbxMax.Text) - double.Parse(tbxRemaining.Text);
                VacationsInformationRequestsInformation vacationsInformationRequestsInformation = new VacationsInformationRequestsInformation(vacationsInformationTDS);
                vacationsInformationRequestsInformation.SaveForEdit(newTakenDays);

                VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation(vacationsInformationTDS);
                vacationsInformationDaysInformation.Save();

                vacationsInformationTDS.AcceptChanges();

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

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        protected void tkrsVacations_AppointmentUpdate(object sender, AppointmentUpdateEventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Validate if the user can delete older vacations
                if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_FULL_EDITING"])) && (e.Appointment.Start < DateTime.Now))
                {
                    e.Appointment.AllowEdit = false;
                    ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You can not edit older vacations. Please contact your system adminitrator.');", true);
                    e.Cancel = true;
                }
                else
                {
                    Page.Validate();
                    if (Page.IsValid)
                    {
                        if (e.Cancel == false)
                        {
                            // Edit information
                            int vacationId = Convert.ToInt32(e.ModifiedAppointment.ID);

                            double takenDay = 0;

                            VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(vacationsInformationTDS);
                            string oldPaymentType = vacationsInformationDaysInformationGateway.GetPaymentType(vacationId);

                            switch (e.ModifiedAppointment.Subject)
                            {
                                case "Half Vacation Day":
                                    if (oldPaymentType == "Full Vacation Day")
                                    {
                                        takenDay = -0.5;
                                    }
                                    else
                                    {
                                        if (oldPaymentType == "Unpaid Leave Full Day")
                                        {
                                            takenDay = 0.5;
                                        }
                                        else
                                        {
                                            if (oldPaymentType == "Unpaid Leave Half Day")
                                            {
                                                takenDay = 0.0;
                                            }
                                        }
                                    }
                                    break;

                                case "Full Vacation Day":
                                    if (oldPaymentType == "Half Vacation Day")
                                    {
                                        takenDay = 0.5;
                                    }
                                    else
                                    {
                                        if (oldPaymentType == "Unpaid Leave Full Day")
                                        {
                                            takenDay = 1;
                                        }
                                        else
                                        {
                                            if (oldPaymentType == "Unpaid Leave Half Day")
                                            {
                                                takenDay = 1;
                                            }
                                        }
                                    }
                                    break;

                                case "Unpaid Leave Full Day":
                                    if (oldPaymentType == "Full Vacation Day")
                                    {
                                        takenDay = -1;
                                    }
                                    else
                                    {
                                        if (oldPaymentType == "Half Vacation Day")
                                        {
                                            takenDay = -0.5;
                                        }
                                        else
                                        {
                                            if (oldPaymentType == "Unpaid Leave Half Day")
                                            {
                                                takenDay = 0.0;
                                            }
                                        }
                                    }
                                    break;

                                case "Unpaid Leave Half Day":
                                    if (oldPaymentType == "Full Vacation Day")
                                    {
                                        takenDay = -1;
                                    }
                                    else
                                    {
                                        if (oldPaymentType == "Half Vacation Day")
                                        {
                                            takenDay = -0.5;
                                        }
                                        else
                                        {
                                            if (oldPaymentType == "Unpaid Leave Full Day")
                                            {
                                                takenDay = 0.0;
                                            }
                                        }
                                    }
                                    break;
                            }

                            VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation(vacationsInformationTDS);
                            vacationsInformationDaysInformation.Update(vacationId, e.ModifiedAppointment.Subject);

                            // 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 assigned. If you continue this will be discounted the next year. Please review your information.');", true);
                            }
                        }
                    }
                    else
                    {
                        e.Cancel = true;
                    }
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
        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;
            }
        }
        protected void tkrsVacations_AppointmentDelete(object sender, SchedulerCancelEventArgs e)
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Validate if the user can delete older vacations
                if ((!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_FULL_EDITING"]))) && (e.Appointment.Start < DateTime.Now))
                {
                    e.Appointment.AllowDelete = false;
                    ScriptManager.RegisterStartupScript(Page, GetType(), "alert", "alert('You can not delete older vacations. Please contact your system adminitrator.');", true);
                    e.Cancel = true;

                }
                else
                {
                    int vacationId = Convert.ToInt32(e.Appointment.ID);
                    double takenDay = 0;

                    VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(vacationsInformationTDS);
                    string oldPaymentType = vacationsInformationDaysInformationGateway.GetPaymentType(vacationId);

                    switch (oldPaymentType)
                    {
                        case "Half Vacation Day":
                            takenDay = 0.5;
                            break;

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

                    VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation(vacationsInformationTDS);
                    vacationsInformationDaysInformation.Delete(vacationId);

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

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

                    tkrsVacations.DataBind();
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PRIVATE METHODS
        //
        /// <summary>
        /// UpdateForReport
        /// </summary>
        /// <param name="companyId"></param>
        private void UpdateForReport(int companyId)
        {
            VacationsSummaryReportVacationDetailsGateway vacationsSummaryReportVacationDetailsGateway = new VacationsSummaryReportVacationDetailsGateway(Data);
            vacationsSummaryReportVacationDetailsGateway.ClearBeforeFill = false;

            VacationsSummaryReportVacationDetails vacationsSummaryReportVacationDetails = new VacationsSummaryReportVacationDetails(Data);

            foreach (VacationsSummaryReportTDS.EmployeeDetailsRow row in (VacationsSummaryReportTDS.EmployeeDetailsDataTable)Table)
            {
                DateTime startDate = new DateTime(row.Year, 1, 1);
                DateTime endDate = new DateTime(row.Year, 12, 31);

                // Load vacation details
                vacationsSummaryReportVacationDetailsGateway.LoadByEmployeeIdStartDateEndDate(row.EmployeeID, startDate, endDate, companyId);

                foreach (VacationsSummaryReportTDS.VacationDetailsRow row2 in (VacationsSummaryReportTDS.VacationDetailsDataTable)vacationsSummaryReportVacationDetailsGateway.Table)
                {
                    int requestId = row2.RequestID;
                    string vacationDetail = "";

                    VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation();
                    vacationsInformationDaysInformation.LoadByRequestId(requestId, companyId);

                    foreach (VacationsInformationTDS.DaysInformationRow row3 in (VacationsInformationTDS.DaysInformationDataTable)vacationsInformationDaysInformation.Table)
                    {
                        if (row3.StartDate.Year == row.Year)
                        {
                            switch (row3.PaymentType)
                            {
                                case "Full Vacation Day":
                                    vacationDetail += row3.StartDate.ToString("MMM/dd") + " Full Vacation Day, ";
                                    break;

                                case "Half Vacation Day":
                                    vacationDetail += row3.StartDate.ToString("MMM/dd") + " Half Vacation Day, ";
                                    break;

                                case "Unpaid Leave Full Day":
                                    vacationDetail += row3.StartDate.ToString("MMM/dd") + " Unpaid Leave Full Day, ";
                                    break;

                                case "Unpaid Leave Half Day":
                                    vacationDetail += row3.StartDate.ToString("MMM/dd") + " Unpaid Leave Half Day, ";
                                    break;
                            }
                        }
                    }

                    vacationDetail = vacationDetail.Remove(vacationDetail.Length - 2, 2);

                    row2.Details = vacationDetail;
                }

                // Update for location
                if (row.EmployeeType.Contains("CA"))
                {
                    row.EmployeeType = "Canada";
                }
                else
                {
                    row.EmployeeType = "USA";
                }
            }
        }
        protected void tkrsVacations_AppointmentDataBound(object sender, SchedulerEventArgs e)
        {
            int vacationId = Int32.Parse(e.Appointment.ID.ToString());
            int companyId = Int32.Parse(hdfCompanyId.Value);

            VacationsInformationDaysInformation vacationsInformationDaysInformation = new VacationsInformationDaysInformation();
            vacationsInformationDaysInformation.LoadByVacationId(vacationId, companyId);
            VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(vacationsInformationDaysInformation.Data);

            int requestId = vacationsInformationDaysInformationGateway.GetRequestID(vacationId);
            string paymentType = vacationsInformationDaysInformationGateway.GetPaymentType(vacationId);

            e.Appointment.ToolTip = paymentType;

            switch (paymentType)
            {
                case "Unpaid Leave Full Day":
                    e.Appointment.CssClass = "rsCategoryRed2";
                    break;

                case "Unpaid Leave Half Day":
                    e.Appointment.CssClass = "rsCategoryRed2";
                    break;

                case "Full Vacation Day":
                    e.Appointment.CssClass = "rsCategoryGreen2";
                    break;

                case "Half Vacation Day":
                    e.Appointment.CssClass = "rsCategoryGreen2";
                    break;
            }
        }