private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            int companyId = Int32.Parse(hdfCompanyId.Value);
            string period = ddlPeriod.SelectedItem.Value;

            int loginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

            LiquiForce.LFSLive.BL.FleetManagement.Services.ServicesSRAboutToExpireReport servicesSRAboutToExpireReport = new LiquiForce.LFSLive.BL.FleetManagement.Services.ServicesSRAboutToExpireReport();

            if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
            {
                servicesSRAboutToExpireReport.LoadItemsAboutToExpire(period, companyId);
            }
            else
            {
                servicesSRAboutToExpireReport.LoadItemsAboutToExpireByAssignTeamMemberID(period, employeeId, companyId);
            }

            // ... set properties to master page
            master.Data = servicesSRAboutToExpireReport.Data;
            master.Table = servicesSRAboutToExpireReport.TableName;

            // Get report
            if (servicesSRAboutToExpireReport.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new ServicesSRAboutToExpireReport();

                    // Report format
                    master.Report.PrintOptions.PaperOrientation = PaperOrientation.Landscape;
                    master.Report.PrintOptions.PaperSize = PaperSize.PaperLegal;
                }
                else
                {
                    master.Report = new ServicesSRAboutToExpireReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());

                    master.SetParameter("Period", period.ToString());
                }
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int loginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

            LiquiForce.LFSLive.BL.FleetManagement.Services.ServicesSRExpiredReport servicesSRExpiredReport = new LiquiForce.LFSLive.BL.FleetManagement.Services.ServicesSRExpiredReport();

            if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
            {
                servicesSRExpiredReport.LoadExpiredItems(companyId);
            }
            else
            {
                servicesSRExpiredReport.LoadExpiredItemsByAssignTeamMemberID(employeeId, companyId);
            }

            // ... set properties to master page
            master.Data = servicesSRExpiredReport.Data;
            master.Table = servicesSRExpiredReport.TableName;

            // Get report
            if (servicesSRExpiredReport.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new ServicesSRExpiredReport();
                }
                else
                {
                    master.Report = new ServicesSRExpiredReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                EmployeeGateway employeeGatewayManager = new EmployeeGateway();
                int employeeIdNow = employeeGatewayManager.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                employeeGatewayManager.LoadByEmployeeId(employeeIdNow);

                if (!employeeGatewayManager.GetIsVacationsManager(employeeIdNow))
                {
                    // Security check
                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_REPORTS"]))
                    {
                        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_summary_report.aspx");
                }

                EmployeeInformationPayVacationDaysInformationList employeeInformationPayVacationDaysInformationList = new EmployeeInformationPayVacationDaysInformationList();
                employeeInformationPayVacationDaysInformationList.Load();
                ddlYear.DataSource = employeeInformationPayVacationDaysInformationList.Table;
                ddlYear.DataValueField = "Year";
                ddlYear.DataTextField = "Year";
                ddlYear.DataBind();

                try
                {
                    ddlYear.SelectedValue = DateTime.Now.Year.ToString();
                }
                catch
                {
                }

                // Register delegates
                this.RegisterDelegates();
            }
            else
            {
                // Register delegates
                this.RegisterDelegates();
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int loginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

            LiquiForce.LFSLive.BL.FleetManagement.ToDoList.ToDoListToDoAssignedToMeReport toDoListToDoAssignedToMeReport = new LiquiForce.LFSLive.BL.FleetManagement.ToDoList.ToDoListToDoAssignedToMeReport();

            // could see all to do lists
            toDoListToDoAssignedToMeReport.LoadToDoAssignedToMeByEmployeeId(employeeId, companyId);

            toDoListToDoAssignedToMeReport.Table.AcceptChanges();

            // ... set properties to master page
            master.Data = toDoListToDoAssignedToMeReport.Data;
            master.Table = toDoListToDoAssignedToMeReport.TableName;

            // Get report
            if (toDoListToDoAssignedToMeReport.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new ToDoListToDoAssignedToMeReport();
                }
                else
                {
                    master.Report = new ToDoListToDoAssignedToMeReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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 (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_VACATIONS_ADD"])))
                //{
                if (hdfIsVacationManager.Value == "False")
                {
                    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["employee_id"] == null) && ((string)Request.QueryString["date_to_show"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in vacations_add.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfEmployeeId.Value = (string)Request.QueryString["employee_id"];

                Session.Remove("vacationsAddTDS");

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

                // Prepare initial data
                // ... For employee list

                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)");
                }

                DropDownList ddlVacationsFor = (DropDownList)tkrpbLeftMenuAllVacations.FindItemByValue("nbVacationsForDDL").FindControl("ddlVacationsFor");
                ddlVacationsFor.DataSource = employeeList.Table;
                ddlVacationsFor.DataValueField = "EmployeeID";
                ddlVacationsFor.DataTextField = "FullName";
                ddlVacationsFor.DataBind();
                ddlVacationsFor.SelectedValue = Session["ddlVacationsForSelectedValue"].ToString();

                // ... For employee ddl
                ddlEmployee.DataSource = employeeList.Table;
                ddlEmployee.DataValueField = "EmployeeID";
                ddlEmployee.DataTextField = "FullName";
                ddlEmployee.DataBind();

                vacationsAddTDS = new VacationsAddTDS();
                vacationDaysInformation = new VacationsAddTDS.DaysInformationDataTable();

                // If there is a selected employee
                if (hdfEmployeeId.Value != "-1")
                {
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    int employeeId = Int32.Parse(hdfEmployeeId.Value);

                    // ... Verify basic information
                    VacationsAddBasicInformationGateway vacationsAddBasicInformationGateway = new VacationsAddBasicInformationGateway(vacationsAddTDS);
                    vacationsAddBasicInformationGateway.LoadByEmployeeIdYear(employeeId, dateToShow.Year, companyId);

                    if (vacationsAddBasicInformationGateway.Table.Rows.Count == 0)
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "The team member don't have total paid day vacations defined in the system. Contact your system administrator.");
                    }
                    else
                    {
                        LoadData(employeeId, dateToShow.Year);

                        // ... Load non working days
                        EmployeeGateway employeeGateway = new EmployeeGateway();
                        employeeGateway.LoadByEmployeeId(employeeId);

                        string employeeType = employeeGateway.GetType(employeeId);
                        int companyLevelId = 3; //USA

                        if (employeeType.Contains("CA"))
                        {
                            companyLevelId = 2;//Canada
                        }

                        VacationsAddDaysInformation vacationsAddDaysInformation = new VacationsAddDaysInformation(vacationsAddTDS);
                        //vacationsAddDaysInformation.LoadNonWorkingDaysByCompanyLevelId(companyLevelId, companyId);

                        // ... Load previews vacations
                        //vacationsAddDaysInformation.LoadPreviousVacations(employeeId, companyId);
                        vacationsAddDaysInformation.LoadDataForVacationsAdd(companyLevelId, employeeId, companyId);
                    }
                }

                ViewState["employee_id"] = hdfEmployeeId.Value;

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

                Page.DataBind();
            }
            else
            {
                vacationsAddTDS = (VacationsAddTDS)Session["vacationsAddTDS"];
                vacationDaysInformation = (VacationsAddTDS.DaysInformationDataTable)Session["vacationDaysInformation"];

                hdfEmployeeId.Value = ViewState["employee_id"].ToString();
            }
        }
        private bool StepStepsInformationNext()
        {
            bool valid = ValidatePage();

            if (valid)
            {
                // Assigment Information
                if (pnlAssignmentInformation.Visible)
                {
                    hdfDeadlineDate.Value = ""; if (tkrdpDeadlineDate.SelectedDate.HasValue) hdfDeadlineDate.Value = tkrdpDeadlineDate.SelectedDate.Value.ToString();

                    // ... Myself
                    hdfAssignToMyself.Value = rbtnAssignToMyself.Checked.ToString();
                    if (rbtnAssignToMyself.Checked)
                    {
                        int loginId = Convert.ToInt32(Session["loginID"]);
                        EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                        hdfTeamMemberId.Value = employeeGateway.GetEmployeIdByLoginId(loginId).ToString();
                    }

                    // ... Team Member
                    hdfAssignToTeamMember.Value = rbtnAssignToTeamMember.Checked.ToString();
                    if (rbtnAssignToTeamMember.Checked)
                    {
                        hdfTeamMemberId.Value = ""; if (ddlAssignToTeamMember.SelectedValue != "") hdfTeamMemberId.Value = ddlAssignToTeamMember.SelectedValue;
                        hdfTeamMemberFullName.Value = ""; if (ddlAssignToTeamMember.SelectedItem.Text != "") hdfTeamMemberFullName.Value = ddlAssignToTeamMember.SelectedItem.Text;
                        hdfThirdPartyVendor.Value = "";
                    }

                    // ... Third party vendor
                    hdfAssignToThirdPartyVendor.Value = rbtnAssignToThirdPartyVendor.Checked.ToString();
                    if (rbtnAssignToThirdPartyVendor.Checked)
                    {
                        hdfTeamMemberId.Value = "";
                        hdfTeamMemberFullName.Value = "";
                        hdfThirdPartyVendor.Value = ""; if (tbxAssignToThirdPartyVendor.Text != "") hdfThirdPartyVendor.Value = tbxAssignToThirdPartyVendor.Text.Trim();
                    }
                }

                // Accept information
                if (pnlAcceptInformation.Visible)
                {
                    hdfAcceptSR.Value = ckbxAcceptSR.Checked.ToString();
                }

                // Start work information
                if (pnlStartWorkInformation.Visible)
                {
                    hdfStartSR.Value = ckbxStartSR.Checked.ToString();

                    if (ckbxStartSR.Checked)
                    {
                        hdfUnitOutOfServiceDate.Value = ""; if (tkrdpStartWorkUnitOutOfServiceDate.SelectedDate.HasValue) hdfUnitOutOfServiceDate.Value = tkrdpStartWorkUnitOutOfServiceDate.SelectedDate.Value.ToString();
                        hdfUnitOutOfServiceTime.Value = "8:00 AM";
                        hdfStartMileage.Value = tbxStartWorkStartMileage.Text.Trim();
                    }
                }

                // Complete work information
                if (pnlCompleteWorkInformation.Visible)
                {
                    // Costs Gridview, if the gridview is edition mode
                    if (grdCosts.EditIndex >= 0)
                    {
                        grdCosts.UpdateRow(grdCosts.EditIndex, true);
                    }

                    // ... Save cost
                    GrdCostsAdd();

                    // ... Tag values
                    hdfUnitBackInServiceDate.Value = ""; if (tkrdpCompleteWorkUnitBackInServiceDate.SelectedDate.HasValue) hdfUnitBackInServiceDate.Value = tkrdpCompleteWorkUnitBackInServiceDate.SelectedDate.Value.ToString();
                    hdfUnitBackInServiceTime.Value = "8:00 AM";
                    hdfCompleteWorkMileage.Value = tbxCompleteWorkCompleteMileage.Text.Trim();

                    if (hdfAssignToThirdPartyVendor.Value == "")
                    {
                        hdfCompleteWorkDescription.Value = tbxCompleteWorkDataDescription.Text.Trim();
                        hdfCompleteWorkPreventable.Value = ckbxCompleteWorkDataPreventable.Checked.ToString();
                        hdfCompleteWorkLabourHours.Value = tbxCompleteWorkDataLabourHours.Text.Trim();
                        hdfCompleteWorkCosts.Value = tbxTotalCost.Text.Trim();
                        hdfInvoiceNumber.Value = "";
                        hdfInvoiceAmount.Value = "";
                    }
                    else
                    {
                        hdfCompleteWorkDescription.Value = tbxDescriptionTPV.Text.Trim();
                        hdfCompleteWorkPreventable.Value = ckbxPreventableTPV.Checked.ToString();
                        hdfInvoiceNumber.Value = tbxInvoiceNumberTPV.Text.Trim();
                        hdfInvoiceAmount.Value = tbxInvoiceAmountTPV.Text.Trim();
                        hdfCompleteWorkLabourHours.Value = "";
                        hdfCompleteWorkCosts.Value = "";
                    }
                }

                // Notes
                // Notes Gridview, if the gridview is edition mode
                if (grdNotes.EditIndex >= 0)
                {
                    grdNotes.UpdateRow(grdNotes.EditIndex, true);
                }

                GrdNotesAdd();
            }

            return valid;
        }
        private void LoadData()
        {
            dashboardMyToDoListTDS = new DashboardTDS();
            DashboardMyToDoList model = new DashboardMyToDoList(dashboardMyToDoListTDS);
            DashboardMyToDoListOnHold modelOnHold = new DashboardMyToDoListOnHold(dashboardMyToDoListTDS);

            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());

            int companyId = Int32.Parse(hdfCompanyId.Value);
            int loginId = Convert.ToInt32(Session["loginID"]);
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
            string state = "%"; if (ddlStateMyToDo.SelectedValue != "(All)") state = ddlStateMyToDo.SelectedValue;

            // ... Load to do list
            // ... ...Load for admin
            if (!Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_ADMIN"]))
            {
                if (state == "New & In Progress")
                {
                    model.LoadMyNewAndInProgressToDoListByCreated(employeeId, companyId);
                }
                else
                {
                    // ... ... Load for assigned employee
                    model.LoadMyCurrentToDoListByCreatedByIdState(employeeId, state, companyId);
                }

                modelOnHold.LoadMyCurrentToDoListOnHoldByCreatedById(employeeId, companyId);
            }
            else
            {
                if (state == "New & In Progress")
                {
                    model.LoadNewAndInProgressToDoList(companyId);
                }
                else
                {
                    // ... ... Loads all (current)
                    model.LoadCurrentToDoListByState(state, companyId);
                }

                modelOnHold.LoadCurrentToDoListOnHold(companyId);
            }

            HttpContext.Current.Session.Add("dashboardMyToDoListTDS", dashboardMyToDoListTDS);

            Page.DataBind();
        }
        protected void grdProjectTimeApprove_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Normal items
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
            {
                Label lblJobClass = (Label)e.Row.FindControl("lblJobClass");
                Label lblTypeOfWork = (Label)e.Row.FindControl("lblTypeOfWork");

                 EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                employeeGateway1.LoadByEmployeeId(employeeId);
                string employeeType = employeeGateway1.GetType(employeeId);

                if (lblTypeOfWork.Text == "Mobilization" && employeeType.Contains("US"))
                {
                    lblJobClass.Visible = false;
                }
            }
        }
        private ProjectTimeApproveTDS SubmitSearch()
        {
            // Load data
            ProjectTimeApproveTDS dataSet = new ProjectTimeApproveTDS();
            ProjectTimeApproveGateway projectTimeApproveGateway = new ProjectTimeApproveGateway(dataSet);

            EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
            employeeGateway1.LoadByEmployeeId(employeeId);
            string employeeType = employeeGateway1.GetType(employeeId);

            if (employeeType.Contains("CA"))
            {
                projectTimeApproveGateway.LoadByEmployeeTypeEmployeeIdApproveManager("CA", employeeId);
            }
            else
            {
                if (employeeType.Contains("US"))
                {
                    projectTimeApproveGateway.LoadByEmployeeTypeEmployeeIdApproveManager("US", employeeId);
                }
                else
                {
                    projectTimeApproveGateway.LoadByEmployeeTypeEmployeeIdApproveManager("SOTA", employeeId);
                }
            }

            return dataSet;
        }
        private void GrdToDoAdd()
        {
            if (ValidateToDoFooter())
            {
                Page.Validate("activityDataNew");

                if (Page.IsValid)
                {
                    int employeeId = 0;
                    EmployeeGateway employeeGateway = new EmployeeGateway();
                    string dateTime_ = ((TextBox)grdToDoList.FooterRow.FindControl("tbxDateTimeNew")).Text;
                    string comment = ((TextBox)grdToDoList.FooterRow.FindControl("tbxCommentsNew")).Text;
                    string type_ = "";
                    string employeeFullName = "";

                    GridViewRow row = grdToDoList.FooterRow;
                    DropDownList action = ((DropDownList)row.FindControl("ddlActionsNew"));

                    switch (action.SelectedValue)
                    {
                        case "Assign To User":
                            employeeId = Int32.Parse(((DropDownList)grdToDoList.FooterRow.FindControl("ddlAssignToTeamMemberNew")).SelectedValue);
                            employeeGateway.LoadByEmployeeId(employeeId);
                            employeeFullName = employeeGateway.GetFullName(employeeId);
                            type_ = "AssignUser";
                            hdfToDoListState.Value = "In Progress";
                            break;

                        case "Add Comment":
                            int loginId = Convert.ToInt32(Session["loginID"]);
                            employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
                            type_ = "AddComment";
                            employeeFullName = employeeGateway.GetFullName(employeeId);
                            hdfToDoListState.Value = "In Progress";
                            break;

                        case "Complete":
                            employeeId = Int32.Parse(hdfAssignedUser.Value);
                            employeeGateway.LoadByEmployeeId(employeeId);
                            employeeFullName = employeeGateway.GetFullName(employeeId);
                            type_ = "CloseToDo";
                            hdfCompleted.Value = "True";
                            hdfToDoListState.Value = "Completed";
                            break;

                        case "Put On Hold":
                            int loginIdOnHold = Convert.ToInt32(Session["loginID"]);
                            employeeId = employeeGateway.GetEmployeIdByLoginId(loginIdOnHold);
                            type_ = "OnHoldToDo";
                            employeeFullName = employeeGateway.GetFullName(employeeId);
                            hdfToDoListState.Value = "On Hold";
                            break;
                    }

                    // static values
                    int toDoId = Int32.Parse(hdfToDoId.Value);
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    bool inDatabase = false;

                    ToDoListInformationBasicInformation generalModel = new ToDoListInformationBasicInformation(toDoListInformationTDS);
                    generalModel.UpdateState(toDoId, hdfToDoListState.Value);

                    ToDoListInformationActivityInformation model = new ToDoListInformationActivityInformation(toDoListInformationTDS);
                    model.Insert(toDoId, employeeId, type_, DateTime.Parse(dateTime_), comment, false, companyId, inDatabase, employeeFullName);

                    Session.Remove("activityInformationDummy");
                    Session["toDoListInformationTDS"] = toDoListInformationTDS;

                    grdToDoList.DataBind();
                }
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "LabourHours";

            // ... Labour Hours Mode
            if ((string)ViewState["LHMode"] == "Partial")
            {
                // Access control
                // ... Employees
                EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());
                employeeListGateway.LoadByRequestProjectTime(1);

                DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                ddlOthersFor.DataSource = employeeListGateway.Table;
                ddlOthersFor.DataValueField = "EmployeeID";
                ddlOthersFor.DataTextField = "FullName";
                ddlOthersFor.DataBind();

                tkrpbLeftMenuMyTimesheets.Visible = false;
                tkrpbLeftMenuOthersTimesheets.Items[0].Text = "Timesheets";
                tkrpbLeftMenuTools.Items[0].Items[1].Visible = false;
            }
            else
            {
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                employeeGateway1.LoadByEmployeeId(employeeId);

                if (Request.QueryString["source_page"] == "timesheet_approve.aspx")
                {
                    tkrmTop.Items[3].Visible = false; //Timesheet
                    tkrmTop.Items[4].Visible = true; //Approve Project Times
                }
                else
                {
                    tkrmTop.Items[3].Visible = true; //Timesheet

                    // Timesheet state check
                    ProjectTimeGateway projectTimeGatewayForState = new ProjectTimeGateway(projectTimeTDS);
                    int projecttime_id = Int32.Parse(ViewState["projecttime_id"].ToString());

                    if (projectTimeGatewayForState.GetProjectTimeState(projecttime_id) == "For Approval")
                    {
                        tkrmTop.Items[4].Visible = true; //Approve Project Times
                    }
                    else
                    {
                        tkrmTop.Items[4].Visible = false; //Approve Project Times
                    }
                }

                if (!employeeGateway1.GetApproveTimesheets(employeeId))
                {
                    tkrpbLeftMenuTools.Items[0].Items[1].Visible = false; //Approve Project Times
                }

                if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    tkrpbLeftMenuOthersTimesheets.Visible = true;
                    tkrpbLeftMenuTools.Items[0].Items[0].Visible = true; // Add Team Project Time
                    tkrpbLeftMenuTools.Items[0].Items[2].Visible = true; // Missing Project Time

                    // Access control
                    // ... Employees
                    EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());

                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                    {
                        employeeListGateway.LoadByRequestProjectTimeWithoutEmployeeId(1, employeeId);
                    }
                    else
                    {
                        employeeListGateway.LoadByRequestProjectTime(1);
                    }

                    DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                    ddlOthersFor.DataSource = employeeListGateway.Table;
                    ddlOthersFor.DataValueField = "EmployeeID";
                    ddlOthersFor.DataTextField = "FullName";
                    ddlOthersFor.DataBind();
                    try
                    {
                        ddlOthersFor.SelectedValue = Session["ddlOthersForSelectedValue"].ToString();
                    }
                    catch
                    {
                    }
                }
                else
                {
                    tkrpbLeftMenuOthersTimesheets.Visible = false;

                    if (!employeeGateway1.GetApproveTimesheets(employeeId))
                    {
                        tkrpbLeftMenuTools.Visible = false;
                    }

                    tkrpbLeftMenuTools.Items[0].Items[0].Visible = false; // Add Team Project Time
                    tkrpbLeftMenuTools.Items[0].Items[2].Visible = false; // Missing Project Time
                }

                if (!((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway1.GetRequestProjectTime(employeeId))))
                {
                    tkrpbLeftMenuMyTimesheets.Visible = false;
                    tkrpbLeftMenuOthersTimesheets.Items[0].Text = "Timesheets";
                }

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_REPORTS"]))
                    {
                        tkrpbLeftMenuReports.Visible = false;
                    }
                }

                // Get ProjectTime record, can't edit or delete approved timesheets
                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (projectTimeGateway.GetProjectTimeState((int)ViewState["projecttime_id"]) == "Approved")
                    {
                        tkrmTop.Items[1].Visible = false;
                        tkrmTop.Items[2].Visible = false;
                    }
                }

            }
        }
        private void LoadData()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int loginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
            string period = ddlPeriod.SelectedItem.Value.ToString();
            int companyLevelId = Int32.Parse(ddlWorkingLocation.SelectedValue);

            dashboardItemsAboutToExpireTDS = (DashboardTDS)HttpContext.Current.Session["dashboardItemsAboutToExpireTDS"];
            DashboardItemsAboutToExpire model = new DashboardItemsAboutToExpire(dashboardItemsAboutToExpireTDS);

            if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
            {
                if (companyLevelId == 0)
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllItemsAboutToExpireByUnitType(period, companyId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllItemsAboutToExpire(period, companyId);
                    }
                }
                else
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllItemsAboutToExpireByCompanyLevelIdUnitType(period, companyId, companyLevelId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllItemsAboutToExpireByCompanyLevelId(period, companyId, companyLevelId);
                    }
                }
            }
            else
            {
                if (companyLevelId == 0)
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllItemsAboutToExpireByAssignTeamMemberIDUnitType(period, employeeId, companyId, ddlType.SelectedValue);
                    }
                    else
                    {
                        // ... Load for assigned employee
                        model.LoadAllItemsAboutToExpireByAssignTeamMemberID(period, employeeId, companyId);
                    }
                }
                else
                {
                    if (ddlType.SelectedValue != "(All)")
                    {
                        model.LoadAllItemsAboutToExpireByAssignTeamMemberIDCompanyLevelIdUnitType(period, employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                    }
                    else
                    {
                        model.LoadAllItemsAboutToExpireByAssignTeamMemberIDCompanyLevelId(period, employeeId, companyId, companyLevelId);
                    }
                }
            }

            model.UpdateForDashboard(companyId);

            HttpContext.Current.Session.Add("dashboardItemsAboutToExpireTDS", dashboardItemsAboutToExpireTDS);

            Page.DataBind();
        }
        protected void grdToDoList_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Control of footer row
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway();
                int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                // Select action
                DropDownList actions = (DropDownList)e.Row.FindControl("ddlActionsNew");
                actions.SelectedValue = hdfAction.Value;

                // Only the assigned user could close the todo
                if (hdfAssignedUser.Value != employeeId.ToString())
                {
                    actions.Items.Remove("Close");
                }

                // Make fields visible for actions
                if (hdfAction.Value == "Assign To User")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = true;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = true;
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = false;
                    ((Label)e.Row.FindControl("lblClosed")).Visible = false;
                    ((Label)e.Row.FindControl("lblUserNew")).Text = "Assign To";
                }

                if (hdfAction.Value == "Add Comment")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true;

                    EmployeeGateway employeeGatewayForUser = new EmployeeGateway();
                    employeeGatewayForUser.LoadByEmployeeId(employeeId);
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForUser.GetFullName(employeeId);
                    ((Label)e.Row.FindControl("lblClosed")).Visible = false;
                    ((Label)e.Row.FindControl("lblUserNew")).Text = "Comment Added By";
                }

                if (hdfAction.Value == "Complete")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true;

                    EmployeeGateway employeeGatewayForUser = new EmployeeGateway();
                    employeeGatewayForUser.LoadByEmployeeId(Int32.Parse(hdfAssignedUser.Value));
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForUser.GetFullName(Int32.Parse(hdfAssignedUser.Value));
                    ((Label)e.Row.FindControl("lblClosed")).Visible = false;

                    ((Label)e.Row.FindControl("lblUserNew")).Text = "To Do Completed By";
                }

                if (hdfCompleted.Value == "True")
                {
                    ((DropDownList)e.Row.FindControl("ddlActionsNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxDateTimeNew")).Visible = false;
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxCommentsNew")).Visible = false;
                    ((Label)e.Row.FindControl("lblActionNew")).Visible = false;
                    ((Label)e.Row.FindControl("lblDateTimeNew")).Visible = false;
                    ((Label)e.Row.FindControl("lblUserNew")).Visible = false;
                    ((Label)e.Row.FindControl("lblCommentsNew")).Visible = false;
                    ((ImageButton)e.Row.FindControl("ibtnAdd")).Visible = false;
                    ((Label)e.Row.FindControl("lblClosed")).Visible = true;
                }

                if (hdfAction.Value == "Put On Hold")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Visible = true;

                    EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway();
                    employeeGatewayForOnHold.LoadByEmployeeId(employeeId);
                    ((TextBox)e.Row.FindControl("tbxUserNew")).Text = employeeGatewayForOnHold.GetFullName(employeeId);
                    ((Label)e.Row.FindControl("lblClosed")).Visible = false;
                    ((Label)e.Row.FindControl("lblUserNew")).Text = "On Hold By";
                }

                // Date and time
                DateTime creationDate = DateTime.Now;
                ((TextBox)e.Row.FindControl("tbxDateTimeNew")).Text = creationDate.ToString();
            }

            // Control of edit rows
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                // Date and time
                DateTime creationDate = DateTime.Now;
                ((TextBox)e.Row.FindControl("tbxDateTimeEdit")).Text = creationDate.ToString();
                string type_ = ((Label)e.Row.FindControl("lblType")).Text;
                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway();
                int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
                int toDoId = Int32.Parse(((Label)e.Row.FindControl("lblToDoID")).Text);
                int refId = Int32.Parse(((Label)e.Row.FindControl("lblRefID")).Text);

                ToDoListInformationActivityInformationGateway toDoListInformationActivityInformationGateway = new ToDoListInformationActivityInformationGateway(toDoListInformationTDS);

                // Make fields visible for actions
                if (type_ == "AssignUser")
                {
                    int employeeIdForAssign = toDoListInformationActivityInformationGateway.GetEmployeeID(toDoId, refId);
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = true;
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).SelectedValue = employeeIdForAssign.ToString();
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = true;
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = false;
                    ((Label)e.Row.FindControl("lblUserEdit")).Text = "Assign To";
                }

                if (type_ == "AddComment")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true;

                    EmployeeGateway employeeGatewayForUser = new EmployeeGateway();
                    employeeGatewayForUser.LoadByEmployeeId(employeeId);
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForUser.GetFullName(employeeId);
                    ((Label)e.Row.FindControl("lblUserEdit")).Text = "Comment Added By";
                }

                if (type_ == "CloseToDo")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true;

                    EmployeeGateway employeeGatewayForUser = new EmployeeGateway();
                    employeeGatewayForUser.LoadByEmployeeId(Int32.Parse(hdfAssignedUser.Value));
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForUser.GetFullName(Int32.Parse(hdfAssignedUser.Value));
                    ((Label)e.Row.FindControl("lblUserEdit")).Text = "To Do Completed By";
                }

                if (type_ == "OnHoldToDo")
                {
                    ((DropDownList)e.Row.FindControl("ddlAssignToTeamMemberEdit")).Visible = false;
                    ((CustomValidator)e.Row.FindControl("cvTeamMemberEdit")).Visible = false;
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Visible = true;

                    EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway();
                    employeeGatewayForOnHold.LoadByEmployeeId(employeeId);
                    ((TextBox)e.Row.FindControl("tbxUserEdit")).Text = employeeGatewayForOnHold.GetFullName(employeeId);
                    ((Label)e.Row.FindControl("lblUserEdit")).Text = "On Hold By";
                }
            }

            // Control normal rows
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Normal) || (e.Row.RowState == (DataControlRowState.Normal | DataControlRowState.Alternate))))
            {
                // Validate admin actions
                if ((Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_ADMIN"])))
                {
                    ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = true;
                    ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = true;
                }
                else
                {
                    bool inDataBase = bool.Parse(((Label)e.Row.FindControl("lblInDataBase")).Text);
                    if (inDataBase)
                    {
                        ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = false;
                        ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = false;
                    }
                    else
                    {
                        ((ImageButton)e.Row.FindControl("ibtnEdit")).Visible = true;
                        ((ImageButton)e.Row.FindControl("ibtnDelete")).Visible = true;
                    }
                }

                // Change label text
                string type_ = ((Label)e.Row.FindControl("lblType")).Text;
                if (type_ == "AssignUser")
                {
                    ((Label)e.Row.FindControl("lblUser")).Text = "Assign To";
                }

                if (type_ == "AddComment")
                {
                    ((Label)e.Row.FindControl("lblUser")).Text = "Comment Added By";
                }

                if (type_ == "CloseToDo")
                {
                    ((Label)e.Row.FindControl("lblUser")).Text = "To Do Completed By";
                }

                if (type_ == "OnHoldToDo")
                {
                    ((Label)e.Row.FindControl("lblUser")).Text = "On Hold By";
                }
            }
        }
        private void PostPageChanges()
        {
            int projectTimeId = (int)ViewState["projecttime_id"];

            EmployeeGateway employeeGateway = new EmployeeGateway();
            int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

            // Delete project time
            LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime projectTime = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime(projectTimeTDS);
            projectTime.Delete(projectTimeId, employeeId);
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_ITTST_SUPPORTTICKET_ADMIN"])))
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_ITTST_SUPPORTTICKET_VIEW"]) && Convert.ToBoolean(Session["sgLFS_ITTST_SUPPORTTICKET_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)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in wucSupportTicketAssignedToMe.ascx");
                }

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

                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardSupportTicketAssignedToMeDataTableDummy");
                HttpContext.Current.Session.Remove("dashboardSupportTicketAssignedToMeOnHoldDataTableDummy");
                ArrayList arrayListWidgetData = (ArrayList)HttpContext.Current.Session["mySupportTicketAssignedToMeWidget"];
                ArrayList arrayListWidgetDataOnHold = (ArrayList)HttpContext.Current.Session["mySupportTicketAssignedToMeOnHoldWidget"];

                // If coming from
                // ... Out
                if (Request.QueryString["source_page"] == "out")
                {
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                    int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                    // ... For Grid
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    dashboardSupportTicketAssignedToMeTDS = new DashboardTDS();
                    DashboardSupportTicketAssignedToMe model = new DashboardSupportTicketAssignedToMe(dashboardSupportTicketAssignedToMeTDS);
                    DashboardSupportTicketAssignedToMeOnHold modelOnHold = new DashboardSupportTicketAssignedToMeOnHold(dashboardSupportTicketAssignedToMeTDS);

                    // ... Load support ticket
                    model.LoadCurrentSupportTicketAssignedToMeByEmployeeId(employeeId, companyId);
                    modelOnHold.LoadSupportTicketAssignedToMeOnHoldByEmployeeId(employeeId, companyId);

                    // ... Store datasets
                    HttpContext.Current.Session.Add("dashboardSupportTicketAssignedToMeTDS", dashboardSupportTicketAssignedToMeTDS);
                }
            }
            else
            {
                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardSupportTicketAssignedToMeDataTableDummy");
                HttpContext.Current.Session.Remove("dashboardSupportTicketAssignedToMeOnHoldDataTableDummy");

                // Restore dataset
                dashboardSupportTicketAssignedToMeTDS = (DashboardTDS)HttpContext.Current.Session["dashboardSupportTicketAssignedToMeTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_HOLIDAY_FULL_EDITING"])))
                {
                    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_setup.aspx");
                }

                // 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";
                }

                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfUpdate.Value = "no";

                Session.Remove("vacationsSetup");
                Session.Remove("vacationsSetupDummy");

                // Prepare initial data

                // ... For Grids
                vacationsSetup = new VacationsSetupTDS.VacationsSetupDataTable();

                // ... Store datasets
                Session["vacationsSetup"] = vacationsSetup;

                // StepSection1In
                wizard.ActiveStepIndex = 0;
                StepBeginIn();
            }
            else
            {
                // Restore datasets
                vacationsSetup = (VacationsSetupTDS.VacationsSetupDataTable)Session["vacationsSetup"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_FULL_EDITING"]))
                {
                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) && !Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                    {
                        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["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null) && ((string)Request.QueryString["projecttime_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet.aspx");
                }

                // Tag page
                Session.Remove("timesheetNavigatorDummy");

                // Initialize  variables
                lblError.Visible = false;

                // ... Labour Hours Mode
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // ... If coming from out
                if ((string)Request.QueryString["source_page"] == "out")
                {
                    Session.Remove("ddlOthersForSelectedValue");

                    // Store search parameters
                    ViewState["current"] = "yes";
                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                    {
                        ViewState["others"] = "yes";
                    }
                    else
                    {
                        ViewState["others"] = "no";
                    }

                    EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);

                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_AUTOREPORT"]))
                    {
                        string script = "<script language='javascript'>";
                        script += "window.open('./../projecttime/timesheet_missing.aspx?source_page=timesheet.aspx', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=550, height=420')";
                        script += "</script>";
                        ScriptManager.RegisterStartupScript(this, this.GetType(), "Report", script, false);
                    }
                }

                // ... If coming from left menu
                if ((string)Request.QueryString["source_page"] == "lm")
                {
                    // Store search parameters
                    ViewState["current"] = "yes";
                    ViewState["others"] = Request.QueryString["others"];

                    if (Request.QueryString["others"] == "yes")
                    {
                        ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    }
                    else
                    {
                        EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                        ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                    }

                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);
                }

                // ... If coming from timesheet_all.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet_all.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);
                }

                // ... If coming from timesheet.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);

                    if (Session["OpenTimesheetMissing"] == null)
                    {
                        if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_AUTOREPORT"]))
                        {
                            string script = "<script language='javascript'>";
                            script += "window.open('./../projecttime/timesheet_missing.aspx?source_page=timesheet.aspx', '_blank', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=550, height=420')";
                            script += "</script>";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "Report", script, false);
                        }
                    }
                }

                // ... If coming from timesheet_summary.aspx, timesheet_add.aspx, timesheet_edit.aspx, timesheet_delete.aspx or timesheet_state.aspx
                if (((string)Request.QueryString["source_page"] == "timesheet_summary.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_add.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_edit.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_delete.aspx") || ((string)Request.QueryString["source_page"] == "timesheet_state.aspx"))
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();

                    if (currentPeriod == int.Parse((string)Request.QueryString["period_id"]))
                    {
                        ViewState["current"] = "yes";
                    }
                    else
                    {
                        ViewState["current"] = "no";
                    }

                    ViewState["others"] = Request.QueryString["others"];
                    ViewState["employee_id"] = int.Parse((string)Request.QueryString["employee_id"]);
                    ViewState["period_id"] = int.Parse((string)Request.QueryString["period_id"]);
                }

                // ... If coming from timesheet_approve.aspx
                if ((string)Request.QueryString["source_page"] == "timesheet_approve.aspx")
                {
                    // Store search parameters
                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                    int currentPeriod = payPeriodGateway.GetCurrent();
                    EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());

                    ViewState["current"] = "yes";
                    ViewState["others"] = "yes";
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                    ViewState["period_id"] = currentPeriod;
                }

                // Access control
                // ... Employees
                EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    employeeListGateway.LoadByRequestProjectTimeWithoutEmployeeId(1, (int)ViewState["employee_id"]);
                }
                else
                {
                    employeeListGateway.LoadByRequestProjectTime(1);
                }

                DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                ddlOthersFor.DataSource = employeeListGateway.Table;
                ddlOthersFor.DataValueField = "EmployeeID";
                ddlOthersFor.DataTextField = "FullName";
                ddlOthersFor.DataBind();

                // ... Title
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());

                if ((int)ViewState["employee_id"] != 0)
                {
                    employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                    if ((string)ViewState["others"] == "no")
                    {
                        if ((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway.GetRequestProjectTime((int)ViewState["employee_id"])))
                        {
                            if ((string)ViewState["current"] == "yes")
                            {
                                lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                            }
                            else
                            {
                                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                            }
                        }
                        else
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                        }
                    }
                    else
                    {
                        EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                        int employeeIdNow = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

                        if ((int)ViewState["employee_id"] == employeeIdNow)
                        {
                            if (((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway.GetRequestProjectTime((int)ViewState["employee_id"]))))
                            {
                                if ((string)ViewState["current"] == "yes")
                                {
                                    lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                                }
                                else
                                {
                                    PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                    payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                    lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                                }
                            }
                            else
                            {
                                if (ddlOthersFor.Items.Count > 0)
                                {
                                    Session["ddlOthersForSelectedValue"] = ddlOthersFor.SelectedValue;
                                    Response.Redirect("./timesheet.aspx?source_page=timesheet.aspx&others=yes&employee_id=" + ddlOthersFor.SelectedValue + "&period_id=" + ((int)ViewState["period_id"]).ToString());
                                }
                                else
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "No team members with 'Request Timesheet' property are defined in the system. Contact your system administrator for further assistance.");
                                }
                            }
                        }
                        else
                        {
                            if ((string)ViewState["current"] == "yes")
                            {
                                lblTitle.Text = "Current Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                            }
                            else
                            {
                                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                                payPeriodGateway.LoadByPayPeriodId((int)ViewState["period_id"]);
                                lblTitle.Text = "Timesheet For " + employeeGateway.GetFullName((int)ViewState["employee_id"]) + " From " + payPeriodGateway.GetStartDate((int)ViewState["period_id"]).ToShortDateString() + " To " + payPeriodGateway.GetEndDate((int)ViewState["period_id"]).ToShortDateString();
                            }
                        }
                    }
                }
                else
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You cannot use the Labour Hours subsystem since you are not registered as a team member in LFS Live. Please contact your system administrator for further assistance."); ;
                }

                // Load data
                timesheetNavigatorTDS = this.SubmitSearch();
                Session["timesheetNavigatorTDS"] = timesheetNavigatorTDS;
                timesheetNavigator = timesheetNavigatorTDS.LFS_PROJECT_TIME;
                Session["timesheetNavigator"] = timesheetNavigator;

                // Set Total project time
                TimesheetNavigator timesheetNavigatorForTotal = new TimesheetNavigator(timesheetNavigatorTDS);
                tbxTotalCost.Text = timesheetNavigatorForTotal.GetTotalProjectTime().ToString();
            }
            else
            {
                // Restore dataset
                timesheetNavigatorTDS = (TimesheetNavigatorTDS)Session["timesheetNavigatorTDS"];
                timesheetNavigator = timesheetNavigatorTDS.LFS_PROJECT_TIME;

                // Store datase
                Session["timesheetNavigator"] = timesheetNavigator;
            }
        }
        public void SendMailFleetManager()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "Service request has been modified.";
            string body = "";

            // MailtTo, nameTo
            int companyLevelId = Int32.Parse(hdfCompanyLevel.Value);

            Employee employees = new Employee();
            employees.LoadByFleetManager(companyLevelId);

            mailTo = employees.GetAllFleetManagersEMails();
            nameTo = employees.GetAllFleetManagersNames();

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following service request has been modified. \n";

            body = body + "\n Service Number: " + hdfServiceNumber.Value;
            body = body + "\n Service Description: " + hdfServiceDescription.Value;

            // ... Assignation of work
            // ... ... Deadline date
            if (hdfDeadlineDate.Value != "")
            {
                DateTime deadlineDate = DateTime.Parse(hdfDeadlineDate.Value);
                string deadlineDateText = deadlineDate.Month.ToString() + "/" + deadlineDate.Day.ToString() + "/" + deadlineDate.Year.ToString();
                body = body + "\n Deadline date: " + deadlineDateText;
            }
            else
            {
                body = body + "\n Deadline date: ";
            }

            // ... ... Assigned Personal
            if (hdfAssignToTeamMember.Value == "True")
            {
                int employeeId = Int32.Parse(hdfTeamMemberId.Value);
                EmployeeGateway employeesGateway = new EmployeeGateway();
                employeesGateway.LoadForMailsByEmployeeId(employeeId);
                string assignedTo = "";
                if (employeesGateway.Table.Rows.Count > 0)
                {
                    // Assigned TeamMember
                    assignedTo = employeesGateway.GetFirstName(employeeId) + " " + employeesGateway.GetLastName(employeeId);
                }

                body = body + "\n Assigned Team Member: " + assignedTo;
            }

            // ... ... Assigned third party vendor
            if (hdfAssignToThirdPartyVendor.Value == "True")
            {
                body = body + "\n Assigned Third Party Vendor: " + hdfThirdPartyVendor.Value;
            }

            int registeredByLoginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByLoginId(registeredByLoginId);
            int registeredByEmployeeId = employeeGateway.GetEmployeIdByLoginId(registeredByLoginId);

            // ... ... Assigned myself
            if (hdfAssignToMyself.Value == "True")
            {
                if (employeeGateway.Table.Rows.Count > 0)
                {
                    body = body + "\n Assigned to myself: " + employeeGateway.GetFirstName(registeredByEmployeeId) + " " + employeeGateway.GetLastName(registeredByEmployeeId);
                }
            }

            // Registered by
            if (employeeGateway.Table.Rows.Count > 0)
            {
                body = body + "\n Registered By: " + employeeGateway.GetFirstName(registeredByEmployeeId) + " " + employeeGateway.GetLastName(registeredByEmployeeId);
            }

            // Service State
            body = body + "\n\n Service State: " + hdfServiceState.Value;

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        protected void ddlActionsNew_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = grdToDoList.FooterRow;
            DropDownList action = ((DropDownList)row.FindControl("ddlActionsNew"));

            switch (action.SelectedValue)
            {
                case "Assign To User":
                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).Visible = true;
                    ((CustomValidator)row.FindControl("cvTeamMemberNew")).Visible = true;
                    ((TextBox)row.FindControl("tbxUserNew")).Visible = false;
                    ((Label)row.FindControl("lblUserNew")).Text = "Assign To";
                    break;

                case "Add Comment":
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    EmployeeGateway employeeGateway = new EmployeeGateway();
                    int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)row.FindControl("tbxUserNew")).Visible = true;
                    ((Label)row.FindControl("lblUserNew")).Text = "Comment Added By";

                    EmployeeGateway employeeGatewayForUser = new EmployeeGateway();
                    employeeGatewayForUser.LoadByEmployeeId(employeeId);
                    ((TextBox)row.FindControl("tbxUserNew")).Text = employeeGatewayForUser.GetFullName(employeeId);
                    break;

                case "Complete":
                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)row.FindControl("tbxUserNew")).Visible = true;
                    ((Label)row.FindControl("lblUserNew")).Text = "To Do Completed By";

                    EmployeeGateway employeeGatewayForUserComplete = new EmployeeGateway();
                    employeeGatewayForUserComplete.LoadByEmployeeId(Int32.Parse(hdfAssignedUser.Value));
                    ((TextBox)row.FindControl("tbxUserNew")).Text = employeeGatewayForUserComplete.GetFullName(Int32.Parse(hdfAssignedUser.Value));
                    break;

                case "Put On Hold":
                    int loginIdOnHold = Convert.ToInt32(Session["loginID"]);
                    EmployeeGateway employeeGatewayOnHold = new EmployeeGateway();
                    int employeeIdOnHold = employeeGatewayOnHold.GetEmployeIdByLoginId(loginIdOnHold);

                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).Visible = false;
                    ((CustomValidator)row.FindControl("cvTeamMemberNew")).Visible = false;
                    ((TextBox)row.FindControl("tbxUserNew")).Visible = true;
                    ((Label)row.FindControl("lblUserNew")).Text = "On Hold By";

                    EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway();
                    employeeGatewayForOnHold.LoadByEmployeeId(employeeIdOnHold);
                    ((TextBox)row.FindControl("tbxUserNew")).Text = employeeGatewayForOnHold.GetFullName(employeeIdOnHold);
                    break;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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 grdToDoList_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("activityDataEdit");

            if (Page.IsValid)
            {
                int toDoId = (int)e.Keys["ToDoID"];
                int refId = (int)e.Keys["RefID"];

                int employeeId = 0;
                int loginId = Convert.ToInt32(Session["loginID"]);

                EmployeeGateway employeeGateway = new EmployeeGateway();
                string comment = ((TextBox)grdToDoList.Rows[e.RowIndex].Cells[4].FindControl("tbxCommentsEdit")).Text;
                string employeeFullName = "";

                string type_ = ((Label)grdToDoList.Rows[e.RowIndex].Cells[4].FindControl("lblType")).Text;
                switch (type_)
                {
                    case "AssignUser":
                        employeeId = Int32.Parse(((DropDownList)grdToDoList.Rows[e.RowIndex].Cells[4].FindControl("ddlAssignToTeamMemberEdit")).SelectedValue);
                        employeeGateway.LoadByEmployeeId(employeeId);
                        employeeFullName = employeeGateway.GetFullName(employeeId);
                        break;

                    case "AddComment":
                        employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
                        EmployeeGateway employeeGatewayForComment = new EmployeeGateway();
                        employeeGatewayForComment.LoadByEmployeeId(employeeId);
                        employeeFullName = employeeGatewayForComment.GetFullName(employeeId);
                        break;

                    case "CloseToDo":
                        employeeId = Int32.Parse(hdfAssignedUser.Value);
                        employeeGateway.LoadByEmployeeId(employeeId);
                        employeeFullName = employeeGateway.GetFullName(employeeId);
                        hdfCompleted.Value = "True";
                        break;

                    case "OnHoldToDo":
                        employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
                        EmployeeGateway employeeGatewayForOnHold = new EmployeeGateway();
                        employeeGatewayForOnHold.LoadByEmployeeId(employeeId);
                        employeeFullName = employeeGatewayForOnHold.GetFullName(employeeId);
                        break;
                }

                ToDoListInformationActivityInformation model = new ToDoListInformationActivityInformation(toDoListInformationTDS);
                model.Update(toDoId, refId, employeeId, employeeFullName, comment);

                // Store dataset
                Session["toDoListInformationTDS"] = toDoListInformationTDS;
            }
            else
            {
                e.Cancel = true;
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "LabourHours";

            // ... Labour Hours Mode
            if ((string)ViewState["LHMode"] == "Partial")
            {
                // Access control
                // ... Employees
                EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());
                employeeListGateway.LoadByRequestProjectTime(1);

                DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                ddlOthersFor.DataSource = employeeListGateway.Table;
                ddlOthersFor.DataValueField = "EmployeeID";
                ddlOthersFor.DataTextField = "FullName";
                ddlOthersFor.DataBind();

                tkrpbLeftMenuMyTimesheets.Visible = false;
                tkrpbLeftMenuOthersTimesheets.Items[0].Text = "Timesheets";
                tkrpbLeftMenuTools.Items[0].Items[1].Visible = false;
            }
            else
            {
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeIdForMenu = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                employeeGateway1.LoadByEmployeeId(employeeIdForMenu);

                if (!employeeGateway1.GetApproveTimesheets(employeeIdForMenu))
                {
                    tkrpbLeftMenuTools.Items[0].Items[1].Visible = false; // Timesheets To Approve
                }

                if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    tkrpbLeftMenuOthersTimesheets.Visible = true;
                    tkrpbLeftMenuTools.Items[0].Items[0].Visible = true; // Add Team Project Time
                    tkrpbLeftMenuTools.Items[0].Items[2].Visible = true; // Missing Project Time

                    // Access control
                    // ... Employees
                    EmployeeListGateway employeeListGateway = new EmployeeListGateway(new DataSet());

                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                    {
                        employeeListGateway.LoadByRequestProjectTimeWithoutEmployeeId(1, employeeIdForMenu);
                    }
                    else
                    {
                        employeeListGateway.LoadByRequestProjectTime(1);
                    }

                    DropDownList ddlOthersFor = (DropDownList)tkrpbLeftMenuOthersTimesheets.FindItemByValue("nbOthersTimesheetsDDL").FindControl("ddlOthersFor");
                    ddlOthersFor.DataSource = employeeListGateway.Table;
                    ddlOthersFor.DataValueField = "EmployeeID";
                    ddlOthersFor.DataTextField = "FullName";
                    ddlOthersFor.DataBind();
                    try
                    {
                        ddlOthersFor.SelectedValue = Session["ddlOthersForSelectedValue"].ToString();
                    }
                    catch
                    {
                    }
                }
                else
                {
                    tkrpbLeftMenuOthersTimesheets.Visible = false;

                    if (!employeeGateway1.GetApproveTimesheets(employeeIdForMenu))
                    {
                        tkrpbLeftMenuTools.Visible = false;
                    }

                    tkrpbLeftMenuTools.Items[0].Items[0].Visible = false; // Add Team Project Time
                    tkrpbLeftMenuTools.Items[0].Items[2].Visible = false; // Missing Project Time
                }

                if (!((Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])) && (employeeGateway1.GetRequestProjectTime(employeeIdForMenu))))
                {
                    tkrpbLeftMenuMyTimesheets.Visible = false;
                    tkrpbLeftMenuOthersTimesheets.Items[0].Text = "Timesheets";
                }

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_REPORTS"]))
                    {
                        tkrpbLeftMenuReports.Visible = false;
                    }
                }
            }
        }
        private bool ValidateToDoFooter()
        {
            bool validFooter = false;
            int employeeId = 0;
            string comment = ((TextBox)grdToDoList.FooterRow.FindControl("tbxCommentsNew")).Text;

            if (hdfAction.Value == "Assign To User")
            {
                employeeId = Int32.Parse(((DropDownList)grdToDoList.FooterRow.FindControl("ddlAssignToTeamMemberNew")).SelectedValue);

                if (employeeId != 0)
                {
                    validFooter = true;
                }
            }

            if (hdfAction.Value == "Add Comment")
            {
                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                if ((employeeId != 0) && (comment != ""))
                {
                    validFooter = true;
                }
            }

            if (hdfAction.Value == "Complete")
            {
                employeeId = Int32.Parse(hdfAssignedUser.Value);

                if ((employeeId != 0) && (comment != ""))
                {
                    validFooter = true;
                }
            }

            if (hdfAction.Value == "Put On Hold")
            {
                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

                if ((employeeId != 0) && (comment != ""))
                {
                    validFooter = true;
                }
            }

            return validFooter;
        }
        private void PostPageChanges()
        {
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));

            projectTimeTDSToSave = new ProjectTimeTDS();
            LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime projectTime = new LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime(projectTimeTDS);
            projectTime.Insert(projectTimeTDSToSave, employeeId);
        }
        private void LoadData()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int companyLevelId = Int32.Parse(ddlWorkingLocation.SelectedValue);

            dashboardMyServiceRequestsTDS = (DashboardTDS)HttpContext.Current.Session["dashboardMyServiceRequestsTDS"];
            DashboardMyServiceRequests model = new DashboardMyServiceRequests(dashboardMyServiceRequestsTDS);

            // ... Load
            int loginId = Convert.ToInt32(Session["loginID"]);
            EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
            int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);

            if (companyLevelId == 0)
            {
                if (ddlType.SelectedValue != "(All)")
                {
                    model.LoadMyServicesByAssignTeamMemberIDUnitType(employeeId, companyId, ddlType.SelectedValue);
                }
                else
                {
                    model.LoadMyServicesByAssignTeamMemberID(employeeId, companyId);
                }
            }
            else
            {
                if (ddlType.SelectedValue != "(All)")
                {
                    model.LoadMyServicesByAssignTeamMemberIDCompanyLevelIdUnitType(employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                }
                else
                {
                    model.LoadMyServicesByAssignTeamMemberIDCompanyLevelId(employeeId, companyId, companyLevelId);
                }
            }

            model.UpdateForDashboard(companyId);

            HttpContext.Current.Session.Add("dashboardMyServiceRequestsTDS", dashboardMyServiceRequestsTDS);

            Page.DataBind();
        }
        private void UpdateTimesheet()
        {
            int employeeId = Int32.Parse(hdfEmployeeID.Value);
            int periodId = Int32.Parse(hdfPeriodId.Value);

            TimesheetTDS timesheetTDS = new TimesheetTDS();
            TimesheetGateway timesheetGateway = new TimesheetGateway(timesheetTDS);
            timesheetGateway.LoadByEmployeeIdPayPeriodId(employeeId, periodId);
            LiquiForce.LFSLive.BL.LabourHours.Timesheet.Timesheet timesheet = new LiquiForce.LFSLive.BL.LabourHours.Timesheet.Timesheet(timesheetTDS);

            // Approve timesheet
            if (ViewState["timesheetState"].ToString() == "Approved")
            {
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                ViewState["approved_by_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                timesheet.Approve(employeeId, periodId, (int)ViewState["approved_by_id"]);
            }

            // Reject timesheet
            if (ViewState["timesheetState"].ToString() == "Rejected")
            {
                timesheet.Reject(employeeId, periodId);
            }

            // Submit timesheet
            if (ViewState["timesheetState"].ToString() == "Submitted")
            {
                timesheet.Submit(employeeId, periodId);
            }

            try
            {
                timesheetGateway.Update2();
                timesheetTDS.AcceptChanges();
            }
            catch (Exception ex)
            {
                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                // Security check
                EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                int employeeId = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                hdfCurrentEmployeeId.Value = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"])).ToString();
                employeeGateway1.LoadByEmployeeId(employeeId);

                if (!employeeGateway1.GetApproveTimesheets(employeeId))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Tag page
                Session.Remove("projectTimeApproveDummy");

                // Initialize  variables
                lblError.Visible = false;

                // ... Initialize viewstate variables
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Labour Hours Mode check
                if ((string)ViewState["LHMode"] == "Partial")
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "The system is on partial mode. Contact your system administrator.");
                }

                ViewState["others"] = Request.QueryString["others"];

                PayPeriodGateway payPeriodGateway = new PayPeriodGateway(new DataSet());
                ViewState["period_id"] = payPeriodGateway.GetPayPeriodId(DateTime.Now);

                // Load data
                // ... Loading employees accordingly to the admins country.
                EmployeeList employeeList = new EmployeeList(new DataSet());
                string employeeType = employeeGateway1.GetType(employeeId);
                odsClient.SelectParameters.RemoveAt(2);
                if (employeeType.Contains("CA"))
                {
                    employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "CA", -1, "(All)", employeeId);

                    odsClient.SelectParameters.Add("countryId", "1");
                }
                else
                {
                    if (employeeType.Contains("US"))
                    {
                        employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "US", -1, "(All)", employeeId);

                        odsClient.SelectParameters.Add("countryId", "2");
                    }
                    else
                    {
                        employeeList.LoadByRequestProjectTimeEmployeeTypeEmployeeIdApproveManagerAndAddItem(1, "SOTA", -1, "(All)", employeeId);

                        odsClient.SelectParameters.Add("countryId", "-1");
                    }
                }

                odsClient.Select();
                ddlClient.SelectedIndex = 0;
                upnlClient.Update();

                ddlTeamMember.DataSource = employeeList.Table;
                ddlTeamMember.DataValueField = "EmployeeID";
                ddlTeamMember.DataTextField = "FullName";
                ddlTeamMember.DataBind();

                odsProject.SelectParameters.RemoveAt(2);
                odsProject.SelectParameters.Add("clientId", "-1");
                odsProject.Select();
                ddlProject.DataBind();
                ddlProject.SelectedIndex = 0;
                upnlProject.Update();

                projectTimeApproveTDS = this.SubmitSearch();

                // Store Datasets
                Session["projectTimeApproveTDS"] = projectTimeApproveTDS;
                projectTimeApprove = projectTimeApproveTDS.ProjectTimeApprove;
                Session["projectTimeApprove"] = projectTimeApproveTDS.ProjectTimeApprove;

                // If coming from
                // ... timesheet_edit.aspx, timesheet_summary.aspx or timesheet_delete.aspx
                if ((Request.QueryString["source_page"] == "timesheet_edit.aspx") || (Request.QueryString["source_page"] == "timesheet_summary.aspx") || (Request.QueryString["source_page"] == "timesheet_delete.aspx"))
                {
                    // ... restore top values
                    RestoreNavigatorState();

                    // ... filter grid information
                    //SetFilterByCountryIdClientIdProjectId();
                    //SetFilterByEmployeeIdDate();
                    SetFilterByClientIdProjectIdEmployeeIdDate();
                }

                ViewState["filter_expression"] = "Deleted = 0";

                SetFocus();
            }
            else
            {
                // Restore dataset
                projectTimeApproveTDS = (ProjectTimeApproveTDS)Session["projectTimeApproveTDS"];
                projectTimeApprove = projectTimeApproveTDS.ProjectTimeApprove;
                Session["projectTimeApprove"] = projectTimeApproveTDS.ProjectTimeApprove;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_FULL_EDITING"]))
                {
                    if (Request.QueryString["others"] == "no")
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                                }
                            }
                        }
                    }
                    else
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_VIEW"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]))
                            {
                                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT_WED"]))
                                {
                                    if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]))
                                    {
                                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                                        {
                                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                                            {
                                                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["others"] == null) && ((string)Request.QueryString["employee_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_all.aspx");
                }

                // Tag page
                Session.Remove("timesheetAllDummy");

                // Initialize  variables
                lblError.Visible = false;

                ViewState["others"] = Request.QueryString["others"];
                if ((string)ViewState["others"] == "yes")
                {
                    ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                }
                else
                {
                    EmployeeGateway employeeGateway1 = new EmployeeGateway(new DataSet());
                    ViewState["employee_id"] = employeeGateway1.GetEmployeIdByLoginId(Convert.ToInt32(Session["loginID"]));
                }
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();

                // Prepare initial data for client
                // ... Title
                if ((string)ViewState["others"] == "no")
                {
                    lblTitle.Text = "All My Timesheets";
                }
                else
                {
                    EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                    employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                    lblTitle.Text = "All Timesheets For " + employeeGateway.GetFullName((int)ViewState["employee_id"]);
                }

                // Load data
                timesheetAllTDS = this.SubmitSearch();
                Session["timesheetAllTDS"] = timesheetAllTDS;
                timesheetAll = timesheetAllTDS.TIMESHEET_ALL;
                Session["timesheetAll"] = timesheetAll;
            }
            else
            {
                // Restore dataset
                timesheetAllTDS = (TimesheetAllTDS)Session["timesheetAllTDS"];
                timesheetAll = timesheetAllTDS.TIMESHEET_ALL;
                Session["timesheetAll"] = timesheetAll;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_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)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in wucSRUnassigned.ascx");
                }

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

                int loginId = Convert.ToInt32(Session["loginID"]);
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                hdfEmployeeId.Value = employeeGateway.GetEmployeIdByLoginId(loginId).ToString();

                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardUnassignedServiceRequestsDummy");
                ArrayList arrayListWidgetData = (ArrayList)HttpContext.Current.Session["unassignedSRWidget"];

                // If coming from
                // ... Out
                if (Request.QueryString["source_page"] == "out")
                {
                    CompanyLevelsManagersGateway companyLevelsManagersGateway = new CompanyLevelsManagersGateway();

                    // ... For Grid
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    int employeeId = Convert.ToInt32(hdfEmployeeId.Value);
                    int companyLevelId = companyLevelsManagersGateway.GetCompanyLevelId(employeeId, companyId);

                    // ... For ddl working location
                    companyLevelsForSRUnassignedTDS = new CompanyLevelsTDS();

                    CompanyLevel companyLevel = new CompanyLevel(companyLevelsForSRUnassignedTDS);
                    companyLevel.LoadNodes(companyId);

                    GetNodeForCompanyLevel(1);

                    ddlWorkingLocation.Items.Insert(0, new ListItem("(All)", "0"));

                    if (HttpContext.Current.Session["unassignedSRWidget"] != null)
                    {
                        ddlWorkingLocation.SelectedIndex = Convert.ToInt32(arrayListWidgetData[0].ToString());
                        ddlType.SelectedIndex = Convert.ToInt32(arrayListWidgetData[1].ToString());

                        companyLevelId = Convert.ToInt32(ddlWorkingLocation.SelectedValue);
                    }
                    else
                    {
                        ddlWorkingLocation.SelectedValue = companyLevelId.ToString();
                    }

                    dashboardUnassignedServiceRequestsTDS = new DashboardTDS();
                    DashboardUnassignedServiceRequests model = new DashboardUnassignedServiceRequests(dashboardUnassignedServiceRequestsTDS);

                    // ... Load for admin
                    if (Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_SERVICES_ADMIN"]))
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByUnitType(companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServices(companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByCompanyLevelIdUnitType(companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServicesByCompanyLevelId(companyId, companyLevelId);
                            }
                        }
                    }
                    else
                    {
                        if (companyLevelId == 0)
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDUnitType(employeeId, companyId, ddlType.SelectedValue);
                            }
                            else
                            {
                                // ... Load for assigned employee
                                model.LoadAllUnassignedServicesByAssignTeamMemberID(employeeId, companyId);
                            }
                        }
                        else
                        {
                            if (ddlType.SelectedValue != "(All)")
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDCompanyLevelIdUnitType(employeeId, companyId, companyLevelId, ddlType.SelectedValue);
                            }
                            else
                            {
                                model.LoadAllUnassignedServicesByAssignTeamMemberIDCompanyLevelId(employeeId, companyId, companyLevelId);
                            }
                        }
                    }

                    model.UpdateForDashboard(companyId);

                    // ... Store datasets
                    HttpContext.Current.Session.Add("dashboardUnassignedServiceRequestsTDS", dashboardUnassignedServiceRequestsTDS);
                    HttpContext.Current.Session.Add("companyLevelsForSRUnassignedTDS", companyLevelsForSRUnassignedTDS);
                }
            }
            else
            {
                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardUnassignedServiceRequestsDummy");

                // Restore datasets
                dashboardUnassignedServiceRequestsTDS = (DashboardTDS)HttpContext.Current.Session["dashboardUnassignedServiceRequestsTDS"];
                companyLevelsForSRUnassignedTDS = (CompanyLevelsTDS)HttpContext.Current.Session["companyLevelsForSRUnassignedTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_VIEW"]) && Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_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)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in wucMyToDoList.ascx");
                }

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

                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardMyToDoListDataTableDummy");
                HttpContext.Current.Session.Remove("dashboardMyToDoListOnHoldDataTableDummy");
                ArrayList arrayListWidgetData = (ArrayList)HttpContext.Current.Session["myToDoListWidget"];
                ArrayList arrayListWidgetDataOnHold = (ArrayList)HttpContext.Current.Session["myToDoListOnHoldWidget"];

                // If coming from
                // ... Out
                if (Request.QueryString["source_page"] == "out")
                {
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                    int employeeId = employeeGateway.GetEmployeIdByLoginId(loginId);
                    string state = "%"; if (ddlStateMyToDo.SelectedValue != "(All)") state = ddlStateMyToDo.SelectedValue;

                    // ... For Grid
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    dashboardMyToDoListTDS = new DashboardTDS();
                    DashboardMyToDoList model = new DashboardMyToDoList(dashboardMyToDoListTDS);
                    DashboardMyToDoListOnHold modelOnHold = new DashboardMyToDoListOnHold(dashboardMyToDoListTDS);

                    if (HttpContext.Current.Session["myToDoListWidget"] != null)
                    {
                        ddlStateMyToDo.SelectedIndex = Convert.ToInt32(arrayListWidgetData[1].ToString());
                        if (ddlStateMyToDo.SelectedValue != "(All)") state = ddlStateMyToDo.SelectedValue;
                    }

                    // ... Load to do list
                    // ... ...Load for admin
                    if (!Convert.ToBoolean(Session["sgLFS_FLEETMANAGEMENT_TODOLIST_ADMIN"]))
                    {
                        // ... Load for assigned employee
                        model.LoadMyCurrentToDoListByCreatedByIdState(employeeId, state, companyId);
                        modelOnHold.LoadMyCurrentToDoListOnHoldByCreatedById(employeeId, companyId);
                    }
                    else
                    {
                        // ... ... Loads all  (current)
                        model.LoadCurrentToDoListByState(state, companyId);
                        modelOnHold.LoadCurrentToDoListOnHold(companyId);
                    }

                    // ... Store datasets
                    HttpContext.Current.Session.Add("dashboardMyToDoListTDS", dashboardMyToDoListTDS);
                }
            }
            else
            {
                // Prepare initial data
                HttpContext.Current.Session.Remove("dashboardMyToDoListDataTableDummy");
                HttpContext.Current.Session.Remove("dashboardMyToDoListOnHoldDataTableDummy");

                // Restore dataset
                dashboardMyToDoListTDS = (DashboardTDS)HttpContext.Current.Session["dashboardMyToDoListTDS"];
            }
        }