string cn = ConfigurationManager.ConnectionStrings["sqlCon"].ToString();
DataSet ds = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
lbluser.Text = Session["username"].ToString();
lbltype.Text = Session["TName"].ToString();
if (!Page.IsPostBack)
{
string sql = "Select BNAME,BPrice from book where TID ='" + Session["TID"] + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, cn);
da.Fill(ds, "Book");
gv.DataSource = ds.Tables["Book"];
gv.DataBind();
}
}
int total = 0;
int price = 0;
int pricetotal = 0;
protected void Button1_Click(object sender, EventArgs e) ปุ่มแสดงรายการใน listbox
{
ltblist.Items.Add(txtname.Text + " " + "จำนวน" + " " + txtunit.Text + " " + "เล่ม");
string books = ltblist.Items.ToString();
int unitprice = Convert.ToInt16(txtunitprice.Text);
int unit = Convert.ToInt16(txtunit.Text);
pricetotal = Convert.ToInt16(txttotal.Text);
price = unit * unitprice;
total += price;
pricetotal += total;
txttotal.Text = pricetotal.ToString();
}
protected void gv_SelectedIndexChanged(object sender, EventArgs e)
{
int index = gv.SelectedIndex;
GridViewRow gvr = gv.Rows[index];
txtname.Text = gvr.Cells[1].Text;
txtunitprice.Text = gvr.Cells[2].Text;
}
protected void Button2_Click(object sender, EventArgs e) ปุ่มที่ไปเพจ2
{
Session["username"] = lbluser.Text;
Session["TName"] = lbltype.Text;
Session["books"] = ltblist.Items.ToString();
Session["pricetotal"] = txttotal.Text;
Response.Redirect("finish.aspx");
}
}