Exemplo n.º 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      StateID = Localization.ParseUSInt(keys[1]);
                    int      DispOrd = 1;
                    try
                    {
                        DispOrd = Localization.ParseUSInt(Request.Form[Request.Form.Keys[i]]);
                    }
                    catch { }
                    DB.ExecuteSQL("update State set DisplayOrder=" + DispOrd.ToString() + " where StateID=" + StateID.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      StateID = 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 { }
                    StateTaxRate ctr = AppLogic.StateTaxRatesTable[StateID, ClassID];
                    try
                    {
                        if (ctr == null)
                        {
                            AppLogic.StateTaxRatesTable.Add(StateID, ClassID, tax);
                        }
                        else
                        {
                            ctr.Update(tax);
                        }
                    }
                    catch (Exception ex)
                    {
                        string err = ex.Message;
                    }
                }
            }
        }
Exemplo n.º 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 abbr      = ((TextBox)row.FindControl("txtAbbreviation")).Text.Trim();
                bool   published = ((CheckBox)row.FindControl("cbPublished")).Checked;
                int    country   = Localization.ParseNativeInt(((DropDownList)row.FindControl("ddCountry")).SelectedValue);
                int    order     = Localization.ParseNativeInt(((TextBox)row.FindControl("txtOrder")).Text.Trim());

                // see if already exists:
                int N = DB.GetSqlN("select count(Name) as N from State   with (NOLOCK)  where StateID<>" + iden + " and lower(Name)=" + DB.SQuote(name.ToLowerInvariant()));
                if (N != 0)
                {
                    resetError("There is already another state with that name.", true);
                    return;
                }

                StringBuilder sql = new StringBuilder(4096);

                sql.Append("update State set ");
                sql.Append("Name=" + DB.SQuote(name) + ",");
                sql.Append("CountryID=" + country + ",");
                sql.Append("Published=" + CommonLogic.IIF(published, 1, 0) + ",");
                sql.Append("DisplayOrder=" + order + ",");
                sql.Append("Abbreviation=" + DB.SQuote(CommonLogic.Left(abbr, 5)));
                sql.Append(" where StateID=" + iden);

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

                    //UpdateTaxOrder();
                    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      StateID = Localization.ParseUSInt(keys[2]);
                            int      ClassID = Localization.ParseUSInt(keys[1]);
                            if (StateID == Localization.ParseUSInt(iden))
                            {
                                decimal tax = Decimal.Zero;
                                try
                                {
                                    tax = Localization.ParseNativeDecimal(Request.Form[Request.Form.Keys[i]]);
                                }
                                catch { }
                                StateTaxRate str = AppLogic.StateTaxRatesTable[StateID, ClassID];
                                try
                                {
                                    if (str == null)
                                    {
                                        AppLogic.StateTaxRatesTable.Add(StateID, ClassID, tax);
                                    }
                                    else
                                    {
                                        str.Update(tax);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    string err = ex.Message;
                                }
                            }
                        }
                    }

                    buildGridData();
                }
                catch (Exception ex)
                {
                    throw new Exception("Couldn't update database: " + sql.ToString() + ex.ToString());
                }
            }
        }