private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = "Full Length Lining";
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfErrorFieldList.Value = "";

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

            // Get workId
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            string workType = hdfWorkType.Value;

            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);
            hdfWorkId.Value = workGateway.GetWorkId(assetId, workType, projectId).ToString();
            hdfWorkIdJl.Value = GetWorkId(projectId, assetId, "Junction Lining Section", companyId).ToString();
        }
        private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int sectionAssetId = Int32.Parse(hdfAssetId.Value);
            bool isNewMeasuredFromDsmh = false;

            FullLengthLiningLateralDetails flLateralDetails = new FullLengthLiningLateralDetails();
            flLateralDetails.LoadForEdit(workId, sectionAssetId, companyId, projectId);

            if (flLateralDetails.Table.Rows.Count == 0)
            {
                if (ddlM1DataMeasuredFromMh.SelectedValue == "DSMH")
                {
                    isNewMeasuredFromDsmh = true;
                    FullLengthLiningLateralDetails fllLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                    fllLateralDetails.ModifyLateralId();
                }
            }

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save lateral details
                // Save lateral details
                bool roboticPrepCompleted = ckbxPrepDataRoboticPrepCompleted.Checked;
                DateTime? roboticPrepCompletedCompleted = null; if (tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.HasValue) roboticPrepCompletedCompleted = tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.Value;

                FullLengthLiningLateralDetails fullLengthLiningLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                fullLengthLiningLateralDetails.Save(workId, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, tbxVideoLength.Text.Trim(), companyId, isNewMeasuredFromDsmh, roboticPrepCompleted, roboticPrepCompletedCompleted);

                // Save catalyst details
                string newRunDetails = "";
                foreach (ListItem lst in cbxlSectionId.Items)
                {
                    if (lst.Selected)
                    {
                        newRunDetails = newRunDetails + lst.Value + ">";
                    }
                }
                newRunDetails = newRunDetails.Substring(0, newRunDetails.Length - 1);
                FullLengthLiningWetOutCatalystsDetails fullLengthLiningWetOutCatalystsDetails = new FullLengthLiningWetOutCatalystsDetails(fullLengthLiningTDS);
                fullLengthLiningWetOutCatalystsDetails.Save(companyId, newRunDetails, projectId);

                // Save section details
                FullLengthLiningSectionDetails fullLengthLiningSectionDetails = new FullLengthLiningSectionDetails(fullLengthLiningTDS);
                fullLengthLiningSectionDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId);

                // Save work details
                FullLengthLiningWorkDetails fullLengthLiningWorkDetails = new FullLengthLiningWorkDetails(fullLengthLiningTDS);
                fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, sectionAssetId, companyId, ckbxWetOutDataIncludeWetOutInformation.Checked, ckbxInversionDataIncludeInversionInformation.Checked);

                // Save material details
                string newMaterial = ddlM1DataMaterial.SelectedValue;

                if (ddlM1DataMaterial.SelectedIndex > 0)
                {
                    LfsAssetSewerLateralGateway lfsAssetSewertLateralGateway = new LfsAssetSewerLateralGateway(null);
                    if (!lfsAssetSewertLateralGateway.IsUsedInMaterials(sectionAssetId, newMaterial, companyId))
                    {
                        MaterialInformation materialInformation = new MaterialInformation(materialInformationTDS);
                        materialInformation.Save(companyId);
                    }
                }

                DB.CommitTransaction();

                // Store datasets
                fullLengthLiningTDS.AcceptChanges();
                Session["fullLengthLiningTDS"] = fullLengthLiningTDS;

                materialInformationTDS.AcceptChanges();
                Session["materialInformationTDS"] = materialInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private int UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            Int64? countryId = null;
            Int64? provinceId = null;
            Int64? countyId = null;
            Int64? cityId = null;

            if (projectGateway.Table.Rows.Count > 0)
            {
                // ... Get ids
                try
                {//TODO MH
                    countryId = projectGateway.GetCountryID(projectId);
                }
                catch
                {
                }
                if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
                if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
                if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);
            }

            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            bool inProject = bool.Parse(hdfInProject.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save section details
                ManholeRehabilitationManholeDetails manholeRehabilitationManholeDetails = new ManholeRehabilitationManholeDetails(manholeRehabilitationTDS);
                manholeRehabilitationManholeDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId);

                // Save work details
                ManholeRehabilitationWorkDetails fullLengthLiningWorkDetails = new ManholeRehabilitationWorkDetails(manholeRehabilitationTDS);
                workId = fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, inProject);

                DB.CommitTransaction();

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

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }

            return workId;
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);

            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

            // Get workId
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, "Point Repairs", companyId);
            hdfWorkId.Value = workGateway.GetWorkId(assetId, "Point Repairs", projectId).ToString();
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="loginId">loginId</param>
        public void Save(int companyId, int loginId)
        {
            foreach (DataMigrationTDS.JlDataMigrationRow row in (DataMigrationTDS.JlDataMigrationDataTable)Table)
            {
                // Get ids & location
                ProjectGateway projectGateway = new ProjectGateway();
                DataMigrationProjectGateway dataMigrationProjectGateway = new DataMigrationProjectGateway(null);
                string name = string.Format("{0} Data Migration Project", row.Client);

                int projectId = dataMigrationProjectGateway.GetProjectIdByName(name);

                if (projectId != 0)
                {
                    projectGateway.LoadByProjectId(projectId);

                    // get parameters
                    Int64 countryId = projectGateway.GetCountryID(projectId);
                    Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = projectGateway.GetProvinceID(projectId);
                    Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = projectGateway.GetCountyID(projectId);
                    Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = projectGateway.GetCityID(projectId);

                    //Save section
                    int section_assetId = SaveSection(row, projectId, countryId, provinceId, countyId, cityId, companyId);
                    Guid originalId = row.OriginalID;

                    if (row.JLiner)
                    {
                        SaveJLWork(originalId, section_assetId, row.NumLats, row.NotLinedYet, row.AllMeasured, row.IssueWithLaterals, row.NotMeasuredYet, row.NotDeliveredYet, projectId, countryId, provinceId, countyId, cityId, companyId);
                    }

                    // Insert in DataMigration Table
                    string originalSectionId = row.OriginalSectionID;
                    AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                    assetSewerSectionGateway.LoadByAssetId(section_assetId, companyId);
                    string newSectionId = assetSewerSectionGateway.GetSectionId(section_assetId);

                    DataMigrationGateway dataMigrationGateway = new DataMigrationGateway(null);
                    dataMigrationGateway.InsertDataMigration(originalId, originalSectionId, section_assetId, newSectionId);
                }
            }
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = "Manhole Rehabilitation";
            hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
            hdfActiveTab.Value = Request.QueryString["active_tab"].ToString();
            hdfInProject.Value = Request.QueryString["in_project"].ToString();
            hdfExistBatchId.Value = "False";

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            if (projectGateway.Table.Rows.Count > 0)
            {
                // ... Get ids
                Int64 currentCountry = projectGateway.GetCountryID(projectId);
                Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
                Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
                Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

                hdfCountryId.Value = currentCountry.ToString();
                hdfProvinceId.Value = currentProvince.ToString();
                hdfCountyId.Value = currentCounty.ToString();
                hdfCityId.Value = currentCity.ToString();
            }
            else
            {
                hdfCountryId.Value = "";
                hdfProvinceId.Value = "";
                hdfCountyId.Value = "";
                hdfCityId.Value = "";
            }

            // Get workId
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            string workType = hdfWorkType.Value;

            WorkGateway workGateway = new WorkGateway();
            hdfWorkId.Value = "0";

            workGateway.LoadByProjectIdAssetIdWorkType(projectId, assetId, workType, companyId);

            if (workGateway.Table.Rows.Count > 0)
            {
                hdfWorkId.Value = workGateway.GetWorkId(assetId, workType, projectId).ToString();
            }
        }
        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()));
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="projectId">projectId</param>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="loginId">loginId</param>
        public void Save(int companyId, int loginId)
        {
            foreach (DataMigrationTDS.DataMigrationRow row in (DataMigrationTDS.DataMigrationDataTable)Table)
            {
                // Get ids & location
                ProjectGateway projectGateway = new ProjectGateway();
                DataMigrationProjectGateway dataMigrationProjectGateway = new DataMigrationProjectGateway(null);
                string name = string.Format("{0} Data Migration Project", row.Client);

                int projectId = dataMigrationProjectGateway.GetProjectIdByName(name);

                if (projectId != 0)
                {
                    projectGateway.LoadByProjectId(projectId);

                    // get parameters
                    Int64 countryId = projectGateway.GetCountryID(projectId);
                    Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = projectGateway.GetProvinceID(projectId);
                    Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = projectGateway.GetCountyID(projectId);
                    Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = projectGateway.GetCityID(projectId);

                    //Save section
                    int section_assetId = SaveSection(row, projectId, countryId, provinceId, countyId, cityId, companyId);

                    if (row.RehabAssessment)
                    {
                        string raComments = "";
                        SaveRAWork(row, projectId, section_assetId, companyId, raComments, loginId);
                    }

                    if (row.FullLengthLining)
                    {
                        string fllComments = "";
                        SaveFLLWork(row, projectId, section_assetId, companyId, fllComments, loginId);
                    }

                    if (row.JLiner)
                    {
                        SaveJLWork(projectId, section_assetId, companyId);
                    }

                    // Insert in DataMigration Table
                    Guid originalId = row.OriginalID;
                    string originalSectionId = row.OriginalSectionID;
                    AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                    assetSewerSectionGateway.LoadByAssetId(section_assetId, companyId);
                    string newSectionId = assetSewerSectionGateway.GetSectionId(section_assetId);

                    DataMigrationGateway dataMigrationGateway = new DataMigrationGateway(null);
                    dataMigrationGateway.InsertDataMigration(originalId, originalSectionId, section_assetId, newSectionId);
                }
            }
        }
        private void TagPage()
        {
            //hdfWorkType.Value = Request.QueryString["work_type"].ToString();
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfProjectId.Value = Request.QueryString["project_id"].ToString();

            // Get ids & location
            int projectId = Int32.Parse(hdfProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            if (projectGateway.Table.Rows.Count > 0)
            {
                // ... Get ids
                Int64 currentCountry = projectGateway.GetCountryID(projectId);
                Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
                Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
                Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

                hdfCountryId.Value = currentCountry.ToString();
                hdfProvinceId.Value = currentProvince.ToString();
                hdfCountyId.Value = currentCounty.ToString();
                hdfCityId.Value = currentCity.ToString();
            }
            else
            {
                hdfCountryId.Value = "0";
                hdfProvinceId.Value = "0";
                hdfCountyId.Value = "0";
                hdfCityId.Value = "0";
            }
        }
        private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int workIdFll = Int32.Parse(hdfWorkIdFll.Value);
            int sectionAssetId = Int32.Parse(hdfAssetId.Value);

            bool isNewMeasuredFromDsmh = false;

            RehabAssessmentLateralDetails raLateralDetails = new RehabAssessmentLateralDetails();
            raLateralDetails.LoadForEdit(workIdFll, sectionAssetId, companyId, projectId);

            if (raLateralDetails.Table.Rows.Count == 0)
            {
                if (ddlM1DataMeasuredFromMh.SelectedValue == "DSMH")
                {
                    isNewMeasuredFromDsmh = true;
                    RehabAssessmentLateralDetails raaLateralDetails = new RehabAssessmentLateralDetails(rehabAssessmentTDS);
                    raaLateralDetails.ModifyLateralId();
                }
            }

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save lateral details
                bool roboticPrepCompleted = ckbxPrepDataRoboticPrepCompleted.Checked;
                DateTime? roboticPrepCompletedCompleted = null; if (tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.HasValue) roboticPrepCompletedCompleted = tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate.Value;

                RehabAssessmentLateralDetails rehabAssessmentLateralDetails = new RehabAssessmentLateralDetails(rehabAssessmentTDS);
                rehabAssessmentLateralDetails.Save(workIdFll, projectId, sectionAssetId, countryId, provinceId, countyId, cityId, tbxVideoLength.Text.Trim(), companyId, isNewMeasuredFromDsmh, roboticPrepCompleted, roboticPrepCompletedCompleted);

                // Save section details
                RehabAssessmentSectionDetails rehabAssessmentSectionDetails = new RehabAssessmentSectionDetails(rehabAssessmentTDS);
                rehabAssessmentSectionDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId);

                // Save work details
                RehabAssessmentWorkDetails rehabAssessmentWorkDetails = new RehabAssessmentWorkDetails(rehabAssessmentTDS);
                rehabAssessmentWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId, sectionAssetId);

                // Save material details
                string newMaterial = ddlM1DataMaterial.SelectedValue;

                if (ddlM1DataMaterial.SelectedIndex > 0)
                {
                    LfsAssetSewerLateralGateway lfsAssetSewertLateralGateway = new LfsAssetSewerLateralGateway(null);
                    if (!lfsAssetSewertLateralGateway.IsUsedInMaterials(sectionAssetId, newMaterial, companyId))
                    {
                        MaterialInformation materialInformation = new MaterialInformation(materialInformationTDS);
                        materialInformation.Save(companyId);
                    }
                }

                DB.CommitTransaction();

                // Store datasets
                rehabAssessmentTDS.AcceptChanges();
                Session["rehabAssessmentTDS"] = rehabAssessmentTDS;

                materialInformationTDS.AcceptChanges();
                Session["materialInformationTDS"] = materialInformationTDS;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProject.Value.Trim());
            int companyId = Int32.Parse(Session["companyID"].ToString());

            // Load project
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // Get location
            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            // Save
            DB.Open();
            DB.BeginTransaction();
            try
            {
                FlatSectionJl flatSectionJl = new FlatSectionJl(flatSectionJlTDS);

                if (Convert.ToBoolean(ViewState["UpdateComments"]))
                {
                    // Update Comments
                    FlatSectionJlCommentDetails flatSectionJlCommentDetails = new FlatSectionJlCommentDetails(flatSectionJlTDS);
                    flatSectionJlCommentDetails.Save(companyId);

                    // Update works
                    WorkUpdate();
                }
                else
                {
                    flatSectionJl.UpdateDirect(countryId, provinceId, countyId, cityId, projectId, companyId);
                }

                DB.CommitTransaction();

                flatSectionJlTDS.AcceptChanges();

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

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void TagPage()
        {
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
            hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
            hdfWorkType.Value = Request.QueryString["work_type"].ToString();
            hdfDataChangedMessage.Value = "Changes made to this lateral will not be saved.";

            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();
        }
        private void UpdateState()
        {
            ProjectGateway projectGateway = new ProjectGateway(projectTDS);
            int projectId = int.Parse(hdfProjectId.Value);
            projectGateway.LoadByProjectId(projectId);

            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 = projectGateway.GetProjectLeadID(projectId);
            int salesmanId = projectGateway.GetSalesmanID(projectId);
            string projectType = projectGateway.GetProjectType(projectId);
            string projectState = null;

            switch ((string)Request.QueryString["state"])
            {
                //Proposal
                case "proposal_award":
                    projectState = "Awarded";
                    break;

                case "proposal_lost_bid":
                    projectState = "Lost Bid";
                    break;

                case "proposal_cancel":
                    projectState = "Canceled";
                    break;

                case "proposal_bidding":
                    projectState = "Bidding";
                    break;

                case "proposal_unpromote_to_ballpark":
                    projectState = "Active";
                    projectType = "Ballpark";
                    break;

                case "proposal_promote_to_project":
                    projectState = "Active";
                    projectType = "Project";
                    break;

                //Project
                case "project_waiting":
                    projectState = "Waiting";
                    break;

                case "project_activate":
                    projectState = "Active";
                    break;

                case "project_inactivate":
                    projectState = "Inactive";
                    break;

                case "project_complete":
                    projectState = "Complete";
                    break;

                case "project_cancel":
                    projectState = "Canceled";
                    break;

                case "project_unpromote_to_ballpark":
                    projectState = "Active";
                    projectType = "Ballpark";
                    break;

                case "project_unpromote_to_proposal":
                    projectState = "Awarded";
                    projectType = "Proposal";
                    break;

                case "project_tagAsInternal":
                    projectState = "Active";
                    projectType = "Internal";
                    break;

                //Internal Project
                case "internalProject_activate":
                    projectState = "Active";
                    break;

                case "internalProject_complete":
                    projectState = "Complete";
                    break;

                case "internalProject_cancel":
                    projectState = "Canceled";
                    break;

                case "internalProject_promote_to_proposal":
                    projectState = "Awarded";
                    projectType = "Proposal";
                    break;

                case "internalProject_promote_to_project":
                    projectState = "Active";
                    projectType = "Project";
                    break;

                //Ballpark
                case "ballparkProject_activate":
                    projectState = "Active";
                    break;

                case "ballparkProject_cancel":
                    projectState = "Canceled";
                    break;

                case "ballparkProject_promote_to_proposal":
                    projectState = "Bidding";
                    projectType = "Proposal";
                    break;

                case "ballparkProject_promote_to_project":
                    projectState = "Active";
                    projectType = "Project";
                    break;
            }

            string name = projectGateway.GetName(projectId);
            string description = projectGateway.GetDescription(projectId);
            DateTime? proposalDate = projectGateway.GetProposalDate(projectId);
            DateTime? startDate = projectGateway.GetStartDate(projectId);
            DateTime? endDate = projectGateway.GetEndDate(projectId);
            int clientId = projectGateway.GetClientID(projectId);
            string clientProjectNumber = projectGateway.GetClientProjectNumber(projectId);
            int? clientPrimaryContactId = projectGateway.GetClientPrimaryContactID(projectId);
            int? clientSecondaryContactId = projectGateway.GetClientSecondaryContactID(projectId);
            bool deleted = projectGateway.GetDeleted(projectId);
            int? libraryCategoriesId = projectGateway.GetLibraryCategoriesId(projectId);
            bool fairWageApplies = projectGateway.GetFairWageApplies(projectId);

            // Update project
            Project project = new Project(projectTDS);
            string projectNumber = project.UpdateProjectNumber(projectId, salesmanId);
            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);

            //Insert in history
            ProjectHistory projectHistory = new ProjectHistory(projectTDS);
            int newRefId = projectHistory.GetNewRefId();
            projectHistory.Insert(projectId, newRefId, projectState, DateTime.Now, Convert.ToInt32(Session["loginID"]), Int32.Parse(hdfCompanyId.Value.Trim()));
        }
        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, "");
                }
            }
        }
        private void UpdateDatabase()
        {
            // Get ids & location
            int projectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            Int64 countryId = projectGateway.GetCountryID(projectId);
            Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
            Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

            string workType = hdfWorkType.Value.Trim();
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int workIdFll = Int32.Parse(hdfWorkIdFll.Value);
            int sectionAssetId = Int32.Parse(hdfAssetId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                // Save repair details
                PointRepairsRepairDetails pointRepairsRepairDetails = new PointRepairsRepairDetails(pointRepairsTDS);
                pointRepairsRepairDetails.Save(companyId);

                // Save comment details
                PointRepairsCommentDetails pointRepairsCommentDetails = new PointRepairsCommentDetails(pointRepairsTDS);
                pointRepairsCommentDetails.Save(companyId);

                // Save section details
                PointRepairsSectionDetails pointRepairsSectionDetails = new PointRepairsSectionDetails(pointRepairsTDS);
                pointRepairsSectionDetails.Save(countryId, provinceId, countyId, cityId, projectId, companyId);

                // Save work details
                PointRepairsWorkDetails pointRepairsWorkDetails = new PointRepairsWorkDetails(pointRepairsTDS);
                pointRepairsWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, sectionAssetId, companyId);

                DB.CommitTransaction();

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

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void TagPage()
        {
            hdfWorkType.Value = Request.QueryString["work_type"].ToString();
            hdfCompanyId.Value = Session["companyID"].ToString();
            hdfProjectId.Value = Request.QueryString["project_id"].ToString();

            // Get ids & location
            int projectId = Int32.Parse(hdfProjectId.Value.Trim());
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            // ... Get ids
            Int64 currentCountry = projectGateway.GetCountryID(projectId);
            Int64? currentProvince = null; if (projectGateway.GetProvinceID(projectId).HasValue) currentProvince = (Int64)projectGateway.GetProvinceID(projectId);
            Int64? currentCounty = null; if (projectGateway.GetCountyID(projectId).HasValue) currentCounty = (Int64)projectGateway.GetCountyID(projectId);
            Int64? currentCity = null; if (projectGateway.GetCityID(projectId).HasValue) currentCity = (Int64)projectGateway.GetCityID(projectId);

            hdfCountryId.Value = currentCountry.ToString();
            hdfProvinceId.Value = currentProvince.ToString();
            hdfCountyId.Value = currentCounty.ToString();
            hdfCityId.Value = currentCity.ToString();

            // .. Get location
            string projectLocation = "";

            CountryGateway countryGateway = new CountryGateway();
            countryGateway.LoadByCountryId(currentCountry);
            projectLocation = projectLocation + countryGateway.GetName(currentCountry);

            if (currentProvince.HasValue)
            {
                ProvinceGateway provinceGateway = new ProvinceGateway();
                provinceGateway.LoadByProvinceId((Int64)currentProvince);
                projectLocation = projectLocation + ", " + provinceGateway.GetName((Int64)currentProvince);
            }

            if (currentCounty.HasValue)
            {
                CountyGateway countyGateway = new CountyGateway();
                countyGateway.LoadByCountyId((Int64)currentCounty);
                projectLocation = projectLocation + ", " + countyGateway.GetName((Int64)currentCounty);
            }

            if (currentCity.HasValue)
            {
                CityGateway cityGateway = new CityGateway();
                cityGateway.LoadByCityId((Int64)currentCity);
                projectLocation = projectLocation + ", " + cityGateway.GetName((Int64)currentCity);
            }

            hdfSearchTitle.Value = projectLocation;
        }
        private void UpdateDatabase()
        {
            try
            {
                TeamProjectTime2Gateway teamProjectTime2Gateway = new TeamProjectTime2Gateway(teamProjectTime2TDSToSave);
                teamProjectTime2Gateway.Update(projectTime2TDS);

                teamProjectTime2TDSToSave.AcceptChanges();
                teamProjectTime2TDS.AcceptChanges();
                projectTime2TDS.AcceptChanges();
                Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            }
            catch (Exception ex)
            {
                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }

            DB.Open();
            DB.BeginTransaction();
            try
            {
                if (ddlTypeOfWork.SelectedValue == "MH Rehab")
                {
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    // Get ids & location
                    int projectId = Int32.Parse(ddlProject.SelectedValue);
                    ProjectGateway projectGateway = new ProjectGateway();
                    projectGateway.LoadByProjectId(projectId);

                    Int64 countryId = projectGateway.GetCountryID(projectId);
                    Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
                    Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
                    Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

                    manholeRehabilitationTDS = new ManholeRehabilitationTDS();
                    ManholeRehabilitationWorkDetails manholeRehabilitationWorkDetails = new ManholeRehabilitationWorkDetails(manholeRehabilitationTDS);
                    ManholeRehabilitationWorkDetailsGateway manholeRehabilitationWorkDetailsGateway = new ManholeRehabilitationWorkDetailsGateway(manholeRehabilitationTDS);

                    switch (ddlFunction.SelectedValue)
                    {
                        case "Prep":
                            foreach (GridViewRow row in grdManholesRehabPrep.Rows)
                            {
                                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                DateTime? prepDate = Convert.ToDateTime(((Label)row.FindControl("lblPrepDate")).Text);

                                if (selected)
                                {
                                    int assetId = Convert.ToInt32(grdManholesRehabPrep.DataKeys[row.RowIndex].Values["AssetID"].ToString());
                                    int workId = 0;

                                    workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Manhole Rehabilitation", companyId);

                                    manholeRehabilitationWorkDetails.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));

                                    if (manholeRehabilitationWorkDetailsGateway.Table.Rows.Count > 0)
                                    {
                                        int? batchId = manholeRehabilitationWorkDetailsGateway.GetBatchID(workId);
                                        manholeRehabilitationWorkDetails.Update(workId, prepDate, manholeRehabilitationWorkDetailsGateway.GetSprayedDate(workId), batchId, manholeRehabilitationWorkDetailsGateway.GetDate(workId).Value, companyId);
                                    }
                                    else
                                    {
                                        manholeRehabilitationWorkDetails.Update(workId, prepDate, null, null, DateTime.Now, companyId);
                                    }

                                    manholeRehabilitationWorkDetails.Save2(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, true);
                                }
                            }
                            break;

                        case "Spray":
                            foreach (GridViewRow row in grdManholesRehabSpray.Rows)
                            {
                                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                DateTime? sprayDate = Convert.ToDateTime(((Label)row.FindControl("lblSprayDate")).Text);

                                if (selected)
                                {
                                    int assetId = Convert.ToInt32(grdManholesRehabSpray.DataKeys[row.RowIndex].Values["AssetID"].ToString());
                                    int workId = 0;

                                    workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Manhole Rehabilitation", companyId);

                                    manholeRehabilitationWorkDetails.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));

                                    if (manholeRehabilitationWorkDetailsGateway.Table.Rows.Count > 0)
                                    {
                                        int? batchId = manholeRehabilitationWorkDetailsGateway.GetBatchID(workId);
                                        manholeRehabilitationWorkDetails.Update(workId, manholeRehabilitationWorkDetailsGateway.GetPreppedDate(workId), sprayDate, batchId, manholeRehabilitationWorkDetailsGateway.GetDate(workId).Value, companyId);
                                    }
                                    else
                                    {
                                        manholeRehabilitationWorkDetails.Update(workId, null, sprayDate, null, DateTime.Now, companyId);
                                    }

                                    manholeRehabilitationWorkDetails.Save2(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, true);
                                }
                            }
                            break;
                    }

                    DB.CommitTransaction();

                    // Store datasets
                    manholeRehabilitationTDS.AcceptChanges();
                }
                else
                {
                    if (ddlTypeOfWork.SelectedValue == "Full Length")
                    {
                        fullLengthLiningTDS = new FullLengthLiningTDS();
                        AssetSewerSectionGateway aass = new AssetSewerSectionGateway();
                        FullLengthLiningWorkDetails fullLengthLiningWorkDetails = new FullLengthLiningWorkDetails(fullLengthLiningTDS);
                        FullLengthLiningWorkDetailsGateway fullLengthLiningWorkDetailsGateway = new FullLengthLiningWorkDetailsGateway(fullLengthLiningTDS);

                        int assetId = 0;
                        int workId = 0;

                        // Get ids & location
                        int projectId = Int32.Parse(ddlProject.SelectedValue);
                        ProjectGateway projectGateway = new ProjectGateway();
                        projectGateway.LoadByProjectId(projectId);

                        Int64 countryId = projectGateway.GetCountryID(projectId);
                        Int64? provinceId = null; if (projectGateway.GetProvinceID(projectId).HasValue) provinceId = (Int64)projectGateway.GetProvinceID(projectId);
                        Int64? countyId = null; if (projectGateway.GetCountyID(projectId).HasValue) countyId = (Int64)projectGateway.GetCountyID(projectId);
                        Int64? cityId = null; if (projectGateway.GetCityID(projectId).HasValue) cityId = (Int64)projectGateway.GetCityID(projectId);

                        int companyId = Int32.Parse(hdfCompanyId.Value);

                        switch (ddlFunction.SelectedValue)
                        {
                            case "Install":
                                foreach (GridViewRow row in grdSectionsInstall.Rows)
                                {
                                    bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                    DateTime? installDate = Convert.ToDateTime(((Label)row.FindControl("lblInstallDate")).Text);

                                    if (selected)
                                    {
                                        if (installDate != tkrdpDate_.SelectedDate.Value)
                                        {
                                            installDate = tkrdpDate_.SelectedDate.Value;
                                        }

                                        string sectionId = grdSectionsInstall.DataKeys[row.RowIndex].Values["SectionID"].ToString();
                                        aass.LoadBySectionId(sectionId, companyId);
                                        assetId = aass.GetAssetID(sectionId);
                                        workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Full Length Lining", companyId);

                                        fullLengthLiningWorkDetails.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));
                                        fullLengthLiningWorkDetails.Update(workId, fullLengthLiningWorkDetailsGateway.GetP1Date(workId), fullLengthLiningWorkDetailsGateway.GetP1Completed(workId), installDate, fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId));
                                        fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, false, false);
                                    }
                                }
                                break;

                            case "Prep & Measure":
                                foreach (GridViewRow row in grdSections.Rows)
                                {
                                    bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                    bool completed = ((CheckBox)row.FindControl("cbxCompleted")).Checked;
                                    DateTime? prepDate = Convert.ToDateTime(((Label)row.FindControl("lblPrepDate")).Text);

                                    if (selected)
                                    {
                                        if (completed)
                                        {
                                            if (prepDate != tkrdpDate_.SelectedDate.Value)
                                            {
                                                prepDate = tkrdpDate_.SelectedDate.Value;
                                            }
                                        }
                                        else
                                        {
                                            prepDate = null;
                                        }

                                        string sectionId = grdSections.DataKeys[row.RowIndex].Values["SectionID"].ToString();
                                        aass.LoadBySectionId(sectionId, companyId);
                                        assetId = aass.GetAssetID(sectionId);
                                        workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Full Length Lining", companyId);

                                        fullLengthLiningWorkDetails.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));
                                        fullLengthLiningWorkDetails.Update(workId, prepDate, completed, fullLengthLiningWorkDetailsGateway.GetInstallDate(workId), fullLengthLiningWorkDetailsGateway.GetFinalVideoDate(workId));
                                        fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, false, false);
                                    }
                                }
                                break;

                            case "Reinstate & Post Video":
                                FullLengthLiningLateralDetails fullLengthLiningLateralDetails = new FullLengthLiningLateralDetails(fullLengthLiningTDS);
                                FullLengthLiningLateralDetailsGateway fullLengthLiningLateralDetailsGateway = new FullLengthLiningLateralDetailsGateway(fullLengthLiningTDS);

                                foreach (GridViewRow row in grdSectionsReinstatePostVideo.Rows)
                                {
                                    bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                    bool completed = ((CheckBox)row.FindControl("cbxCompleted")).Checked;
                                    DateTime? postVideo = Convert.ToDateTime(((Label)row.FindControl("lblPostVideo")).Text);
                                    string sectionId = grdSectionsReinstatePostVideo.DataKeys[row.RowIndex].Values["SectionID"].ToString();

                                    aass.LoadBySectionId(sectionId, companyId);
                                    assetId = aass.GetAssetID(sectionId);
                                    workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Full Length Lining", companyId);

                                    if (selected)
                                    {
                                        if (completed)
                                        {
                                            if (postVideo != tkrdpDate_.SelectedDate.Value)
                                            {
                                                postVideo = tkrdpDate_.SelectedDate.Value;
                                            }
                                        }
                                        else
                                        {
                                            postVideo = null;
                                        }

                                        fullLengthLiningWorkDetails.LoadByWorkIdAssetId(workId, assetId, Int32.Parse(hdfCompanyId.Value));
                                        fullLengthLiningWorkDetails.Update(workId, fullLengthLiningWorkDetailsGateway.GetP1Date(workId), fullLengthLiningWorkDetailsGateway.GetP1Completed(workId), fullLengthLiningWorkDetailsGateway.GetInstallDate(workId), postVideo);
                                        fullLengthLiningWorkDetails.Save(countryId, provinceId, countyId, cityId, projectId, assetId, companyId, false, false);
                                    }
                                }

                                foreach (GridViewRow row in grdLaterals.Rows)
                                {
                                    string sectionId = grdLaterals.DataKeys[row.RowIndex].Values["SectionID"].ToString();
                                    int assetIdLateral = Convert.ToInt32(((Label)row.FindControl("lblAssetIDLateral")).Text);
                                    bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                    DateTime? opened = null; if (((CheckBox)row.FindControl("cbxOpened")).Checked) opened = tkrdpDate_.SelectedDate;
                                    DateTime? brushed = null; if (((CheckBox)row.FindControl("cbxBrushed")).Checked) brushed = tkrdpDate_.SelectedDate;

                                    if (selected)
                                    {
                                        aass.LoadBySectionId(sectionId, companyId);
                                        assetId = aass.GetAssetID(sectionId);
                                        workId = GetWorkId(Int32.Parse(ddlProject.SelectedValue), assetId, "Full Length Lining", companyId);

                                        fullLengthLiningLateralDetails.SaveFll(workId, assetIdLateral, companyId, opened, brushed);
                                    }
                                }
                                break;
                        }

                        DB.CommitTransaction();

                        // Store datasets
                        fullLengthLiningTDS.AcceptChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }