public virtual ZipTaxRate UpdateZipTaxRate(ZipTaxRate entity)
        {
            if (entity.IsTransient())
            {
                return(entity);
            }
            ZipTaxRate other = GetZipTaxRate(entity.ZipTaxId);

            if (entity.Equals(other))
            {
                return(entity);
            }
            string sql = @"Update ZipTaxRate set  [ZipCode]=@ZipCode
							, [TaxClassID]=@TaxClassID
							, [TaxRate]=@TaxRate
							, [CreatedOn]=@CreatedOn
							, [CountryID]=@CountryID 
							 where ZipTaxID=@ZipTaxID"                            ;

            SqlParameter[] parameterArray = new SqlParameter[] {
                new SqlParameter("@ZipTaxID", entity.ZipTaxId)
                , new SqlParameter("@ZipCode", entity.ZipCode)
                , new SqlParameter("@TaxClassID", entity.TaxClassId)
                , new SqlParameter("@TaxRate", entity.TaxRate ?? (object)DBNull.Value)
                , new SqlParameter("@CreatedOn", entity.CreatedOn)
                , new SqlParameter("@CountryID", entity.CountryId)
            };
            SqlHelper.ExecuteNonQuery(this.ConnectionString, CommandType.Text, sql, parameterArray);
            return(GetZipTaxRate(entity.ZipTaxId));
        }
예제 #2
0
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            resetError("", false);
            StringBuilder sql = new StringBuilder(2500);

            string  zip       = txtZip.Text.Trim();
            decimal tax       = Localization.ParseNativeDecimal(txtTax.Text.Trim());
            string  countryId = ddlCountry.SelectedValue.Trim();

            if (!CommonLogic.IsStringNullOrEmpty(countryId))
            {
                if (AppLogic.ValidatePostalCode(zip, Convert.ToInt32(countryId)))
                {
                    // ok to add them:
                    ZipTaxRate ztr = AppLogic.ZipTaxRatesTable[CommonLogic.Left(zip, 10), AppLogic.AppConfigNativeInt("Admin_DefaultTaxClassID"), Convert.ToInt32(countryId)];
                    if (ztr == null)
                    {
                        AppLogic.ZipTaxRatesTable.Add(CommonLogic.Left(zip, 10), AppLogic.AppConfigNativeInt("Admin_DefaultTaxClassID"), tax, Convert.ToInt32(countryId));
                        resetError("Zip Code added.", false);
                    }
                    else
                    {
                        ztr.Update(tax, Convert.ToInt32(countryId));
                        resetError("Zip Code already exists and was updated.", false);
                    }
                }
                else
                {
                    resetError(AppLogic.GetCountryPostalErrorMessage(Convert.ToInt32(countryId), cust.SkinID, cust.LocaleSetting), true);
                }
            }
            buildGridData();

            ShowAddPanel(false);
        }
        public virtual ZipTaxRate ZipTaxRateFromDataRow(DataRow dr)
        {
            if (dr == null)
            {
                return(null);
            }
            ZipTaxRate entity = new ZipTaxRate();

            entity.ZipTaxId   = (System.Int32)dr["ZipTaxID"];
            entity.ZipCode    = dr["ZipCode"].ToString();
            entity.TaxClassId = (System.Int32)dr["TaxClassID"];
            entity.TaxRate    = dr["TaxRate"] == DBNull.Value?(System.Decimal?)null : (System.Decimal?)dr["TaxRate"];
            entity.CreatedOn  = (System.DateTime)dr["CreatedOn"];
            entity.CountryId  = (System.Int32)dr["CountryID"];
            return(entity);
        }
예제 #4
0
        protected void btnUpdateOrder_Click(object sender, EventArgs e)
        {
            for (int i = 0; i <= Request.Form.Count - 1; i++)
            {
                //TR_CLASSID_ZipCode
                if (Request.Form.Keys[i].IndexOf("TR_") != -1)
                {
                    String[]    keys         = Request.Form.Keys[i].Split('_');
                    string      ZipCode      = keys[2];
                    int         ClassID      = Localization.ParseUSInt(keys[1]);
                    decimal     taxrate      = Decimal.Zero;
                    GridViewRow row          = gMain.Rows[Convert.ToInt32(keys[3])];
                    HiddenField hdfCountryID = (HiddenField)row.FindControl("hdfCountryID");
                    int         CountryID    = Convert.ToInt32(hdfCountryID.Value);

                    resetError("Items updated", false);

                    try
                    {
                        taxrate = Localization.ParseNativeDecimal(Request.Form[Request.Form.Keys[i]]);
                    }
                    catch { }
                    ZipTaxRate ztr = AppLogic.ZipTaxRatesTable[ZipCode, ClassID, CountryID];
                    try
                    {
                        if (ztr == null)
                        {
                            AppLogic.ZipTaxRatesTable.Add(ZipCode, ClassID, taxrate, CountryID);
                        }
                        else
                        {
                            ztr.Update(taxrate, CountryID);
                        }
                    }
                    catch (Exception ex)
                    {
                        string err = ex.Message;
                    }
                }
            }


            buildGridData();
        }
        public virtual ZipTaxRate InsertZipTaxRate(ZipTaxRate entity)
        {
            ZipTaxRate other = new ZipTaxRate();

            other = entity;
            if (entity.IsTransient())
            {
                string         sql            = @"Insert into ZipTaxRate ( [ZipCode]
				,[TaxClassID]
				,[TaxRate]
				,[CreatedOn]
				,[CountryID] )
				Values
				( @ZipCode
				, @TaxClassID
				, @TaxRate
				, @CreatedOn
				, @CountryID );
				Select scope_identity()"                ;
                SqlParameter[] parameterArray = new SqlParameter[] {
                    new SqlParameter("@ZipTaxID", entity.ZipTaxId)
                    , new SqlParameter("@ZipCode", entity.ZipCode)
                    , new SqlParameter("@TaxClassID", entity.TaxClassId)
                    , new SqlParameter("@TaxRate", entity.TaxRate ?? (object)DBNull.Value)
                    , new SqlParameter("@CreatedOn", entity.CreatedOn)
                    , new SqlParameter("@CountryID", entity.CountryId)
                };
                var identity = SqlHelper.ExecuteScalar(this.ConnectionString, CommandType.Text, sql, parameterArray);
                if (identity == DBNull.Value)
                {
                    throw new DataException("Identity column was null as a result of the insert operation.");
                }
                return(GetZipTaxRate(Convert.ToInt32(identity)));
            }
            return(entity);
        }
