/// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        /// <returns></returns>
        public bool DeleteDirect(int assetId, int companyId)
        {
            // verify use
            if (!InUse(assetId, companyId))
            {
                // delete in LFS tables
                LfsAssetSewerMHGateway lfsAssetSewerMHGateway = new LfsAssetSewerMHGateway(null);
                lfsAssetSewerMHGateway.Delete(assetId, companyId);

                LfsAssetSewer lfsAssetSewer = new LfsAssetSewer(null);
                lfsAssetSewer.DeleteDirect(assetId, companyId);

                LfsAsset lfsAsset = new LfsAsset(null);
                lfsAsset.DeleteDirect(assetId, companyId);

                // delete in AM tables
                AssetSewerMH assetSewerMh = new AssetSewerMH(null);
                assetSewerMh.DeleteDirect(assetId, companyId);

                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// UpdateMH
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="mhId">mhId</param>
        /// <param name="originalUsmhAddress">originalUsmhAddress</param>
        /// <param name="newUsmhAddress">newUsmhAddress</param>
        /// <param name="companyId">companyId</param>
        private void UpdateMH(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string mhId, string originalAddress, string newAddress, int companyId)
        {
            // Get unchanged data
            // ... mh
            AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();
            assetSewerMHGateway.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, mhId, companyId, "", "", ""); //TODO MH

            // Update mh
            if (assetSewerMHGateway.Table.Rows.Count > 0)
            {
                int originalAssetId = assetSewerMHGateway.GetAssetID(mhId);
                string originalLatitude = assetSewerMHGateway.GetLatitude(mhId);
                string originalLongitude = assetSewerMHGateway.GetLongitude(mhId);
                bool originalDeleted = assetSewerMHGateway.GetDeleted(mhId);
                int originalCompanyId = assetSewerMHGateway.GetCompanyId(mhId);

                string originalManholeShape = assetSewerMHGateway.GetManholeShape(mhId);
                string originalLocation = assetSewerMHGateway.GetLocation(mhId);
                int? originalMaterialID = assetSewerMHGateway.GetMaterialID(mhId);
                string originalTopDiameter = assetSewerMHGateway.GetTopDepth(mhId);
                string originalTopDepth = assetSewerMHGateway.GetTopDepth(mhId);
                string originalTopFloor = assetSewerMHGateway.GetTopFloor(mhId);
                string originalTopCeiling = assetSewerMHGateway.GetTopFloor(mhId);
                string originalTopBenching = assetSewerMHGateway.GetTopBenching(mhId);
                string originalDownDiameter = assetSewerMHGateway.GetDownDiameter(mhId);
                string originalDownDepth = assetSewerMHGateway.GetDownDepth(mhId);
                string originalDownFloor = assetSewerMHGateway.GetDownFloor(mhId);
                string originalDownCeiling = assetSewerMHGateway.GetDownCeiling(mhId);
                string originalDownBenching = assetSewerMHGateway.GetDownBenching(mhId);
                string originalRectangle1LongSide = assetSewerMHGateway.GetRectangle1LongSide(mhId);
                string originalRectangle1ShortSide = assetSewerMHGateway.GetRectangle1ShortSide(mhId);
                string originalRectangle2LongSide = assetSewerMHGateway.GetRectangle2LongSide(mhId);
                string originalRectangle2ShortSide = assetSewerMHGateway.GetRectangle2ShortSide(mhId);
                string originalTopSurfaceArea = assetSewerMHGateway.GetTopSurfaceArea(mhId);
                string originalDownSurfaceArea = assetSewerMHGateway.GetDownSurfaceArea(mhId);
                int? originalManholeRugs = assetSewerMHGateway.GetManholeRugs(mhId);
                string originalTotalDepth = assetSewerMHGateway.GetTotalDepth(mhId);
                string originalTotalSurfaceArea = assetSewerMHGateway.GetTotalSurfaceArea(mhId);

                AssetSewerMH assetSewerMH = new AssetSewerMH(assetSewerMHGateway.Data);
                assetSewerMH.UpdateDirect(originalAssetId, mhId, originalLatitude, originalLongitude, originalAddress, originalManholeShape, originalLocation, originalMaterialID, originalTopDiameter, originalTopDepth, originalTopFloor, originalTopCeiling, originalTopBenching, originalDownDiameter, originalDownDepth, originalDownFloor, originalDownCeiling, originalDownBenching, originalRectangle1LongSide, originalRectangle1ShortSide, originalRectangle2LongSide, originalRectangle2ShortSide, originalTopSurfaceArea, originalDownSurfaceArea, originalManholeRugs, originalTotalDepth, originalTotalSurfaceArea, originalDeleted, originalCompanyId, originalAssetId, mhId, originalLatitude, originalLongitude, newAddress,  originalManholeShape, originalLocation, originalMaterialID, originalTopDiameter, originalTopDepth, originalTopFloor, originalTopCeiling, originalTopBenching, originalDownDiameter, originalDownDepth, originalDownFloor, originalDownCeiling, originalDownBenching, originalRectangle1LongSide, originalRectangle1ShortSide, originalRectangle2LongSide, originalRectangle2ShortSide, originalTopSurfaceArea, originalDownSurfaceArea, originalManholeRugs, originalTotalDepth, originalTotalSurfaceArea, originalDeleted, originalCompanyId);
            }
        }
 /// <summary>
 /// Verify if MH is in use for any entity
 /// </summary>
 /// <param name="assetId">assetId</param>
 /// <param name="companyId">companyId</param>
 /// <returns></returns>
 public bool InUse(int assetId, int companyId)
 {
     AssetSewerMH assetSewerMh = new AssetSewerMH(null);
     return assetSewerMh.InUse(assetId, companyId);
 }
        // ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// InsertDirect
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="mhid">mhid</param>
        /// <param name="latitude">latitude</param>
        /// <param name="longitude">longitude</param>
        /// <param name="address">address</param>
        /// <param name="deleted">deleted</param>
        /// <param name="companyId">companyId</param>
        /// <param name="manholeShape">manholeShape</param>
        /// <param name="location">location</param>
        /// <param name="materialID">materialID</param>
        /// <param name="topDiameter">topDiameter</param>
        /// <param name="topDepth">topDepth</param>
        /// <param name="topFloor">topFloor</param>
        /// <param name="topCeiling">topCeiling</param>
        /// <param name="topBenching">topBenching</param>
        /// <param name="downDiameter">downDiameter</param>
        /// <param name="downDepth">downDepth</param>
        /// <param name="downFloor">downFloor</param>
        /// <param name="downCeiling">downCeiling</param>
        /// <param name="downBenching">downBenching</param>
        /// <param name="rectangle1LongSide">rectangle1LongSide</param>
        /// <param name="rectangle1ShortSide">rectangle1ShortSide</param>
        /// <param name="rectangle2LongSide">rectangle2LongSide</param>
        /// <param name="rectangle2ShortSide">rectangle2ShortSide</param>
        /// <param name="topSurfaceArea">topSurfaceArea</param>
        /// <param name="downSurfaceArea">downSurfaceArea</param>
        /// <param name="manholeRugs">manholeRugs</param>
        /// <param name="totalDepth">totalDepth</param>
        /// <param name="totalSurfaceArea">totalSurfaceArea</param>
        /// <param name="conditionRating">conditionRating</param>
        /// <returns></returns>
        public int InsertDirect(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, string mhid, string latitude, string longitude, string address, bool deleted, int companyId, string manholeShape, string location, int? materialID, string topDiameter, string topDepth, string topFloor, string topCeiling, string topBenching, string downDiameter, string downDepth, string downFloor, string downCeiling, string downBenching, string rectangle1LongSide, string rectangle1ShortSide, string rectangle2LongSide, string rectangle2ShortSide, string topSurfaceArea, string downSurfaceArea, int? manholeRugs, string totalDepth, string totalSurfaceArea, int? conditionRating)
        {
            // insert in AM tables (only if not exists)
            AssetSewerMH assetSewerMh = new AssetSewerMH(null);
            int mh_assetId = assetSewerMh.InsertDirect(countryId, provinceId, countyId, cityId, mhid, latitude, longitude, address, deleted, companyId, manholeShape, location, materialID, topDiameter, topDepth, topFloor, topCeiling, topBenching, downDiameter, downDepth, downFloor, downCeiling, downBenching, rectangle1LongSide, rectangle1ShortSide, rectangle2LongSide, rectangle2ShortSide, topSurfaceArea, downSurfaceArea, manholeRugs, totalDepth, totalSurfaceArea);

            // insert in LFS tables (only if not exists)
            LfsAssetSewerMHGateway lfsAssetSewerMhGateway = new LfsAssetSewerMHGateway();
            lfsAssetSewerMhGateway.LoadByAssetId(mh_assetId, companyId);

            if (lfsAssetSewerMhGateway.Table.Rows.Count == 0)
            {
                new LfsAsset(new DataSet()).InsertDirect(mh_assetId, deleted, companyId);
                new LfsAssetSewer(new DataSet()).InsertDirect(mh_assetId, deleted, companyId);
                new LfsAssetSewerMHGateway(new DataSet()).Insert(mh_assetId, deleted, companyId, conditionRating);
            }

            return mh_assetId;
        }
        /// <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);
                    }
                }
            }
        }
        private void Delete()
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Delete
                int workId = Int32.Parse(hdfWorkId.Value);
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int assetId = Int32.Parse(hdfAssetId.Value);

                AssetSewerMH assetSewerMh = new AssetSewerMH(null);
                bool usedBySection = assetSewerMh.InUse(assetId, companyId);

                if (usedBySection)
                {
                    lblDelete.Text = "The Manhole could not be deleted, it is used by sections";
                }
                else
                {
                    // Update databse
                    UpdateDatabase();

                    // Redirect
                    string url = "";
                    url = "./mr_navigator2.aspx?source_page=mr_delete.aspx&client_id=" + hdfCurrentClientId.Value + "&project_id=" + hdfCurrentProjectId.Value + "&in_project=" + hdfInProject.Value + GetNavigatorState() + "&update=yes";
                    Response.Redirect(url);
                }
            }
        }