private void PostPageChanges()
        {
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            int projectId = int.Parse(hdfProjectId.Value);

            // General Data
            Int64 countryId = projectGateway.GetCountryID(projectId);
            int officeId = projectGateway.GetOfficeID(projectId);
            Int64? provinceId = projectGateway.GetProvinceID(projectId);
            Int64? cityId = projectGateway.GetCityID(projectId);
            Int64? countyId = projectGateway.GetCountyID(projectId);
            int? projectLeadId = null; if ((ddlProjectLeadId.SelectedValue != "-1") && (ddlProjectLeadId.SelectedIndex > -1)) projectLeadId = int.Parse(ddlProjectLeadId.SelectedValue);
            int salesmanId = int.Parse(ddlSalesmanId.SelectedValue);
            string projectType = projectGateway.GetProjectType(projectId);
            string projectState = projectGateway.GetProjectState(projectId);
            string name = tbxName.Text.Trim();
            string description = tbxDescription.Text.Trim();
            DateTime? proposalDate = null; if (tkrdpProposalDate.SelectedDate.HasValue) proposalDate = tkrdpProposalDate.SelectedDate.Value;
            DateTime? startDate = null; if (tkrdpStartDate.SelectedDate.HasValue) startDate = tkrdpStartDate.SelectedDate.Value;
            DateTime? endDate = null; if (tkrdpEndDate.SelectedDate.HasValue) endDate = tkrdpEndDate.SelectedDate.Value;
            int clientId = projectGateway.GetClientID(projectId);
            string clientProjectNumber = tbxClientProjectNumber.Text.Trim();
            int? clientPrimaryContactId = null; if ((ddlClientPrimaryContactId.SelectedValue != "-1") && (ddlClientPrimaryContactId.SelectedIndex > -1)) clientPrimaryContactId = int.Parse(ddlClientPrimaryContactId.SelectedValue);
            int? clientSecondaryContactId = null; if ((ddlClientSecondaryContactId.SelectedValue != "-1") && (ddlClientSecondaryContactId.SelectedIndex > -1)) clientSecondaryContactId = int.Parse(ddlClientSecondaryContactId.SelectedValue);
            bool deleted = projectGateway.GetDeleted(projectId);
            int? libraryCategoriesId = null; if (projectGateway.GetLibraryCategoriesId(projectId).HasValue) libraryCategoriesId = (int)projectGateway.GetLibraryCategoriesId(projectId);
            bool fairWageApplies = cbxFairWageApplies.Checked;

            // ... Update Project Number
            Project project = new Project(projectTDS);
            string projectNumber;

            if (projectGateway.GetOriginalProjectID(projectId) == null)
            {
                projectNumber = project.UpdateProjectNumber(projectId, salesmanId);
            }
            else
            {
                projectNumber = projectGateway.GetProjectNumber(projectId);
            }

            // ... Update Project
            project.Update(projectId, countryId, officeId, projectLeadId, salesmanId, projectNumber, projectType, projectState, name, description, proposalDate, startDate, endDate, clientId, clientProjectNumber, clientPrimaryContactId, clientSecondaryContactId, deleted, libraryCategoriesId, provinceId, cityId, Int32.Parse(hdfCompanyId.Value.Trim()), countyId, fairWageApplies);

            // ... If project type is Ballpark update Bill Price and Bill Money
            if (projectType == "Ballpark")
            {
                ProjectSaleBillingPricing projectSaleBillingPricingForGeneralData = new ProjectSaleBillingPricing(projectTDS);

                decimal? billPrice = null; if (tbxBillPrice.Text != "") billPrice = Convert.ToDecimal(tbxBillPrice.Text);
                string billMoney = ddlBillMoney.SelectedValue;

                projectSaleBillingPricingForGeneralData.UpdateBillPrice(projectId, billPrice, billMoney);
            }

            if ((projectType != "Ballpark") && (projectType != "Internal"))
            {
                // Sale/Billing/Pricing
                //bool saleBidProject = cbxSaleBidProject.Checked;
                //bool saleRFP = cbxSaleRFP.Checked;
                //bool saleSoleSource = cbxSaleSoleSource.Checked;
                //bool saleTermContract = cbxSaleTermContract.Checked;
                //string saleTermContractDetail = tbxSaleTermContractDetail.Text.Trim();
                //bool saleOther = cbxSaleOther.Checked;
                //string saleOtherDetail = tbxSaleOtherDetail.Text.Trim();
                //int? saleGettingJob = null; if (tbxSaleGettingJob.Text.Trim() != "") saleGettingJob = int.Parse(tbxSaleGettingJob.Text.Trim());
                decimal? billPriceSaleBillingPricing = null; if (tbxBillPriceSaleBillingPricing.Text.Trim() != "") billPriceSaleBillingPricing = decimal.Parse(tbxBillPriceSaleBillingPricing.Text.Trim());
                string billMoneySaleBillingPricing = ddlBillMoneySaleBillingPricing.SelectedValue;
                decimal? billSubcontractorAmount = null; if (tbxBillSubcontractorAmount.Text.Trim() != "") billSubcontractorAmount = decimal.Parse(tbxBillSubcontractorAmount.Text.Trim());
                //string billBidHardDollar = tbxBillBidHardDollar.Text.Trim();
                //bool billPerUnit = cbxBillPerUnit.Checked;
                //bool billHourly = cbxBillHourly.Checked;
                //string billExpectExtras = tbxBillExpectExtras.Text.Trim();
                //bool chargesWater = cbxChargesWater.Checked;
                //decimal? chargesWaterAmount = null; if (tbxChargesWaterAmount.Text.Trim() != "") chargesWaterAmount = decimal.Parse(tbxChargesWaterAmount.Text.Trim());
                //bool chargesDisposal = cbxChargesDisposal.Checked;
                //decimal? chargesDisposalAmount = null; if (tbxChargesDisposalAmount.Text.Trim() != "") chargesDisposalAmount = decimal.Parse(tbxChargesDisposalAmount.Text.Trim());

                // ... Update Sale/Billing/Pricing
                ProjectSaleBillingPricing projectSaleBillingPricing = new ProjectSaleBillingPricing(projectTDS);
                //projectSaleBillingPricing.Update(projectId, saleBidProject, saleRFP, saleSoleSource, saleTermContract, saleTermContractDetail, saleOther, saleOtherDetail, saleGettingJob, billPriceSaleBillingPricing, billMoneySaleBillingPricing, billBidHardDollar, billPerUnit, billHourly, billExpectExtras, billSubcontractorAmount, chargesWater, chargesWaterAmount, chargesDisposal, chargesDisposalAmount, Int32.Parse(hdfCompanyId.Value.Trim()));
                projectSaleBillingPricing.Update(projectId, billPriceSaleBillingPricing, billMoneySaleBillingPricing, billSubcontractorAmount, Int32.Parse(hdfCompanyId.Value.Trim()));

                // ... Update job info
                bool typeOfWorkMhRehab = ckbxMhRehab.Checked;
                bool typeOfWorkJunctionLining = ckbxJunctionLining.Checked;
                bool typeOfWorkProjectManagement = ckbxProjectManagement.Checked;
                bool typeOfWorkFullLenghtLining = ckbxFullLengthLining.Checked;
                bool typeOfWorkPointRepairs = ckbxPointRepairs.Checked;
                bool typeOfWorkRehabAssessment = ckbxRehabAssessment.Checked;
                bool typeOfWorkGrout = ckbxGrout.Checked;
                bool typeOfWorkOther = ckbxOther.Checked;
                bool agreement = cbxSubcontractorAgreement.Checked;
                bool writtenQuote = cbxSubcontractorWrittenQuote.Checked;
                string role = tbxSubcontractorRole.Text;

                ProjectNavigatorProjectJobInfo projectNavigatorProjectJobInfo = new ProjectNavigatorProjectJobInfo(projectNavigatorTDS);
                projectNavigatorProjectJobInfo.Update(projectId, typeOfWorkMhRehab, typeOfWorkJunctionLining, typeOfWorkProjectManagement, typeOfWorkFullLenghtLining, typeOfWorkPointRepairs, typeOfWorkRehabAssessment, typeOfWorkGrout, typeOfWorkOther, agreement, writtenQuote, role);

                // Costing Updates
                //decimal? extrasToDate = null; if (tbxExtrasToDate.Text.Trim() != "") extrasToDate = decimal.Parse(tbxExtrasToDate.Text.Trim());
                //decimal? costsIncurred = null; if (tbxCostsIncurred.Text.Trim() != "") costsIncurred = decimal.Parse(tbxCostsIncurred.Text.Trim());
                //decimal? costToComplete = null; if (tbxCostToComplete.Text.Trim() != "") costToComplete = decimal.Parse(tbxCostToComplete.Text.Trim());
                //decimal? originalProfitEstimated = null; if (tbxOriginalProfitEstimated.Text.Trim() != "") originalProfitEstimated = decimal.Parse(tbxOriginalProfitEstimated.Text.Trim());
                //decimal? invoicedToDate = null; if (tbxInvoicedToDate.Text.Trim() != "") invoicedToDate = decimal.Parse(tbxInvoicedToDate.Text.Trim());

                // ... Update Costing Updates
                //ProjectCostingUpdates projectCostingUpdates = new ProjectCostingUpdates(projectTDS);
                //projectCostingUpdates.Update(projectId, extrasToDate, costsIncurred, costToComplete, originalProfitEstimated, invoicedToDate, Int32.Parse(hdfCompanyId.Value.Trim()));

                // Terms/PO
                // ... Liquidated Damage
                //bool liquidateDamage = cbxLiquidatedDamages.Checked;
                //decimal? liquidatedRate = null;
                //if (tbxLiquidatedDamagesRate.Text.Trim() != "") { decimal damages = Decimal.Parse(tbxLiquidatedDamagesRate.Text.Trim()); liquidatedRate = Decimal.Round(damages, 2); }
                //string liquidatedUnit = null; if (tbxLiquidatedDamagesUnit.Text != "") liquidatedUnit = tbxLiquidatedDamagesUnit.Text.Trim();

                //// ... Client LFS Relationship
                //bool clientWorkedBefore = cbxWorkedBefore.Checked;
                //string clientQuirks = null; if (tbxClientQuirks.Text.Trim() != "") clientQuirks = tbxClientQuirks.Text.Trim();
                //bool clientPromises = cbxClientPromises.Checked;
                //string clientPromisesNotes = null; if (tbxClientPromises.Text.Trim() != "") clientPromisesNotes = tbxClientPromises.Text.Trim();
                //string waterObtain = null; if (tbxWaterObtain.Text.Trim() != "") waterObtain = tbxWaterObtain.Text.Trim();
                //string materialDispose = null; if (tbxMaterialDispose.Text.Trim() != "") materialDispose = tbxMaterialDispose.Text.Trim();
                //bool requireRPZ = cbxRequireRPZ.Checked;
                //string standardHydrantFitting = null; if (tbxStandardHydrantFitting.Text.Trim() != "") standardHydrantFitting = tbxStandardHydrantFitting.Text.Trim();
                //bool preconstructionMeeting = cbxPreConstructionMeetingNeed.Checked;
                //bool specificMeetingLocation = cbxSpecificMeetingLocation.Checked;
                //string specificMeetingLocationNotes = null; if (tbxSpecificMeetingLocation.Text.Trim() != "") specificMeetingLocationNotes = tbxSpecificMeetingLocation.Text.Trim();
                //string vehicleAccess = null; if (ddlVehicleAccess.Text.Trim() != "") vehicleAccess = ddlVehicleAccess.Text.Trim();
                //string vehicleAccessNotes = null; if (tbxVehicleAccess.Text.Trim() != "") vehicleAccessNotes = tbxVehicleAccess.Text.Trim();
                string projectOutcome = null; if (tbxDesireOutcomeOfProject.Text.Trim() != "") projectOutcome = tbxDesireOutcomeOfProject.Text.Trim();
                string specificReportingNeeds = null; if (tbxSpecificReportingNeeds.Text.Trim() != "") specificReportingNeeds = tbxSpecificReportingNeeds.Text.Trim();
                bool vehicleAccessRoad = ckbxVehicleAccessRoad.Checked;
                bool vehicleAccessEasement = ckbxVehicleAccessEasement.Checked;
                bool vehicleAccessOther = ckbxVehicleAccessOther.Checked;

                //... Purchase Order
                //bool orderAttached = cbxPurchaseOrderAttach.Checked;
                string orderNumber = null; if (tbxPurchaseOrderNumber.Text.Trim() != "") orderNumber = tbxPurchaseOrderNumber.Text.Trim();
                //string orderNotes = null; if (tbxPurchaseOrderWillNotProvided.Text.Trim() != "") orderNotes = tbxPurchaseOrderWillNotProvided.Text.Trim();

                // ... Update Term/PO
                ProjectTermsPO projectTermsPO = new ProjectTermsPO(projectTDS);
                //projectTermsPO.Update(projectId, liquidateDamage, 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()));
                projectTermsPO.Update(projectId, projectOutcome, specificReportingNeeds, orderNumber,  Int32.Parse(hdfCompanyId.Value.Trim()), vehicleAccessRoad, vehicleAccessEasement, vehicleAccessOther);

                // Technical
                bool availableDrawings = cbxAvailableDrawings.Checked;
                bool availableVideo = cbxAvailableVideo.Checked;
                //bool groundConditions = cbxGroundConditions.Checked;
                //string groundConditionNotes = null; if (tbxGroundCondition.Text != "") groundConditionNotes = tbxGroundCondition.Text.Trim();
                //bool reviewVideoInspections = cbxReviewVideoInspections.Checked;
                //bool strangeConfigurations = cbxStrangeConfigurations.Checked;
                //string strangeConfigurationsNotes = null; if (tbxStrangeConfigurations.Text != "") strangeConfigurationsNotes = tbxStrangeConfigurations.Text.Trim();
                //string furtherObservations = null; if (tbxFurtherObservations.Text != "") furtherObservations = tbxFurtherObservations.Text.Trim();
                //string restrictiveFactors = null; if (tbxRestrictiveFactors.Text != "") restrictiveFactors = tbxRestrictiveFactors.Text.Trim();

                // ... Update Technical
                ProjectTechnical projectTechnical = new ProjectTechnical(projectTDS);
                //projectTechnical.Update(projectId, availableDrawings, availableVideo, groundConditions, groundConditionNotes, reviewVideoInspections, strangeConfigurations, strangeConfigurationsNotes, furtherObservations, restrictiveFactors, Int32.Parse(hdfCompanyId.Value.Trim()));
                projectTechnical.Update(projectId, availableDrawings, availableVideo,  Int32.Parse(hdfCompanyId.Value.Trim()));

                // Engineer/Subcontractors
                bool generalContractor = cbxGeneralContractor.Checked;
                bool generalWSIB = cbxGeneralWSIB.Checked;
                bool generalInsuranceCertificate = cbxGeneralInsuranceCertificate.Checked;
                string generalBondingSupplied = ddlGeneralBondingSupplied.SelectedValue;
                //string generalMOLForm = ddlGeneralMOLForm.SelectedValue;
                //bool generalNoticeProject = rbtnGeneralNoticeProject.Checked;
                //bool generalForm1000 = rbtnGeneralForm1000.Checked;
                //int? engineeringFirmId = null; if (ddlEngineeringFirmId.SelectedValue != "") engineeringFirmId = int.Parse(ddlEngineeringFirmId.SelectedValue);
                //int? engineerId = null; if (ddlEngineerId.SelectedValue != "") engineerId = int.Parse(ddlEngineerId.SelectedValue);
                //string engineerNumber = tbxEngineerNumber.Text.Trim();
                bool subcontractorUsed = cbxSubcontractorUsed.Checked;
                string bondNumber = tbxBondNumber.Text.Trim();

                // ... Update Engineer/Subcontractors
                ProjectEngineerSubcontractors projectEngineerSubcontractors = new ProjectEngineerSubcontractors(projectTDS);
                //projectEngineerSubcontractors.Update(projectId, generalContractor, generalWSIB, generalInsuranceCertificate, generalBondingSupplied, generalMOLForm, generalNoticeProject, generalForm1000, engineeringFirmId, engineerId, engineerNumber, subcontractorUsed, Int32.Parse(hdfCompanyId.Value.Trim()), bondNumber);
                projectEngineerSubcontractors.Update(projectId, generalContractor, generalWSIB, generalInsuranceCertificate, generalBondingSupplied, subcontractorUsed, Int32.Parse(hdfCompanyId.Value.Trim()), bondNumber);

                // ... Update subcontractors
                //ProjectSubcontractor projectSubcontractor = new ProjectSubcontractor(projectTDS);

                //bool subcontractorWrittenQuote = ((CheckBox)row.FindControl("cbxSubcontractorWrittenQuote")).Checked;
                //bool subcontractorAgreement = ((CheckBox)row.FindControl("cbxSubcontractorAgreement")).Checked;

                ////foreach (GridViewRow row in grdvSubcontractors.Rows)
                //{
                //    int subcontractorRefId = int.Parse(((HiddenField)row.FindControl("hdfRefId")).Value);
                //    int subcontractorId = int.Parse(((DropDownList)row.FindControl("ddlSubcontractorId")).SelectedValue);

                //    bool subcontractorSurveyedSite = ((CheckBox)row.FindControl("cbxSubcontractorSurveyedSite")).Checked;
                //    bool subcontractorWorkedBefore = ((CheckBox)row.FindControl("cbxSubcontractorWorkedBefore")).Checked;
                //    string subcontractorRole = ((TextBox)row.FindControl("tbxSubcontractorRole")).Text.Trim();

                //    string subcontractorIssues = ((TextBox)row.FindControl("tbxSubcontractorIssues")).Text.Trim();
                //    bool subcontractorPurchaseOrder = ((CheckBox)row.FindControl("cbxSubcontractorPurchaseOrder")).Checked;
                //    bool subcontractorInsuranceCertificate = ((CheckBox)row.FindControl("cbxSubcontractorInsuranceCertificate")).Checked;
                //    bool subcontractorWSIB = ((CheckBox)row.FindControl("cbxSubcontractorWSIB")).Checked;
                //    string subcontractorMOLForm1000 = ((DropDownList)row.FindControl("ddlSubcontractorMolForm1000")).SelectedValue;
                //    int? royalties = null;
                //    if (((TextBox)row.FindControl("tbxRoyalties")).Text != "")
                //    {
                //        royalties = Int32.Parse(((TextBox)row.FindControl("tbxRoyalties")).Text);
                //    }

                    //projectSubcontractor.Update(projectId, subcontractorRefId, subcontractorId, subcontractorWrittenQuote, subcontractorSurveyedSite, subcontractorWorkedBefore, subcontractorRole, subcontractorAgreement, subcontractorIssues, subcontractorPurchaseOrder, subcontractorInsuranceCertificate, subcontractorWSIB, subcontractorMOLForm1000, false, Int32.Parse(hdfCompanyId.Value.Trim()), royalties);
                    //projectSubcontractor.Update(projectId, 1,  subcontractorWrittenQuote, subcontractorAgreement, Int32.Parse(hdfCompanyId.Value.Trim()));
                //}

                decimal unitsBudget = 0M; if (tbxUnitsBudget.Text.Trim() != "") unitsBudget = decimal.Parse(tbxUnitsBudget.Text);
                decimal materialsBudget = 0M; if (tbxMaterialsBudget.Text.Trim() != "") materialsBudget = decimal.Parse(tbxMaterialsBudget.Text);
                decimal subcontractorsBudget = 0M; if (tbxSubcontractorsBudget.Text.Trim() != "") subcontractorsBudget = decimal.Parse(tbxSubcontractorsBudget.Text);
                decimal hotelsBudget = 0M; if (tbxHotelsBudget.Text.Trim() != "") hotelsBudget = decimal.Parse(tbxHotelsBudget.Text);
                decimal bondingsBudget = 0M; if (tbxBondingsBudget.Text.Trim() != "") bondingsBudget = decimal.Parse(tbxBondingsBudget.Text);
                decimal insurancesBudget = 0M; if (tbxInsurancesBudget.Text.Trim() != "") insurancesBudget = decimal.Parse(tbxInsurancesBudget.Text);

                ProjectNavigatorProjectUnitsBudget projectNavigatorProjectUnitsBudget = new ProjectNavigatorProjectUnitsBudget(projectNavigatorTDS);
                if (projectNavigatorProjectUnitsBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectUnitsBudget.Update(projectId, unitsBudget);
                }
                else
                {
                    projectNavigatorProjectUnitsBudget.Insert(projectId, unitsBudget, false, Int32.Parse(hdfCompanyId.Value), false);
                }

                ProjectNavigatorProjectMaterialsBudget projectNavigatorProjectMaterialsBudget = new ProjectNavigatorProjectMaterialsBudget(projectNavigatorTDS);
                if (projectNavigatorProjectMaterialsBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectMaterialsBudget.Update(projectId, materialsBudget);
                }
                else
                {
                    projectNavigatorProjectMaterialsBudget.Insert(projectId, materialsBudget, false, Int32.Parse(hdfCompanyId.Value), false);
                }

                ProjectNavigatorProjectSubcontractorsBudget projectNavigatorProjectSubcontractorsBudget = new ProjectNavigatorProjectSubcontractorsBudget(projectNavigatorTDS);
                if (projectNavigatorProjectSubcontractorsBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectSubcontractorsBudget.Update(projectId, 1, 1, subcontractorsBudget, false, Int32.Parse(hdfCompanyId.Value));
                }
                else
                {
                    projectNavigatorProjectSubcontractorsBudget.Insert(projectId, 1, subcontractorsBudget, false, Int32.Parse(hdfCompanyId.Value), false, "");
                }

                ProjectNavigatorProjectHotelsBudget projectNavigatorProjectHotelsBudget = new ProjectNavigatorProjectHotelsBudget(projectNavigatorTDS);
                if (projectNavigatorProjectHotelsBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectHotelsBudget.Update(projectId, 1, 1, hotelsBudget, false, Int32.Parse(hdfCompanyId.Value));
                }
                else
                {
                    projectNavigatorProjectHotelsBudget.Insert(projectId, 1, hotelsBudget, false, Int32.Parse(hdfCompanyId.Value), false, "");
                }

                ProjectNavigatorProjectBondingsBudget projectNavigatorProjectBondingsBudget = new ProjectNavigatorProjectBondingsBudget(projectNavigatorTDS);
                if (projectNavigatorProjectBondingsBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectBondingsBudget.Update(projectId, 1, 1, bondingsBudget, false, Int32.Parse(hdfCompanyId.Value));
                }
                else
                {
                    projectNavigatorProjectBondingsBudget.Insert(projectId, 1, bondingsBudget, false, Int32.Parse(hdfCompanyId.Value), false, "");
                }

                ProjectNavigatorProjectInsurancesBudget projectNavigatorProjectInsurancesBudget = new ProjectNavigatorProjectInsurancesBudget(projectNavigatorTDS);
                if (projectNavigatorProjectInsurancesBudget.Table.Rows.Count > 0)
                {
                    projectNavigatorProjectInsurancesBudget.Update(projectId, 1, 1, insurancesBudget, false, Int32.Parse(hdfCompanyId.Value));
                }
                else
                {
                    projectNavigatorProjectInsurancesBudget.Insert(projectId, 1, insurancesBudget, false, Int32.Parse(hdfCompanyId.Value), false, "");
                }
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Reload data for work and functions depending if it's faire wage or not.
            grdTypeOfWorkFunctionClassification.DataBind();

            // Security check
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);

            if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
            {
                // ... menu reports
                tkrpbLeftMenuReports.Visible = false;

                // ... for job info tab
                tpJobInfo.Enabled = true;

                // ... for values that comes from sales billing pricing tab
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = false;
            }
            else
            {
                // ... menu reports
                tkrpbLeftMenuReports.Visible = true;

                // ... for job info tab
                tpJobInfo.Enabled = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;
            }

            // Country check
            if (projectGateway.GetCountryID(int.Parse(hdfProjectId.Value)) == 1)
            {
                //ddlGeneralMOLForm.Visible = true;
                //tbxGeneralMOLForm.Visible = false;
                //lblGeneralNoticeProject.Visible = true;
                //rbtnGeneralNoticeProject.Visible = true;
                //lblGeneralForm1000.Visible = true;
                //rbtnGeneralForm1000.Visible = true;

                grdJobClassClassification.Columns[4].HeaderText = "Rate (CAD)";
                grdJobClassClassification.Columns[5].HeaderText = "Fringe Rate (CAD)";
            }
            else
            {
                //ddlGeneralMOLForm.Visible = false;
                //tbxGeneralMOLForm.Visible = true;
                //lblGeneralNoticeProject.Visible = false;
                //rbtnGeneralNoticeProject.Visible = false;
                //lblGeneralForm1000.Visible = false;
                //rbtnGeneralForm1000.Visible = false;

                grdJobClassClassification.Columns[4].HeaderText = "Rate (USD)";
                grdJobClassClassification.Columns[5].HeaderText = "Fringe Rate (USD)";
            }

            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "Projects";

            // Project type check
            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
            {
                // Active Tab
                tcDetailedInformation.ActiveTabIndex = 1;

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Ballpark";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Ballpark";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                lblHeaderTitle.Text = "Ballpark Summary";
                lblTitleProject.Text = " > Ballpark: ";

                // Initial section
                lblProposalDate.Text = "Ballpark Date";
                lblStartDate.Text = "Potential Start Date";
                lblEndDate.Text = "Potential End Date";
                lblStartDate.Visible = true;
                tkrdpStartDate.Visible = true;
                lblEndDate.Visible = true;
                tkrdpEndDate.Visible = true;

                // Client section
                lblClientProjectNumber.Visible = false;
                tbxClientProjectNumber.Visible = false;
                lblClientPrimaryContactId.Visible = false;
                ddlClientPrimaryContactId.Visible = false;
                btnClientPrimaryContact.Visible = false;
                lblClientSecondaryContactId.Visible = false;
                ddlClientSecondaryContactId.Visible = false;
                btnClientSecondaryContact.Visible = false;

                // Pricing section
                pnlPricing.Visible = true;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = false;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing update
                //tpCostingUpdates.Enabled = false;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = false;
                upnlTermsPO.Visible = false;
                upnlTermsPO1.Visible = false;
                upnlTermsPO2.Visible = false;
                upnlTermsPO3.Visible = false;

                // ... for values that comes from technical
                //tpTechnical.Enabled = false;
                upnlTechnical.Visible = false;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = false;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this ballpark";
                upnlEngineerSubcontractors.Visible = false;
                upnlEngineerSubcontractors1.Visible = false;
                upnlEngineerSubcontractors2.Visible = false;
                upnlEngineerSubcontractors3.Visible = false;
                upnlEngineerSubcontractors4.Visible = false;
                upnlEngineerSubcontractors5.Visible = false;
                upnlEngineerSubcontractors6.Visible = false;
                upnlEngineerSubcontractors7.Visible = false;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Proposal")
            {
                // Set initial tab
                tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Proposal";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Proposal";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                lblHeaderTitle.Text = "Proposal Summary";
                lblTitleProject.Text = " > Proposal: ";

                lblStartDate.Text = "Potential Start Date";
                lblEndDate.Text = "Potential End Date";

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = true;
                upnlTermsPO.Visible = true;
                upnlTermsPO1.Visible = true;
                upnlTermsPO2.Visible = true;
                upnlTermsPO3.Visible = true;

                // ... for values that comes from technical
                //tpTechnical.Enabled = true;
                upnlTechnical.Visible = true;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this proposal";
                upnlEngineerSubcontractors.Visible = true;
                upnlEngineerSubcontractors1.Visible = true;
                upnlEngineerSubcontractors2.Visible = true;
                upnlEngineerSubcontractors3.Visible = true;
                upnlEngineerSubcontractors4.Visible = true;
                upnlEngineerSubcontractors5.Visible = true;
                upnlEngineerSubcontractors6.Visible = true;
                upnlEngineerSubcontractors7.Visible = true;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                if ((projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)) == "Awarded") || (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)) == "Bidding"))
                {
                    tpJobInfo.Enabled = true;

                    //tpCostExceptions.Enabled = true;
                    pnlCostsExceptions.Visible = true;
                }

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Project")
            {
                // Set initial tab
                tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Project";

                lblHeaderTitle.Text = "Project Summary";
                lblTitleProject.Text = " > Project: ";

                lblStartDate.Text = "Start Date";
                lblEndDate.Text = "End Date";

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;

                // ... for values that comes from terms po
                // tpTermsPo.Enabled = true;
                upnlTermsPO.Visible = true;
                upnlTermsPO1.Visible = true;
                upnlTermsPO2.Visible = true;
                upnlTermsPO3.Visible = true;

                // ... for values that comes from technical
                // tpTechnical.Enabled = true;
                upnlTechnical.Visible = true;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this project";
                upnlEngineerSubcontractors.Visible = true;
                upnlEngineerSubcontractors1.Visible = true;
                upnlEngineerSubcontractors2.Visible = true;
                upnlEngineerSubcontractors3.Visible = true;
                upnlEngineerSubcontractors4.Visible = true;
                upnlEngineerSubcontractors5.Visible = true;
                upnlEngineerSubcontractors6.Visible = true;
                upnlEngineerSubcontractors7.Visible = true;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = true;
                pnlCostsExceptions.Visible = true;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Internal")
            {
                // Active Tab
                tcDetailedInformation.ActiveTabIndex = 1;

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Internal Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Internal Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                lblHeaderTitle.Text = "Internal Project Summary";
                lblTitleProject.Text = " > Internal Project: ";

                // Initial section
                lblProposalDate.Text = "Internal Project Date";
                lblStartDate.Visible = false;
                tkrdpStartDate.Visible = false;
                lblEndDate.Visible = false;
                tkrdpEndDate.Visible = false;
                tbxDescription.Width = Unit.Pixel(510);

                // Client section
                lblClientProjectNumber.Visible = false;
                tbxClientProjectNumber.Visible = false;
                lblClientPrimaryContactId.Visible = false;
                ddlClientPrimaryContactId.Visible = false;
                btnClientPrimaryContact.Visible = false;
                lblClientSecondaryContactId.Visible = false;
                ddlClientSecondaryContactId.Visible = false;
                btnClientSecondaryContact.Visible = false;

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = false;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing updates
                // tpCostingUpdates.Enabled = false;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = false;
                upnlTermsPO.Visible = false;
                upnlTermsPO1.Visible = false;
                upnlTermsPO2.Visible = false;
                upnlTermsPO3.Visible = false;

                // ... for values that comes from technical
                //tpTechnical.Enabled = false;
                upnlTechnical.Visible = false;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this internal project";
                upnlEngineerSubcontractors.Visible = false;
                upnlEngineerSubcontractors1.Visible = false;
                upnlEngineerSubcontractors2.Visible = false;
                upnlEngineerSubcontractors3.Visible = false;
                upnlEngineerSubcontractors4.Visible = false;
                upnlEngineerSubcontractors5.Visible = false;
                upnlEngineerSubcontractors6.Visible = false;
                upnlEngineerSubcontractors7.Visible = false;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);

            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "Projects";

            // Security check
            if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
            {
                // ... menu reports
                tkrpbLeftMenuReports.Visible = false;

                // ... for job info tab
                tpJobInfo.Enabled = true;

                // ... for values that comes from sales billing pricing tab
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = false;
            }
            else
            {
                // ... menu reports
                tkrpbLeftMenuReports.Visible = true;

                // ... for job info tab
                tpJobInfo.Enabled = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;
            }

            // Country check
            if (projectGateway.GetCountryID(int.Parse(hdfProjectId.Value)) == 1)
            {
                //lblGeneralNoticeProject.Visible = true;
                //rbtnGeneralNoticeProject.Visible = true;
                //lblGeneralForm1000.Visible = true;
                //rbtnGeneralForm1000.Visible = true;

                grdJobClassClassification.Columns[4].HeaderText = "Rate (CAD)";
                grdJobClassClassification.Columns[5].HeaderText = "Fringe Rate (CAD)";
            }
            else
            {
                //lblGeneralNoticeProject.Visible = false;
                //rbtnGeneralNoticeProject.Visible = false;
                //lblGeneralForm1000.Visible = false;
                //rbtnGeneralForm1000.Visible = false;

                grdJobClassClassification.Columns[4].HeaderText = "Rate (USD)";
                grdJobClassClassification.Columns[5].HeaderText = "Fringe Rate (USD)";
            }

            // Project type check
            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
            {
                // Active Tab
                tcDetailedInformation.ActiveTabIndex = 1;

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Ballpark";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Ballpark";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                // Top Menu
                tkrmTop.Items[1].Visible = false;
                tkrmTop.Items[2].Visible = false;
                tkrmTop.Items[3].Visible = false;
                tkrmTop.Items[4].Visible = true;

                lblHeaderTitle.Text = "Ballpark Summary";
                lblTitleProject.Text = " > Ballpark: ";

                // Initial section
                lblProposalDate.Text = "Ballpark Date";
                lblStartDate.Text = "Potential Start Date";
                lblEndDate.Text = "Potential End Date";
                lblStartDate.Visible = true;
                tbxStartDate.Visible = true;
                lblEndDate.Visible = true;
                tbxEndDate.Visible = true;

                // Client section
                lblClientProjectNumber.Visible = false;
                tbxClientProjectNumber.Visible = false;
                lblClientPrimaryContactId.Visible = false;
                tbxClientPrimaryContact.Visible = false;
                btnClientPrimaryContact.Visible = false;
                lblClientSecondaryContactId.Visible = false;
                tbxClientSecondaryContact.Visible = false;
                btnClientSecondaryContact.Visible = false;

                // Pricing section
                pnlPricing.Visible = true;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = false;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing update
                //tpCostingUpdates.Enabled = false;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = false;
                upnlTermsPO.Visible = false;
                upnlTermsPO1.Visible = false;
                upnlTermsPO2.Visible = false;
                upnlTermsPO3.Visible = false;

                // ... for values that comes from technical
                //tpTechnical.Enabled = false;
                upnlTechnical.Visible = false;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this ballpark";
                upnlEngineerSubcontractors.Visible = false;
                upnlEngineerSubcontractors1.Visible = false;
                upnlEngineerSubcontractors2.Visible = false;
                upnlEngineerSubcontractors3.Visible = false;
                upnlEngineerSubcontractors4.Visible = false;
                upnlEngineerSubcontractors5.Visible = false;
                upnlEngineerSubcontractors6.Visible = false;
                upnlEngineerSubcontractors7.Visible = false;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;

                // Project state check
                switch (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)))
                {
                    case "Active":
                        tkrmTop.Items[4].Items[0].Visible = false; //activate
                        tkrmTop.Items[4].Items[1].Visible = true; //cancel
                        tkrmTop.Items[4].Items[2].Visible = true; //hr
                        tkrmTop.Items[4].Items[3].Visible = true; //Promote to proposal
                        tkrmTop.Items[4].Items[4].Visible = true; //Promote to project
                        break;

                    case "Canceled":
                        tkrmTop.Items[4].Items[0].Visible = true; //activate
                        tkrmTop.Items[4].Items[1].Visible = false; //cancel
                        tkrmTop.Items[4].Items[2].Visible = false; //hr
                        tkrmTop.Items[4].Items[3].Visible = false; //Promote to proposal
                        tkrmTop.Items[4].Items[4].Visible = false; //Promote to project
                        break;
                }
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Proposal")
            {
                // Set initial tab
                tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Proposal";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Proposal";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                // Top Menu
                tkrmTop.Items[1].Visible = true;
                tkrmTop.Items[2].Visible = false;
                tkrmTop.Items[3].Visible = false;
                tkrmTop.Items[4].Visible = false;

                lblHeaderTitle.Text = "Proposal Summary";
                lblTitleProject.Text = " > Proposal: ";

                lblStartDate.Text = "Potential Start Date";
                lblEndDate.Text = "Potential End Date";

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = true;
                upnlTermsPO.Visible = true;
                upnlTermsPO1.Visible = true;
                upnlTermsPO2.Visible = true;
                upnlTermsPO3.Visible = true;

                // ... for values that comes from technical
                //tpTechnical.Enabled = true;
                upnlTechnical.Visible = true;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this proposal";
                upnlEngineerSubcontractors.Visible = true;
                upnlEngineerSubcontractors1.Visible = true;
                upnlEngineerSubcontractors2.Visible = true;
                upnlEngineerSubcontractors3.Visible = true;
                upnlEngineerSubcontractors4.Visible = true;
                upnlEngineerSubcontractors5.Visible = true;
                upnlEngineerSubcontractors6.Visible = true;
                upnlEngineerSubcontractors7.Visible = true;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                if ((projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)) == "Awarded") || (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)) == "Bidding"))
                {
                    tpJobInfo.Enabled = true;

                    //tpCostExceptions.Enabled = true;
                    pnlCostsExceptions.Visible = true;
                }

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;

                // Project state check
                switch (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)))
                {
                    case "Bidding":
                        tkrmTop.Items[1].Items[0].Visible = true; //award
                        tkrmTop.Items[1].Items[1].Visible = true; //lost bid
                        tkrmTop.Items[1].Items[2].Visible = true; //cancel
                        tkrmTop.Items[1].Items[3].Visible = false; //bidding
                        tkrmTop.Items[1].Items[4].Visible = true; //hr
                        tkrmTop.Items[1].Items[5].Visible = true; //unpromote
                        tkrmTop.Items[1].Items[6].Visible = false; //promote
                        break;

                    case "Canceled":
                        tkrmTop.Items[1].Items[0].Visible = false;
                        tkrmTop.Items[1].Items[1].Visible = false;
                        tkrmTop.Items[1].Items[2].Visible = false;
                        tkrmTop.Items[1].Items[3].Visible = true;
                        tkrmTop.Items[1].Items[4].Visible = false;
                        tkrmTop.Items[1].Items[5].Visible = false;
                        tkrmTop.Items[1].Items[6].Visible = false;
                        break;

                    case "Lost Bid":
                        tkrmTop.Items[1].Items[0].Visible = false;
                        tkrmTop.Items[1].Items[1].Visible = false;
                        tkrmTop.Items[1].Items[2].Visible = false;
                        tkrmTop.Items[1].Items[3].Visible = true;
                        tkrmTop.Items[1].Items[4].Visible = false; //hr
                        tkrmTop.Items[1].Items[5].Visible = false;
                        tkrmTop.Items[1].Items[6].Visible = false;
                        break;

                    case "Awarded":
                        tkrmTop.Items[1].Items[0].Visible = false;
                        tkrmTop.Items[1].Items[1].Visible = false;
                        tkrmTop.Items[1].Items[2].Visible = false;
                        tkrmTop.Items[1].Items[3].Visible = true;
                        tkrmTop.Items[1].Items[4].Visible = true; //hr
                        tkrmTop.Items[1].Items[5].Visible = false;
                        if (Convert.ToBoolean(Session["sgLFS_PROJECTS_PROMOTEPROPOSALTOPROJECT"]))
                        {
                            tkrmTop.Items[1].Items[6].Visible = true;
                        }
                        else
                        {
                            tkrmTop.Items[1].Items[6].Visible = false;
                        }
                        break;
                }
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Project")
            {
                // Set initial tab
                tcDetailedInformation.ActiveTabIndex = Int32.Parse(hdfActiveTab.Value);

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Project";

                // Top Menu
                tkrmTop.Items[1].Visible = false;
                tkrmTop.Items[2].Visible = true;
                tkrmTop.Items[3].Visible = false;
                tkrmTop.Items[4].Visible = false;

                lblHeaderTitle.Text = "Project Summary";
                lblTitleProject.Text = " > Project: ";

                lblStartDate.Text = "Start Date";
                lblEndDate.Text = "End Date";

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = true;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = true;
                upnlSaleBillingPricingValues.Visible = true;
                upnlSaleBillingPricingValues1.Visible = true;

                // ... for values that comes from costing updates
                //tpCostingUpdates.Enabled = true;

                // ... for values that comes from terms po
                // tpTermsPo.Enabled = true;
                upnlTermsPO.Visible = true;
                upnlTermsPO1.Visible = true;
                upnlTermsPO2.Visible = true;
                upnlTermsPO3.Visible = true;

                // ... for values that comes from technical
                // tpTechnical.Enabled = true;
                upnlTechnical.Visible = true;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this project";
                upnlEngineerSubcontractors.Visible = true;
                upnlEngineerSubcontractors1.Visible = true;
                upnlEngineerSubcontractors2.Visible = true;
                upnlEngineerSubcontractors3.Visible = true;
                upnlEngineerSubcontractors4.Visible = true;
                upnlEngineerSubcontractors5.Visible = true;
                upnlEngineerSubcontractors6.Visible = true;
                upnlEngineerSubcontractors7.Visible = true;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = true;
                pnlCostsExceptions.Visible = true;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;

                // Project state check
                switch (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)))
                {
                    case "Waiting":
                        tkrmTop.Items[2].Items[0].Visible = false; //waiting
                        tkrmTop.Items[2].Items[1].Visible = true; //activate
                        tkrmTop.Items[2].Items[2].Visible = false; //inactive
                        tkrmTop.Items[2].Items[3].Visible = false; //complete
                        tkrmTop.Items[2].Items[4].Visible = true; //cancel
                        tkrmTop.Items[2].Items[5].Visible = false; //hr
                        tkrmTop.Items[2].Items[6].Visible = false; //un promote to ballpark
                        tkrmTop.Items[2].Items[7].Visible = false; //un promote to proposal
                        tkrmTop.Items[2].Items[8].Visible = false; //hr
                        tkrmTop.Items[2].Items[9].Visible = false; //tag as internal
                        break;

                    case "Active":
                        tkrmTop.Items[2].Items[0].Visible = true; //waiting
                        tkrmTop.Items[2].Items[1].Visible = false; //activate
                        tkrmTop.Items[2].Items[2].Visible = true; //inactive
                        tkrmTop.Items[2].Items[3].Visible = true; //complete
                        tkrmTop.Items[2].Items[4].Visible = true; //cancel
                        tkrmTop.Items[2].Items[5].Visible = true; //hr
                        tkrmTop.Items[2].Items[6].Visible = true; //un promote to ballpark
                        tkrmTop.Items[2].Items[7].Visible = true; //un promote to proposal
                        tkrmTop.Items[2].Items[8].Visible = true; //hr
                        tkrmTop.Items[2].Items[9].Visible = true; //tag as internal
                        break;

                    case "Inactive":
                        tkrmTop.Items[2].Items[0].Visible = false; //waiting
                        tkrmTop.Items[2].Items[1].Visible = true; //activate
                        tkrmTop.Items[2].Items[2].Visible = false; //inactive
                        tkrmTop.Items[2].Items[3].Visible = false; //complete
                        tkrmTop.Items[2].Items[4].Visible = true; //cancel
                        tkrmTop.Items[2].Items[5].Visible = false; //hr
                        tkrmTop.Items[2].Items[6].Visible = false; //un promote to ballpark
                        tkrmTop.Items[2].Items[7].Visible = false; //un promote to proposal
                        tkrmTop.Items[2].Items[8].Visible = false; //hr
                        tkrmTop.Items[2].Items[9].Visible = false; //tag as internal
                        break;

                    case "Canceled":
                        tkrmTop.Items[2].Items[0].Visible = false; //waiting
                        tkrmTop.Items[2].Items[1].Visible = true; //activate
                        tkrmTop.Items[2].Items[2].Visible = false; //inactive
                        tkrmTop.Items[2].Items[3].Visible = false; //complete
                        tkrmTop.Items[2].Items[4].Visible = false; //cancel
                        tkrmTop.Items[2].Items[5].Visible = false; //hr
                        tkrmTop.Items[2].Items[6].Visible = false; //un promote to ballpark
                        tkrmTop.Items[2].Items[7].Visible = false; //un promote to proposal
                        tkrmTop.Items[2].Items[8].Visible = false; //hr
                        tkrmTop.Items[2].Items[9].Visible = false; //tag as internal
                        break;

                    case "Complete":
                        tkrmTop.Items[2].Items[0].Visible = false; //waiting
                        tkrmTop.Items[2].Items[1].Visible = true; //activate
                        tkrmTop.Items[2].Items[2].Visible = false; //inactive
                        tkrmTop.Items[2].Items[3].Visible = false; //complete
                        tkrmTop.Items[2].Items[4].Visible = false; //cancel
                        tkrmTop.Items[2].Items[5].Visible = false; //hr
                        tkrmTop.Items[2].Items[6].Visible = false; //un promote to ballpark
                        tkrmTop.Items[2].Items[7].Visible = false; //un promote to proposal
                        tkrmTop.Items[2].Items[8].Visible = false; //hr
                        tkrmTop.Items[2].Items[9].Visible = false; //tag as internal
                        break;
                }
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Internal")
            {
                // Active Tab
                tcDetailedInformation.ActiveTabIndex = 1;

                // Left menu
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Internal Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Internal Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[2].Visible = false; //mSeparator
                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections

                // Top Menu
                tkrmTop.Items[1].Visible = false;
                tkrmTop.Items[2].Visible = false;
                tkrmTop.Items[3].Visible = true;
                tkrmTop.Items[4].Visible = false;

                lblHeaderTitle.Text = "Internal Project Summary";
                lblTitleProject.Text = " > Internal Project: ";

                // Initial section
                lblProposalDate.Text = "Internal Project Date";
                lblStartDate.Visible = false;
                tbxStartDate.Visible = false;
                lblEndDate.Visible = false;
                tbxEndDate.Visible = false;
                tbxDescription.Width = Unit.Pixel(510);

                // Client section
                lblClientProjectNumber.Visible = false;
                tbxClientProjectNumber.Visible = false;
                lblClientPrimaryContactId.Visible = false;
                tbxClientPrimaryContact.Visible = false;
                btnClientPrimaryContact.Visible = false;
                lblClientSecondaryContactId.Visible = false;
                tbxClientSecondaryContact.Visible = false;
                btnClientSecondaryContact.Visible = false;

                // Pricing section
                pnlPricing.Visible = false;

                // Tabs visibility
                tpJobInfo.Enabled = true;
                upnlTypeOfWork.Visible = false;

                // ... for values that comes from sales billing pricing
                //tpSaleBillingPricing.Enabled = false;
                upnlSaleBillingPricingValues.Visible = false;
                upnlSaleBillingPricingValues1.Visible = false;

                // ... for values that comes from costing updates
                // tpCostingUpdates.Enabled = false;

                // ... for values that comes from terms po
                //tpTermsPo.Enabled = false;
                upnlTermsPO.Visible = false;
                upnlTermsPO1.Visible = false;
                upnlTermsPO2.Visible = false;
                upnlTermsPO3.Visible = false;

                // ... for values that comes from technical
                //tpTechnical.Enabled = false;
                upnlTechnical.Visible = false;

                // ... for values that comes from engineer subcontractors
                // tpEngineerSubcontractors.Enabled = true;
                // Subcontractor section
                // lblNoResults.Text = "Sub-Contractors are not defined for this internal project";
                upnlEngineerSubcontractors.Visible = false;
                upnlEngineerSubcontractors1.Visible = false;
                upnlEngineerSubcontractors2.Visible = false;
                upnlEngineerSubcontractors3.Visible = false;
                upnlEngineerSubcontractors4.Visible = false;
                upnlEngineerSubcontractors5.Visible = false;
                upnlEngineerSubcontractors6.Visible = false;
                upnlEngineerSubcontractors7.Visible = false;

                // ... for values that comes from cost exceptions
                //tpCostExceptions.Enabled = false;
                pnlCostsExceptions.Visible = false;

                // ... for values that comes from notes
                //tpNotes.Enabled = true;
                upnlNotes.Visible = true;

                // Project state check
                switch (projectGateway.GetProjectState(int.Parse(hdfProjectId.Value)))
                {
                    case "Active":
                        tkrmTop.Items[3].Items[0].Visible = false; //activate
                        tkrmTop.Items[3].Items[1].Visible = true; //cancel
                        tkrmTop.Items[3].Items[2].Visible = true; //complete
                        tkrmTop.Items[2].Items[3].Visible = true; //hr
                        tkrmTop.Items[3].Items[4].Visible = true; //promote to proposal
                        tkrmTop.Items[3].Items[5].Visible = true; //promote to project
                        break;

                    case "Canceled":
                        tkrmTop.Items[3].Items[0].Visible = true; //activate
                        tkrmTop.Items[3].Items[1].Visible = false; //cancel
                        tkrmTop.Items[3].Items[2].Visible = false; //complete
                        tkrmTop.Items[2].Items[3].Visible = false; //hr
                        tkrmTop.Items[3].Items[4].Visible = false; //promote to proposal
                        tkrmTop.Items[3].Items[5].Visible = false; //promote to project
                        break;

                    case "Complete":
                        tkrmTop.Items[3].Items[0].Visible = true; //activate
                        tkrmTop.Items[3].Items[1].Visible = false; //cancel
                        tkrmTop.Items[3].Items[2].Visible = false; //complete
                        tkrmTop.Items[2].Items[3].Visible = false; //hr
                        tkrmTop.Items[3].Items[4].Visible = false; //promote to proposal
                        tkrmTop.Items[3].Items[5].Visible = false; //promote to project
                        break;
                }
            }
        }
        private void InsertProject(int projectId)
        {
            // ... Data for current project
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            projectGateway.LoadByProjectId(projectId);

            // ... Definition of general variables
            Int64 countryId = projectGateway.GetCountryID(projectId);
            int officeId = projectGateway.GetOfficeID(projectId);
            Int64? provinceId = projectGateway.GetProvinceID(projectId);
            Int64? cityId = projectGateway.GetCityID(projectId);
            Int64? countyId = projectGateway.GetCountyID(projectId);
            int? projectLeadId = null; if (projectGateway.GetProjectLeadID(projectId).HasValue) projectLeadId = (int)projectGateway.GetProjectLeadID(projectId);
            int salesmanId = projectGateway.GetSalesmanID(projectId);
            bool deleted = false;
            int? clientPrimaryContactID = null; if (projectGateway.GetClientPrimaryContactID(projectId).HasValue) clientPrimaryContactID = (int)projectGateway.GetClientPrimaryContactID(projectId);
            int? clientSecondaryContactID = null; if (projectGateway.GetClientSecondaryContactID(projectId).HasValue) clientSecondaryContactID = (int)projectGateway.GetClientSecondaryContactID(projectId);
            int? OriginalProjectID = projectId;
            int? projectNumberCopy = null; if (projectGateway.GetLastProjectNumberCopy(projectId).HasValue) projectNumberCopy = (int)projectGateway.GetLastProjectNumberCopy(projectId) + 1; else projectNumberCopy = 1;
            string projectNumber = projectGateway.GetProjectNumber(projectId) + "-" + projectNumberCopy.ToString();
            string projectType = "Proposal";
            string projectState = projectGateway.GetProjectState(projectId);
            string name = projectGateway.GetName(projectId);
            string description = projectGateway.GetDescription(projectId);
            DateTime? proposalDate = null; if (projectGateway.GetProposalDate(projectId).HasValue) proposalDate = projectGateway.GetProposalDate(projectId);
            DateTime? startDate = null; if (projectGateway.GetStartDate(projectId).HasValue) startDate = projectGateway.GetStartDate(projectId);
            DateTime? endDate = null; if (projectGateway.GetEndDate(projectId).HasValue) endDate = projectGateway.GetEndDate(projectId);
            int clientId = projectGateway.GetClientID(projectId);
            string clientProjectNumber = projectGateway.GetClientProjectNumber(projectId);
            int? libraryCategoriesId = null; if (projectGateway.GetLibraryCategoriesId(projectId).HasValue) libraryCategoriesId = (int)projectGateway.GetLibraryCategoriesId(projectId);
            bool fairWageApplies = projectGateway.GetFairWageApplies(projectId);

            // ... Insert Project
            Project project = new Project(projectTDS);
            project.Insert(countryId, officeId, projectLeadId, salesmanId, projectNumber, projectType, projectState, name, description, proposalDate, startDate, endDate, clientId, clientPrimaryContactID, clientSecondaryContactID, clientProjectNumber, deleted, OriginalProjectID, projectNumberCopy, libraryCategoriesId, provinceId, cityId, Int32.Parse(hdfCompanyId.Value.Trim()), countyId, fairWageApplies);

            // ... Insert History
            ProjectHistory projectHistory = new ProjectHistory(projectTDS);
            projectHistory.Insert(0, 1, projectState, DateTime.Now, Convert.ToInt32(Session["loginID"]), Int32.Parse(hdfCompanyId.Value.Trim()));
        }
        protected void cvProject_ServerValidate(object source, ServerValidateEventArgs args)
        {
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(Convert.ToInt32(ddlProject.SelectedValue));

            if (projectGateway.GetProjectState(Convert.ToInt32(ddlProject.SelectedValue)) != "Active")
            {
                if (projectGateway.GetProjectType(Convert.ToInt32(ddlProject.SelectedValue)) != "Ballpark")
                {
                    cvProject.ErrorMessage = "Please select an active project or an active internal project";
                }

                if (projectGateway.GetProjectType(Convert.ToInt32(ddlProject.SelectedValue)) == "Ballpark")
                {
                    cvProject.ErrorMessage = "Please select an active ballpark";
                }

                args.IsValid = false;
            }
            else
            {
                args.IsValid = true;
            }
        }