예제 #6
0
        protected void gMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = gMain.Rows[e.RowIndex];

            if (row != null)
            {
                string orig              = ViewState["OriginalZip"].ToString();
                string zip               = (((TextBox)row.FindControl("txtZip")).Text.Trim()).ToString();
                string countryid         = ((DropDownList)row.FindControl("ddlCountry")).SelectedValue.Trim();
                string OriginalCountryID = AppLogic.GetCountryID(ViewState["OriginalCountryID"].ToString()).ToString();

                StringBuilder sql = new StringBuilder(1024);

                //make sure no duplicates
                if (!orig.Equals(zip))
                {
                    int count = DB.GetSqlN(String.Format("SELECT count(*) AS N FROM ZipTaxRate WHERE ZipCode = {0} and CountryId = {1}", DB.SQuote(zip), CommonLogic.IIF(someCountryRequirePostalCode > 0, Convert.ToInt32(countryid), -1)));
                    if (count > 0)
                    {
                        resetError("Duplicate Zip Code exists", true);
                        return;
                    }
                }

                try
                {
                    resetError("Item updated", false);
                    gMain.EditIndex        = -1;
                    ViewState["SQLString"] = selectSQL;

                    for (int i = 0; i <= Request.Form.Count - 1; i++)
                    {
                        //TR_CLASSID_ZipCode
                        if (Request.Form.Keys[i].IndexOf("TR_") != -1)
                        {
                            String[] keys    = Request.Form.Keys[i].Split('_');
                            string   ZipCode = keys[2];
                            int      ClassID = Localization.ParseUSInt(keys[1]);
                            decimal  taxrate = Decimal.Zero;
                            if (ZipCode == orig && e.RowIndex == Convert.ToInt32(keys[3]))
                            {
                                try
                                {
                                    taxrate = Localization.ParseNativeDecimal(Request.Form[Request.Form.Keys[i]]);
                                }
                                catch { }

                                ZipTaxRate ztr3 = AppLogic.ZipTaxRatesTable[zip, ClassID, Convert.ToInt32(countryid)];
                                try
                                {
                                    if (ztr3 != null)
                                    {
                                        if (Convert.ToInt32(countryid) != Convert.ToInt32(OriginalCountryID))
                                        {
                                            resetError("Zip Code, Tax Class ID and Country ID already exists.", false);
                                        }
                                        else
                                        {
                                            ztr3.Update(taxrate, Convert.ToInt32(countryid));
                                        }
                                    }
                                    else
                                    {
                                        bool validZipFormat = true;
                                        if ((Convert.ToInt32(countryid) != Convert.ToInt32(OriginalCountryID)) || (orig != zip))
                                        {
                                            if (Convert.ToInt32(countryid) != Convert.ToInt32(OriginalCountryID))
                                            {
                                                validZipFormat = AppLogic.ValidatePostalCode(zip, Convert.ToInt32(countryid));
                                            }
                                            if (validZipFormat)
                                            {
                                                ZipTaxRates ztr2 = new ZipTaxRates();
                                                foreach (ZipTaxRate ztr in ztr2.All)
                                                {
                                                    if (ztr.ZipCode == orig && ztr.TaxClassID == ClassID && ztr.CountryID == Convert.ToInt32(OriginalCountryID))
                                                    {
                                                        ztr.Update(taxrate, zip, Convert.ToInt32(countryid), Convert.ToInt32(OriginalCountryID));
                                                        AppLogic.ZipTaxRatesTable.AddNewRate(ztr.ZipTaxID, zip, ClassID, taxrate, Convert.ToInt32(countryid));
                                                    }
                                                }
                                            }
                                            else
                                            {
                                                resetError(AppLogic.GetCountryPostalErrorMessage(Convert.ToInt32(countryid), cust.SkinID, cust.LocaleSetting), true);
                                            }
                                        }
                                        else
                                        {
                                            AppLogic.ZipTaxRatesTable.Add(ZipCode, ClassID, taxrate, Convert.ToInt32(countryid));
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string err = ex.Message;
                                }
                            }
                        }
                    }
                    buildGridData();
                }
                catch (Exception ex)
                {
                    throw new Exception("Couldn't update database: " + sql.ToString() + ex.ToString());
                }
            }
        }
예제 #7
0
 public ZipTaxRate InsertZipTaxRate(ZipTaxRate entity)
 {
     return(_iZipTaxRateRepository.InsertZipTaxRate(entity));
 }
예제 #8
0
 public ZipTaxRate UpdateZipTaxRate(ZipTaxRate entity)
 {
     return(_iZipTaxRateRepository.UpdateZipTaxRate(entity));
 }
 public virtual ZipTaxRate DeleteZipTaxRate(ZipTaxRate entity)
 {
     this.DeleteZipTaxRate(entity.ZipTaxId);
     return(entity);
 }