// ////////////////////////////////////////////////////////////////////////
        // METHODS
        //
        public ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable GetProjectTime()
        {
            projectTimeTemp = (ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable)Session["projectTimeTempNewDummy"];
            if (projectTimeTemp == null)
            {
                projectTimeTemp = ((ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable)Session["projectTimeTemp"]);
            }

            return projectTimeTemp;
        }
        protected void AddProjectTimeNewEmptyFix(GridView grdProjectTime)
        {
            if (grdProjectTime.Rows.Count == 0)
            {
                ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable dt = new ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable();
                dt.AddLFS_PROJECT_TIME_TEMPRow(-1, -1, -1, -1, DateTime.Now, "", "", -1, -1, "", "", -1, "", -1, -1,-1, "", "", false, "", "", "", false, false, "");
                Session["projectTimeTempNewDummy"] = dt;

                grdProjectTime.DataBind();
            }

            // normally executes at all postbacks
            if (grdProjectTime.Rows.Count == 1)
            {
                ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable dt = (ProjectTimeTDS.LFS_PROJECT_TIME_TEMPDataTable)Session["projectTimeTempNewDummy"];
                if (dt != null)
                {
                    grdProjectTime.Rows[0].Visible = false;
                    grdProjectTime.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((string)Request.QueryString["others"] == null) && ((string)Request.QueryString["employee_id"] == null) && ((string)Request.QueryString["period_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_add.aspx");
                }

                // 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"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"])))
                        {
                            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"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_ADD"])))
                        {
                            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"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_ADD"])))
                                    {
                                        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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Tag Page
                hdfSaveClick.Value = "false";
                hdfEmployeeID.Value = Request.QueryString["employee_id"].ToString();
                hdfPeriodId.Value = Request.QueryString["period_id"];
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfIsMoreThan15.Value = "false";
                hdfIsMoreThan15Edit.Value = "false";
                Session.Remove("projectTimeTempNewDummy");

                // Initialize viewstate variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["timesheetState"] = "For Approval";

                // Get State
                int employeeId = Int32.Parse(hdfEmployeeID.Value);
                int periodId = Int32.Parse(hdfPeriodId.Value);

                TimesheetGateway timesheet = new TimesheetGateway();
                timesheet.LoadByEmployeeIdPayPeriodId(employeeId, periodId);
                if (timesheet.Table.Rows.Count != 0)
                {
                    ViewState["timesheetState"] = timesheet.GetStateByEmployeeIdPayPeriodId(employeeId, periodId);
                }

                if (Request.QueryString["source_page"] == "timesheet_summary.aspx" || Request.QueryString["source_page"] == "timesheet_summary_from_approve_project_times.aspx")
                {
                    ViewState["projecttime_id"] = int.Parse(Request.QueryString["projecttime_id"]);
                }

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

                // Timesheet state check
                if (((string)ViewState["LHMode"] == "Full") && (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"])))
                {
                    TimesheetGateway timesheetGateway = new TimesheetGateway();
                    timesheetGateway.LoadByEmployeeIdPayPeriodId(employeeId, periodId);

                    if ((timesheetGateway.Table.Rows.Count != 0) && (timesheetGateway.GetStateByEmployeeIdPayPeriodId(employeeId, periodId) != "Rejected"))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You cannot add project time to an approved or submitted timesheet.");
                    }
                }

                // Prepare initial data for client
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId(employeeId);
                tbxEmployee.Text = employeeGateway.GetFullName(employeeId);

                tbxState.Text = "For Approval";

                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesList companiesList = new CompaniesList(new DataSet());
                companiesList.LoadAndAddItem(-1, "(Select a client)", companyId);
                ddlClient.DataSource = companiesList.Table;
                ddlClient.DataValueField = "COMPANIES_ID";
                ddlClient.DataTextField = "Name";
                ddlClient.DataBind();
                ddlClient.SelectedIndex = 0;

                ProjectList projectList = new ProjectList();
                projectList.LoadActiveProjectsActiveInternalProjectsActiveBallparkProjectsAndAddItem(-1, "(Select a project)", -1);
                ddlProject.DataSource = projectList.Table;
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataTextField = "Name";
                ddlProject.DataBind();
                ddlProject.SelectedIndex = 0;

                CountryList countryList = new CountryList(new DataSet());
                countryList.LoadAndAddItem(-1, " ");
                ddlMealsCountry.DataSource = countryList.Table;
                ddlMealsCountry.DataValueField = "CountryID";
                ddlMealsCountry.DataTextField = "Name";
                ddlMealsCountry.DataBind();

                tkrdpStartDate.SelectedDate = DateTime.Now;
                tkrdpEndDate.SelectedDate = DateTime.Now;

                // Store timesheet dataset
                projectTimeTDS = new ProjectTimeTDS();
                Session["projectTimeTDS"] = projectTimeTDS;
                projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
                Session["projectTimeTemp"] = projectTimeTDS.LFS_PROJECT_TIME_TEMP;
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
                projectTimeTemp = projectTimeTDS.LFS_PROJECT_TIME_TEMP;

                // Store datasets
                Session["projectTimeTemp"] = projectTimeTemp;
            }
        }