// //////////////////////////////////////////////////////////////////////// // STEP5 - NEW INTERMEDIATE SECTIONS - AUXILIARY EVENTS // protected void cvSectionId_ServerValidate(object source, ServerValidateEventArgs args) { ProjectAddSectionsTDS dataSet = new ProjectAddSectionsTDS(); dataSet.ProjectAddSectionsNew.Merge(projectAddSectionsNew, true); dataSet.ProjectAddSectionsTemp.Merge(projectAddSectionsTemp, true); ProjectAddSectionsNew projectAddSectionsNewModel = new ProjectAddSectionsNew(dataSet); ProjectAddSectionsTemp projectAddSectionsTempModel = new ProjectAddSectionsTemp(dataSet); // Initialize CustomValidator cvSectionId = (CustomValidator)source; args.IsValid = true; // verify in this step if (projectAddSectionsNewModel.ExistsBySectionId(args.Value)) { cvSectionId.Text = "Duplicated section. (you already have this section here)"; args.IsValid = false; } // verify before added or selected if (args.IsValid) { if (projectAddSectionsTempModel.ExistsBySectionId(args.Value)) { cvSectionId.Text = "Duplicated section. (this section was already created or added previously)"; args.IsValid = false; } } // verify in project with specific work if (args.IsValid) { string workType; switch (hdfWorkType.Value) { case "All": workType = "%"; break; case "Rehab Assessment": workType = "Rehab Assessment"; break; case "Full Length Lining": workType = "Full Length Lining"; break; case "Point Repairs": workType = "Point Repairs"; break; case "Junction Lining": workType = "Junction Lining Section"; break; case "Manhole Rehabilitation": workType = "%"; break; default: throw new Exception("Erroneus work type in Add Section query string."); } WorkGateway workGateway = new WorkGateway(null); if (workGateway.ExistsSectionByProjectIdSectionIdWorkType(int.Parse(hdfProjectId.Value), args.Value, workType, int.Parse(hdfCompanyId.Value))) { cvSectionId.Text = "This section is already associated with this project. (if you would like to see it go to the Sections data of this project)"; args.IsValid = false; } } // verify in project general if (args.IsValid) { Int64? countryId = int.Parse(hdfCountryId.Value); Int64? provinceId = null; if (hdfProvinceId.Value != "") provinceId = Int64.Parse(hdfProvinceId.Value); Int64? countyId = null; if (hdfCountyId.Value != "") countyId = Int64.Parse(hdfCountyId.Value); Int64? cityId = null; if (hdfCityId.Value != "") cityId = Int64.Parse(hdfCityId.Value); int companyId = int.Parse(hdfCompanyId.Value); AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway(null); if (assetSewerSectionGateway.ExistsByCountryIdProvinceIdCountyIdCityIdSectionId(countryId, provinceId, countyId, cityId, args.Value, companyId)) { cvSectionId.Text = "This section is already in the database. (you can try adding it using the Add Existing Sections option)"; args.IsValid = false; } } }