コード例 #1
0
        static public ZipTaxRate Create(string ZipCode, int TaxClassID, decimal TaxRate, int CountryId)
        {
            int           ZipTaxID = 0;
            string        err      = String.Empty;
            SqlConnection cn       = new SqlConnection(DB.GetDBConn());

            cn.Open();
            SqlCommand cmd = new SqlCommand();

            cmd.Connection  = cn;
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.CommandText = "dbo.aspdnsf_insZipTaxRate";

            cmd.Parameters.Add(new SqlParameter("@ZipCode", SqlDbType.NVarChar, 20));
            cmd.Parameters.Add(new SqlParameter("@TaxClassID", SqlDbType.Int, 4));
            cmd.Parameters.Add(new SqlParameter("@TaxRate", SqlDbType.Decimal, 8));
            cmd.Parameters.Add(new SqlParameter("@CountryId", SqlDbType.Int));

            cmd.Parameters["@ZipCode"].Value    = ZipCode;
            cmd.Parameters["@TaxClassID"].Value = TaxClassID;
            cmd.Parameters["@TaxRate"].Value    = TaxRate;
            cmd.Parameters["@CountryId"].Value  = CountryId;

            try
            {
                using (IDataReader rs = cmd.ExecuteReader())
                {
                    if (rs.Read())
                    {
                        ZipTaxID = Int32.Parse(rs.GetValue(0).ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                err = ex.Message;
            }

            if (ZipTaxID > 0)
            {
                ZipTaxRate str = new ZipTaxRate(ZipTaxID);
                return(str);
            }

            cn.Close();
            cmd.Dispose();
            cn.Dispose();

            return(null);
        }
コード例 #2
0
 public ZipTaxRate this[string ZipCode, int TaxClassID, int CountryID]
 {
     get
     {
         for (int i = 0; i < m_ZipTaxRates.Count; i++)
         {
             ZipTaxRate ztr = (ZipTaxRate)m_ZipTaxRates.GetByIndex(i);
             if (ztr.ZipCode == ZipCode && ztr.TaxClassID == TaxClassID && ztr.CountryID == CountryID)
             {
                 return(ztr);
             }
         }
         return(null);
     }
 }
コード例 #3
0
        public decimal GetTaxRate(string ZipCode, int TaxClassID, int CountryID)
        {
            if (ZipCode == string.Empty)
            {
                return(0.0M);
            }
            for (int i = 0; i < m_ZipTaxRates.Count; i++)
            {
                ZipTaxRate ztr = (ZipTaxRate)m_ZipTaxRates.GetByIndex(i);

                if (ztr.ZipCode.Equals(ZipCode, StringComparison.InvariantCultureIgnoreCase) && ztr.TaxClassID == TaxClassID && ztr.CountryID == CountryID)
                {
                    return(ztr.TaxRate);
                }
            }
            return(0.0M);
        }
コード例 #4
0
        public void RemoveAll(string ZipCode, int CountryID)
        {
            try
            {
                List <ZipTaxRate> itemsToBeRemoved = new List <ZipTaxRate>();
                foreach (int ziptaxid in this.m_ZipTaxRates.Keys)
                {
                    ZipTaxRate taxRate = this.m_ZipTaxRates[ziptaxid] as ZipTaxRate;
                    if (taxRate.ZipCode.Equals(ZipCode, StringComparison.InvariantCultureIgnoreCase) && taxRate.CountryID.Equals(CountryID))
                    {
                        itemsToBeRemoved.Add(taxRate);
                    }
                }

                foreach (ZipTaxRate taxRate in itemsToBeRemoved)
                {
                    this.m_ZipTaxRates.Remove(taxRate.ZipTaxID);
                }
            }
            catch { }
        }
コード例 #5
0
        public decimal GetTaxRateUSOnly(string ZipCode, int TaxClassID)
        {
            if (ZipCode == string.Empty)
            {
                return(0.0M);
            }
            for (int i = 0; i < m_ZipTaxRates.Count; i++)
            {
                ZipTaxRate ztr = (ZipTaxRate)m_ZipTaxRates.GetByIndex(i);

                int ziplen = ztr.ZipCode.Trim().Length;

                if (ziplen > 5)
                {
                    ziplen = 5;
                }

                if (ztr.ZipCode.Substring(0, ziplen).Equals(ZipCode.Substring(0, ziplen), StringComparison.InvariantCultureIgnoreCase) && ztr.TaxClassID == TaxClassID)
                {
                    return(ztr.TaxRate);
                }
            }
            return(0.0M);
        }
コード例 #6
0
        /// <summary>
        /// Creates a new CountryTaxRate record and adds it to the collection
        /// </summary>
        public void Add(string ZipCode, int TaxClassID, decimal TaxRate, int CountryId)
        {
            ZipTaxRate ztr = ZipTaxRate.Create(ZipCode, TaxClassID, TaxRate, CountryId);

            this.Add(ztr);
        }
コード例 #7
0
 /// <summary>
 /// Adds an existing StateTaxRate object to the collection
 /// </summary>
 public void Add(ZipTaxRate ziptaxrate)
 {
     m_ZipTaxRates.Add(ziptaxrate.ZipTaxID, ziptaxrate);
 }