/// <summary>
        ///Save
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="companyId">companyId</param>
        public void Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int companyId)
        {
            //Update Section
            ManholeRehabilitationTDS manholeChanges = (ManholeRehabilitationTDS)Data.GetChanges();

            if (manholeChanges.ManholeDetails.Rows.Count > 0)
            {
                ManholeRehabilitationManholeDetailsGateway manholeRehabilitationManholeDetailsGateway = new ManholeRehabilitationManholeDetailsGateway(manholeChanges);

                // Update sections
                foreach (ManholeRehabilitationTDS.ManholeDetailsRow manholeDetailsRow in (ManholeRehabilitationTDS.ManholeDetailsDataTable)manholeChanges.ManholeDetails)
                {
                    // Unchanged values
                    int assetId = manholeDetailsRow.AssetID;
                    string mhId = manholeDetailsRow.MHID;

                    // Original values
                    string originalLatitud = manholeRehabilitationManholeDetailsGateway.GetLatitudOriginal(assetId);
                    string originalLongitude = manholeRehabilitationManholeDetailsGateway.GetLongitudeOriginal(assetId);
                    string originalAddress = manholeRehabilitationManholeDetailsGateway.GetAddressOriginal(assetId);
                    string originalManholeShape = manholeRehabilitationManholeDetailsGateway.GetManholeShapeOriginal(assetId);
                    string originalLocation = manholeRehabilitationManholeDetailsGateway.GetLocationOriginal(assetId);
                    int? originalMaterialID = manholeRehabilitationManholeDetailsGateway.GetMaterialIDOriginal(assetId);
                    string originalTopDiameter = manholeRehabilitationManholeDetailsGateway.GetTopDiameterOriginal(assetId);
                    string originalTopDepth = manholeRehabilitationManholeDetailsGateway.GetTopDepthOriginal(assetId);
                    string originalTopFloor = manholeRehabilitationManholeDetailsGateway.GetTopFloorOriginal(assetId);
                    string originalTopCeiling = manholeRehabilitationManholeDetailsGateway.GetTopCeilingOriginal(assetId);
                    string originalTopBenching = manholeRehabilitationManholeDetailsGateway.GetTopBenchingOriginal(assetId);
                    string originalDownDiameter = manholeRehabilitationManholeDetailsGateway.GetDownDiameterOriginal(assetId);
                    string originalDownDepth = manholeRehabilitationManholeDetailsGateway.GetDownDepthOriginal(assetId);
                    string originalDownFloor = manholeRehabilitationManholeDetailsGateway.GetDownFloorOriginal(assetId);
                    string originalDownCeiling = manholeRehabilitationManholeDetailsGateway.GetDownCeilingOriginal(assetId);
                    string originalDownBenching = manholeRehabilitationManholeDetailsGateway.GetDownBenchingOriginal(assetId);
                    string originalRectangle1LongSide = manholeRehabilitationManholeDetailsGateway.GetRectangle1LongSideOriginal(assetId);
                    string originalRectangle1ShortSide = manholeRehabilitationManholeDetailsGateway.GetRectangle1ShortSideOriginal(assetId);
                    string originalRectangle2LongSide = manholeRehabilitationManholeDetailsGateway.GetRectangle2LongSideOriginal(assetId);
                    string originalRectangle2ShortSide = manholeRehabilitationManholeDetailsGateway.GetRectangle2ShortSideOriginal(assetId);
                    string originalTopSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetTopSurfaceAreaOriginal(assetId);
                    string originalDownSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetDownSurfaceAreaOriginal(assetId);
                    int? originalManholeRugs = manholeRehabilitationManholeDetailsGateway.GetManholeRugsOriginal(assetId);
                    string originalTotalDepth = manholeRehabilitationManholeDetailsGateway.GetTotalDepthOriginal(assetId);
                    string originalTotalSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetTotalSurfaceAreaOriginal(assetId);
                    int? originalConditionRating = manholeRehabilitationManholeDetailsGateway.GetConditionRatingOriginal(assetId);

                    // New variables
                    string newLatitud = manholeRehabilitationManholeDetailsGateway.GetLatitud(assetId);
                    string newLongitude = manholeRehabilitationManholeDetailsGateway.GetLongitude(assetId);
                    string newAddress = manholeRehabilitationManholeDetailsGateway.GetAddress(assetId);
                    string newManholeShape = manholeRehabilitationManholeDetailsGateway.GetManholeShape(assetId);
                    string newLocation = manholeRehabilitationManholeDetailsGateway.GetLocation(assetId);
                    int? newMaterialID = manholeRehabilitationManholeDetailsGateway.GetMaterialID(assetId);
                    string newTopDiameter = manholeRehabilitationManholeDetailsGateway.GetTopDiameter(assetId);
                    string newTopDepth = manholeRehabilitationManholeDetailsGateway.GetTopDepth(assetId);
                    string newTopFloor = manholeRehabilitationManholeDetailsGateway.GetTopFloor(assetId);
                    string newTopCeiling = manholeRehabilitationManholeDetailsGateway.GetTopCeiling(assetId);
                    string newTopBenching = manholeRehabilitationManholeDetailsGateway.GetTopBenching(assetId);
                    string newDownDiameter = manholeRehabilitationManholeDetailsGateway.GetDownDiameter(assetId);
                    string newDownDepth = manholeRehabilitationManholeDetailsGateway.GetDownDepth(assetId);
                    string newDownFloor = manholeRehabilitationManholeDetailsGateway.GetDownFloor(assetId);
                    string newDownCeiling = manholeRehabilitationManholeDetailsGateway.GetDownCeiling(assetId);
                    string newDownBenching = manholeRehabilitationManholeDetailsGateway.GetDownBenching(assetId);
                    string newRectangle1LongSide = manholeRehabilitationManholeDetailsGateway.GetRectangle1LongSide(assetId);
                    string newRectangle1ShortSide = manholeRehabilitationManholeDetailsGateway.GetRectangle1ShortSide(assetId);
                    string newRectangle2LongSide = manholeRehabilitationManholeDetailsGateway.GetRectangle2LongSide(assetId);
                    string newRectangle2ShortSide = manholeRehabilitationManholeDetailsGateway.GetRectangle2ShortSide(assetId);
                    string newTopSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetTopSurfaceArea(assetId);
                    string newDownSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetDownSurfaceArea(assetId);
                    int? newManholeRugs = manholeRehabilitationManholeDetailsGateway.GetManholeRugs(assetId);
                    string newTotalDepth = manholeRehabilitationManholeDetailsGateway.GetTotalDepth(assetId);
                    string newTotalSurfaceArea = manholeRehabilitationManholeDetailsGateway.GetTotalSurfaceArea(assetId);
                    int? newConditionRating = manholeRehabilitationManholeDetailsGateway.GetConditionRating(assetId);

                    // Update
                    AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();
                    assetSewerMHGateway.LoadByAssetId(assetId, companyId);

                    if (assetSewerMHGateway.Table.Rows.Count > 0)
                    {
                        // ... update asset manhole
                        AssetSewerMH assetSewerMH = new AssetSewerMH(assetSewerMHGateway.Data);
                        assetSewerMH.UpdateDirect(assetId, mhId, originalLatitud, originalLongitude, originalAddress, originalManholeShape, originalLocation, originalMaterialID, originalTopDiameter, originalTopDepth, originalTopFloor, originalTopCeiling, originalTopBenching, originalDownDiameter, originalDownDepth, originalDownFloor, originalDownCeiling, originalDownBenching, originalRectangle1LongSide, originalRectangle1ShortSide, originalRectangle2LongSide, originalRectangle2ShortSide, originalTopSurfaceArea, originalDownSurfaceArea, originalManholeRugs, originalTotalDepth, originalTotalSurfaceArea, false, companyId, assetId, mhId, newLatitud, newLongitude, newAddress, newManholeShape, newLocation, newMaterialID, newTopDiameter, newTopDepth, newTopFloor, newTopCeiling, newTopBenching, newDownDiameter, newDownDepth, newDownFloor, newDownCeiling, newDownBenching, newRectangle1LongSide, newRectangle1ShortSide, newRectangle2LongSide, newRectangle2ShortSide, newTopSurfaceArea, newDownSurfaceArea, newManholeRugs, newTotalDepth, newTotalSurfaceArea, false, companyId);

                        // ... update lfs manhole
                        LfsAssetSewerMH lfsAssetSewerMH = new LfsAssetSewerMH(null);
                        lfsAssetSewerMH.UpdateDirect(assetId, false, companyId, originalConditionRating, false, companyId, newConditionRating);
                    }
                }
            }
        }
        /// <summary>
        /// UpdateFieldsForSections
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <param name="currentProjectId">currentProjectId</param>
        private void UpdateFieldsForSections(int companyId, int currentProjectId)
        {
            AssetSewerSectionGateway assetSewerFindSectionGateway = new AssetSewerSectionGateway();

            AssetSewerMHGateway assetSewerFindMHGateway = new AssetSewerMHGateway();
            WorkGateway workGateway = new WorkGateway();
            foreach (ProjectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATORRow row in (ProjectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATORDataTable)Table)
            {
                //General data for asset
                assetSewerFindSectionGateway.LoadByAssetId(row.AssetID, companyId); //COMPANY_ID

                // ... For usmh
                row.USMHDescription = "";
                if (!row.IsUSMHNull())
                {
                    assetSewerFindMHGateway.LoadByAssetId(row.USMH, companyId);
                    row.USMHDescription = assetSewerFindMHGateway.GetMHID(row.USMH);
                }

                // ... For dsmh
                row.DSMHDescription = "";
                if (!row.IsDSMHNull())
                {
                    assetSewerFindMHGateway.LoadByAssetId(row.DSMH, companyId);
                    row.DSMHDescription = assetSewerFindMHGateway.GetMHID(row.DSMH);
                }

                // ... For Works
                row.RehabAssessment = workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(row.AssetID, currentProjectId, "Rehab Assessment", companyId);
                row.FullLengthLining = workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(row.AssetID, currentProjectId, "Full Length Lining", companyId);
                row.JunctionLining = workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(row.AssetID, currentProjectId, "Junction Lining Section", companyId);

                row.WorksDescription = "";
                if (row.RehabAssessment) row.WorksDescription = row.WorksDescription + "Rehab Assessment";

                if (row.FullLengthLining)
                {
                    if (row.WorksDescription.Trim().Length > 0)
                    {
                        row.WorksDescription = row.WorksDescription + ", Full Length Lining";
                    }
                    else
                    {
                        row.WorksDescription = row.WorksDescription + "Full Length Lining";
                    }
                }
                if (row.JunctionLining)
                {
                    if (row.WorksDescription.Trim().Length > 0)
                    {
                        row.WorksDescription = row.WorksDescription + ", Junction Lining";
                    }
                    else
                    {
                        row.WorksDescription = row.WorksDescription + "Junction Lining";
                    }
                }

                // ... For Laterals
                AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway();

                assetSewerLateralGateway.LoadBySectionId(row.AssetID, companyId);

                AssetSewerLateral assetSewerLateral = new AssetSewerLateral(assetSewerLateralGateway.Data);
                row.LateralsDescription = assetSewerLateral.GetAllLaterals(row.AssetID, companyId);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                }

                // Validate query string
                if (Request.QueryString["source_page"] == null)
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in projects2.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfAssetID.Value = Request.QueryString["asset_id"];
                Session.Remove("projectSectionsNavigatorLateralsNewDummy");
                Session.Remove("projectSectionsNavigatorLaterals");

                // Initialize data
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                assetsTDS = new AssetsTDS();
                lfsAssetsTDS = new LfsAssetsTDS();
                workTDS = new WorkTDS();
                projectSectionsNavigatorTDS = new ProjectSectionsNavigatorTDS();

                // Load data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int assetId = Int32.Parse(hdfAssetID.Value);
                int projectId = Int32.Parse(hdfProjectId.Value);

                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                assetSewerSectionGateway.LoadByAssetId(assetId, companyId);

                if (assetSewerSectionGateway.Table.Rows.Count > 0)
                {
                    tbxSectionId.Text = assetSewerSectionGateway.GetFlowOrderID(assetId);
                    tbxStreet.Text = assetSewerSectionGateway.GetStreet(assetId);

                    // ... For usmh
                    if (assetSewerSectionGateway.GetUSMH(assetId).HasValue)
                    {
                        AssetSewerMHGateway assetSewerFindMHGateway = new AssetSewerMHGateway();
                        int USMH = (int)assetSewerSectionGateway.GetUSMH(assetId);

                        assetSewerFindMHGateway.LoadByAssetId(USMH, companyId);
                        tbxUSMH.Text = assetSewerFindMHGateway.GetMHID(USMH);
                    }

                    // ... For usmh
                    if (assetSewerSectionGateway.GetDSMH(assetId).HasValue)
                    {
                        AssetSewerMHGateway assetSewerFindMHGateway = new AssetSewerMHGateway();
                        int DSMH = (int)assetSewerSectionGateway.GetDSMH(assetId);

                        assetSewerFindMHGateway.LoadByAssetId(DSMH, companyId);
                        tbxDSMH.Text = assetSewerFindMHGateway.GetMHID(DSMH);
                    }

                    // ... For Works
                    WorkGateway workGateway = new WorkGateway();
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Rehab Assessment", companyId))
                        ckbxRehabAssessment.Checked = true;
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Full Length Lining", companyId))
                        ckbxFullLengthLining.Checked = true;
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Junction Lining Section", companyId))
                        ckbxJunctionLining.Checked = true;

                    // ... For Laterals
                    if (assetSewerSectionGateway.GetLaterals(int.Parse(hdfAssetID.Value)).HasValue)
                    {
                        tbxTotalLaterals.Text = ((int)assetSewerSectionGateway.GetLaterals(assetId)).ToString();
                    }
                    else
                    {
                        tbxTotalLaterals.Text = "0";
                    }

                    ProjectSectionsNavigatorLateralsGateway projectSectionsNavigatorLateralsGateway = new ProjectSectionsNavigatorLateralsGateway(projectSectionsNavigatorTDS);
                    projectSectionsNavigatorLateralsGateway.LoadBySection_ProjectId(assetId, projectId, companyId);

                    AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway(assetsTDS);
                    assetSewerLateralGateway.LoadBySectionProjectId(assetId, projectId, companyId);

                    // ... store datasets
                    Session["projectSectionsNavigatorTDS"] = projectSectionsNavigatorTDS;
                    projectSectionsNavigatorLaterals = projectSectionsNavigatorTDS.ProjectSectionNavigatorLaterals;
                    Session["projectSectionsNavigatorLaterals"] = projectSectionsNavigatorLaterals;
                }
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                projectSectionsNavigatorLaterals = (ProjectSectionsNavigatorTDS.ProjectSectionNavigatorLateralsDataTable)Session["projectSectionsNavigatorLaterals"];
                assetsTDS = (AssetsTDS)Session["assetsTDS"];
                lfsAssetsTDS = (LfsAssetsTDS)Session["lfsAssetsTDS"];
                workTDS = (WorkTDS)Session["workTDS"];
            }
        }