Exemplo n.º 1
0
        /// <summary>
        /// Check if the VAT number is valid or not
        /// </summary>
        /// <returns>True if the VAT number could be validated otherwise false</returns>
        public bool CheckVat()
        {
            if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
            {
                return(false);
            }

            //If the country code is AT for Austria we need a U before the UID
            if (CountryCode.ToUpper().Equals("AT"))
            {
                if (!VATNumber.StartsWith("U"))
                {
                    VATNumber = "U" + VATNumber;
                }
            }

            string strVat     = VATNumber;
            string strCountry = CountryCode;

            bool   bValid     = false;
            string strName    = string.Empty;
            string strAddress = string.Empty;

            try
            {
                checkVatService visService = new checkVatService();

                RetDate = visService.checkVat(ref strCountry, ref strVat,
                                              out bValid, out strName, out strAddress);

                IsValid = bValid;
                Name    = strName;
                Address = strAddress;

                return(IsValid);
            }
            catch (Exception err)
            {
                System.Diagnostics.Trace.TraceError(err.ToString());
                return(false);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Check if the VAT number is valid or not
        /// </summary>
        /// <returns>True if the VAT number could be validated otherwise false</returns>
        public bool CheckVat()
        {
            if (string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode))
            {
                Log.Instance.LogDebug("CheckVat() FALSE: string.IsNullOrEmpty(VATNumber) || string.IsNullOrEmpty(CountryCode)");
                return(false);
            }

            //If the country code is AT for Austria we need a U before the UID
            if (CountryCode.ToUpper().Equals("AT"))
            {
                if (!VATNumber.StartsWith("U"))
                {
                    VATNumber = "U" + VATNumber;
                }
            }

            string strVat     = VATNumber;
            string strCountry = CountryCode;

            try
            {
                var visService = new checkVatService();

                bool   bValid;
                string strName;
                string strAddress;
                RetDate = visService.checkVat(ref strCountry, ref strVat, out bValid, out strName, out strAddress);
                IsValid = bValid;
                Name    = strName;
                Address = strAddress;

                Log.Instance.LogDebug("CheckVat() IsValid: " + IsValid);
                return(IsValid);
            }
            catch (Exception err)
            {
                Trace.TraceError(err.ToString());
                Log.Instance.LogDebug("CheckVat() FALSE: EXCEPTION");
                return(false);
            }
        }