示例#1
0
        protected void UpdateTaxOrder()
        {
            for (int i = 0; i <= Request.Form.Count - 1; i++)
            {
                if (Request.Form.Keys[i].IndexOf("DisplayOrder_") != -1)
                {
                    String[] keys      = Request.Form.Keys[i].Split('_');
                    int      CountryID = Localization.ParseUSInt(keys[1]);
                    int      DispOrd   = 1;
                    try
                    {
                        DispOrd = Localization.ParseUSInt(Request.Form[Request.Form.Keys[i]]);
                    }
                    catch { }
                    DB.ExecuteSQL("update Country set DisplayOrder=" + DispOrd.ToString() + " where CountryID=" + CountryID.ToString());
                }
            }

            //handle taxes
            for (int i = 0; i <= Request.Form.Count - 1; i++)
            {
                //TR_CLASSID_STATEID
                if (Request.Form.Keys[i].IndexOf("TR_") != -1)
                {
                    String[] keys      = Request.Form.Keys[i].Split('_');
                    int      CountryID = Localization.ParseUSInt(keys[2]);
                    int      ClassID   = Localization.ParseUSInt(keys[1]);
                    decimal  tax       = Decimal.Zero;
                    try
                    {
                        tax = Localization.ParseNativeDecimal(Request.Form[Request.Form.Keys[i]]);
                    }
                    catch { }
                    CountryTaxRate ctr = AppLogic.CountryTaxRatesTable[CountryID, ClassID];
                    try
                    {
                        if (ctr == null)
                        {
                            AppLogic.CountryTaxRatesTable.Add(CountryID, ClassID, tax);
                        }
                        else
                        {
                            ctr.Update(tax);
                        }
                    }
                    catch (Exception ex)
                    {
                        string err = ex.Message;
                    }
                }
            }
        }
示例#2
0
        protected void gMain_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            GridViewRow row = gMain.Rows[e.RowIndex];

            if (row != null)
            {
                string iden              = row.Cells[1].Text.ToString();
                string name              = ((TextBox)row.FindControl("txtName")).Text.Trim();
                string twoLetter         = ((TextBox)row.FindControl("txt2LetterIso")).Text.Trim();
                string threeLetter       = ((TextBox)row.FindControl("txt3LetterIso")).Text.Trim();
                string numericISO        = ((TextBox)row.FindControl("txtNumericISOCode")).Text.Trim();
                bool   published         = ((CheckBox)row.FindControl("cbPublished")).Checked;
                bool   postalCodeReq     = ((CheckBox)row.FindControl("cbPostalCodeRequired")).Checked;
                string postalCodeRegEx   = ((TextBox)row.FindControl("txtPostalCodeRegex")).Text.Trim();
                string postalCodeExample = ((TextBox)row.FindControl("txtPostalCodeExample")).Text.Trim();
                int    order             = Localization.ParseNativeInt(((TextBox)row.FindControl("txtOrder")).Text.Trim());

                // see if already exists:
                int N = DB.GetSqlN("select count(Name) as N from Country   with (NOLOCK)  where CountryID<>" + iden + " and lower(Name)=" + DB.SQuote(name.ToLowerInvariant()));
                if (N != 0)
                {
                    resetError(AppLogic.GetString("admin.countries.ExistingCountry", SkinID, LocaleSetting), true);
                    return;
                }

                StringBuilder sql = new StringBuilder(1024);

                sql.Append("update Country set ");
                sql.Append("Name=" + DB.SQuote(name) + ",");
                sql.Append("TwoLetterISOCode=" + DB.SQuote(CommonLogic.Left(twoLetter, 2)) + ",");
                sql.Append("ThreeLetterISOCode=" + DB.SQuote(CommonLogic.Left(threeLetter, 3)) + ",");
                sql.Append("NumericISOCode=" + DB.SQuote(CommonLogic.Left(numericISO, 3)) + ",");
                sql.Append("Published=" + CommonLogic.IIF(published, 1, 0) + ",");
                sql.Append("PostalCodeRequired=" + CommonLogic.IIF(postalCodeReq, 1, 0) + ",");
                sql.Append("PostalCodeRegex=" + DB.SQuote(postalCodeRegEx) + ",");
                sql.Append("PostalCodeExample=" + DB.SQuote(postalCodeExample) + ",");
                sql.Append("DisplayOrder=" + order);
                sql.Append(" where CountryID=" + iden.ToString());


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



                    for (int i = 0; i <= Request.Form.Count - 1; i++)
                    {
                        //TR_CLASSID_STATEID
                        if (Request.Form.Keys[i].IndexOf("TR_") != -1)
                        {
                            String[] keys      = Request.Form.Keys[i].Split('_');
                            int      CountryID = Localization.ParseUSInt(keys[2]);
                            int      ClassID   = Localization.ParseUSInt(keys[1]);
                            decimal  tax       = Decimal.Zero;
                            if (CountryID == Localization.ParseUSInt(iden))
                            {
                                try
                                {
                                    tax = Localization.ParseNativeDecimal(Request.Form[Request.Form.Keys[i]]);
                                }
                                catch { }
                                CountryTaxRate ctr = AppLogic.CountryTaxRatesTable[CountryID, ClassID];
                                try
                                {
                                    if (ctr == null)
                                    {
                                        AppLogic.CountryTaxRatesTable.Add(CountryID, ClassID, tax);
                                    }
                                    else
                                    {
                                        ctr.Update(tax);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string err = ex.Message;
                                }
                            }
                        }
                    }

                    BuildGridData();
                }
                catch (Exception ex)
                {
                    throw new Exception(String.Format(AppLogic.GetString("admin.common.ErrUpdateDB", SkinID, LocaleSetting), sql.ToString() + ex.ToString()));
                }
            }
        }