protected void updateGList(object sender, GridViewCommandEventArgs e) { if ((e.CommandName == "buyAll") || (e.CommandName == "buyOne")) { string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + Server.MapPath("~\\App_Data\\G2C.mdb"); OleDbConnection conn = new OleDbConnection(connectionString); int index = Convert.ToInt32(e.CommandArgument); string item = GoShopping.DataKeys[index].Values[0].ToString(); string sql; string svUserId = (string)(Session["UserId"]); if (e.CommandName == "buyAll") { sql = "Update Item set Item.ItemQuantity=0, ItemModifyDate=now Where Item.ItemUserId='" + svUserId + "' and Item.ItemId=" + item; } else { sql = "Update Item set Item.ItemQuantity=Item.ItemQuantity-1, ItemModifyDate=now Where Item.ItemUserId='" + svUserId + "' and Item.ItemId=" + item; } OleDbCommand cmd = new OleDbCommand(sql, conn); conn.Open(); OleDbDataReader reader; reader = cmd.ExecuteReader(); reader.Close(); conn.Close(); GoShopping.DataBind(); } }
protected void btnClear_Click(object sender, EventArgs e) { string connectionString = "Provider=Microsoft.JET.OLEDB.4.0;data source=" + Server.MapPath("~\\App_Data\\G2C.mdb"); OleDbConnection conn = new OleDbConnection(connectionString); string sql; string svUserId = (string)(Session["UserId"]); sql = "Update Item set Item.ItemQuantity=0, ItemModifyDate=now Where Item.ItemQuantity > 0 and Item.ItemUserId='" + svUserId + "'"; OleDbCommand cmd = new OleDbCommand(sql, conn); OleDbDataReader reader = null; string errorMsg = ""; try { conn.Open(); reader = cmd.ExecuteReader(); } catch (Exception ex) { errorMsg = ex.Message; } finally { if (reader != null) { reader.Close(); } if (conn != null) { conn.Close(); } GoShopping.DataBind(); } }
private void GoShoppingPage() { GoShopping?.Invoke(); }