⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 default.aspx.cs

📁 互联网程序设计的课程
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class backup_Default : System.Web.UI.Page
{double sumMoney = 0;
    DataTable table;

 


    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["shopcart"] != null)
        {
            table = (DataTable)Session["shopcart"];
        
        }
        if(!Page.IsPostBack )
        {
            if (Session["shopcart"] == null)
            { table = MakeNamesTable(); }
            Session["shopcart"] = table;
        }
              //初使化列表

    }

    //根据商品编号查询商品基本信息
// protected void btn_search_Click(object sender, EventArgs e)
  //{
     //  tbx_productname.Text = "";//清空框里的数据
      // tbx_productprice.Text = "";
    //tbx_ordernum.Text = "";
   //string queryStr = "select product_name,product_sellprice from product_info where product_id='" + tbx_productid.Text.Trim() + "'";
     // SqlDataReader myDataReader = DataBaseOperate.myExecuteReader(queryStr);

     // while (myDataReader.Read())
   // {
       //  for (int i = 0; i < myDataReader.FieldCount; i++)
     //  {
     //       if (myDataReader.GetName(i) == "product_name")
      //           tbx_productname.Text = myDataReader.GetValue(i).ToString();
     //       if (myDataReader.GetName(i) == "product_sellprice")
      //          tbx_productprice.Text = myDataReader.GetValue(i).ToString();
    //      }
  //   }       
//  }

    //将选中的商品信息加入到列表中去
     
    protected void Button2_Click(object sender, EventArgs e)
    {
        if ((tbx_productid.Text.Trim() == "") ||
            (tbx_productname.Text.Trim() == "") || (tbx_productprice.Text.Trim() == ""))
            Response.Write("<script>alert('没有选中任何商品!')</script>");
        else if (tbx_ordernum.Text.Trim() == "")
        {
            Response.Write("<script>alert('请输入订购数量!')</script>");
        }
        else
        {
           

        
            DataRow row;
            row = table.NewRow();
            row["product_id"] = tbx_productid.Text.Trim();
            row["order_num"] = tbx_ordernum.Text.Trim();
            row["product_name"] = tbx_productname.Text.Trim();
            row["product_sellprice"] = tbx_productprice.Text.Trim();
            table.Rows.Add(row);

           DataGrid1.DataSource = new DataView(table); 
            DataGrid1.DataBind();

           



        }
        double theMoney = Int32.Parse(tbx_ordernum.Text.Trim()) * Double.Parse(tbx_productprice.Text.Trim());
        sumMoney += theMoney;
        tbx_sum.Text = sumMoney.ToString();

    }
    //成生DataTable并设定table的格式
    private DataTable MakeNamesTable()
    {
        DataTable namesTable = new DataTable("Names");

        //将table初使化为四列
        DataColumn idColumn = new  DataColumn();
        idColumn.DataType = System.Type.GetType("System.String");
        idColumn.ColumnName = "product_id";
  //      idColumn.AutoIncrement = true;
        namesTable.Columns.Add(idColumn);

        
        DataColumn numColumn = new DataColumn();
        numColumn.DataType = System.Type.GetType("System.Int32");
        numColumn.ColumnName = "order_num";
        namesTable.Columns.Add(numColumn);

        DataColumn nameColumn = new DataColumn();
        nameColumn.DataType = System.Type.GetType("System.String");
        nameColumn.ColumnName = "product_name";
        namesTable.Columns.Add(nameColumn);

        DataColumn priceColumn = new DataColumn();
        priceColumn.DataType = System.Type.GetType("System.String");
        priceColumn.ColumnName = "product_sellprice";
        namesTable.Columns.Add(priceColumn);       

        
        DataColumn [] keys = new DataColumn [1];
        keys[0] = idColumn;
        namesTable.PrimaryKey = keys;

        return namesTable;
    }

  
protected void  btn_search_Click(object sender, EventArgs e)
{

}
    protected void btn_submit_Click(object sender, EventArgs e)
    {

    }
    protected void btn_reset_Click(object sender, EventArgs e)
    {

    }
}











⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -