// ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Tag page
                // ... for non vacation managers
                EmployeeGateway employeeGatewayManager = new EmployeeGateway();
                int employeeIdNow = employeeGatewayManager.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                employeeGatewayManager.LoadByEmployeeId(employeeIdNow);

                if (employeeGatewayManager.GetIsVacationsManager(employeeIdNow))
                {
                    hdfIsVacationManager.Value = "True";
                }
                else
                {
                    hdfIsVacationManager.Value = "False";
                }

                // Security check
                if (hdfIsVacationManager.Value == "False")
                {
                    //if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_EDIT"])))
                    //{
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    //}
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null) && ((string)Request.QueryString["vacation_id"] == null) && ((string)Request.QueryString["request_id"] == null) && ((string)Request.QueryString["date_to_show"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in vacations_edit.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfVacationId.Value = (string)Request.QueryString["vacation_id"];
                hdfRequestId.Value = (string)Request.QueryString["request_id"];

                int requestId = Int32.Parse(hdfRequestId.Value);
                int companyId = Int32.Parse(hdfCompanyId.Value);

                ViewState["date_to_show"] = (string)Request.QueryString["date_to_show"];
                DateTime dateToShow = DateTime.Parse((string)Request.QueryString["date_to_show"]);

                // Initialize values
                DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                EmployeeList employeeList = new EmployeeList();
                string employeeTypeNow = employeeGatewayManager.GetType(employeeIdNow);
                if (employeeTypeNow.Contains("CA"))
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "CA", -1, "(All)");
                }
                else
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "US", -1, "(All)");
                }
                ddlVacationsFor.DataSource = employeeList.Table;
                ddlVacationsFor.DataValueField = "EmployeeID";
                ddlVacationsFor.DataTextField = "FullName";
                ddlVacationsFor.DataBind();
                ddlVacationsFor.SelectedValue = Session["ddlVacationsForSelectedValue"].ToString();

                // Load Data
                vacationsInformationTDS = new VacationsInformationTDS();
                vacationDaysInformation = new VacationsInformationTDS.DaysInformationDataTable();

                VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(vacationsInformationTDS);
                vacationsInformationDaysInformationGateway.LoadByRequestId(requestId, companyId);

                VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationTDS);
                vacationsInformationRequestsInformationGateway.LoadByRequestId(requestId, companyId);

                hdfEmployeeId.Value = vacationsInformationRequestsInformationGateway.GetEmployeeID(requestId).ToString();
                int employeeId = Int32.Parse(hdfEmployeeId.Value);

                VacationsInformationBasicInformationGateway vacationsInformationBasicInformationGateway = new VacationsInformationBasicInformationGateway(vacationsInformationTDS);
                vacationsInformationBasicInformationGateway.LoadByEmployeeIdYear(employeeId, dateToShow.Year, companyId);

                Session["vacationsInformationTDS"] = vacationsInformationTDS;
                Session["vacationDaysInformation"] = vacationsInformationTDS.DaysInformation;

                LoadData(employeeId, dateToShow.Year, requestId);

                Page.DataBind();
            }
            else
            {
                vacationsInformationTDS = (VacationsInformationTDS)Session["vacationsInformationTDS"];
                vacationDaysInformation = (VacationsInformationTDS.DaysInformationDataTable)Session["vacationDaysInformation"];
            }
        }
        protected void tkrsVacations_FormCreated(object sender, SchedulerFormCreatedEventArgs e)
        {
            if (e.Container.Mode == SchedulerFormMode.Edit)
            {
                int vacationId = Convert.ToInt32(e.Appointment.ID);

                vacationsInformationTDS = (VacationsInformationTDS)Session["vacationsInformationTDS"];
                vacationDaysInformation = (VacationsInformationTDS.DaysInformationDataTable)Session["vacationDaysInformation"];

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

                RadioButtonList rbtnPaymentType = (RadioButtonList)e.Container.FindControl("rbtnPaymentType");
                rbtnPaymentType.SelectedValue = paymentType;
            }
        }
        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;
            }
        }
        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;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_VIEW"])))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (((string)Request.QueryString["source_page"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in vacations_all.aspx");
                }

                // Tag page
                int companyId = Int32.Parse(Session["companyID"].ToString());
                hdfCompanyId.Value = companyId.ToString();

                // ... For non vacation managers
                EmployeeGateway employeeGatewayManager = new EmployeeGateway();

                int employeeIdNow = employeeGatewayManager.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                employeeGatewayManager.LoadByEmployeeId(employeeIdNow);

                if (employeeGatewayManager.GetIsVacationsManager(employeeIdNow))
                {
                    hdfIsVacationManager.Value = "True";
                }
                else
                {
                    hdfIsVacationManager.Value = "False";
                }

                // Initialize values
                DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                EmployeeList employeeList = new EmployeeList();

                string employeeTypeNow = employeeGatewayManager.GetType(employeeIdNow);

                if (employeeTypeNow.Contains("CA"))
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "CA", -1, "(All)");
                }
                else
                {
                    employeeList.LoadBySalariedEmployeeTypeAndAddItem(1, "US", -1, "(All)");
                }
                ddlVacationsFor.DataSource = employeeList.Table;
                ddlVacationsFor.DataValueField = "EmployeeID";
                ddlVacationsFor.DataTextField = "FullName";
                ddlVacationsFor.DataBind();

                //... date_to_show
                if ((string)Request.QueryString["date_to_show"] == null)
                {
                    ViewState["date_to_show"] = DateTime.Now.ToString();
                }
                else
                {
                    ViewState["date_to_show"] = (string)Request.QueryString["date_to_show"];
                }

                // Load vacations
                vacationsInformationTDS = new VacationsInformationTDS();
                vacationsInformation = new VacationsInformationTDS.VacationsInformationDataTable();

                VacationsInformationGateway vacationsInformationGateway = new VacationsInformationGateway(vacationsInformationTDS);

                if (hdfIsVacationManager.Value == "False")
                {
                    EmployeeGateway employeeGateway1 = new EmployeeGateway();
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                    EmployeeInformationBasicInformationGateway employeeInformationBasicInformationGateway = new EmployeeInformationBasicInformationGateway();
                    employeeInformationBasicInformationGateway.LoadByEmployeeId(Int32.Parse(ViewState["employee_id"].ToString()));

                    string employeeType = employeeInformationBasicInformationGateway.GetType(Int32.Parse(ViewState["employee_id"].ToString()));

                    if (employeeType.Contains("CA"))
                    {
                        ddlWorkingLocation.SelectedValue = "CA";

                    }
                    else
                    {
                        ddlWorkingLocation.SelectedValue = "US";
                    }

                    vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ViewState["employee_id"].ToString()), employeeType, companyId);
                }
                else
                {
                    if ((string)Request.QueryString["employee_id"] == null)
                    {
                        ViewState["employee_id"] = "-1";

                        if (employeeTypeNow.Contains("CA"))
                        {
                            ddlWorkingLocation.SelectedValue = "CA";
                        }
                        else
                        {
                            ddlWorkingLocation.SelectedValue = "US";
                        }

                        vacationsInformationGateway.LoadByEmployeeType(employeeTypeNow, companyId);
                    }
                    else
                    {
                        ViewState["employee_id"] = (string)Request.QueryString["employee_id"];

                        EmployeeInformationBasicInformationGateway employeeInformationBasicInformationGateway = new EmployeeInformationBasicInformationGateway();
                        employeeInformationBasicInformationGateway.LoadByEmployeeId(Int32.Parse(ViewState["employee_id"].ToString()));

                        string employeeType = employeeInformationBasicInformationGateway.GetType(Int32.Parse(ViewState["employee_id"].ToString()));

                        if (employeeTypeNow.Contains("CA"))
                        {
                            ddlWorkingLocation.SelectedValue = "CA";
                        }
                        else
                        {
                            ddlWorkingLocation.SelectedValue = "US";
                        }

                        vacationsInformationGateway.LoadByEmployeeIdEmployeeType(Int32.Parse(ViewState["employee_id"].ToString()), employeeType, companyId);

                        ddlVacationsFor.SelectedValue = ViewState["employee_id"].ToString();
                    }
                }

                Session["vacationsInformationTDS"] = vacationsInformationTDS;
                Session["vacationsInformation"] = vacationsInformationTDS.VacationsInformation;

                tkrsVacations.SelectedDate = DateTime.Parse(ViewState["date_to_show"].ToString());
                lblTitle.Text = "Vacations Calendar for " + tkrsVacations.SelectedDate.ToString("MMMM") + " " + tkrsVacations.SelectedDate.Year.ToString();

                // Databind
                Page.DataBind();

                // For Open Vacation event
                if ((Request.Params["__EVENTTARGET"]) == "openVacation")
                {
                    int vacationId = Int32.Parse(Request.Params.Get("__EVENTARGUMENT").ToString()) ;
                    VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway();
                    vacationsInformationDaysInformationGateway.LoadByVacationId(vacationId, companyId);
                    int requestId = vacationsInformationDaysInformationGateway.GetRequestID(vacationId);

                    Session["ddlVacationsForSelectedValue"] = ddlVacationsFor.SelectedValue;

                    Response.Redirect("./vacations_summary.aspx?source_page=vacations_all.aspx&vacation_id=" + vacationId.ToString() + "&request_id=" + requestId.ToString() + "&date_to_show=" + ViewState["date_to_show"]);
                }
            }
            else
            {
                vacationsInformationTDS = (VacationsInformationTDS)Session["vacationsInformationTDS"];
                vacationsInformation = (VacationsInformationTDS.VacationsInformationDataTable)Session["vacationsInformation"];

                // For Open Vacation event
                if ((Request.Params["__EVENTTARGET"]) == "openVacation")
                {
                    int vacationId = Int32.Parse(Request.Params.Get("__EVENTARGUMENT").ToString());
                    VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway();
                    vacationsInformationDaysInformationGateway.LoadByVacationId(vacationId, Int32.Parse(hdfCompanyId.Value));
                    int requestId = vacationsInformationDaysInformationGateway.GetRequestID(vacationId);

                    DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                    Session["ddlVacationsForSelectedValue"] = ddlVacationsFor.SelectedValue;

                    Response.Redirect("./vacations_summary.aspx?source_page=vacations_all.aspx&vacation_id=" + vacationId.ToString() + "&request_id=" + requestId.ToString() + "&date_to_show=" + ViewState["date_to_show"]);
                }
            }
        }
        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;
            }
        }
 /// <summary>
 /// LoadByVacationId
 /// </summary>
 /// <param name="vacationId">vacationId</param>
 /// <param name="companyId">companyId</param>
 public void LoadByVacationId(int vacationId, int companyId)
 {
     VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(Data);
     vacationsInformationDaysInformationGateway.LoadByVacationId(vacationId, companyId);
 }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS - DATASET
 //
 /// <summary>
 /// LoadByRequestId
 /// </summary>
 /// <param name="requestId">requestId</param>
 /// <param name="companyId">companyId</param>
 public void LoadByRequestId(int requestId, int companyId)
 {
     VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(Data);
     vacationsInformationDaysInformationGateway.LoadByRequestId(requestId, companyId);
 }
        /// <summary>
        /// Save
        /// </summary>
        public void Save()
        {
            VacationsInformationTDS vacationsInformationChanges = (VacationsInformationTDS)Data.GetChanges();

            if (vacationsInformationChanges.DaysInformation.Rows.Count > 0)
            {
                VacationsInformationDaysInformationGateway vacationsInformationDaysInformationGateway = new VacationsInformationDaysInformationGateway(vacationsInformationChanges);

                foreach (VacationsInformationTDS.DaysInformationRow row in (VacationsInformationTDS.DaysInformationDataTable)vacationsInformationChanges.DaysInformation)
                {
                    // Insert new vacation day
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        int requestId = row.RequestID;

                        VacationDays vacationDays = new VacationDays(null);
                        vacationDays.InsertDirect(requestId, row.StartDate, row.EndDate, row.Description, row.PaymentType, row.Deleted, row.COMPANY_ID);
                    }

                    // Update vacation day
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int vacationId = row.VacationID;
                        int requestId = row.RequestID;
                        bool deleted = row.Deleted;
                        int companyId = row.COMPANY_ID;

                        // original values
                        DateTime originalStartDate = vacationsInformationDaysInformationGateway.GetStartDateOriginal(vacationId);
                        DateTime originalEndDate = vacationsInformationDaysInformationGateway.GetEndDateOriginal(vacationId);
                        string originalDescription = vacationsInformationDaysInformationGateway.GetDescriptionOriginal(vacationId);
                        string originalPaymentType = vacationsInformationDaysInformationGateway.GetPaymentTypeOriginal(vacationId);

                        // new values
                        DateTime newStartDate = vacationsInformationDaysInformationGateway.GetStartDate(vacationId);
                        DateTime newEndDate = vacationsInformationDaysInformationGateway.GetEndDate(vacationId);
                        string newDescription = vacationsInformationDaysInformationGateway.GetDescription(vacationId);
                        string newPaymentType = vacationsInformationDaysInformationGateway.GetPaymentType(vacationId);

                        VacationDays vacationDays = new VacationDays(null);
                        vacationDays.UpdateDirect(vacationId, requestId, originalStartDate, originalEndDate, originalDescription, originalPaymentType, deleted, companyId, vacationId, requestId, newStartDate, newEndDate, newDescription, newPaymentType, deleted, companyId);
                    }

                    // Delete vacation day
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        VacationDays vacationDays = new VacationDays(null);
                        vacationDays.DeleteDirect(row.VacationID);
                    }
                }
            }
        }