// ////////////////////////////////////////////////////////////////////////
        // 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"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_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["project_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_edit.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfDataChanged.Value = Request.QueryString["data_changed"];
                hdfDataChangedMessage.Value = "Changes made to this project will not be saved.";

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

                Session["fairWage"] = "None";

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

                // ... For Library
                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }

                // 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, Update control and Origin
                    StoreNavigatorState();
                    ViewState["update"] = "no";
                    ViewState["origin"] = "navigator";

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

                    // ... Attachment control
                    if (Session["fromAttachment"] != null)
                    {
                        if (Session["fromAttachment"].ToString() == "yes")
                        {
                            // Restore dataset
                            projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                            projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                            projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];
                            projectServices = (ProjectNavigatorTDS.ProjectServiceDataTable)Session["projectServices"];
                            projectJobClassClassification = (ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable)Session["projectJobClassClassification"];
                            projectTypeOfWorkFunctionClassification = (ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable)Session["projectTypeOfWorkFunctionClassification"];
                            projectBudget = (ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable)Session["projectBudget"];
                            unitsBudget = (ProjectNavigatorTDS.ProjectUnitsBudgetDataTable)Session["unitsBudget"];
                            materialsBudget = (ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable)Session["materialsBudget"];
                            subcontractorsBudget = (ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable)Session["subcontractorsBudget"];
                            hotelsBudget = (ProjectNavigatorTDS.ProjectHotelsBudgetDataTable)Session["hotelsBudget"];
                            bondingsBudget = (ProjectNavigatorTDS.ProjectBondingsBudgetDataTable)Session["bondingsBudget"];
                            insurancesBudget = (ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable)Session["insurancesBudget"];
                            otherCostsBudget = (ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable)Session["otherCostsBudget"];
                        }

                        Session.Remove("fromAttachment");
                    }
                    else
                    {
                        // 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
                        ProjectJobInfoGateway projectJobInfoGateway = new ProjectJobInfoGateway(projectNavigatorTDS);
                        projectJobInfoGateway.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
                        ProjectNavigatorProjectNotes projectNavigatorProjectNotes = new ProjectNavigatorProjectNotes(projectNavigatorTDS);
                        projectNavigatorProjectNotes.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;
                    }

                    //grdNotes.DataBind();
                    //grdServices.DataBind();
                    grdTypeOfWorkFunctionClassification.DataBind();
                    grdJobClassClassification.DataBind();
                    grdBudget.DataBind();
                    /*grdSubcontractorsBudget.DataBind();
                    grdHotelsBudget.DataBind();
                    grdBondingsBudget.DataBind();
                    grdInsurancesBudget.DataBind();*/
                    grdOtherCostsBudget.DataBind();
                }

                // ... project_summary.aspx or project_edit.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "lm"))
                {
                    // Store Navigator State, update control and origin
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                    ViewState["origin"] = Request.QueryString["origin"]; //summary

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

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

                    if (ViewState["update"].ToString().Trim() == "yes")
                    {
                        // Get General Data
                        ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS);
                        projectGatewayForLoad.LoadByProjectId(projectId);

                        // Get job info
                        ProjectJobInfoGateway projectJobInfoGateway = new ProjectJobInfoGateway(projectNavigatorTDS);
                        projectJobInfoGateway.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
                        ProjectNavigatorProjectNotes projectNavigatorProjectNotes = new ProjectNavigatorProjectNotes(projectNavigatorTDS);
                        projectNavigatorProjectNotes.LoadAllByProjectId(projectId);

                        //grdNotes.DataBind();
                        //grdServices.DataBind();
                        grdTypeOfWorkFunctionClassification.DataBind();
                        grdJobClassClassification.DataBind();
                        grdBudget.DataBind();
                        /*grdSubcontractorsBudget.DataBind();
                        grdHotelsBudget.DataBind();
                        grdBondingsBudget.DataBind();
                        grdInsurancesBudget.DataBind();*/
                        grdOtherCostsBudget.DataBind();

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

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

                //// ... 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"];
                projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];
                projectServices = (ProjectNavigatorTDS.ProjectServiceDataTable)Session["projectServices"];
                projectJobClassClassification = (ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable)Session["projectJobClassClassification"];
                projectTypeOfWorkFunctionClassification = (ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable)Session["projectTypeOfWorkFunctionClassification"];
                projectBudget = (ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable)Session["projectBudget"];
                unitsBudget = (ProjectNavigatorTDS.ProjectUnitsBudgetDataTable)Session["unitsBudget"];
                materialsBudget = (ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable)Session["materialsBudget"];
                subcontractorsBudget = (ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable)Session["subcontractorsBudget"];
                hotelsBudget = (ProjectNavigatorTDS.ProjectHotelsBudgetDataTable)Session["hotelsBudget"];
                bondingsBudget = (ProjectNavigatorTDS.ProjectBondingsBudgetDataTable)Session["bondingsBudget"];
                insurancesBudget = (ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable)Session["insurancesBudget"];
                otherCostsBudget = (ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable)Session["otherCostsBudget"];

                tbxProjectNumber.DataBind();

                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }
            }
        }
        private void LoadTermsPo()
        {
            // Data for Terms/PO tab

            // ... Value for Vehicle Access
            //TermsRelationshipVehicleAccess termsRelationshipVehicleAccess = new TermsRelationshipVehicleAccess(new DataSet());
            //termsRelationshipVehicleAccess.LoadAndAddItem(" ");
            //ddlVehicleAccess.DataSource = termsRelationshipVehicleAccess.Table;
            //ddlVehicleAccess.DataValueField = "RelationshipVehicleAccess";
            //ddlVehicleAccess.DataTextField = "RelationshipVehicleAccess";
            //ddlVehicleAccess.DataBind();
            //ddlVehicleAccess.SelectedValue = "";

            // ... Data for Terms/PO
            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(projectTDS);

            if (projectTDS.LFS_PROJECT_TERMS.Rows.Count == 0)
            {
                // ... If the project has no Terms/PO
                ProjectTermsPO projectTermsPO = new ProjectTermsPO(projectTDS);
                projectTermsPO.Insert(int.Parse(hdfProjectId.Value), false, 0.00M, null, false, null, false, null, null, null, false, null, false, false, null, null, null, null, null, null, false, null, Int32.Parse(hdfCompanyId.Value.Trim()), false, false, false);
            }
            else
            {
                // ... If the project has Terms/PO
                // ... Liquidated Damage
                //cbxLiquidatedDamages.Checked = projectTermsPOGateway.GetLiquidatedDamage(int.Parse(hdfProjectId.Value));
                //if (projectTermsPOGateway.GetLiquidatedRate(int.Parse(hdfProjectId.Value)).HasValue) tbxLiquidatedDamagesRate.Text = (Decimal.Round((decimal)projectTermsPOGateway.GetLiquidatedRate(int.Parse(hdfProjectId.Value)), 2)).ToString(); else tbxLiquidatedDamagesRate.Text = "";
                //tbxLiquidatedDamagesUnit.Text = projectTermsPOGateway.GetLiquidatedUnit(int.Parse(hdfProjectId.Value));

                // ... Client LFS Relationship
                //cbxWorkedBefore.Checked = projectTermsPOGateway.GetRelationshipClientWorkedBefore(int.Parse(hdfProjectId.Value));
                //tbxClientQuirks.Text = projectTermsPOGateway.GetRelationshipClientQuirks(int.Parse(hdfProjectId.Value));
                //cbxClientPromises.Checked = projectTermsPOGateway.GetRelationshipClientPromises(int.Parse(hdfProjectId.Value));
                //tbxClientPromises.Text = projectTermsPOGateway.GetRelationshipClientPromisesNotes(int.Parse(hdfProjectId.Value));
                //tbxWaterObtain.Text = projectTermsPOGateway.GetRelationshipWaterObtain(int.Parse(hdfProjectId.Value));
                //tbxMaterialDispose.Text = projectTermsPOGateway.GetRelationshipMaterialDispose(int.Parse(hdfProjectId.Value));
                //cbxRequireRPZ.Checked = projectTermsPOGateway.GetRelationshipRequireRPZ(int.Parse(hdfProjectId.Value));
                //tbxStandardHydrantFitting.Text = projectTermsPOGateway.GetRelationshipStandardHydrantFitting(int.Parse(hdfProjectId.Value));
                //cbxPreConstructionMeetingNeed.Checked = projectTermsPOGateway.GetRelationshipPreConstructionMeeting(int.Parse(hdfProjectId.Value));
                //cbxSpecificMeetingLocation.Checked = projectTermsPOGateway.GetRelationshipSpecificMeetingLocation(int.Parse(hdfProjectId.Value));
                //tbxSpecificMeetingLocation.Text = projectTermsPOGateway.GetRelationshipSpecificMeetingLocationNotes(int.Parse(hdfProjectId.Value));
                //ddlVehicleAccess.SelectedValue = projectTermsPOGateway.GetRelationshipVehicleAccess(int.Parse(hdfProjectId.Value));
                //tbxVehicleAccess.Text = projectTermsPOGateway.GetRelationshipVehicleAccessNotes(int.Parse(hdfProjectId.Value));
                tbxDesireOutcomeOfProject.Text = projectTermsPOGateway.GetRelationshipProjectOutcome(int.Parse(hdfProjectId.Value));
                tbxSpecificReportingNeeds.Text = projectTermsPOGateway.GetRelationshipSpecificReportingNeeds(int.Parse(hdfProjectId.Value));

                //... Purchase Order
                //cbxPurchaseOrderAttach.Checked = projectTermsPOGateway.GetPurchaseOrderAttached(int.Parse(hdfProjectId.Value));
                tbxPurchaseOrderNumber.Text = projectTermsPOGateway.GetPurchaseOrderNumber(int.Parse(hdfProjectId.Value));
                //tbxPurchaseOrderWillNotProvided.Text = projectTermsPOGateway.GetPurchaseOrderNotes(int.Parse(hdfProjectId.Value));

                // ... Vehicle Access
                ckbxVehicleAccessRoad.Checked = projectTermsPOGateway.GetVehicleAccessRoad(int.Parse(hdfProjectId.Value));
                ckbxVehicleAccessEasement.Checked = projectTermsPOGateway.GetVehicleAccessEasement(int.Parse(hdfProjectId.Value));
                ckbxVehicleAccessOther.Checked = projectTermsPOGateway.GetVehicleAccessOther(int.Parse(hdfProjectId.Value));
            }
        }
        private void InsertProjectTerms(int originalProjectId)
        {
            // ... Data for current project
            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(projectTDS);
            projectTermsPOGateway.LoadByProjectId(originalProjectId);

            if (projectTermsPOGateway.Table.Rows.Count > 0)
            {
                // ... Definition of general variables
                bool liquidatedDamage = projectTermsPOGateway.GetLiquidatedDamage(originalProjectId);
                decimal? liquidatedRate = null; if (projectTermsPOGateway.GetLiquidatedRate(originalProjectId).HasValue) liquidatedRate = (decimal)projectTermsPOGateway.GetLiquidatedRate(originalProjectId);
                string liquidatedUnit = projectTermsPOGateway.GetLiquidatedUnit(originalProjectId);
                bool clientWorkedBefore = projectTermsPOGateway.GetRelationshipClientWorkedBefore(originalProjectId);
                string clientQuirks = projectTermsPOGateway.GetRelationshipClientQuirks(originalProjectId);
                bool clientPromises = projectTermsPOGateway.GetRelationshipClientPromises(originalProjectId);
                string clientPromisesNotes = projectTermsPOGateway.GetRelationshipClientPromisesNotes(originalProjectId);
                string waterObtain = projectTermsPOGateway.GetRelationshipWaterObtain(originalProjectId);
                string materialDispose = projectTermsPOGateway.GetRelationshipMaterialDispose(originalProjectId);
                bool requireRPZ = projectTermsPOGateway.GetRelationshipRequireRPZ(originalProjectId);
                string standardHydrantFitting = projectTermsPOGateway.GetRelationshipStandardHydrantFitting(originalProjectId);
                bool preConstructionMeeting = projectTermsPOGateway.GetRelationshipPreConstructionMeeting(originalProjectId);
                bool specificMeetingLocation = projectTermsPOGateway.GetRelationshipSpecificMeetingLocation(originalProjectId);
                string specificMeetingLocationNotes = projectTermsPOGateway.GetRelationshipSpecificMeetingLocationNotes(originalProjectId);
                string vehicleAccess = "Fair"; if (projectTermsPOGateway.GetRelationshipVehicleAccess(originalProjectId) != "") vehicleAccess = projectTermsPOGateway.GetRelationshipVehicleAccess(originalProjectId);
                string vehicleAccessNotes = projectTermsPOGateway.GetRelationshipVehicleAccessNotes(originalProjectId);
                string projectOutcome = projectTermsPOGateway.GetRelationshipProjectOutcome(originalProjectId);
                string specificReportingNeeds = projectTermsPOGateway.GetRelationshipSpecificReportingNeeds(originalProjectId);
                bool orderAttached = projectTermsPOGateway.GetPurchaseOrderAttached(originalProjectId);
                string orderNumber = projectTermsPOGateway.GetPurchaseOrderNumber(originalProjectId);
                string orderNotes = projectTermsPOGateway.GetPurchaseOrderNotes(originalProjectId);
                bool vehicleAccessRoad = projectTermsPOGateway.GetVehicleAccessRoad(originalProjectId);
                bool vehicleAccessEasement = projectTermsPOGateway.GetVehicleAccessEasement(originalProjectId);
                bool vehicleAccessOther = projectTermsPOGateway.GetVehicleAccessOther(originalProjectId);

                // ... Insert Terms/PO
                ProjectTermsPO projectTermsPO = new ProjectTermsPO(projectTDS);
                projectTermsPO.Insert(0, liquidatedDamage, liquidatedRate, liquidatedUnit, clientWorkedBefore, clientQuirks, clientPromises, clientPromisesNotes, waterObtain, materialDispose, requireRPZ, standardHydrantFitting, preConstructionMeeting, specificMeetingLocation, specificMeetingLocationNotes, vehicleAccess, vehicleAccessNotes, projectOutcome, specificReportingNeeds, orderNumber, orderAttached, orderNotes, Int32.Parse(hdfCompanyId.Value.Trim()), vehicleAccessRoad, vehicleAccessEasement, vehicleAccessOther);
            }
        }
