// ////////////////////////////////////////////////////////////////////////
        // 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"];
            }
        }
        private void SendMailEmployee(string newState)
        {
            if (newState == "Rejected")
            {
                // Update grid rows
                foreach (GridViewRow row in grdVacations.Rows)
                {
                    int requestId = Int32.Parse(grdVacations.DataKeys[row.RowIndex].Values["RequestID"].ToString());
                    if (((CheckBox)row.FindControl("cbxSelected")).Checked)
                    {
                        string rejectReason = ((TextBox)row.FindControl("tbxRejectReason")).Text;

                        // Get mail information
                        string mailTo = "";
                        string nameTo = "";
                        string body = "";
                        string subject = "";

                        VacationsInformationRequestsInformationGateway vacationsInformationRequestsInformationGateway = new VacationsInformationRequestsInformationGateway(vacationsInformationTDS);

                        int employeeId = vacationsInformationRequestsInformationGateway.GetEmployeeID(requestId);
                        int rejectedById = (int)ViewState["rejected_by_id"];

                        EmployeeGateway employeesGateway = new EmployeeGateway();
                        employeesGateway.LoadByEmployeeId(employeeId);

                        if (employeesGateway.Table.Rows.Count > 0)
                        {
                            // Assigned TeamMember
                            mailTo = employeesGateway.GetEMail(employeeId);
                            nameTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
                        }

                        subject = "Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString();

                        // Mails body
                        body = body + "\nHi " + nameTo + ",\n\nThe following vacation request has been rejected: \n\n";
                        body = body + "\t - Vacation request from " + vacationsInformationRequestsInformationGateway.GetStartDate(requestId).ToShortDateString() + " to " + vacationsInformationRequestsInformationGateway.GetEndDate(requestId).ToShortDateString() + "\n";
                        body = body + "\t - Detail: " + vacationsInformationRequestsInformationGateway.GetDetails(requestId) + "\n";
                        body = body + "\t - Comment: " + rejectReason;

                        EmployeeGateway employeeRejected = new EmployeeGateway();
                        employeeRejected.LoadByEmployeeId(rejectedById);

                        if (employeeRejected.Table.Rows.Count > 0)
                        {
                            body = body + "\n" + "\t - Rejected by: " + employeeRejected.GetFirstName(rejectedById) + " " + employeeRejected.GetLastName(rejectedById);
                        }

                        //Send Mail
                        SendMail(mailTo, subject, body);
                    }
                }
            }
        }