📄 regclass.aspx.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
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 Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] == null)
Response.Redirect("index.aspx");
if (!this.Page.IsPostBack)
{
bindEnterYear();
}
}
public void bindEnterYear()
{ ArrayList ETRyear = new ArrayList();
ETRyear.Add("选择年份");
for (int j = 1964; j <= 2020; j++)
ETRyear.Add(j);
this.ETRTime.DataSource = ETRyear;
this.ETRTime.DataBind();
}
protected void ETRTime_SelectedIndexChanged(object sender, EventArgs e)
{
//
string cmd;
//////if ( other != "")
//////{
// cmd = " SELECT [UserID], [Email], [Tele], [MobilePh], [PicName], [QQ], [StudentID] FROM [UserInfo] where " + field + "='" + condition + "' or" + other + "='" + condition + "'"; ;//设置SQL命令
//}
//else
//{
cmd = " SELECT [ClassName], [Teacher], [Monitor], [classyear], [ClassNum], [Gyuan] FROM [ClassInfo] where [classyear]='" + this.ETRTime.SelectedItem.Text.Trim() + "'"; ;//设置SQL命令
//}
this.SqlDataSource1.SelectCommand = cmd;
this.SqlDataSource1.DataBind(); //将SqlDataSource重新绑定
this.GridView1.DataBind(); //对GridView进行绑定
}
protected void SerchClass_Click(object sender, EventArgs e)
{
string cmd;
//////if ( other != "")
//////{
// cmd = " SELECT [UserID], [Email], [Tele], [MobilePh], [PicName], [QQ], [StudentID] FROM [UserInfo] where " + field + "='" + condition + "' or" + other + "='" + condition + "'"; ;//设置SQL命令
//}//Name LIKE '" + "%" + this.SerchText.Text.ToString() + "%" + "')";//"+this.Province.Text.ToString()+" ; //设置SQL命令
//else
//{
cmd = " SELECT [ClassName], [Teacher], [Monitor], [classyear], [ClassNum], [Gyuan] FROM [ClassInfo] where [ClassName] LIKE '" + "%" + this.classname.Text.Trim() + "%" + "'"; ;//设置SQL命令
//}
this.SqlDataSource1.SelectCommand = cmd;
this.SqlDataSource1.DataBind(); //将SqlDataSource重新绑定
this.GridView1.DataBind(); //对GridView进行绑定
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//LinkEmail
switch (e.CommandName)
{
case "addclass":
{
// this.GridView1.EditRowStyle.BackColor = Color.FromName("#F7CE90");
int index = Convert.ToInt32(e.CommandArgument) - this.GridView1.PageIndex * 10;
//获取行的位置
GridViewRow row = GridView1.Rows[index];
//获取选定行的列的位置,比如第三列,付给你自己的变量表达式,这里是全局变量varImpID
// Session["MailTo"] = row.Cells[0].Text;
Label lb = (Label)row.FindControl("classlab");
// this.testtext.Text = row.Cells[4].Text;
String StrTemp = lb.Text.Trim();
Session["classname"] = StrTemp;
upusertoclass(StrTemp, Session["UserID"].ToString());
Response.Redirect("classview.aspx");
break;
}
default: break;
}
}
public void upusertoclass( string classname ,string userid)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
SqlCommand cmd = new SqlCommand();
cmd.Connection = conn;
cmd.CommandText = "select * from UserToClass where UserID='" + userid + "'and ClassName='" + classname + "'"; ;
cmd.Connection.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.HasRows != true)
{
cmd.Connection.Close();
string sql;
sql = "insert into UserToClass (UserID,ClassName,lognum,identify,lasttime) values('" + userid + "','" + classname + "','1','成员','" + System.DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "')";
cmd.Connection = conn;
cmd.CommandText = sql;
cmd.Connection.Open();
cmd.ExecuteNonQuery();
cmd.Connection.Close();
}
cmd.Connection.Close();
conn.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button lb = (( Button)e.Row.FindControl("addbtn"));
if (lb == null)
{
return;
}
lb.Enabled = true;
//switch (Convert.ToInt32((e.Row.Cells[4].Text.Trim())))
//{
lb.CommandArgument = e.Row.DataItemIndex.ToString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -