public String[] GetMHList(string prefixText, int count, string contextKey)
        {
            // split country, province, ...
            string[] location = Regex.Split(contextKey, ",");

            Int64 countryId = Int64.Parse(location[0]);
            Int64? provinceId = null; if (location[1] != "0") provinceId = Int64.Parse(location[1]);
            Int64? countyId = null; if (location[2] != "0") countyId = Int64.Parse(location[2]);
            Int64? cityId = null; if (location[3] != "0") cityId = Int64.Parse(location[3]);
            int companyId = int.Parse(location[4]);

            // load MHs
            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway();
            assetSewerMhGateway.LoadSimilarTop12ByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, prefixText, companyId);

            // process list and return
            if (assetSewerMhGateway.Table.Rows.Count == 0)
            {
                return new string[0];
            }
            else
            {
                List<string> items = new List<string>(count);
                for (int i = 0; (i < count) & (i < assetSewerMhGateway.Table.Rows.Count); i++)
                {
                    items.Add(assetSewerMhGateway.Table.Rows[i]["MHID"].ToString());
                }

                return items.ToArray();
            }
        }
        /// <summary>
        /// DeleteDirect
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        public bool DeleteDirect(int assetId, int companyId)
        {
            if (!InUse(assetId, companyId))
            {
                AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
                assetSewerMhGateway.Delete(assetId, companyId);

                AssetSewer assetSewer = new AssetSewer(null);
                assetSewer.DeleteDirect(assetId, companyId);

                Asset asset = new Asset(null);
                asset.DeleteDirect(assetId, companyId);

                return true;
            }
            else
            {
                return false;
            }
        }
        protected void cvUsmhDsmhDBEdit_ServerValidate(object source, ServerValidateEventArgs args)
        {
            // Initialize
            args.IsValid = true;

            // Validate if mh already exists
            int companyId = Int32.Parse(hdfCompanyId.Value);
            Int64? countryId = null; if (hdfCountryId.Value != "0") countryId = Int64.Parse(hdfCountryId.Value);
            Int64? provinceId = null; if (hdfProvinceId.Value != "0") provinceId = Int64.Parse(hdfProvinceId.Value);
            Int64? countyId = null; if (hdfCountyId.Value != "0") countyId = Int64.Parse(hdfCountyId.Value);
            Int64? cityId = null; if (hdfCityId.Value != "0") cityId = Int64.Parse(hdfCityId.Value);
            int projectId = int.Parse(hdfProjectId.Value);

            CustomValidator cvUsmhDsmhDBEdit = (CustomValidator)source;
            GridViewRow gridRow = (GridViewRow)cvUsmhDsmhDBEdit.NamingContainer;

            string usmh = ((TextBox)gridRow.FindControl("tbxUsmhEdit")).Text;
            string dsmh = ((TextBox)gridRow.FindControl("tbxDsmhEdit")).Text;

            AssetSewerMHGateway assetSewerMhGatewayUSMH = new AssetSewerMHGateway();
            assetSewerMhGatewayUSMH.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, usmh, companyId, "", "", "");//TODO MH

            AssetSewerMHGateway assetSewerMhGatewayDSMH = new AssetSewerMHGateway();
            assetSewerMhGatewayDSMH.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, dsmh, companyId, "", "", "");//TODO MH

            if (assetSewerMhGatewayUSMH.Table.Rows.Count > 0 && assetSewerMhGatewayDSMH.Table.Rows.Count > 0)
            {
                int assetIdUsmh = assetSewerMhGatewayUSMH.GetAssetID(usmh);
                int assetIdDsmh = assetSewerMhGatewayDSMH.GetAssetID(dsmh);

                AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
                if (assetSewerMhGateway.USmhDsmhInUseForSections(assetIdUsmh, assetIdDsmh, companyId))
                {
                    args.IsValid = false;
                }
            }
        }
        protected void cvUsmhDsmhDBAdd_ServerValidate(object source, ServerValidateEventArgs args)
        {
            bool usmhAndDsmhValid = true;
            args.IsValid = true;

            // Validate if mh already exists
            int companyId = Int32.Parse(hdfCompanyId.Value);
            Int64? countryId = null; if (hdfCountryId.Value != "0") countryId = Int64.Parse(hdfCountryId.Value);
            Int64? provinceId = null; if (hdfProvinceId.Value != "0") provinceId = Int64.Parse(hdfProvinceId.Value);
            Int64? countyId = null; if (hdfCountyId.Value != "0") countyId = Int64.Parse(hdfCountyId.Value);
            Int64? cityId = null; if (hdfCityId.Value != "0") cityId = Int64.Parse(hdfCityId.Value);
            int projectId = int.Parse(hdfProjectId.Value);

            string usmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxUsmhAdd")).Text;
            string dsmh = ((TextBox)grdProjectAddSectionsNew.FooterRow.FindControl("tbxDsmhAdd")).Text;

            AssetSewerMHGateway assetSewerMhGatewayUSMH = new AssetSewerMHGateway();
            assetSewerMhGatewayUSMH.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, usmh, companyId, "", "", "");// TODO MH

            AssetSewerMHGateway assetSewerMhGatewayDSMH = new AssetSewerMHGateway();
            assetSewerMhGatewayDSMH.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, dsmh, companyId, "", "", ""); // TODO MH

            if (assetSewerMhGatewayUSMH.Table.Rows.Count > 0 && assetSewerMhGatewayDSMH.Table.Rows.Count > 0)
            {
                int assetIdUsmh = assetSewerMhGatewayUSMH.GetAssetID(usmh);
                int assetIdDsmh = assetSewerMhGatewayDSMH.GetAssetID(dsmh);

                AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
                if (assetSewerMhGateway.USmhDsmhInUseForSections(assetIdUsmh, assetIdDsmh, companyId))
                {
                    usmhAndDsmhValid = false;
                }
            }

            if (usmhAndDsmhValid)
            {
                foreach (GridViewRow row in grdProjectAddSectionsNew.Rows)
                {
                    string usmhRow = ((TextBox)row.FindControl("tbxUsmh")).Text;
                    string dsmhRow = ((TextBox)row.FindControl("tbxDsmh")).Text;

                    if ((usmhRow == usmh && dsmhRow == dsmh) || (usmhRow == dsmh && dsmhRow == usmh))
                    {
                        usmhAndDsmhValid = false;
                    }
                }
            }

            args.IsValid = usmhAndDsmhValid;
        }
        /// <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>
        /// Save a section
        /// </summary>
        /// <param name="row">row</param>
        /// <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>
        /// <returns>section_assetId</returns>
        private int SaveSection(ProjectAddSectionsTDS.ProjectAddSectionsTempRow row, int projectId, Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int companyId)
        {
            string street = ""; if (!row.IsStreetNull()) street = row.Street;
            string usmh = ""; if (!row.IsUSMHNull()) usmh = row.USMH;
            string dsmh = ""; if (!row.IsDSMHNull()) dsmh = row.DSMH;

            string usmhStreet = ""; if (!row.IsUsmhStreetNull()) usmhStreet = row.UsmhStreet;
            string usmhLatitude = ""; if (!row.IsUsmhLatitudeNull()) usmhLatitude = row.UsmhLatitude;
            string usmhLongitude = ""; if (!row.IsUsmhLongitudeNull()) usmhLongitude = row.UsmhLongitude;
            string usmhShape = ""; if (!row.IsUsmhShapeNull()) usmhShape = row.UsmhShape;
            string usmhLocation = ""; if (!row.IsUsmhLocationNull()) usmhLocation = row.UsmhLocation;
            int? usmhConditionRating = null; if (!row.IsUsmhConditionRatingNull()) usmhConditionRating = row.UsmhConditionRating;
            int? usmhMaterialId = null; if (!row.IsUsmhMaterialIdNull()) usmhMaterialId = row.UsmhMaterialId;
            string usmhTopDiameter = ""; if (!row.IsUsmhTopDiameterNull()) usmhTopDiameter = row.UsmhTopDiameter;
            string usmhTopDepth = ""; if (!row.IsUsmhTopDepthNull()) usmhTopDepth = row.UsmhTopDepth;
            string usmhDownDiameter = ""; if (!row.IsUsmhDownDiameterNull()) usmhDownDiameter = row.UsmhDownDiameter;
            string usmhDownDepth = ""; if (!row.IsUsmhDownDepthNull()) usmhDownDepth = row.UsmhDownDepth;
            int? usmhManholeRugs = null; if (!row.IsUsmhManholeRugsNull()) usmhManholeRugs = row.UsmhManholeRugs;
            string usmhRectangle1LongSide = ""; if (!row.IsUsmhRectangle1LongSideNull()) usmhRectangle1LongSide = row.UsmhRectangle1LongSide;
            string usmhRectangle1ShortSide = ""; if (!row.IsUsmhRectangle1ShortSideNull()) usmhRectangle1ShortSide = row.UsmhRectangle1ShortSide;
            string usmhRectangle2LongSide = ""; if (!row.IsUsmhRectangle2LongSideNull()) usmhRectangle2LongSide = row.UsmhRectangle2LongSide;
            string usmhRectangle2ShortSide = ""; if (!row.IsUsmhRectangle2ShortSideNull()) usmhRectangle2ShortSide = row.UsmhRectangle2ShortSide;
            string usmhTotalSurfaceArea = ""; if (!row.IsUsmhTotalSurfaceAreaNull()) usmhTotalSurfaceArea = row.UsmhTotalSurfaceArea;

            string dsmhStreet = ""; if (!row.IsDsmhStreetNull()) dsmhStreet = row.DsmhStreet;
            string dsmhLatitude = ""; if (!row.IsDsmhLatitudeNull()) dsmhLatitude = row.DsmhLatitude;
            string dsmhLongitude = ""; if (!row.IsDsmhLongitudeNull()) dsmhLongitude = row.DsmhLongitude;
            string dsmhShape = ""; if (!row.IsDsmhShapeNull()) dsmhShape = row.DsmhShape;
            string dsmhLocation = ""; if (!row.IsDsmhLocationNull()) dsmhLocation = row.DsmhLocation;
            int? dsmhConditionRating = null; if (!row.IsDsmhConditionRatingNull()) dsmhConditionRating = row.DsmhConditionRating;
            int? dsmhMaterialId = null; if (!row.IsDsmhMaterialIdNull()) dsmhMaterialId = row.DsmhMaterialId;
            string dsmhTopDiameter = ""; if (!row.IsDsmhTopDiameterNull()) dsmhTopDiameter = row.DsmhTopDiameter;
            string dsmhTopDepth = ""; if (!row.IsDsmhTopDepthNull()) dsmhTopDepth = row.DsmhTopDepth;
            string dsmhDownDiameter = ""; if (!row.IsDsmhDownDiameterNull()) dsmhDownDiameter = row.DsmhDownDiameter;
            string dsmhDownDepth = ""; if (!row.IsDsmhDownDepthNull()) dsmhDownDepth = row.DsmhDownDepth;
            int? dsmhManholeRugs = null; if (!row.IsDsmhManholeRugsNull()) dsmhManholeRugs = row.DsmhManholeRugs;
            string dsmhRectangle1LongSide = ""; if (!row.IsDsmhRectangle1LongSideNull()) dsmhRectangle1LongSide = row.DsmhRectangle1LongSide;
            string dsmhRectangle1ShortSide = ""; if (!row.IsDsmhRectangle1ShortSideNull()) dsmhRectangle1ShortSide = row.DsmhRectangle1ShortSide;
            string dsmhRectangle2LongSide = ""; if (!row.IsDsmhRectangle2LongSideNull()) dsmhRectangle2LongSide = row.DsmhRectangle2LongSide;
            string dsmhRectangle2ShortSide = ""; if (!row.IsDsmhRectangle2ShortSideNull()) dsmhRectangle2ShortSide = row.DsmhRectangle2ShortSide;
            string dsmhTotalSurfaceArea = ""; if (!row.IsDsmhTotalSurfaceAreaNull()) dsmhTotalSurfaceArea = row.DsmhTotalSurfaceArea;

            // insert usmh (if not exists)
            int? usmh_assetId = null;
            if (usmh != "")
            {
                LfsAssetSewerMH lfsAssetSewerUsmh = new LfsAssetSewerMH(null);
                usmh_assetId = lfsAssetSewerUsmh.InsertDirect(countryId, provinceId, countyId, cityId, usmh, usmhLatitude, usmhLongitude, usmhStreet, false, companyId, usmhShape, usmhLocation, usmhMaterialId, usmhTopDiameter, usmhTopDepth, "", "", "", usmhDownDiameter, usmhDownDepth, "", "", "", usmhRectangle1LongSide, usmhRectangle1ShortSide, usmhRectangle2LongSide, usmhRectangle2ShortSide, "", "", usmhManholeRugs, "", usmhTotalSurfaceArea, usmhConditionRating);

                // insert in LFS tables (only if not exists)
                AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();

                if (!assetSewerMHGateway.IsUsedInMHProject(projectId, usmh_assetId.Value))
                {
                    AssetSewerMHGateway assetSewerMhGatewayForUSMH = new AssetSewerMHGateway(null);
                    assetSewerMhGatewayForUSMH.InsertMHProject(usmh_assetId.Value, projectId, DateTime.Now, false, companyId);
                }

                if (row.MHRehabUsmh)
                {
                    //TODO MH
                    SaveMHRehabWork(projectId, usmh_assetId.Value, companyId);
                }
            }

            // insert dsmh (if not exists)
            int? dsmh_assetId = null;
            if (dsmh != "")
            {
                LfsAssetSewerMH lfsAssetSewerDsmh = new LfsAssetSewerMH(null);
                dsmh_assetId = lfsAssetSewerDsmh.InsertDirect(countryId, provinceId, countyId, cityId, dsmh, dsmhLatitude, dsmhLongitude, dsmhStreet, false, companyId, dsmhShape, dsmhLocation, dsmhMaterialId, dsmhTopDiameter, dsmhTopDepth, "", "", "", dsmhDownDiameter, dsmhDownDepth, "", "", "", dsmhRectangle1LongSide, dsmhRectangle1ShortSide, dsmhRectangle2LongSide, dsmhRectangle2ShortSide, "", "", dsmhManholeRugs, "", dsmhTotalSurfaceArea, dsmhConditionRating);

                // insert in LFS tables (only if not exists)
                AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();

                if (!assetSewerMHGateway.IsUsedInMHProject(projectId, dsmh_assetId.Value))
                {
                    AssetSewerMHGateway assetSewerMhGatewayForDSMH = new AssetSewerMHGateway(null);
                    assetSewerMhGatewayForDSMH.InsertMHProject(dsmh_assetId.Value, projectId, DateTime.Now, false, companyId);
                }

                if (row.MHRehabDsmh)
                {
                    //TODO MH
                    SaveMHRehabWork(projectId, dsmh_assetId.Value, companyId);
                }
            }

            // insert section
            LfsAssetSewerSection lfsAssetSewerSection = new LfsAssetSewerSection(null);
            string mapSize = ""; if (!row.IsMapSizeNull()) mapSize = row.MapSize;
            string mapLength = ""; if (!row.IsMapLengthNull()) mapLength = row.MapLength;

            int sectionMaterialRefId = 1; // first material when adding new section
            string sectionMaterial = ""; if (!row.IsSectionMaterialNull()) sectionMaterial = row.SectionMaterial;
            DateTime sectionMaterialDate = DateTime.Now;

            int section_assetId = lfsAssetSewerSection.InsertDirect(countryId, provinceId, countyId, cityId, row.SectionID, street, usmh_assetId, dsmh_assetId, mapSize, "", mapLength, "", null, null, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", false, companyId, "", "", sectionMaterialRefId, sectionMaterial, sectionMaterialDate);

            return section_assetId;
        }
        /// <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);
            }
        }
        /// <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);
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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"];
            }
        }
Example #10
0
 /// <summary>
 /// UpdateDirect
 /// </summary>
 /// <param name="originalAssetId">originalAssetId</param>
 /// <param name="originalMhId">originalMhId</param>
 /// <param name="originalLatitud">originalLatitud</param>
 /// <param name="originalLongitude">originalLongitude</param>
 /// <param name="originalAddress">originalAddress</param>
 /// <param name="originalManholeShape">originalManholeShape</param>
 /// <param name="originalLocation">originalLocation</param>
 /// <param name="originalMaterialID">originalMaterialID</param>
 /// <param name="originalTopDiameter">originalTopDiameter</param>
 /// <param name="originalTopDepth">originalTopDepth</param>
 /// <param name="originalTopFloor">originalTopFloor</param>
 /// <param name="originalTopCeiling">originalTopCeiling</param>
 /// <param name="originalTopBenching">originalTopBenching</param>
 /// <param name="originalDownDiameter">originalDownDiameter</param>
 /// <param name="originalDownDepth">originalDownDepth</param>
 /// <param name="originalDownFloor">originalDownFloor</param>
 /// <param name="originalDownCeiling">originalDownCeiling</param>
 /// <param name="originalDownBenching">originalDownBenching</param>
 /// <param name="originalRectangle1LongSide">originalRectangle1LongSide</param>
 /// <param name="originalRectangle1ShortSide">originalRectangle1ShortSide</param>
 /// <param name="originalRectangle2LongSide">originalRectangle2LongSide</param>
 /// <param name="originalRectangle2ShortSide">originalRectangle2ShortSide</param>
 /// <param name="originalTopSurfaceArea">originalTopSurfaceArea</param>
 /// <param name="originalDownSurfaceArea">originalDownSurfaceArea</param>
 /// <param name="originalManholeRugs">originalManholeRugs</param>
 /// <param name="originalTotalDepth">originalTotalDepth</param>
 /// <param name="originalTotalSurfaceArea">originalTotalSurfaceArea</param>        
 /// <param name="originalDeleted">originalDeleted</param>
 /// <param name="originalCompanyId">originalCompanyId</param>
 /// 
 /// <param name="newAssetId">newAssetId</param>
 /// <param name="newMhId">newMhId</param>
 /// <param name="newLatitude">newLatitude</param>
 /// <param name="newLongitude">newLongitude</param>
 /// <param name="newAddress">newAddress</param>
 /// <param name="newManholeShape">newManholeShape</param>
 /// <param name="newLocation">newLocation</param>
 /// <param name="newMaterialID">newMaterialID</param>
 /// <param name="newTopDiameter">newTopDiameter</param>
 /// <param name="newTopDepth">newTopDepth</param>
 /// <param name="newTopFloor">newTopFloor</param>
 /// <param name="newTopCeiling">newTopCeiling</param>
 /// <param name="newTopBenching">newTopBenching</param>
 /// <param name="newDownDiameter">newDownDiameter</param>
 /// <param name="newDownDepth">newDownDepth</param>
 /// <param name="newDownFloor">newDownFloor</param>
 /// <param name="newDownCeiling">newDownCeiling</param>
 /// <param name="newDownBenching">newDownBenching</param>
 /// <param name="newRectangle1LongSide">newRectangle1LongSide</param>
 /// <param name="newRectangle1ShortSide">newRectangle1ShortSide</param>
 /// <param name="newRectangle2LongSide">newRectangle2LongSide</param>
 /// <param name="newRectangle2ShortSide">newRectangle2ShortSide</param>
 /// <param name="newTopSurfaceArea">newTopSurfaceArea</param>
 /// <param name="newDownSurfaceArea">newDownSurfaceArea</param>
 /// <param name="newManholeRugs">newManholeRugs</param>
 /// <param name="newTotalDepth">newTotalDepth</param>
 /// <param name="newTotalSurfaceArea">newTotalSurfaceArea</param>              
 /// <param name="newDeleted">newDeleted</param>
 /// <param name="newCompanyId">newCompanyId</param>
 public void UpdateDirect(int originalAssetId, string originalMhId, string originalLatitud, string originalLongitude, string originalAddress, string originalManholeShape, string originalLocation, int? originalMaterialID, string originalTopDiameter, string originalTopDepth, string originalTopFloor, string originalTopCeiling, string originalTopBenching, string originalDownDiameter, string originalDownDepth, string originalDownFloor, string originalDownCeiling, string originalDownBenching, string  originalRectangle1LongSide, string originalRectangle1ShortSide, string originalRectangle2LongSide, string originalRectangle2ShortSide, string originalTopSurfaceArea, string originalDownSurfaceArea,  int? originalManholeRugs, string  originalTotalDepth, string originalTotalSurfaceArea, bool originalDeleted, int originalCompanyId, int newAssetId, string newMhId, string newLatitud, string newLongitude, string newAddress, string newManholeShape, string newLocation, int? newMaterialID,  string newTopDiameter, string newTopDepth, string newTopFloor, string newTopCeiling, string newTopBenching, string newDownDiameter, string newDownDepth, string newDownFloor, string newDownCeiling, string newDownBenching, string newRectangle1LongSide, string newRectangle1ShortSide, string newRectangle2LongSide, string newRectangle2ShortSide, string newTopSurfaceArea, string newDownSurfaceArea, int? newManholeRugs, string newTotalDepth, string newTotalSurfaceArea, bool newDeleted, int newCompanyId)
 {
     AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
     assetSewerMhGateway.Update(originalAssetId, originalMhId, 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, originalDeleted, originalCompanyId, newAssetId, newMhId, 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, newDeleted, newCompanyId);
 }
Example #11
0
        /// <summary>
        /// Verify if MH is in use for any entity
        /// </summary>
        /// <param name="assetId">assetId</param>
        /// <param name="companyId">companyId</param>
        /// <returns>true if MH is in use for any entity, not if it not in use</returns>
        public bool InUse(int assetId, int companyId)
        {
            // verify use for sections like USMH or DSMH
            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
            if (assetSewerMhGateway.InUseForSections(assetId, companyId))
            {
                return true;
            }

            // default return
            return false;
        }
Example #12
0
        // ////////////////////////////////////////////////////////////////////////
        // 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>
        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)
        {
            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway();
            assetSewerMhGateway.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, mhid, companyId, latitude, longitude, address);
            int mh_assetId = 0;

            if (assetSewerMhGateway.Table.Rows.Count == 0)
            {
                mh_assetId = new Asset(new DataSet()).InsertDirect("Sewer", countryId, provinceId, countyId, cityId, deleted, companyId);
                new AssetSewer(new DataSet()).InsertDirect(mh_assetId, "MH", deleted, companyId);
                assetSewerMhGateway.Insert(mh_assetId, 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);

            }
            else
            {
                mh_assetId = assetSewerMhGateway.GetAssetID(mhid);
            }

            return mh_assetId;
        }
        /// <summary>
        /// Save all manhole to database (direct)
        /// </summary>
        /// <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>        
        public void Save(Int64? countryId, Int64?  provinceId, Int64? countyId, Int64? cityId, int companyId, int projectId)
        {
            AddManholeTDS mrManholesAddChanges = (AddManholeTDS)Data.GetChanges();

            if (mrManholesAddChanges.AddManholeNew.Rows.Count > 0)
            {
                AddManholeNewGateway addManholeNewGateway = new AddManholeNewGateway(mrManholesAddChanges);

                foreach (AddManholeTDS.AddManholeNewRow row in (AddManholeTDS.AddManholeNewDataTable)mrManholesAddChanges.AddManholeNew)
                {
                    // Insert new manhole
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        // ... Insert manhole
                        int? manholeRugs = null; if (!row.IsManholeRugsNull()) manholeRugs = row.ManholeRugs;
                        int? conditionRating = null; if (!row.IsConditionRatingNull()) conditionRating = row.ConditionRating;
                        int? materialId = null; if (!row.IsMaterialIDNull()) materialId = row.MaterialID;

                        LfsAssetSewerMH lfsAssetSewerMH = new LfsAssetSewerMH();

                        int assetId = lfsAssetSewerMH.InsertDirect(countryId, provinceId, countyId, cityId, row.MHID, row.Latitud, row.Longitude, row.Address, row.Deleted, companyId, row.ManholeShape, row.Location, materialId, row.TopDiameter, row.TopDepth, row.TopFloor, row.TopCeiling, row.TopBenching, row.DownDiameter, row.DownDepth, row.DownFloor, row.DownCeiling, row.DownBenching, row.Rectangle1LongSide, row.Rectangle1ShortSide, row.Rectangle2LongSide, row.Rectangle2ShortSide, row.TopSurfaceArea, row.DownSurfaceArea, manholeRugs, row.TotalDepth, row.TotalSurfaceArea, conditionRating);

                        // insert in LFS tables (only if not exists)
                        AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();

                        if (!assetSewerMHGateway.IsUsedInMHProject(projectId, assetId))
                        {
                            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway(null);
                            assetSewerMhGateway.InsertMHProject(assetId, projectId, DateTime.Now, false, companyId);
                        }
                    }
                }
            }
        }
        protected void tbxMhIdAdd_TextChanged(object sender, EventArgs e)
        {
            try
            {
                mWizard2 master = (mWizard2)this.Master;
                ScriptManager scriptManager = (ScriptManager)master.FindControl("ScriptManager1");

                if (scriptManager.IsInAsyncPostBack)
                {
                    // cast DropDownList control which has initiated the call:
                    TextBox tbxMhIdAdd = (TextBox)sender;

                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    string mhId = tbxMhIdAdd.Text;

                    Int64? countryId = null; if (hdfCountryId.Value != "0") countryId = Int64.Parse(hdfCountryId.Value);
                    Int64? provinceId = null; if (hdfProvinceId.Value != "0") provinceId = Int64.Parse(hdfProvinceId.Value);
                    Int64? countyId = null; if (hdfCountyId.Value != "0") countyId = Int64.Parse(hdfCountyId.Value);
                    Int64? cityId = null; if (hdfCityId.Value != "0") cityId = Int64.Parse(hdfCityId.Value);

                    AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();
                    assetSewerMHGateway.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, mhId, companyId, "", "", ""); //TODO MH

                    if (assetSewerMHGateway.Table.Rows.Count > 0)
                    {
                        ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxStreetAdd")).Text = assetSewerMHGateway.GetAddress(mhId);
                        ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxLatitudeAdd")).Text = assetSewerMHGateway.GetLatitude(mhId);
                        ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxLongitudeAdd")).Text = assetSewerMHGateway.GetLongitude(mhId);
                    }
                }
            }
            catch
            {
            }
        }
        protected void cvMhIdFooter_ServerValidate(object source, ServerValidateEventArgs args)
        {
            // Validate if mh already exists
            int companyId = Int32.Parse(hdfCompanyId.Value);
            string mhId = ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxMhIdAdd")).Text;
            Int64? countryId = null; if (hdfCountryId.Value != "0") countryId = Int64.Parse(hdfCountryId.Value);
            Int64? provinceId = null; if (hdfProvinceId.Value != "0") provinceId = Int64.Parse(hdfProvinceId.Value);
            Int64? countyId = null; if (hdfCountyId.Value != "0") countyId = Int64.Parse(hdfCountyId.Value);
            Int64? cityId = null; if (hdfCityId.Value != "0") cityId = Int64.Parse(hdfCityId.Value);
            int projectId = Convert.ToInt32(ddlProject.SelectedValue);

            string latitud = ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxLatitudeAdd")).Text;
            string longitude = ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxLongitudeAdd")).Text;
            string address = ((TextBox)grdAddManholeNew.FooterRow.FindControl("tbxStreetAdd")).Text;

            AssetSewerMHGateway assetSewerMhGateway = new AssetSewerMHGateway();
            assetSewerMhGateway.LoadByCountryIdProvinceIdCountyIdCityIdMhId(countryId, provinceId, countyId, cityId, mhId, companyId, latitud, longitude, address);

            if (assetSewerMhGateway.Table.Rows.Count > 0)
            {
                int assetIdMh = assetSewerMhGateway.GetAssetID(mhId);

                if (assetSewerMhGateway.IsUsedInMHProject(projectId, assetIdMh))
                {
                    args.IsValid = false;
                }
                else
                {
                    assetSewerMhGateway.LoadTop1ByMhIdProjectId(mhId, Convert.ToInt32(ddlProject.SelectedValue), companyId);

                    if (assetSewerMhGateway.Table.Rows.Count > 0)
                    {
                        args.IsValid = false;
                    }
                    else
                    {
                        args.IsValid = true;
                    }
                }
            }
            else
            {
                args.IsValid = true;
            }

            //AssetSewerMHGateway assetSewerMHGateway = new AssetSewerMHGateway();

            //if (ddlProject.SelectedIndex != 0)
            //{
            //    assetSewerMHGateway.LoadTop1ByMhIdProjectId(mhId, Convert.ToInt32(ddlProject.SelectedValue), companyId);
            //}
            //else
            //{
            //    assetSewerMHGateway.LoadTop1ByMhId(mhId, companyId);
            //}

            //if (assetSewerMHGateway.Table.Rows.Count > 0)
            //{
            //    args.IsValid = false;
            //}
            //else
            //{
            //    args.IsValid = true;
            //}
        }