using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; public partial class menuCar : System.Web.UI.Page { String SqlStr; DB db = new DB(); DataSet Ds = new DataSet(); public void DataListBind() { SqlStr = "select * from OrderMenu where customerName='" + Session["UserName"] + "'"; //Ds = db.GetDataTableBySql(SqlStr); DataSet das = Dataoperator.getRows(SqlStr); DataList1.DataSource = das; DataList1.DataBind(); //try //{ // this.DataList1.DataSource = Ds.Tables[0].DefaultView; // this.DataList1.DataBind(); //} //catch (Exception) //{ // Response.Write("<script>alert('没有得到数据,请重试!')</script>"); //} } protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { SqlStr = "select * from OrderMenu"; Ds = db.GetDataTableBySql(SqlStr); //try //{ // if (Ds.Tables[0].Rows.Count != 0)//若购物车有此产品则提示用户 // { // Response.Write("<script>alert('你已经购买了此产品,只要更改数量就行!')</script>"); // } // else//若购物车没有此产品则将此产品的相关信息插入购物车 // { // Response.Write("没有!!"); // } //} //catch (Exception) //{ // Response.Write("<script>alert('没有得到数据,请重试!')</script>"); //} DataListBind();//绑定数据 //total_money();//计算价格 } } protected void shoppingbtn_Click(object sender, EventArgs e) { Response.Redirect("orderMainMenu.aspx"); } protected void delallbtn_Click(object sender, EventArgs e) { } protected void orderbtn_Click(object sender, EventArgs e) { Response.Redirect("menuorder.aspx"); } protected void DataList1_DeleteCommand(object source, DataListCommandEventArgs e) { //String book_id = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); //SqlStr = "delete from 购物车表 where 图书编号='" + book_id + "'"; //Boolean Del_Result; //Del_Result = db.UpdateDataBySql(SqlStr); //if (Del_Result == true) //{ // Response.Write("<script>alert('记录删除成功!')</script>"); // DataListBind();//绑定数据 // total_money();//计算价格 //} //else // Response.Write("<script>alert('记录删除失败,请检查!')</script>"); } protected void DataList1_UpdateCommand(object source, DataListCommandEventArgs e) { String book_id = this.DataList1.DataKeys[e.Item.ItemIndex].ToString(); TextBox count = (TextBox)this.DataList1.Items[e.Item.ItemIndex].FindControl("txtcount"); string SqlStr1 = "select * from Menus where menuNumber='" + Session["menu_number"] + "'"; Ds = Dataoperator.getRows(SqlStr1); if (Ds.Tables[0].Rows.Count>0) { int pric = Convert.ToInt32(Ds.Tables[0].Rows[0][6]); int mon = Convert.ToInt32(count.Text) * pric; //Session["payMon"] = mon.ToString(); //total_money_txt.Text = mon.ToString(); SqlStr = "update OrderMenu set number='" + Convert.ToInt32(count.Text) + "',payMoney='" + mon + "' where"; Boolean Update_Result; Update_Result = db.UpdateDataBySql(SqlStr); if (Update_Result == true) { Response.Write("<script>alert('数量修改成功!')</script>"); DataListBind();//绑定数据 // total_money();//计算价格 } else Response.Write("<script>alert('数量修改失败,请检查!')</script>"); } else { } } }
[ASP/Basic]代码