예제 #4
0
        /// <summary>
        /// Update4 - Duplicate proposal
        /// </summary>
        public void Update4()
        {
            ProjectCostingUpdatesGateway projectCostingUpdatesGateway = new ProjectCostingUpdatesGateway(Data);
            ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGateway = new ProjectEngineerSubcontractorsGateway(Data);
            ProjectHistoryGateway projectHistoryGateway = new ProjectHistoryGateway(Data);
            ProjectNotesGateway projectNotesGateway = new ProjectNotesGateway(Data);
            ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(Data);
            ProjectServiceGateway projectServiceGateway = new ProjectServiceGateway(Data);
            ProjectSubcontractorGateway projectSubcontractorGateway = new ProjectSubcontractorGateway(Data);
            ProjectTechnicalGateway projectTechnicalGateway = new ProjectTechnicalGateway(Data);
            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(Data);

            DataTable projectChanges = Table.GetChanges();
            DataTable projectCostingUpdatesChanges = projectCostingUpdatesGateway.Table.GetChanges();
            DataTable projectEngineerSubcontractorsChanges = projectEngineerSubcontractorsGateway.Table.GetChanges();
            DataTable projectHistoryChanges = projectHistoryGateway.Table.GetChanges();
            DataTable projectNotesChanges = projectNotesGateway.Table.GetChanges();
            DataTable projectSaleBillingPricingChanges = projectSaleBillingPricingGateway.Table.GetChanges();
            DataTable projectServiceChanges = projectServiceGateway.Table.GetChanges();
            DataTable projectSubcontractorChanges = projectSubcontractorGateway.Table.GetChanges();
            DataTable projectTechnicalChanges = projectTechnicalGateway.Table.GetChanges();
            DataTable projectTermsPOChanges = projectTermsPOGateway.Table.GetChanges();

            if ((projectChanges == null) && (projectCostingUpdatesChanges == null) && (projectEngineerSubcontractorsChanges == null) && (projectHistoryChanges == null) && (projectNotesChanges == null) && (projectSaleBillingPricingChanges == null) && (projectServiceChanges == null) && (projectSubcontractorChanges == null) && (projectTechnicalChanges == null) && (projectTermsPOChanges == null)) return;

            try
            {
                DB.Open();
                DB.BeginTransaction();

                Adapter.InsertCommand.Transaction = DB.Transaction;
                Adapter.UpdateCommand.Transaction = DB.Transaction;
                Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectCostingUpdatesGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectCostingUpdatesGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectCostingUpdatesGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectEngineerSubcontractorsGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectEngineerSubcontractorsGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectEngineerSubcontractorsGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectHistoryGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectNotesGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectNotesGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectNotesGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectSaleBillingPricingGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectSaleBillingPricingGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectSaleBillingPricingGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectServiceGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectServiceGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectServiceGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectSubcontractorGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectSubcontractorGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectSubcontractorGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTechnicalGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTechnicalGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTechnicalGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTermsPOGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTermsPOGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTermsPOGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                if ((projectChanges != null) && (projectChanges.Rows.Count > 0))
                {
                    Adapter.Update(projectChanges);

                    int newProjectId = DB.GetIdentCurrent("LFS_PROJECT", DB.Transaction);

                    //Getting projectId for History table
                    ProjectTDS.LFS_PROJECT_HISTORYRow rowHistory = ((ProjectTDS.LFS_PROJECT_HISTORYDataTable)projectHistoryGateway.Table).FindByProjectIDRefID(0, 1);
                    rowHistory.ProjectID = newProjectId;
                    projectHistoryChanges = projectHistoryGateway.Table.GetChanges();

                    //Getting projectId for Costing Updates table
                    if (projectCostingUpdatesGateway.Table.Rows.Count > 0)
                    {
                        ProjectTDS.LFS_PROJECT_COSTING_UPDATESRow rowProjectCosting = ((ProjectTDS.LFS_PROJECT_COSTING_UPDATESDataTable)projectCostingUpdatesGateway.Table).FindByProjectID(0);
                        rowProjectCosting.ProjectID = newProjectId;
                        projectCostingUpdatesChanges = projectCostingUpdatesGateway.Table.GetChanges();
                    }

                    //Getting projectId for Engineer Subcontractors table
                    if (projectEngineerSubcontractorsGateway.Table.Rows.Count > 0)
                    {
                        ProjectTDS.LFS_PROJECT_ENGINEER_SUBCONTRACTORSRow rowEngineerSubcontractors = ((ProjectTDS.LFS_PROJECT_ENGINEER_SUBCONTRACTORSDataTable)projectEngineerSubcontractorsGateway.Table).FindByProjectID(0);
                        rowEngineerSubcontractors.ProjectID = newProjectId;
                        projectEngineerSubcontractorsChanges = projectEngineerSubcontractorsGateway.Table.GetChanges();
                    }

                    //Getting projectId for Notes table
                    foreach (ProjectTDS.LFS_PROJECT_NOTERow rowNotes in (ProjectTDS.LFS_PROJECT_NOTEDataTable)projectNotesGateway.Table)
                    {
                        if (rowNotes.ProjectID == 0)
                        {
                            rowNotes.ProjectID = newProjectId;
                        }
                    }
                    projectNotesChanges = projectNotesGateway.Table.GetChanges();

                    //Getting projectId for SaleBillingPricing
                    if (projectSaleBillingPricingGateway.Table.Rows.Count > 0)
                    {
                        ProjectTDS.LFS_PROJECT_SALE_BILLING_PRICINGRow rowSaleBillingPricing = ((ProjectTDS.LFS_PROJECT_SALE_BILLING_PRICINGDataTable)projectSaleBillingPricingGateway.Table).FindByProjectID(0);
                        rowSaleBillingPricing.ProjectID = newProjectId;
                        projectSaleBillingPricingChanges = projectSaleBillingPricingGateway.Table.GetChanges();
                    }

                    //Getting projectId for Subcontractors
                    foreach (ProjectTDS.LFS_PROJECT_SUBCONTRACTORRow rowSubcontractor in (ProjectTDS.LFS_PROJECT_SUBCONTRACTORDataTable)projectSubcontractorGateway.Table)
                    {
                        if (rowSubcontractor.ProjectID == 0)
                        {
                            rowSubcontractor.ProjectID = newProjectId;
                        }
                    }
                    projectSubcontractorChanges = projectSubcontractorGateway.Table.GetChanges();

                    //Getting projectId for Services
                    foreach (ProjectTDS.LFS_PROJECT_SERVICERow rowService in (ProjectTDS.LFS_PROJECT_SERVICEDataTable)projectServiceGateway.Table)
                    {
                        if (rowService.ProjectID == 0)
                        {
                            rowService.ProjectID = newProjectId;
                        }
                    }
                    projectServiceChanges = projectServiceGateway.Table.GetChanges();

                    //Getting projectId for Technical
                    if (projectTechnicalGateway.Table.Rows.Count > 0)
                    {
                        ProjectTDS.LFS_PROJECT_TECHNICALRow rowTechnical = ((ProjectTDS.LFS_PROJECT_TECHNICALDataTable)projectTechnicalGateway.Table).FindByProjectID(0);
                        rowTechnical.ProjectID = newProjectId;
                        projectTechnicalChanges = projectTechnicalGateway.Table.GetChanges();
                    }

                    //Getting projectId for Terms
                    if (projectTermsPOGateway.Table.Rows.Count > 0)
                    {
                        ProjectTDS.LFS_PROJECT_TERMSRow rowTerms = ((ProjectTDS.LFS_PROJECT_TERMSDataTable)projectTermsPOGateway.Table).FindByProjectID(0);
                        rowTerms.ProjectID = newProjectId;
                        projectTermsPOChanges = projectTermsPOGateway.Table.GetChanges();
                    }
                }

                if ((projectCostingUpdatesChanges != null) && (projectCostingUpdatesChanges.Rows.Count > 0))
                {
                    projectCostingUpdatesGateway.Adapter.Update(projectCostingUpdatesChanges);
                }

                if ((projectEngineerSubcontractorsChanges != null) && (projectEngineerSubcontractorsChanges.Rows.Count > 0))
                {
                    projectEngineerSubcontractorsGateway.Adapter.Update(projectEngineerSubcontractorsChanges);
                }

                if ((projectHistoryChanges != null) && (projectHistoryChanges.Rows.Count > 0))
                {
                    projectHistoryGateway.Adapter.Update(projectHistoryChanges);
                }

                if ((projectNotesChanges != null) && (projectNotesChanges.Rows.Count > 0))
                {
                    projectNotesGateway.Adapter.Update(projectNotesChanges);
                }

                if ((projectSaleBillingPricingChanges != null) && (projectSaleBillingPricingChanges.Rows.Count > 0))
                {
                    projectSaleBillingPricingGateway.Adapter.Update(projectSaleBillingPricingChanges);
                }

                if ((projectServiceChanges != null) && (projectServiceChanges.Rows.Count > 0))
                {
                    projectServiceGateway.Adapter.Update(projectServiceChanges);
                }

                if ((projectSubcontractorChanges != null) && (projectSubcontractorChanges.Rows.Count > 0))
                {
                    projectSubcontractorGateway.Adapter.Update(projectSubcontractorChanges);
                }

                if ((projectTechnicalChanges != null) && (projectTechnicalChanges.Rows.Count > 0))
                {
                    projectTechnicalGateway.Adapter.Update(projectTechnicalChanges);
                }

                if ((projectTermsPOChanges != null) && (projectTermsPOChanges.Rows.Count > 0))
                {
                    projectTermsPOGateway.Adapter.Update(projectTermsPOChanges);
                }

                DB.CommitTransaction();
            }

            catch (DBConcurrencyException dBConcurrencyException)
            {
                DB.RollbackTransaction();
                throw new Exception("Concurrency error: Another user already updated the data you are working on.  Your operation has been cancelled.", dBConcurrencyException);
            }

            catch (SqlException sqlException)
            {
                DB.RollbackTransaction();
                byte severityLevel = sqlException.Class;
                if (severityLevel <= 16)
                {
                    throw new Exception("Low severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if ((severityLevel >= 17) && (severityLevel <= 19))
                {
                    throw new Exception("Mid severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if (severityLevel >= 20)
                {
                    throw new Exception("High severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
            }

            catch (Exception e)
            {
                DB.RollbackTransaction();
                throw new Exception("Unknow error. Your operation has been cancelled.", e);
            }

            finally
            {
                DB.Close();
            }
        }
예제 #5
0
        /// <summary>
        /// Update3 - Update all project
        /// </summary>
        public void Update3()
        {
            ProjectCostingUpdatesGateway projectCostingUpdatesGateway = new ProjectCostingUpdatesGateway(Data);
            ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGateway = new ProjectEngineerSubcontractorsGateway(Data);
            ProjectHistoryGateway projectHistoryGateway = new ProjectHistoryGateway(Data);
            ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(Data);
            ProjectSubcontractorGateway projectSubcontractorGateway = new ProjectSubcontractorGateway(Data);
            ProjectTechnicalGateway projectTechnicalGateway = new ProjectTechnicalGateway(Data);
            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(Data);

            DataTable projectChanges = Table.GetChanges();
            DataTable projectCostingUpdatesChanges = projectCostingUpdatesGateway.Table.GetChanges();
            DataTable projectEngineerSubcontractorsChanges = projectEngineerSubcontractorsGateway.Table.GetChanges();
            DataTable projectHistoryChanges = projectHistoryGateway.Table.GetChanges();
            DataTable projectSaleBillingPricingChanges = projectSaleBillingPricingGateway.Table.GetChanges();
            DataTable projectSubcontractorChanges = projectSubcontractorGateway.Table.GetChanges();
            DataTable projectTechnicalChanges = projectTechnicalGateway.Table.GetChanges();
            DataTable projectTermsPOChanges = projectTermsPOGateway.Table.GetChanges();

            if ((projectChanges == null) && (projectCostingUpdatesChanges == null) && (projectEngineerSubcontractorsChanges == null) && (projectHistoryChanges == null)  && (projectSaleBillingPricingChanges == null) && (projectSubcontractorChanges == null) && (projectTechnicalChanges == null) && (projectTermsPOChanges == null)) return;

            try
            {
                DB.Open();
                DB.BeginTransaction();

                Adapter.InsertCommand.Transaction = DB.Transaction;
                Adapter.UpdateCommand.Transaction = DB.Transaction;
                Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectCostingUpdatesGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectCostingUpdatesGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectCostingUpdatesGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectEngineerSubcontractorsGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectEngineerSubcontractorsGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectEngineerSubcontractorsGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectHistoryGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectHistoryGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectSaleBillingPricingGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectSaleBillingPricingGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectSaleBillingPricingGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectSubcontractorGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectSubcontractorGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectSubcontractorGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTechnicalGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTechnicalGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTechnicalGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                projectTermsPOGateway.Adapter.InsertCommand.Transaction = DB.Transaction;
                projectTermsPOGateway.Adapter.UpdateCommand.Transaction = DB.Transaction;
                projectTermsPOGateway.Adapter.DeleteCommand.Transaction = DB.Transaction;

                if ((projectChanges != null) && (projectChanges.Rows.Count > 0))
                {
                    Adapter.Update(projectChanges);
                }

                if ((projectCostingUpdatesChanges != null) && (projectCostingUpdatesChanges.Rows.Count > 0))
                {
                    projectCostingUpdatesGateway.Adapter.Update(projectCostingUpdatesChanges);
                }

                if ((projectEngineerSubcontractorsChanges != null) && (projectEngineerSubcontractorsChanges.Rows.Count > 0))
                {
                    projectEngineerSubcontractorsGateway.Adapter.Update(projectEngineerSubcontractorsChanges);
                }

                if ((projectHistoryChanges != null) && (projectHistoryChanges.Rows.Count > 0))
                {
                    projectHistoryGateway.Adapter.Update(projectHistoryChanges);
                }

                if ((projectSaleBillingPricingChanges != null) && (projectSaleBillingPricingChanges.Rows.Count > 0))
                {
                    projectSaleBillingPricingGateway.Adapter.Update(projectSaleBillingPricingChanges);
                }

                if ((projectSubcontractorChanges != null) && (projectSubcontractorChanges.Rows.Count > 0))
                {
                    projectSubcontractorGateway.Adapter.Update(projectSubcontractorChanges);
                }

                if ((projectTechnicalChanges != null) && (projectTechnicalChanges.Rows.Count > 0))
                {
                    projectTechnicalGateway.Adapter.Update(projectTechnicalChanges);
                }

                if ((projectTermsPOChanges != null) && (projectTermsPOChanges.Rows.Count > 0))
                {
                    projectTermsPOGateway.Adapter.Update(projectTermsPOChanges);
                }

                DB.CommitTransaction();
            }

            catch (DBConcurrencyException dBConcurrencyException)
            {
                DB.RollbackTransaction();
                throw new Exception("Concurrency error: Another user already updated the data you are working on.  Your operation has been cancelled.", dBConcurrencyException);
            }

            catch (SqlException sqlException)
            {
                DB.RollbackTransaction();
                byte severityLevel = sqlException.Class;
                if (severityLevel <= 16)
                {
                    throw new Exception("Low severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if ((severityLevel >= 17) && (severityLevel <= 19))
                {
                    throw new Exception("Mid severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
                if (severityLevel >= 20)
                {
                    throw new Exception("High severity error. Your operation has been cancelled.  SQL Error " + severityLevel + ".");
                }
            }

            catch (Exception e)
            {
                DB.RollbackTransaction();
                throw new Exception("Unknow error. Your operation has been cancelled.", e);
            }

            finally
            {
                DB.Close();
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Load
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="companyId">companyId</param>
        /// <para>Load Original table to process data for Project Costing report without filters  </para>
        public void Load(int projectId, int companyId)
        {
            // Initialization of Gateways
            ProjectGateway projectGateway = new ProjectGateway(Data);
            projectGateway.LoadByProjectId(projectId);
            int companiesId = (int)projectGateway.GetClientID(projectId);

            ProjectJobInfoGateway projectJobInfoGateway = new ProjectJobInfoGateway(Data);
            projectJobInfoGateway.LoadAllByProjectId(projectId);

            ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(Data);
            projectSaleBillingPricingGateway.LoadAllByProjectId(projectId);

            ProjectTechnicalGateway projectTechnicalGateway = new ProjectTechnicalGateway(Data);
            projectTechnicalGateway.LoadByProjectId(projectId);

            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(Data);
            projectTermsPOGateway.LoadByProjectId(projectId);

            ProjectSubcontractorGateway projectSubcontractorGateway = new ProjectSubcontractorGateway(Data);
            projectSubcontractorGateway.LoadByProjectId(projectId);

            ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGateway = new ProjectEngineerSubcontractorsGateway(Data);
            projectEngineerSubcontractorsGateway.LoadAllByProjectId(projectId);

            ProjectHistoryGateway projectHistoryGateway = new ProjectHistoryGateway(Data);
            projectHistoryGateway.LoadFirstRow(projectId);

            ProjectNotesGateway projectNoteGateway = new ProjectNotesGateway(Data);
            projectNoteGateway.LoadByProjectId(projectId);

            ProjectServiceGateway projectServiceGateway = new ProjectServiceGateway(Data);
            projectServiceGateway.LoadByProjectId(projectId);

            // For Updates
            // ...Get the loginId for submitted field at report

            // ...Update LFS_PROJECT
            this.UpdateForReport(projectId, companiesId, projectGateway.GetSalesmanID(projectId), (projectGateway.GetProjectLeadID(projectId)).GetValueOrDefault(), companyId);

            // ...Update LFS_PROJECT_ENGINEER_SUBCONTRACTOR
            ProjectSynopsisEngineerSubcontractors projectSynopsisEngineerSubcontractors = new ProjectSynopsisEngineerSubcontractors(Data);
            if (projectSynopsisEngineerSubcontractors.Table.Rows.Count > 0)
            {
                projectSynopsisEngineerSubcontractors.UpdateForReport(projectId, companiesId, companyId);
            }

            // ...Update LFS_PROJECT_SUBCONTRACTOR
            ProjectSynopsisSubcontractor projectSynopsisSubcontractor = new ProjectSynopsisSubcontractor(Data);
            if (projectSynopsisSubcontractor.Table.Rows.Count > 0)
            {
                projectSynopsisSubcontractor.UpdateForReport(projectId, companiesId, companyId);
            }

            // ...Update LFS_PROJECT_NOTE
            ProjectSynopsisNote projectSynopsisNote = new ProjectSynopsisNote(Data);
            if (projectSynopsisNote.Table.Rows.Count > 0)
            {
                projectSynopsisNote.UpdateForReport(projectId, companyId);
            }

            // ...Update LFS_PROJECT_SERVICE and Total Average Price
            ProjectSynopsisService projectSynopsisService = new ProjectSynopsisService(Data);
            if (projectSynopsisService.Table.Rows.Count > 0)
            {
                ProjectSynopsisReportTDS.LFS_PROJECTRow rowTotalAveragePrice = ((ProjectSynopsisReportTDS.LFS_PROJECTDataTable)Table).FindByProjectID(projectId);
                rowTotalAveragePrice.TotalAveragePrice = projectSynopsisService.UpdateForReport(projectId, companyId);
            }
        }
        private void LoadTermsPo()
        {
            // Data for Terms/PO
            ProjectTermsPOGateway projectTermsPOGateway = new ProjectTermsPOGateway(projectTDS);

            if (projectTermsPOGateway.Table.Rows.Count > 0)
            {
                // ... Liquidated Damage
                //cbxLiquidatedDamages.Checked = projectTermsPOGateway.GetLiquidatedDamage(int.Parse(hdfProjectId.Value));
                //if (projectTermsPOGateway.GetLiquidatedRate(int.Parse(hdfProjectId.Value)).HasValue) tbxLiquidatedDamagesRate.Text = (Decimal.Round((decimal)projectTermsPOGateway.GetLiquidatedRate(int.Parse(hdfProjectId.Value)), 2)).ToString(); else tbxLiquidatedDamagesRate.Text = "";
                //tbxLiquidatedDamagesUnit.Text = projectTermsPOGateway.GetLiquidatedUnit(int.Parse(hdfProjectId.Value));

                // ... Client LFS Relationship
                //cbxWorkedBefore.Checked = projectTermsPOGateway.GetRelationshipClientWorkedBefore(int.Parse(hdfProjectId.Value));
                //tbxClientQuirks.Text = projectTermsPOGateway.GetRelationshipClientQuirks(int.Parse(hdfProjectId.Value));
                //cbxClientPromises.Checked = projectTermsPOGateway.GetRelationshipClientPromises(int.Parse(hdfProjectId.Value));
                //tbxClientPromises.Text = projectTermsPOGateway.GetRelationshipClientPromisesNotes(int.Parse(hdfProjectId.Value));
                //tbxWaterObtain.Text = projectTermsPOGateway.GetRelationshipWaterObtain(int.Parse(hdfProjectId.Value));
                //tbxMaterialDispose.Text = projectTermsPOGateway.GetRelationshipMaterialDispose(int.Parse(hdfProjectId.Value));
                //cbxRequireRPZ.Checked = projectTermsPOGateway.GetRelationshipRequireRPZ(int.Parse(hdfProjectId.Value));
                //tbxStandardHydrantFitting.Text = projectTermsPOGateway.GetRelationshipStandardHydrantFitting(int.Parse(hdfProjectId.Value));
                //cbxPreConstructionMeetingNeed.Checked = projectTermsPOGateway.GetRelationshipPreConstructionMeeting(int.Parse(hdfProjectId.Value));
                //cbxSpecificMeetingLocation.Checked = projectTermsPOGateway.GetRelationshipSpecificMeetingLocation(int.Parse(hdfProjectId.Value));
                //tbxSpecificMeetingLocation.Text = projectTermsPOGateway.GetRelationshipSpecificMeetingLocationNotes(int.Parse(hdfProjectId.Value));
                //tbxVehicleAccess.Text = projectTermsPOGateway.GetRelationshipVehicleAccess(int.Parse(hdfProjectId.Value));
                //tbxVehicleAccessNotes.Text = projectTermsPOGateway.GetRelationshipVehicleAccessNotes(int.Parse(hdfProjectId.Value));
                tbxDesireOutcomeOfProject.Text = projectTermsPOGateway.GetRelationshipProjectOutcome(int.Parse(hdfProjectId.Value));
                tbxSpecificReportingNeeds.Text = projectTermsPOGateway.GetRelationshipSpecificReportingNeeds(int.Parse(hdfProjectId.Value));

                //... Purchase Order
                //cbxPurchaseOrderAttach.Checked = projectTermsPOGateway.GetPurchaseOrderAttached(int.Parse(hdfProjectId.Value));
                tbxPurchaseOrderNumber.Text = projectTermsPOGateway.GetPurchaseOrderNumber(int.Parse(hdfProjectId.Value));
                //tbxPurchaseOrderWillNotProvided.Text = projectTermsPOGateway.GetPurchaseOrderNotes(int.Parse(hdfProjectId.Value));

                // ... Vehicle Access
                ckbxVehicleAccessRoad.Checked = projectTermsPOGateway.GetVehicleAccessRoad(int.Parse(hdfProjectId.Value));
                ckbxVehicleAccessEasement.Checked = projectTermsPOGateway.GetVehicleAccessEasement(int.Parse(hdfProjectId.Value));
                ckbxVehicleAccessOther.Checked = projectTermsPOGateway.GetVehicleAccessOther(int.Parse(hdfProjectId.Value));
            }
        }