Exemplo n.º 1
0
        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;
            //}
        }