public void SendMailForCompletedToDo()
        {
            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "A to do list was completed.";
            string body = "";

            // MailtTo, nameTo
            int createdBy = Int32.Parse(hdfCreatedById.Value);
            EmployeeGateway  employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(createdBy);

            mailTo = employeeGateway.GetEMail(createdBy);
            nameTo = employeeGateway.GetFullName(createdBy);

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following to do list was completed. \n";
            body = body + "\n Subject: "+ lblTitleSubjectName.Text;
            body = body + "\n Created By: " + tbxCreatedBy.Text;
            body = body + "\n Creation Date: " + tbxCreationDate.Text;
            body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
            body = body + "\n Unit / Equipment: " + tbxUnit.Text;

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        public void SendMailForNewTicket()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            // Get mail information
            string mailTo = "";
            string nameTo = "";
            string subject = "A support ticket was created.";
            string body = "";

            // MailtTo, nameTo
            int createdBy = Int32.Parse(hdfTeamMemberId.Value);
            EmployeeGateway employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(createdBy);

            mailTo = employeeGateway.GetEMail(createdBy);
            nameTo = employeeGateway.GetFullName(createdBy);

            // Mails body
            body = body + "\nHi " + nameTo + ",\n\nThe following support ticket was created. \n";
            body = body + "\n Subject: " + hdfSubject.Value;
            body = body + "\n Comment: " + hdfComments.Value;
            body = body + "\n Created By: " + employeeGateway.GetFullName(createdBy);

            if (hdfDueDate.Value != "")
            {
                DateTime dueDate = DateTime.Parse(hdfDueDate.Value);
                string dueDateText = dueDate.Month.ToString() + "/" + dueDate.Day.ToString() + "/" + dueDate.Year.ToString();
                body = body + "\n Due Date: " + dueDateText;
            }

            int categoryId = Int32.Parse(hdfCategoriesSelected.Value);
            SupportTicketCategoryGateway supportTicketCategoryGateway = new SupportTicketCategoryGateway();
            supportTicketCategoryGateway.LoadByCategoryId(categoryId, companyId);
            body = body + "\n Category: " + supportTicketCategoryGateway.GetName(categoryId);

            //int assignTeamMemberId = Int32.Parse(hdfTeamMemberId.Value);
            //EmployeeGateway employeeGatewayForAssignment = new EmployeeGateway();
            //employeeGatewayForAssignment.LoadByEmployeeId(assignTeamMemberId);

            //body = body + "\n Assigned team member: " + employeeGatewayForAssignment.GetFullName(assignTeamMemberId) + "\n";

            body = body + "\n Assigned team member: Anzovino Dan \n";

            //Send Mail
            SendMail(mailTo, subject, body);
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfCurrentEmployeeId.Value = Request.QueryString["employee_id"];
                hdfActiveTab.Value = Request.QueryString["active_tab"];

                // ... for team member title
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int employeeId = Int32.Parse(hdfCurrentEmployeeId.Value);

                EmployeeInformationTDS employeeInformationTDS = new EmployeeInformationTDS();

                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(employeeId);
                lblTitleTeamMember.Text = "Team Member: " + employeeGateway.GetFullName(employeeId);

                // If coming from
                // ... employees_navigator2.aspx
                if (Request.QueryString["source_page"] == "employees_navigator2.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = "no";
                }

                // ... employees_summary.aspx
                if (Request.QueryString["source_page"] == "employees_summary.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                }

                // Restore dataset
                employeeNavigatorTDS = (EmployeeNavigatorTDS)Session["employeeNavigatorTDS"];
            }
            else
            {
                // Restore dataset
                employeeNavigatorTDS = (EmployeeNavigatorTDS)Session["employeeNavigatorTDS"];
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            string employeeType = (ddlEmployeeType.SelectedValue == "(All)") ? "%" : ddlEmployeeType.SelectedValue + "%";
            string projectTimeState = (ddlProjectTimeState.SelectedValue == "(All)") ? "%" : ddlProjectTimeState.SelectedValue;
            DateTime startDate = DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString());
            DateTime endDate = DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString());

            PrintMealsGateway printMealsGateway = new PrintMealsGateway();
            if (ddlEmployee.SelectedValue == "-1")
            {
                if (ddlSalaried.SelectedValue == "(All)")
                {
                    printMealsGateway.LoadByEmployeeTypeStartDateEndDateProjectTimeState(employeeType, startDate, endDate, projectTimeState);
                }
                else
                {
                    printMealsGateway.LoadByEmployeeSalariedTypeStartDateEndDateProjectTimeState(employeeType, startDate, endDate, projectTimeState, int.Parse(ddlSalaried.SelectedValue));
                }
            }
            else
            {
                if (ddlSalaried.SelectedValue == "(All)")
                {
                    printMealsGateway.LoadByEmployeeTypeStartDateEndDateEmployeeIdProjectTimeState(employeeType, startDate, endDate, int.Parse(ddlEmployee.SelectedValue), projectTimeState);
                }
                else
                {
                    printMealsGateway.LoadByEmployeeTypeSalariedEmployeeIdStartDateEndDateProjectTimeState(employeeType, startDate, endDate, int.Parse(ddlEmployee.SelectedValue), projectTimeState, int.Parse(ddlSalaried.SelectedValue));
                }
            }

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

            // Get report
            if (printMealsGateway.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintMealsReport();
                }
                else
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintMealsReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    // ... For report
                    // ... ... project time state
                    if (ddlProjectTimeState.SelectedValue == "(All)")
                    {
                        master.SetParameter("projectTimeState", "All");
                    }
                    else
                    {
                        master.SetParameter("projectTimeState", ddlProjectTimeState.SelectedItem.Text);
                    }

                    // ... ... team member
                    if (ddlEmployee.SelectedValue == "-1")
                    {
                        master.SetParameter("teamMember", "All");
                    }
                    else
                    {
                        int teamMemberId = Int32.Parse(ddlEmployee.SelectedValue);
                        EmployeeGateway employeeGateway = new EmployeeGateway();
                        employeeGateway.LoadByEmployeeId(teamMemberId);
                        string fullName = employeeGateway.GetFullName(teamMemberId);

                        master.SetParameter("teamMember", fullName);
                    }

                    // ... ... team member type
                    if (ddlEmployeeType.SelectedValue == "(All)")
                    {
                        master.SetParameter("teamMemberType", "All");
                    }
                    else
                    {
                        if (ddlEmployeeType.SelectedValue == "LFSCA") master.SetParameter("teamMemberType", "LFS Canada");
                        if (ddlEmployeeType.SelectedValue == "LFSUS") master.SetParameter("teamMemberType", "LFS USA");
                        if (ddlEmployeeType.SelectedValue == "LFS") master.SetParameter("teamMemberType", "All LFS");
                        if (ddlEmployeeType.SelectedValue == "PAGCA") master.SetParameter("teamMemberType", "PAG Canada");
                        if (ddlEmployeeType.SelectedValue == "PAGUS") master.SetParameter("teamMemberType", "PAG USA");
                        if (ddlEmployeeType.SelectedValue == "PAG") master.SetParameter("teamMemberType", "All PAG");
                        if (ddlEmployeeType.SelectedValue == "SOTA") master.SetParameter("teamMemberType", "SOTA");
                        if (ddlEmployeeType.SelectedValue == "Salaried") master.SetParameter("teamMemberType", "Salaried");
                        if (ddlEmployeeType.SelectedValue == "Subcontractor") master.SetParameter("teamMemberType", "Subcontractor");
                    }

                    // ... ...  user
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    int companyId = Convert.ToInt32(Session["companyID"]);

                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());

                    // ... ... salaried
                    if (ddlSalaried.SelectedValue == "(All)")
                    {
                        master.SetParameter("salaried", "All");
                    }
                    else
                    {
                        if (ddlSalaried.SelectedValue == "1")  master.SetParameter("salaried", "Yes");
                        if (ddlSalaried.SelectedValue == "0") master.SetParameter("salaried", "No");
                    }
                    master.SetParameter("dateFrom", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                    master.SetParameter("dateTo", tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                }
                else
                {
                    master.SetParameter("dateFrom", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                    master.SetParameter("dateTo", tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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)
            {
                // 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;
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            string orderBy = ddlOrderBy.SelectedValue;
            string whereClause = "(P.Deleted = 0) AND (P.ProjectType = 'Ballpark') AND (P.ProjectState = 'Active')";

            if (ddlCountry.SelectedValue != "(All)")
            {
                if (whereClause.Length > 0) whereClause += " AND ";
                whereClause += "(P.CountryID = " + ddlCountry.SelectedValue + ")";
            }

            if (ddlClient.SelectedValue != "-1")
            {
                if (whereClause.Length > 0) whereClause += " AND ";
                whereClause += "(P.ClientID = " + ddlClient.SelectedValue + ")";
            }

            if (ddlSalesman.SelectedValue != "-1")
            {
                if (whereClause.Length > 0) whereClause += " AND ";
                whereClause += "(P.SalesmanID = " + ddlSalesman.SelectedValue + ")";
            }

            LiquiForce.LFSLive.BL.Projects.Projects.BallparkSummaryReport ballparkSummayReport = new LiquiForce.LFSLive.BL.Projects.Projects.BallparkSummaryReport();
            ballparkSummayReport.LoadWhereOrderBy(whereClause, orderBy, ddlCurrency.SelectedValue, decimal.Parse(tbxExchangeRate.Text));

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

            // Get report
            if (ballparkSummayReport.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.Projects.Projects.BallparkSummaryReport();
                }
                else
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.Projects.Projects.BallparkSummaryReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    // ... For report
                    master.SetParameter("ExchangeRate", decimal.Parse(tbxExchangeRate.Text.Trim()));
                    master.SetParameter("Total", "Total (" + ddlCurrency.SelectedValue.Trim() + "):");
                    master.SetParameter("Currency", ddlCurrency.SelectedValue.Trim());

                    // ... ...  user
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    int companyId = Convert.ToInt32(Session["companyID"]);

                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(loginId, companyId);
                    string user = loginGateway.GetLastName(loginId, companyId) + " " + loginGateway.GetFirstName(loginId, companyId);
                    master.SetParameter("User", user.Trim());

                    // ... ... client
                    if (ddlClient.SelectedValue == "-1")
                    {
                        master.SetParameter("Client", "All");
                    }
                    else
                    {
                        CompaniesGateway companiesGateway = new CompaniesGateway();
                        companiesGateway.LoadByCompaniesId(Int32.Parse(ddlClient.SelectedValue), companyId);
                        string clientName = companiesGateway.GetName(Int32.Parse(ddlClient.SelectedValue));
                        master.SetParameter("Client", clientName);
                    }

                    // ... ... salesman
                    if (ddlSalesman.SelectedValue == "-1")
                    {
                        master.SetParameter("Salesman", "All");
                    }
                    else
                    {
                        EmployeeGateway employeeGateway = new EmployeeGateway();
                        employeeGateway.LoadByEmployeeId(Int32.Parse(ddlSalesman.SelectedValue));
                        string salesman = employeeGateway.GetFullName(Int32.Parse(ddlSalesman.SelectedValue));
                        master.SetParameter("Salesman", salesman);
                    }

                    // ... ... country
                    if (ddlCountry.SelectedValue == "2")
                    {
                        master.SetParameter("Country", "USA");
                    }
                    else
                    {
                        if (ddlCountry.SelectedValue == "1")
                        {
                            master.SetParameter("Country", "Canada");
                        }
                        else
                        {
                            master.SetParameter("Country", "All");
                        }
                    }

                    // ... ... order by
                    if (ddlOrderBy.SelectedValue == "P.CountryID")
                    {
                        master.SetParameter("OrderBy", "Country");
                    }
                    else
                    {
                        if (ddlOrderBy.SelectedValue == "P.ProjectNumber")
                        {
                            master.SetParameter("OrderBy", "Project Number");
                        }
                        else
                        {
                            if (ddlOrderBy.SelectedValue == "P.Name")
                            {
                                master.SetParameter("OrderBy", "Project Name");
                            }
                            else
                            {
                                if (ddlOrderBy.SelectedValue == "C.Name")
                                {
                                    master.SetParameter("OrderBy", "Client");
                                }
                                else
                                {
                                    master.SetParameter("OrderBy", "Salesman");
                                }
                            }
                        }
                    }
                }
                else
                {
                    master.SetParameter("ExchangeRate", decimal.Parse(tbxExchangeRate.Text.Trim()));
                    master.SetParameter("Total", "Total (" + ddlCurrency.SelectedValue.Trim() + "):");
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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) && ((string)Request.QueryString["projecttime_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in timesheet_summary.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"]))
                        {
                            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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate's variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                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();

                // Get ProjectTime record
                projectTimeTDS =  new ProjectTimeTDS();

                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;

                // Databind
                tbxDate.DataBind();
                tbxWorkingDetails.DataBind();
                tbxStartTime.DataBind();
                tbxEndTime.DataBind();
                tbxLunch.DataBind();
                tbxComments.DataBind();
                tbxState.DataBind();

                // Prepare initial data for client
                StoreNavigatorState();

                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                tbxEmployee.Text = employeeGateway.GetFullName((int)ViewState["employee_id"]);

                int companyId = Int32.Parse(Session["companyID"].ToString());

                CompaniesGateway companiesGateway = new CompaniesGateway(new DataSet());
                companiesGateway.LoadAllByCompaniesId(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]), companyId);
                tbxClient.Text = companiesGateway.GetName(projectTimeGateway.GetCompaniesId((int)ViewState["projecttime_id"]));

                ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                projectGateway.LoadByProjectId(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));
                tbxProject.Text = projectGateway.GetName(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + "(" + projectGateway.GetProjectNumber(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])) + ")";

                if (projectGateway.GetFairWageApplies(projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"])))
                {
                    tbxJobClassType.Visible = true;
                    lblJobClassType.Visible = true;
                    tbxJobClassType.Text = projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]);
                }
                else
                {
                    tbxJobClassType.Visible = false;
                    lblJobClassType.Visible = false;
                }

                if (projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).HasValue)
                {
                    CountryGateway countryGateway = new CountryGateway(new DataSet());
                    countryGateway.LoadByCountryId((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                    tbxMealsCountry.Text = countryGateway.GetName((Int64)projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]));
                }

                //if (projectTimeGateway.GetMealsAllowance((int)ViewState["projecttime_id"]) > 0)
                //{
                //    cbxMealsAllowance.Checked = true;
                //}

                //if (projectTimeGateway.GetFairWage((int)ViewState["projecttime_id"]))
                //{
                //    cbxFairWage.Checked = true;
                //}

                if (projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxUnit.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]));
                }

                if (projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    UnitsGateway unitGateway = new UnitsGateway(new DataSet());
                    unitGateway.LoadByUnitId((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]), Convert.ToInt32(Session["companyID"]));
                    tbxTowed.Text = unitGateway.GetUnitCode((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]));
                }

                tbxTypeOfWork.Text = "";
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) != "")
                {
                    tbxTypeOfWork.Text = projectTimeGateway.GetWork((int)ViewState["projecttime_id"]);
                }

                tbxFunction.Text = "";
                if (projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]) != "")
                {
                    tbxFunction.Text = projectTimeGateway.GetFunction((int)ViewState["projecttime_id"]);
                }
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        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;
            }
        }
        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();
                }
            }
        }
        private void UpdateDatabase()
        {
            // Get ids
            int companyId = Int32.Parse(hdfCompanyId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // ... Update general todo list state
                SupportTicketInformationBasicInformation supportTicketInformationBasicInformation = new SupportTicketInformationBasicInformation(supportTicketInformationTDS);
                supportTicketInformationBasicInformation.Save(companyId);

                // ... Save to do list details
                SupportTicketInformationActivityInformation supportTicketInformationActivityInformation = new SupportTicketInformationActivityInformation(supportTicketInformationTDS);
                supportTicketInformationActivityInformation.Save(companyId);

                // ... Send mails
                int createdBy = Int32.Parse(hdfCreatedById.Value);
                string mailTo = "";
                string nameTo = "";

                // ... ... MailtTo, nameTo
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(createdBy);

                mailTo = employeeGateway.GetEMail(createdBy);
                nameTo = employeeGateway.GetFullName(createdBy);

                SupportTicketInformationActivityInformation supportTicketInformationActivityInformationForMails = new SupportTicketInformationActivityInformation(supportTicketInformationTDS);

                foreach (GridViewRow row in grdSupportTicket.Rows)
                {
                    bool sendMail = bool.Parse(((Label)row.FindControl("lblSendMail")).Text);

                    if (sendMail)
                    {
                        string subject = "";
                        string body = "";
                        string comment = "";

                        string type_ = ((Label)row.FindControl("lblType")).Text;
                        switch (type_)
                        {
                            case "AssignUser":
                                // Get mail information
                                subject = "A usser was assigned to the following ticket.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nA usser was assigned to the following ticket. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                string assignedUser = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

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

                            case "AssignToOwner":
                                // Get mail information
                                subject = "The following ticket was assigned to it's owner.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following ticket was assigned to it's owner. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Owner: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                string assignedOwer = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Assigned To Owner: " + assignedOwer;
                                body = body + "\n Due Date: " + tbxDueDate.Text;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

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

                            case "AddComment":
                                // Get mail information
                                subject = "A comment was added to the following ticket.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nA comment was added to the following ticket. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string commentAddedBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Comment added by: " + commentAddedBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

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

                            case "CloseTicket":
                                // Get mail information
                                subject = "A support ticket was completed.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following support ticket was completed. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string completedBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n Completed by: " + completedBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

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

                            case "OnHold":
                                // Get mail information
                                subject = "The following ticket was put on hold.";

                                // Mails body
                                body = body + "\nHi " + nameTo + ",\n\nThe following ticket was put on hold. \n";
                                body = body + "\n Subject: " + lblTitleSubjectName.Text;
                                body = body + "\n Created By: " + tbxCreatedBy.Text;
                                body = body + "\n Creation Date: " + tbxCreationDate.Text;
                                body = body + "\n Category: " + tbxCategoryName.Text;
                                body = body + "\n Assigned User: "******"\n Due Date: " + tbxDueDate.Text;
                                string onHoldBy = ((TextBox)row.FindControl("tbxUser")).Text;
                                body = body + "\n On hold by: " + onHoldBy;
                                comment = ((TextBox)row.FindControl("tbxComments")).Text;
                                body = body + "\n New comment: " + comment;

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

                DB.CommitTransaction();

                // Store datasets
                supportTicketInformationTDS.AcceptChanges();
                Session["supportTicketInformationTDS"] = supportTicketInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        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;
            }
        }
        private void LoadData(int supportTicketId)
        {
            SupportTicketInformationBasicInformationGateway supportTicketInformationBasicInformationGateway = new SupportTicketInformationBasicInformationGateway(supportTicketInformationTDS);
            if (supportTicketInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load to do Details
                int companyId = Int32.Parse(hdfCompanyId.Value);

                int createdById = supportTicketInformationBasicInformationGateway.GetCreatedByID(supportTicketId);
                hdfCreatedById.Value = createdById.ToString();
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(createdById);
                tbxCreatedBy.Text = employeeGateway.GetFullName(createdById);

                tbxCreationDate.Text = supportTicketInformationBasicInformationGateway.GetCreationDate(supportTicketId).ToString();
                tbxState.Text = supportTicketInformationBasicInformationGateway.GetState(supportTicketId);
                tbxCategoryName.Text = supportTicketInformationBasicInformationGateway.GetCategoryName(supportTicketId);

                if (supportTicketInformationBasicInformationGateway.GetDueDate(supportTicketId).HasValue)
                {
                    DateTime dueDateValue = (DateTime)supportTicketInformationBasicInformationGateway.GetDueDate(supportTicketId);
                    tbxDueDate.Text = dueDateValue.Month.ToString() + "/" + dueDateValue.Day.ToString() + "/" + dueDateValue.Year.ToString();
                }
            }
        }
        protected void ddlActionsNew_SelectedIndexChanged(object sender, EventArgs e)
        {
            GridViewRow row = grdSupportTicket.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 "Assign To Owner":
                    ((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";

                    int currentSupportTicketId = Int32.Parse(hdfSupportTicketId.Value.ToString());
                    SupportTicketInformationBasicInformationGateway supportTicketInformationBasicInformationGatewayForState = new SupportTicketInformationBasicInformationGateway(supportTicketInformationTDS);
                    int ownerId = supportTicketInformationBasicInformationGatewayForState.GetCreatedByID(currentSupportTicketId);
                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).SelectedValue = ownerId.ToString();
                    ((DropDownList)row.FindControl("ddlAssignToTeamMemberNew")).Enabled = false;
                    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 = "Support Ticket 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)
            {
                // 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_edit.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_EDIT"])))
                        {
                            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_EDIT"])))
                        {
                            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_EDIT"])))
                                    {
                                        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.");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Initialize viewstate variables
                ViewState["others"] = Request.QueryString["others"];
                ViewState["employee_id"] = int.Parse(Request.QueryString["employee_id"]);
                ViewState["period_id"] = int.Parse(Request.QueryString["period_id"]);
                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();
                hdfCompanyId.Value = Session["companyID"].ToString();

                // Get ProjectTime record
                ProjectTimeGateway projectTimeGateway = new ProjectTimeGateway(projectTimeTDS);
                projectTimeGateway.LoadByProjectTimeId((int)ViewState["projecttime_id"]);

                // Project time state check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (projectTimeGateway.GetProjectTimeState((int)ViewState["projecttime_id"]) == "Approved")
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You cannot edit an approved project time.");
                    }
                }

                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_MY_TIMESHEETS_MANAGEMENT"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                    {
                        bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

                        if (!isValidLimitPayPeriodToManagementEdit)
                        {
                            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_MANAGEMENT_WED"]) || Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                        {
                            bool isValidLimitPayPeriodToManagementEdit = LiquiForce.LFSLive.BL.LabourHours.ProjectTime.ProjectTime.ValidateLimitedPayPeriodToWednesdayManagementEdit(projectTimeGateway.GetDate_((int)ViewState["projecttime_id"]), projectTimeGateway.GetProjectId((int)ViewState["projecttime_id"]));

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

                // Store datasets
                Session["projectTimeTDS"] = projectTimeTDS;

                // Databind
                tkrdpDate_.DataBind();
                ddlLunch.DataBind();
                tbxComments.DataBind();
                tbxState.DataBind();

                // Prepare initial data for client
                StoreNavigatorState();

                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                employeeGateway.LoadByEmployeeId((int)ViewState["employee_id"]);
                tbxEmployee.Text = employeeGateway.GetFullName(int.Parse(Request.QueryString["employee_id"]));

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

                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(Int32.Parse(DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString()), companyId);

                // ... If Company is active
                bool deleted = companiesGateway.GetDeleted(Int32.Parse(DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString()));

                if (deleted)
                {
                    ddlClient.SelectedIndex = -1;
                }
                else
                {
                    ddlClient.SelectedValue = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].CompaniesID").ToString();
                }

                ProjectList projectList = new ProjectList();
                projectList.LoadProjectsInternalProjectsBallparkProjectsAndAddItem(-1, "(Select a project)", int.Parse(ddlClient.SelectedValue));
                ddlProject.DataSource = projectList.Table;
                ddlProject.DataValueField = "ProjectID";
                ddlProject.DataTextField = "Name";
                ddlProject.DataBind();

                if (!deleted)
                {
                    try
                    {
                        ddlProject.SelectedValue = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].ProjectID").ToString();
                    }
                    catch
                    {
                        ddlProject.SelectedIndex = -1;
                    }
                }
                else
                {
                    ddlProject.SelectedIndex = -1;
                }

                if (ddlProject.SelectedIndex != 0)
                {
                    ProjectGateway projectGateway = new ProjectGateway();
                    projectGateway.LoadByProjectId(Int32.Parse(ddlProject.SelectedValue));

                    if (projectGateway.GetCountryID(Int32.Parse(ddlProject.SelectedValue)) == 1) //Canada
                    {
                        if (projectGateway.GetFairWageApplies(int.Parse(ddlProject.SelectedValue)))
                        {
                            ddlJobClassType.Visible = true;
                            lblJobClassType.Visible = true;

                            ProjectTimeJobClassTypeList projectTimeJobClassTypeList = new ProjectTimeJobClassTypeList();
                            projectTimeJobClassTypeList.LoadAndAddItem(1, companyId, "(Select a Job Class Type)");
                            ddlJobClassType.DataSource = projectTimeJobClassTypeList.Table;
                            ddlJobClassType.DataValueField = "JobClassType";
                            ddlJobClassType.DataTextField = "JobClassType";
                            ddlJobClassType.DataBind();

                            if (projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]).ToString() == "")
                            {
                                ddlJobClassType.SelectedIndex = 0;
                            }
                            else
                            {
                                ddlJobClassType.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].JobClassType");
                            }
                        }
                        else
                        {
                            ddlJobClassType.Visible = false;
                            lblJobClassType.Visible = false;
                        }
                    }
                    else
                    {
                        if (projectGateway.GetFairWageApplies(int.Parse(ddlProject.SelectedValue)))
                        {
                            ddlJobClassType.Visible = true;
                            lblJobClassType.Visible = true;

                            ProjectTimeJobClassTypeList projectTimeJobClassTypeList = new ProjectTimeJobClassTypeList();
                            projectTimeJobClassTypeList.LoadAndAddItem(2, companyId, "(Select a Job Class Type)");
                            ddlJobClassType.DataSource = projectTimeJobClassTypeList.Table;
                            ddlJobClassType.DataValueField = "JobClassType";
                            ddlJobClassType.DataTextField = "JobClassType";
                            ddlJobClassType.DataBind();

                            if (projectTimeGateway.GetJobClassType((int)ViewState["projecttime_id"]).ToString() == "")
                            {
                                ddlJobClassType.SelectedIndex = 0;
                            }
                            else
                            {
                                ddlJobClassType.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].JobClassType");
                            }
                        }
                        else
                        {
                            ddlJobClassType.Visible = false;
                            lblJobClassType.Visible = false;
                        }
                    }
                }
                else
                {
                    ddlJobClassType.Visible = false;
                    lblJobClassType.Visible = false;
                }

                WorkingDetailsGateway workingDetailsGateway = new WorkingDetailsGateway(new DataSet());
                workingDetailsGateway.Load();
                ddlWorkingDetails.DataSource = workingDetailsGateway.Table;
                ddlWorkingDetails.DataValueField = "WorkingDetails";
                ddlWorkingDetails.DataTextField = "WorkingDetails";
                ddlWorkingDetails.DataBind();

                if (!deleted)
                {
                    ddlWorkingDetails.SelectedValue = projectTimeGateway.GetWorkingDetails((int)ViewState["projecttime_id"]);
                }
                else
                {
                    ddlWorkingDetails.SelectedIndex = -1;
                }

                ProjectTimeWorkList projectTimeWorkList = new ProjectTimeWorkList(new DataSet());

                int projectId = 0;
                try
                {
                    projectId = Int32.Parse(ddlProject.SelectedValue);
                }
                catch
                {
                }

                if (projectId == 35 || projectId == 39 || projectId == 716)
                {
                    projectTimeWorkList.LoadAndAddItem("");
                }
                else
                {
                    projectTimeWorkList.LoadAndAddItem("(Select a Type)");
                }

                // Setting start time, end time
                string startTime = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].StartTime", "{0:H:mm}").ToString();
                if (!String.IsNullOrEmpty(startTime))
                {
                    string[] hoursMin1 = startTime.Split(':');
                    ddlStartTimeHour.SelectedValue = hoursMin1[0].Trim();
                    ddlStartTimeMinute.SelectedValue = hoursMin1[1].Trim();
                }
                else
                {
                    ddlStartTimeHour.SelectedIndex = 0;
                    ddlStartTimeMinute.SelectedIndex = 0;
                }

                string endTime = DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].EndTime", "{0:H:mm}").ToString();
                if (!String.IsNullOrEmpty(endTime))
                {
                    string[] endHoursMin1 = endTime.Split(':');
                    ddlEndTimeHour.SelectedValue = endHoursMin1[0].Trim();
                    ddlEndTimeMinute.SelectedValue = endHoursMin1[1].Trim();
                }
                else
                {
                    ddlEndTimeHour.SelectedIndex = 0;
                    ddlEndTimeMinute.SelectedIndex = 0;
                }

                // Setting type of Work
                ddlTypeOfWork.DataSource = projectTimeWorkList.Table;
                ddlTypeOfWork.DataValueField = "Work_";
                ddlTypeOfWork.DataTextField = "Work_";
                ddlTypeOfWork.DataBind();
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) == "") ddlTypeOfWork.SelectedIndex = -1; else ddlTypeOfWork.SelectedValue = projectTimeGateway.GetWork((int)ViewState["projecttime_id"]);

                ProjectTimeWorkFunctionList projectTimeWorkFunctionList = new ProjectTimeWorkFunctionList(new DataSet());
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]) == "")
                {
                    // ... If there is no type of Work, no function should be loaded
                    projectTimeWorkFunctionList.LoadAndAddItem("", "-1");
                }
                else
                {
                    projectTimeWorkFunctionList.LoadAndAddItem("(Select a Function)", projectTimeGateway.GetWork((int)ViewState["projecttime_id"]).ToString());
                }
                ddlFunction.DataSource = projectTimeWorkFunctionList.Table;
                ddlFunction.DataValueField = "Function_";
                ddlFunction.DataTextField = "Function_";
                ddlFunction.DataBind();
                if (projectTimeGateway.GetWork((int)ViewState["projecttime_id"]).ToString() == "")
                {
                    ddlFunction.SelectedValue = "";
                }
                else
                {
                    ddlFunction.SelectedValue = (string)DataBinder.Eval(projectTimeTDS, "Tables[LFS_PROJECT_TIME].DefaultView.[0].Function_");
                }

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

                if (!deleted)
                {
                    if (projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).HasValue)
                    {
                        ddlMealsCountry.SelectedValue = projectTimeGateway.GetMealsCountry((int)ViewState["projecttime_id"]).ToString();
                    }
                    else
                    {
                        ddlMealsCountry.SelectedValue = "-1";
                    }
                }
                else
                {
                    ddlMealsCountry.SelectedIndex = -1;
                }

                //if (projectTimeGateway.GetMealsAllowance((int)ViewState["projecttime_id"]) > 0)
                //{
                //    cbxMealsAllowance.Checked = true;
                //}

                string unitType = "Vehicle";
                UnitsList unitsList = new UnitsList(new DataSet());
                unitsList.LoadAndAddItem("-1", " ", Int32.Parse(Session["companyID"].ToString()), true, 0, unitType);
                ddlUnit.DataSource = unitsList.Table;
                ddlUnit.DataValueField = "UnitID";
                ddlUnit.DataTextField = "UnitCode";
                ddlUnit.DataBind();
                if (projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    ddlUnit.SelectedValue = ((int)projectTimeGateway.GetUnitId((int)ViewState["projecttime_id"])).ToString();
                }

                UnitsList towed = new UnitsList(new DataSet());
                towed.LoadAndAddItem("-1", " ", Int32.Parse(Session["companyID"].ToString()), true, 1, unitType);
                ddlTowed.DataSource = towed.Table;
                ddlTowed.DataValueField = "UnitID";
                ddlTowed.DataTextField = "UnitCode";
                ddlTowed.DataBind();
                if (projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"]).HasValue)
                {
                    ddlTowed.SelectedValue = ((int)projectTimeGateway.GetTowedUnitId((int)ViewState["projecttime_id"])).ToString();
                }
            }
            else
            {
                // Restore datasets
                projectTimeTDS = (ProjectTimeTDS)Session["projectTimeTDS"];
            }
        }
        private void LoadGeneralData()
        {
            // Data for General Data
            tbxProjectNumber.DataBind();
            tbxName.DataBind();
            tbxProposalDate.DataBind();
            tbxStartDate.DataBind();
            tbxEndDate.DataBind();
            tbxDescription.DataBind();
            cbxFairWageApplies.DataBind();

            // ... for geographical location
            hdfCountryId.DataBind();
            if (hdfCountryId.Value != "")
            {
                CountryGateway countryGateway = new CountryGateway();
                countryGateway.LoadByCountryId(Int64.Parse(hdfCountryId.Value));
                tbxCountry.Text = countryGateway.GetName(Int64.Parse(hdfCountryId.Value));
            }
            else
            {
                tbxCountry.Text = "";
            }

            hdfProvinceStateId.DataBind();
            if (hdfProvinceStateId.Value != "")
            {
                ProvinceGateway provinceGateway = new ProvinceGateway();
                provinceGateway.LoadByProvinceId(Int64.Parse(hdfProvinceStateId.Value));
                tbxProvinceState.Text = provinceGateway.GetName(Int64.Parse(hdfProvinceStateId.Value));
            }
            else
            {
                tbxProvinceState.Text = "";
            }

            hdfCountyId.DataBind();
            if (hdfCountyId.Value != "")
            {
                CountyGateway countyGateway = new CountyGateway();
                countyGateway.LoadByCountyId(Int64.Parse(hdfCountyId.Value));
                tbxCounty.Text = countyGateway.GetName(Int64.Parse(hdfCountyId.Value));
            }
            else
            {
                tbxCounty.Text = "";
            }

            hdfCityId.DataBind();
            if (hdfCityId.Value != "")
            {
                CityGateway cityGateway = new CityGateway();
                cityGateway.LoadByCityId(Int64.Parse(hdfCityId.Value));
                tbxCity.Text = cityGateway.GetName(Int64.Parse(hdfCityId.Value));
            }
            else
            {
                tbxCity.Text = "";
            }

            // ... for project
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));

            // ... for client
            int companyId = Int32.Parse(hdfCompanyId.Value);
            CompaniesGateway companiesGateway = new CompaniesGateway();
            companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);

            tbxClientName.Text = companiesGateway.GetName(currentCompanyId);
            hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString();
            tbxClientProjectNumber.DataBind();

            // ... ... for primary contact
            if (projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                hdfClientPrimaryContactID.Value = ((int)projectGateway.GetClientPrimaryContactID(int.Parse(hdfProjectId.Value))).ToString();
                ContactsGateway contactsGatewayForPrimaryContact = new ContactsGateway();
                contactsGatewayForPrimaryContact.LoadAllByContactId(int.Parse(hdfClientPrimaryContactID.Value), companyId);
                tbxClientPrimaryContact.Text = contactsGatewayForPrimaryContact.GetCompleteName(int.Parse(hdfClientPrimaryContactID.Value));
            }

            // ... ... for secondary contact
            if (projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                hdfClientSecondaryContactID.Value = ((int)projectGateway.GetClientSecondaryContactID(int.Parse(hdfProjectId.Value))).ToString();
                ContactsGateway contactsGatewayForSecondaryContact = new ContactsGateway();
                contactsGatewayForSecondaryContact.LoadAllByContactId(int.Parse(hdfClientSecondaryContactID.Value), companyId);
                tbxClientSecondaryContact.Text = contactsGatewayForSecondaryContact.GetCompleteName(int.Parse(hdfClientSecondaryContactID.Value));
            }

            // ... for resources
            // ... ... for project lead
            if (projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)).HasValue)
            {
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId((int)projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)));
                tbxProjectLead.Text = employeeGateway.GetFullName((int)projectGateway.GetProjectLeadID(int.Parse(hdfProjectId.Value)));
            }

            // ... ... for salesman
            SalesmanGateway salesmanGateway = new SalesmanGateway();
            salesmanGateway.LoadExpandedBySalesmanId(projectGateway.GetSalesmanID(int.Parse(hdfProjectId.Value)));
            tbxSalesman.Text = salesmanGateway.GetFullName(projectGateway.GetSalesmanID(int.Parse(hdfProjectId.Value)));

            // ... ... for Pricing
            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
            {
                ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(projectTDS);

                if (projectSaleBillingPricingGateway.Table.Rows.Count > 0)
                {
                    if (projectSaleBillingPricingGateway.GetBillPrice(int.Parse(hdfProjectId.Value)).HasValue) tbxBillPrice.Text = ((decimal)projectSaleBillingPricingGateway.GetBillPrice(int.Parse(hdfProjectId.Value))).ToString("n2");
                    tbxBillMoney.Text = projectSaleBillingPricingGateway.GetBillMoney(int.Parse(hdfProjectId.Value));
                }
                else
                {
                    if (projectGateway.GetCountryID(int.Parse(hdfProjectId.Value)) == 1)
                    {
                        tbxBillMoney.Text = "CAD";
                    }
                    else
                    {
                        tbxBillMoney.Text = "USD";
                    }
                }
            }

            // Data for unit budget tab
            ProjectNavigatorProjectUnitsBudgetGateway projectNavigatorProjectUnitsBudgetGateway = new ProjectNavigatorProjectUnitsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectUnitsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxUnitsBudget.Text = projectNavigatorProjectUnitsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for materials budget tab
            ProjectNavigatorProjectMaterialsBudgetGateway projectNavigatorProjectMaterialsBudgetGateway = new ProjectNavigatorProjectMaterialsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectMaterialsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxMaterialsBudget.Text = projectNavigatorProjectMaterialsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value)).ToString("n2");
            }

            // Data for subcontractors budget tab
            ProjectNavigatorProjectSubcontractorsBudgetGateway projectNavigatorProjectSubcontractorsBudgetGateway = new ProjectNavigatorProjectSubcontractorsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectSubcontractorsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxSubcontractorsBudget.Text = projectNavigatorProjectSubcontractorsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for hotels budget tab
            ProjectNavigatorProjectHotelsBudgetGateway projectNavigatorProjectHotelsBudgetGateway = new ProjectNavigatorProjectHotelsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectHotelsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxHotelsBudget.Text = projectNavigatorProjectHotelsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for bondings budget tab
            ProjectNavigatorProjectBondingsBudgetGateway projectNavigatorProjectBondingsBudgetGateway = new ProjectNavigatorProjectBondingsBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectBondingsBudgetGateway.Table.Rows.Count > 0)
            {
                tbxBondingsBudget.Text = projectNavigatorProjectBondingsBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            // Data for insurances budget tab
            ProjectNavigatorProjectInsurancesBudgetGateway projectNavigatorProjectInsurancesBudgetGateway = new ProjectNavigatorProjectInsurancesBudgetGateway(projectNavigatorTDS);

            if (projectNavigatorProjectInsurancesBudgetGateway.Table.Rows.Count > 0)
            {
                tbxInsurancesBudget.Text = projectNavigatorProjectInsurancesBudgetGateway.GetBudget(int.Parse(hdfProjectId.Value), 1, 1).ToString("n2");
            }

            CalculateTotalBudget();
        }
        // ////////////////////////////////////////////////////////////////////////
        // FINAL EVENTS
        //
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set wizard title
            int employeeId = Int32.Parse(hdfEmployeeId.Value);

            //... Employee
            EmployeeGateway employeeGateway = new EmployeeGateway();
            employeeGateway.LoadByEmployeeId(employeeId);

            Label title = (Label)this.Master.FindControl("lblTitle");
            title.Text = "Add Or Remove Role For " + employeeGateway.GetFullName(employeeId);
        }
        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 bool StepBeginNext()
        {
            Page.Validate("Begin");
            if (Page.IsValid)
            {
                // Tag values
                hdfSubject.Value = tbxSubject.Text.Trim();
                hdfComments.Value = tbxComment.Text.Trim();
                hdfDueDate.Value = tkrdpDueDate.SelectedDate.ToString();

                // Assign Dan Anzovino
                int loginId = 115;
                EmployeeGateway employeeGateway = new EmployeeGateway(new DataSet());
                hdfTeamMemberId.Value = employeeGateway.GetEmployeIdByLoginId(loginId).ToString();
                int employeeId = Int32.Parse(hdfTeamMemberId.Value);
                hdfTeamMemberFullName.Value = employeeGateway.GetFullName(employeeId).ToString();

                //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();
                //    int employeeId = Int32.Parse(hdfTeamMemberId.Value);
                //    hdfTeamMemberFullName.Value = employeeGateway.GetFullName(employeeId).ToString();
                //}

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

                foreach (int categoriesId in arrayCategoriesSelectedForAdd)
                {
                    hdfCategoriesSelected.Value = categoriesId.ToString();
                }

                return true;
            }
            return false;
        }
        private void LoadData(int toDoId)
        {
            ToDoListInformationBasicInformationGateway toDoListInformationBasicInformationGateway = new ToDoListInformationBasicInformationGateway(toDoListInformationTDS);
            if (toDoListInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load to do Details
                int companyId = Int32.Parse(hdfCompanyId.Value);

                int createdById = toDoListInformationBasicInformationGateway.GetCreatedByID(toDoId);
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(createdById);
                tbxCreatedBy.Text = employeeGateway.GetFullName(createdById);

                tbxCreationDate.Text = toDoListInformationBasicInformationGateway.GetCreationDate(toDoId).ToString();
                tbxState.Text = toDoListInformationBasicInformationGateway.GetState(toDoId);

                if (toDoListInformationBasicInformationGateway.GetDueDate(toDoId).HasValue)
                {
                    tkrdpDueDate.SelectedDate = (DateTime)toDoListInformationBasicInformationGateway.GetDueDate(toDoId);
                }

                int? unitId = toDoListInformationBasicInformationGateway.GetUnitID(toDoId);

                if (unitId.HasValue)
                {
                    ddlUnit.SelectedValue = unitId.ToString();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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;
            }
        }
        private void LoadData(int toDoId)
        {
            ToDoListInformationBasicInformationGateway toDoListInformationBasicInformationGateway = new ToDoListInformationBasicInformationGateway(toDoListInformationTDS);
            if (toDoListInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load to do Details
                int companyId = Int32.Parse(hdfCompanyId.Value);

                int createdById = toDoListInformationBasicInformationGateway.GetCreatedByID(toDoId);
                hdfCreatedById.Value = createdById.ToString();
                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(createdById);
                tbxCreatedBy.Text = employeeGateway.GetFullName(createdById);

                tbxCreationDate.Text = toDoListInformationBasicInformationGateway.GetCreationDate(toDoId).ToString();
                tbxState.Text = toDoListInformationBasicInformationGateway.GetState(toDoId);

                if (toDoListInformationBasicInformationGateway.GetDueDate(toDoId).HasValue)
                {
                    DateTime dueDateValue = (DateTime)toDoListInformationBasicInformationGateway.GetDueDate(toDoId);
                    tbxDueDate.Text = dueDateValue.Month.ToString() + "/" + dueDateValue.Day.ToString() + "/" + dueDateValue.Year.ToString();
                }

                int? unitId = toDoListInformationBasicInformationGateway.GetUnitID(toDoId);
                tbxUnit.Text = "";
                if (unitId.HasValue)
                {
                    UnitsGateway unitsGateway = new UnitsGateway();
                    unitsGateway.LoadByUnitId((int)unitId, companyId);
                    tbxUnit.Text = unitsGateway.GetUnitCode((int)unitId) + " " + unitsGateway.GetDescription((int)unitId);
                }
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;

            // Get Data
            string projectTimeState = (ddlProjectTimeState.SelectedValue == "(All)") ? "%" : ddlProjectTimeState.SelectedValue;

            PrintEmployeeLocationGateway printEmployeeLocationGateway = new PrintEmployeeLocationGateway();
            if (ddlEmployee.SelectedValue == "-1")
            {
                if (tbxLocation.Text.Trim() == "yes")
                {
                    printEmployeeLocationGateway.LoadByStartDateEndDateProjectTimeState(DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString()), DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString()), projectTimeState);
                }
                else
                {
                    printEmployeeLocationGateway.LoadByStartDateEndDateLocationProjectTimeState(DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString()), DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString()), tbxLocation.Text.Trim(), projectTimeState);
                }
            }
            else
            {
                if (tbxLocation.Text.Trim() == "yes")
                {
                    printEmployeeLocationGateway.LoadByStartDateEndDateEmployeeIdProjectTimeState(DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString()), DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString()), Int32.Parse(ddlEmployee.SelectedValue), projectTimeState);
                }
                else
                {
                    printEmployeeLocationGateway.LoadByStartDateEndDateEmployeeIdLocationProjectTimeState(DateTime.Parse(tkrdpStartDate.SelectedDate.Value.ToShortDateString()), DateTime.Parse(tkrdpEndDate.SelectedDate.Value.ToShortDateString()), int.Parse(ddlEmployee.SelectedValue), tbxLocation.Text.Trim(), projectTimeState);
                }
            }

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

            // Get report
            if (printEmployeeLocationGateway.Table.Rows.Count > 0)
            {
                if (master.Format == "pdf")
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintEmployeeLocationReport();
                }
                else
                {
                    master.Report = new LiquiForce.LFSLive.WebUI.LabourHours.ProjectTime.PrintEmployeeLocationReportExport();
                }

                // ... set parameters to report
                if (master.Format == "pdf")
                {
                    // ... For report
                    // ... ... project time state
                    if (ddlProjectTimeState.SelectedValue == "(All)")
                    {
                        master.SetParameter("projectTimeState", "All");
                    }
                    else
                    {
                        master.SetParameter("projectTimeState", ddlProjectTimeState.SelectedItem.Text);
                    }

                    // ... ... team member
                    if (ddlEmployee.SelectedValue == "-1")
                    {
                        master.SetParameter("teamMember", "All");
                    }
                    else
                    {
                        int teamMemberId = Int32.Parse(ddlEmployee.SelectedValue);
                        EmployeeGateway employeeGateway = new EmployeeGateway();
                        employeeGateway.LoadByEmployeeId(teamMemberId);
                        string fullName = employeeGateway.GetFullName(teamMemberId);

                        master.SetParameter("teamMember", fullName);
                    }

                    // ... ...  user
                    int loginId = Convert.ToInt32(Session["loginID"]);
                    int companyId = Convert.ToInt32(Session["companyID"]);

                    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("location", tbxLocation.Text.Trim());
                    master.SetParameter("startTime", tkrdpStartDate.SelectedDate.Value.ToShortDateString());
                    master.SetParameter("endTime", tkrdpEndDate.SelectedDate.Value.ToShortDateString());
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_RESOURCES_EMPLOYEES_VIEW"]) && Convert.ToBoolean(Session["sgLFS_RESOURCES_EMPLOYEES_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["employee_id"] == null) || ((string)Request.QueryString["active_tab"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in employees_summary.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfResourceType.Value = "Employees";
                hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfCurrentEmployeeId.Value = Request.QueryString["employee_id"];

                // Prepare initial data
                Session.Remove("employeesNotesDummy");
                Session.Remove("employeesCostsDummy");
                Session.Remove("employeesCostsExceptionsDummy");
                Session.Remove("employeesVacationsDummy");
                Session.Remove("costIdSelected");

                // ... for team member title
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int employeeId = Int32.Parse(hdfCurrentEmployeeId.Value);

                EmployeeGateway employeeGateway = new EmployeeGateway();
                employeeGateway.LoadByEmployeeId(employeeId);
                lblTitleTeamMember.Text = "Team Member: " + employeeGateway.GetFullName(employeeId);

                // If coming from
                // ... employees_navigator2.aspx, employees_add.aspx
                if ((Request.QueryString["source_page"] == "employees_navigator2.aspx") || (Request.QueryString["source_page"] == "employees_add.aspx"))
                {
                    StoreNavigatorState();
                    ViewState["update"] = "yes";

                    // ... ... Set initial tab
                    if ((string)Session["dialogOpenedEmployees"] != "1")
                    {
                        hdfActiveTab.Value = Request.QueryString["active_tab"];

                        employeeInformationTDS = new EmployeeInformationTDS();

                        EmployeeInformationBasicInformation employeeInformationBasicInformation = new EmployeeInformationBasicInformation(employeeInformationTDS);
                        employeeInformationBasicInformation.LoadByEmployeeId(employeeId, companyId);

                        EmployeeInformationCostInformation employeeInformationCostInformation = new EmployeeInformationCostInformation(employeeInformationTDS);
                        employeeInformationCostInformation.LoadAllByEmployeeId(employeeId, companyId);

                        EmployeeInformationCostExceptionsInformation employeeInformationCostExceptionsInformation = new EmployeeInformationCostExceptionsInformation(employeeInformationTDS);
                        employeeInformationCostExceptionsInformation.LoadAllByEmployeeId(employeeId, companyId);

                        Session["costIdSelected"] = 0;

                        EmployeeInformationNoteInformation employeeInformationNoteInformationForEdit = new EmployeeInformationNoteInformation(employeeInformationTDS);
                        employeeInformationNoteInformationForEdit.LoadAllByEmployeeId(employeeId, companyId);

                        EmployeeInformationCategoryApproveTimesheetsInformation employeeInformationCategoryApproveTimesheetsInformation = new EmployeeInformationCategoryApproveTimesheetsInformation(employeeInformationTDS);
                        employeeInformationCategoryApproveTimesheetsInformation.LoadByEmployeeId(employeeId);
                    }
                    else
                    {
                        hdfActiveTab.Value = (string)Session["activeTabEmployees"];

                        // Restore datasets
                        employeeInformationTDS = (EmployeeInformationTDS)Session["employeeInformationTDS"];
                    }

                    tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);

                    // Store dataset
                    Session["employeeInformationTDS"] = employeeInformationTDS;
                }

                // ... employees_delete.aspx or employees_edit.aspx
                if ((Request.QueryString["source_page"] == "employees_delete.aspx") || (Request.QueryString["source_page"] == "employees_edit.aspx"))
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Restore dataset
                    employeeInformationTDS = (EmployeeInformationTDS)Session["employeeInformationTDS"];

                    // ... Set initial tab
                    if ((string)Session["dialogOpenedEmployees"] != "1")
                    {
                        hdfActiveTab.Value = Request.QueryString["active_tab"];
                    }
                    else
                    {
                        hdfActiveTab.Value = (string)Session["activeTabEmployees"];
                    }

                    tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);
                }

                string filterOptions = string.Format("CostID = {0} AND Deleted = {1}", 0, 0);
                odsCostsExceptions.FilterExpression = filterOptions;

                // Prepare initial data
                // ... Data for current employee
                LoadData();

                // Databind
                Page.DataBind();
            }
            else
            {
                // Restore datasets
                employeeInformationTDS = (EmployeeInformationTDS)Session["employeeInformationTDS"];

                // Set initial tab
                int activeTab = Int32.Parse(hdfActiveTab.Value);
                tcDetailedInformation.ActiveTabIndex = activeTab;
            }
        }
        private bool StepBeginNext()
        {
            Page.Validate("Begin");
            if (Page.IsValid)
            {
                // Tag values
                hdfSubject.Value = tbxSubject.Text.Trim();
                hdfComments.Value = tbxComment.Text.Trim();
                hdfDueDate.Value = tkrdpDueDate.SelectedDate.ToString();
                hdfUnitId.Value = ddlUnit.SelectedValue;
                hdfUnitCode.Value = ddlUnit.SelectedItem.Text;

                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();
                    int employeeId = Int32.Parse(hdfTeamMemberId.Value);
                    hdfTeamMemberFullName.Value = employeeGateway.GetFullName(employeeId).ToString();
                }

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

                return true;
            }
            return false;
        }