// ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadAllByProjectId
 /// </summary>
 /// <param name="projectId">projectId</param>              
 public void LoadAllByProjectId(int projectId)
 {
     ProjectNavigatorProjectJobInfoGateway projectNavigatorProjectJobInfoGateway = new ProjectNavigatorProjectJobInfoGateway(Data);
     projectNavigatorProjectJobInfoGateway.LoadAllByProjectId(projectId);
 }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();

                // Prepare initial data
                Session.Remove("projectNotesDummy");
                Session.Remove("projectServicesDummy");
                Session.Remove("projectTypeOfWorkFunctionClassificationDummy");
                Session.Remove("projectJobClassClassificationDummy");
                Session.Remove("projectBudgetDummy");
                Session.Remove("subcontractorsBudgetDummy");
                Session.Remove("hotelsBudgetDummy");
                Session.Remove("bondingsBudgetDummy");
                Session.Remove("insurancesBudgetDummy");
                Session.Remove("otherCostsBudgetDummy");

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

                // If coming from projects2.aspx or project_add.aspx
                if (Request.QueryString["source_page"] == "projects2.aspx" || Request.QueryString["source_page"] == "project_add.aspx")
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = "no";

                    // Get Project ID
                    int projectId = int.Parse(hdfProjectId.Value);

                    // Get dataset
                    projectTDS = new ProjectTDS();
                    projectNavigatorTDS = new ProjectNavigatorTDS();
                    projectNotes = new ProjectNavigatorTDS.ProjectNotesDataTable();
                    projectServices = new ProjectNavigatorTDS.ProjectServiceDataTable();
                    projectTypeOfWorkFunctionClassification = new ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable();
                    projectJobClassClassification = new ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable();
                    projectBudget = new ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable();
                    unitsBudget = new ProjectNavigatorTDS.ProjectUnitsBudgetDataTable();
                    materialsBudget = new ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable();
                    subcontractorsBudget = new ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable();
                    hotelsBudget = new ProjectNavigatorTDS.ProjectHotelsBudgetDataTable();
                    bondingsBudget = new ProjectNavigatorTDS.ProjectBondingsBudgetDataTable();
                    insurancesBudget = new ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable();
                    otherCostsBudget = new ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable();

                    // Get General Data
                    ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS);
                    projectGatewayForLoad.LoadByProjectId(projectId);

                    // Get Job info
                    ProjectNavigatorProjectJobInfoGateway projectNavigatorProjectJobInfoGateway = new ProjectNavigatorProjectJobInfoGateway(projectNavigatorTDS);
                    projectNavigatorProjectJobInfoGateway.LoadAllByProjectId(projectId);

                    // Get Sale/Billing/Pricing
                    ProjectSaleBillingPricingGateway projectSaleBillingPricingGatewayForLoad = new ProjectSaleBillingPricingGateway(projectTDS);
                    projectSaleBillingPricingGatewayForLoad.LoadAllByProjectId(projectId);

                    // ... Get Sale/Billing/Pricing - Services
                    ProjectNavigatorProjectService projectNavigatorProjectService = new ProjectNavigatorProjectService(projectNavigatorTDS);
                    projectNavigatorProjectService.LoadAllByProjectId(projectId);
                    projectNavigatorProjectService.UpdateForLoad();

                    // Get Costing Updates
                    ProjectCostingUpdatesGateway projectCostingUpdatesGatewayForLoad = new ProjectCostingUpdatesGateway(projectTDS);
                    projectCostingUpdatesGatewayForLoad.LoadByProjectId(projectId);

                    // Get Project Terms
                    ProjectTermsPOGateway projectTermsPOGatewayForLoad = new ProjectTermsPOGateway(projectTDS);
                    projectTermsPOGatewayForLoad.LoadByProjectId(projectId);

                    // Get Technical
                    ProjectTechnicalGateway projectTechnicalGatewayForLoad = new ProjectTechnicalGateway(projectTDS);
                    projectTechnicalGatewayForLoad.LoadByProjectId(projectId);

                    // Get Engineer Subcontractors
                    ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGatewayForLoad = new ProjectEngineerSubcontractorsGateway(projectTDS);
                    projectEngineerSubcontractorsGatewayForLoad.LoadAllByProjectId(projectId);

                    // ... Get Subcontractors
                    ProjectSubcontractorGateway projectSubcontractorGatewayForLoad = new ProjectSubcontractorGateway(projectTDS);
                    projectSubcontractorGatewayForLoad.LoadAllByProjectId(projectId);

                    // Cost Exceptions
                    // ... Get Type Of Work & Function Classification
                    ProjectNavigatorProjectWorkFunctionFairWage projectNavigatorProjectWorkFunctionFairWage = new ProjectNavigatorProjectWorkFunctionFairWage(projectNavigatorTDS);
                    projectNavigatorProjectWorkFunctionFairWage.LoadAllByProjectId(projectId);

                    // ... Get Job Class Classification
                    ProjectNavigatorProjectJobClassTypeRate projectNavigatorProjectJobClassTypeRate = new ProjectNavigatorProjectJobClassTypeRate(projectNavigatorTDS);
                    projectNavigatorProjectJobClassTypeRate.LoadAllByProjectId(projectId);

                    // Get Budget
                    ProjectNavigatorProjectWorkFunctionBudget projectNavigatorProjectWorkFunctionBudget = new ProjectNavigatorProjectWorkFunctionBudget(projectNavigatorTDS);
                    projectNavigatorProjectWorkFunctionBudget.LoadAllByProjectId(projectId);

                    // Get Units Budget
                    ProjectNavigatorProjectUnitsBudget projectNavigatorProjectUnitsBudget = new ProjectNavigatorProjectUnitsBudget(projectNavigatorTDS);
                    projectNavigatorProjectUnitsBudget.LoadAllByProjectId(projectId);

                    // Get Materials Budget
                    ProjectNavigatorProjectMaterialsBudget projectNavigatorProjectMaterialsBudget = new ProjectNavigatorProjectMaterialsBudget(projectNavigatorTDS);
                    projectNavigatorProjectMaterialsBudget.LoadAllByProjectId(projectId);

                    // Get Subcontractors Budget
                    ProjectNavigatorProjectSubcontractorsBudget projectNavigatorProjectSubcontractorsBudget = new ProjectNavigatorProjectSubcontractorsBudget(projectNavigatorTDS);
                    projectNavigatorProjectSubcontractorsBudget.LoadAllByProjectId(projectId);

                    // Get Hotels Budget
                    ProjectNavigatorProjectHotelsBudget projectNavigatorProjectHotelsBudget = new ProjectNavigatorProjectHotelsBudget(projectNavigatorTDS);
                    projectNavigatorProjectHotelsBudget.LoadAllByProjectId(projectId);

                    // Get Bondings Budget
                    ProjectNavigatorProjectBondingsBudget projectNavigatorProjectBondingsBudget = new ProjectNavigatorProjectBondingsBudget(projectNavigatorTDS);
                    projectNavigatorProjectBondingsBudget.LoadAllByProjectId(projectId);

                    // Get Insurances Budget
                    ProjectNavigatorProjectInsurancesBudget projectNavigatorProjectInsurancesBudget = new ProjectNavigatorProjectInsurancesBudget(projectNavigatorTDS);
                    projectNavigatorProjectInsurancesBudget.LoadAllByProjectId(projectId);

                    // Get Other Costs Budget
                    ProjectNavigatorProjectOtherCostsBudget projectNavigatorProjectOtherCostsBudget = new ProjectNavigatorProjectOtherCostsBudget(projectNavigatorTDS);
                    projectNavigatorProjectOtherCostsBudget.LoadAllByProjectId(projectId);

                    // Get Notes
                    ProjectNavigatorProjectNotesGateway projectNavigatorProjectNotesGateway = new ProjectNavigatorProjectNotesGateway(projectNavigatorTDS);
                    projectNavigatorProjectNotesGateway.LoadAllByProjectId(projectId);

                    // Store dataset
                    Session["lfsProjectTDS"] = projectTDS;
                    Session["projectNavigatorTDS"] = projectNavigatorTDS;
                    Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                    Session["projectServices"] = projectNavigatorTDS.ProjectService;
                    Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                    Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                    Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;
                    Session["unitsBudget"] = projectNavigatorTDS.ProjectUnitsBudget;
                    Session["materialsBudget"] = projectNavigatorTDS.ProjectMaterialsBudget;
                    Session["subcontractorsBudget"] = projectNavigatorTDS.ProjectSubcontractorsBudget;
                    Session["hotelsBudget"] = projectNavigatorTDS.ProjectHotelsBudget;
                    Session["bondingsBudget"] = projectNavigatorTDS.ProjectBondingsBudget;
                    Session["insurancesBudget"] = projectNavigatorTDS.ProjectInsurancesBudget;
                    Session["otherCostsBudget"] = projectNavigatorTDS.ProjectOtherCostsBudget;

                    projectNotes = projectNavigatorTDS.ProjectNotes;
                    projectServices = projectNavigatorTDS.ProjectService;
                    projectTypeOfWorkFunctionClassification = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                    projectJobClassClassification = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                    projectBudget = projectNavigatorTDS.ProjectWorkFunctionBudget;
                    unitsBudget = projectNavigatorTDS.ProjectUnitsBudget;
                    materialsBudget = projectNavigatorTDS.ProjectMaterialsBudget;
                    hotelsBudget = projectNavigatorTDS.ProjectHotelsBudget;
                    bondingsBudget = projectNavigatorTDS.ProjectBondingsBudget;
                    insurancesBudget = projectNavigatorTDS.ProjectInsurancesBudget;
                    otherCostsBudget = projectNavigatorTDS.ProjectOtherCostsBudget;
                }

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

                // ... left menu, project_edit.aspx, project_delete.aspx or project_state.aspx
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_delete.aspx") || (Request.QueryString["source_page"] == "project_state.aspx"))
                {
                    // Get Project ID
                    int projectId = int.Parse(hdfProjectId.Value);

                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Restore dataset
                    projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                    projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];

                    Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                    Session["projectServices"] = projectNavigatorTDS.ProjectService;

                    // Cost Exceptions
                    // ... Get Type Of Work & Function Classification
                    ProjectNavigatorProjectWorkFunctionFairWage projectNavigatorProjectWorkFunctionFairWage = new ProjectNavigatorProjectWorkFunctionFairWage(projectNavigatorTDS);
                    projectNavigatorProjectWorkFunctionFairWage.LoadAllByProjectId(projectId);

                    Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                    Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;

                    //  ... Get budget
                    ProjectNavigatorProjectWorkFunctionBudget projectNavigatorProjectWorkFunctionBudget = new ProjectNavigatorProjectWorkFunctionBudget(projectNavigatorTDS);
                    projectNavigatorProjectWorkFunctionBudget.LoadAllByProjectId(projectId);

                    Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;

                    projectNotes = projectNavigatorTDS.ProjectNotes;
                    projectServices = projectNavigatorTDS.ProjectService;
                    projectTypeOfWorkFunctionClassification = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                    projectJobClassClassification = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                    projectBudget = projectNavigatorTDS.ProjectWorkFunctionBudget;
                    unitsBudget = projectNavigatorTDS.ProjectUnitsBudget;
                    materialsBudget = projectNavigatorTDS.ProjectMaterialsBudget;
                    hotelsBudget = projectNavigatorTDS.ProjectHotelsBudget;
                    bondingsBudget = projectNavigatorTDS.ProjectBondingsBudget;
                    insurancesBudget = projectNavigatorTDS.ProjectInsurancesBudget;
                    otherCostsBudget = projectNavigatorTDS.ProjectOtherCostsBudget;
                }

                // ... Data for current project
                ProjectGateway projectGateway = new ProjectGateway(projectTDS);

                // ... for project
                int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString());
                string name = projectGateway.GetName(currentProjectId);
                if (name.Length > 23) name = name.Substring(0, 20) + "...";
                lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")";

                // ... for client
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                // Load Data
                LoadData();

                // Store Dataset
                Session["lfsProjectTDS"] = projectTDS;
                Session["projectNavigatorTDS"] = projectNavigatorTDS;
                Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                Session["projectServices"] = projectNavigatorTDS.ProjectService;
                Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;
                Session["unitsBudget"] = projectNavigatorTDS.ProjectUnitsBudget;
                Session["materialsBudget"] = projectNavigatorTDS.ProjectMaterialsBudget;
                Session["subcontractorsBudget"] = projectNavigatorTDS.ProjectSubcontractorsBudget;
                Session["hotelsBudget"] = projectNavigatorTDS.ProjectHotelsBudget;
                Session["bondingsBudget"] = projectNavigatorTDS.ProjectBondingsBudget;
                Session["insurancesBudget"] = projectNavigatorTDS.ProjectInsurancesBudget;
                Session["otherCostsBudget"] = projectNavigatorTDS.ProjectOtherCostsBudget;

                projectNotes = projectNavigatorTDS.ProjectNotes;
                projectServices = projectNavigatorTDS.ProjectService;
                projectTypeOfWorkFunctionClassification = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                projectJobClassClassification = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                projectBudget = projectNavigatorTDS.ProjectWorkFunctionBudget;
                unitsBudget = projectNavigatorTDS.ProjectUnitsBudget;
                materialsBudget = projectNavigatorTDS.ProjectMaterialsBudget;
                hotelsBudget = projectNavigatorTDS.ProjectHotelsBudget;
                bondingsBudget = projectNavigatorTDS.ProjectBondingsBudget;
                insurancesBudget = projectNavigatorTDS.ProjectInsurancesBudget;
                otherCostsBudget = projectNavigatorTDS.ProjectOtherCostsBudget;

                // ... For total cost at services
                //ProjectNavigatorProjectService projectNavigatorProjectServiceForCost = new ProjectNavigatorProjectService(projectNavigatorTDS);
                //tbxTotalCost.Text = Decimal.Round(projectNavigatorProjectServiceForCost.GetTotalCost(), 2).ToString();
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];

                Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                Session["projectServices"] = projectNavigatorTDS.ProjectService;
                Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;
                Session["unitsBudget"] = projectNavigatorTDS.ProjectUnitsBudget;
                Session["materialsBudget"] = projectNavigatorTDS.ProjectMaterialsBudget;
                Session["subcontractorsBudget"] = projectNavigatorTDS.ProjectSubcontractorsBudget;
                Session["hotelsBudget"] = projectNavigatorTDS.ProjectHotelsBudget;
                Session["bondingsBudget"] = projectNavigatorTDS.ProjectBondingsBudget;
                Session["insurancesBudget"] = projectNavigatorTDS.ProjectInsurancesBudget;
                Session["otherCostsBudget"] = projectNavigatorTDS.ProjectOtherCostsBudget;

                projectNotes = projectNavigatorTDS.ProjectNotes;
                projectServices = projectNavigatorTDS.ProjectService;
                projectTypeOfWorkFunctionClassification = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                projectJobClassClassification = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                projectBudget = projectNavigatorTDS.ProjectWorkFunctionBudget;
                unitsBudget = projectNavigatorTDS.ProjectUnitsBudget;
                materialsBudget = projectNavigatorTDS.ProjectMaterialsBudget;
                hotelsBudget = projectNavigatorTDS.ProjectHotelsBudget;
                bondingsBudget = projectNavigatorTDS.ProjectBondingsBudget;
                insurancesBudget = projectNavigatorTDS.ProjectInsurancesBudget;
                otherCostsBudget = projectNavigatorTDS.ProjectOtherCostsBudget;

                // Grid Subcontractors
                //grdvSubcontractors.DataSource = projectTDS.LFS_PROJECT_SUBCONTRACTOR;
                //grdvSubcontractors.DataBind();
            }
        }