📄 class_bookinformation.aspx.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace free
{
/// <summary>
/// Summary description for class_bookinformation.
/// </summary>
public class class_bookinformation : System.Web.UI.Page
{
SqlConnection myconn;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;
protected System.Data.DataTable Cart;
protected System.Web.UI.WebControls.DataGrid DataGrid2;
protected System.Web.UI.WebControls.DataGrid ShopingCart;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.HyperLink HyperLink1;
protected System.Web.UI.HtmlControls.HtmlTable mytable1;
protected System.Web.UI.HtmlControls.HtmlTable mytable2;
protected System.Data.DataView CartView;
private void binding()
{
string connstr;
myconn=new SqlConnection(Session["str_connection"].ToString());
myconn.Open();
connstr="SELECT shuming,id,zhuanjia_xingming,shichang,xuefei FROM class_jiaocheng ";
DataSet mydataset=new DataSet();
SqlDataAdapter MyCommand=new SqlDataAdapter(connstr,myconn);
MyCommand.Fill(mydataset,"class_jiaocheng");
DataGrid1.DataSource = mydataset.Tables["class_jiaocheng"].DefaultView;
DataGrid1.DataBind();
myconn.Close();
}
// private void binding()
// {
// string connstr;
// myconn=new SqlConnection(Session["str_connection"].ToString());
// myconn.Open();
// connstr="SELECT shuming,jieshao,zhuanjia_xingming,shichang,xuefei FROM class_jiaocheng ";
//
// }
private void ShopCart_binding(DataGrid Grid,DataView View)
{
Grid.DataSource=View;
Grid.DataBind();
}
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
// binding();
//
// Cart=new DataTable();
// Cart.Columns.Add(new DataColumn("课程名称"));
// Cart.Columns.Add(new DataColumn("学费(元)"));
// CartView=new DataView(Cart);
}
/*public void ChangePage(Object sender,DataGridPageChangedEventArgs e)
{
start=e.NewPageIndex*DataGrid1.PageSize;
DataGrid1.CurrentPageIndex = e.NewPageIndex;
binding();
}*/
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Cart = new System.Data.DataTable();
this.CartView = new System.Data.DataView();
((System.ComponentModel.ISupportInitialize)(this.Cart)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.CartView)).BeginInit();
this.Button1.Click += new System.EventHandler(this.Button1_Click);
// this.ShopingCart.SelectedIndexChanged += new System.EventHandler(this.ShopingCart_SelectedIndexChanged);
// this.Load += new System.EventHandler(this.Page_Load);
((System.ComponentModel.ISupportInitialize)(this.Cart)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.CartView)).EndInit();
binding();
Cart=new DataTable();
Cart.Columns.Add(new DataColumn("课程名称"));
Cart.Columns.Add(new DataColumn("学费(元)"));
CartView=new DataView(Cart);
try
{
Session["user_id"]=Request.Cookies["free_xueyuan"].Value.ToString();
}
catch
{
Response.Redirect("class_error.aspx");
}
}
#endregion
private void Button1_Click(object sender, System.EventArgs e)
{
int i=0;
double sum=0.0;
DataGridItem item;
DataRow dr;
CheckBox Book_checked;
string Class_Name,Schooling;
//stu_name=Session["user_id"].ToString();
string myconn_str;
int Book_Id;
for(i=0;i<DataGrid1.Items.Count;i++)
{
item=DataGrid1.Items[i];
Book_checked=(CheckBox)item.FindControl("CheckBook");
// j=DataGrid1.Items[i].ItemIndex;
if(Book_checked.Checked)
{
Class_Name=item.Cells[0].Text;
Schooling=item.Cells[4].Text;
dr=Cart.NewRow();
dr[0]=Class_Name;
dr[1]=Schooling;
Cart.Rows.Add(dr);
sum+=double.Parse(Schooling.ToString());
// j=1;
myconn.Close();
myconn.Open();
myconn_str="SELECT id FROM class_jiaocheng WHERE shuming='"+Class_Name.ToString()+"'";
SqlCommand mycomm = new SqlCommand(myconn_str,myconn);
SqlDataReader DR2;
DR2=mycomm.ExecuteReader();
try
{
if(DR2.Read())
{
Book_Id=int.Parse(DR2.GetValue(0).ToString());
DR2.Close();
myconn_str ="INSERT INTO class_student_buybook(stu_name,book_id) VALUES('"+Session["user_id"].ToString()+"','"+Book_Id+"')";
SqlCommand mycommand=new SqlCommand(myconn_str,myconn);
mycommand.ExecuteNonQuery();
/////////////////////////////
ShopingCart.Visible=true;
DataGrid1.Visible=false;
Button1.Visible=false;
Label1.Visible=true;
Label1.Text="已购教程信息";
Label2.Visible=true;
Label3.Text=sum.ToString();
HyperLink1.Visible=true;
}
}
catch
{
Label1.Visible=true;
Label1.Text="至少选择一门课程";
Response.Write("<script>alert('对不起,您已经购买了该课程!')</script>");
}
}
ShopCart_binding(ShopingCart,CartView);
}
// if(j==1)
// {
// ShopingCart.Visible=true;
// DataGrid1.Visible=false;
// Button1.Visible=false;
// Label1.Visible=true;
// Label1.Text="已购教程信息";
// Label2.Visible=true;
// Label3.Text=sum.ToString();
// HyperLink1.Visible=true;
//
//
//
// }
// else
// {
// Label1.Visible=true;
// Label1.Text="至少选择一门课程";
// }
}
private void DataGrid1_SelectedIndexChanged(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
//
CheckBox Book_checked = (CheckBox)e.Item.FindControl("CheckBook");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -