// ////////////////////////////////////////////////////////////////////////
        // 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;
            }
        }
 /// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new TimesheetNavigatorTDS();
 }