?? myclass.aspx.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;
using System.Data.SqlClient;
using lalablog;
public partial class tongxue_myclass : System.Web.UI.Page
{
int userid;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["userid"] != null)
{
this.userid = Convert.ToInt32(Session["userid"].ToString());
}
else
Response.Redirect("userLogin.aspx?url=" + Server.HtmlEncode(Request.RawUrl));
if (!IsPostBack)
{
ddlxuexiao.DataBind();
ddlnian.DataBind();
}
if (Request.QueryString["action"] != null)
{
string action = Request.QueryString["action"].ToString ();
if (action == "join")
joinClass();
}
}
private void joinClass()
{
bool validate = false;
int cid=0,tid=0;
if (Request.QueryString["cid"] != null)
cid = Convert.ToInt32(Request.QueryString["cid"].ToString());
else
Response.Redirect("myclass.aspx");
if (Session["userid"] != null)
tid = Convert.ToInt32(Session["userid"].ToString());
string sqlvalidate = "select * from tidcid where tid=" + tid+ " and cid=" + cid;
openDb o2 = new openDb(sqlvalidate);
validate = !o2.haveRows();
if (validate)
{
string sql = "delete from tapply where tid=" + tid + " and cid=" + cid;
sql += ";insert into tapply(tid,cid) values(" + tid + "," + cid + ")";
openDb o1 = new openDb(sql);
string msg = o1.update();
myfunc m1;
if (msg == "更新成功!")
m1 = new myfunc("成功申請,請等待班級管理員的批準");
else
m1 = new myfunc(msg);
Response.Write(m1.JavaMsg());
}
else
{
myfunc m1 = new myfunc("您已經是此班級的成員了,不要重復加入!");
Response.Write(m1.JavaMsg());
}
}
protected void btnAddClassName_Click(object sender, EventArgs e)
{
bool validate=false ;
string college;
if (tbCollege.Text.Length > 5)
college = Server.HtmlEncode(tbCollege.Text);
else
college = ddlCollege.SelectedValue;
int comeyear;
comeyear = Convert.ToInt32(tbComeYear.Text);
if (comeyear > 1950 && comeyear < 2010)
validate = true;
string classname = Server.HtmlEncode (tbClassname.Text);
int adminuserid = this.userid;
//加入班級已經存在的驗證
string sqlValidate = "select * from tbanji where college='" + college + "' and comeyear=" + comeyear;
sqlValidate += " and classname='" + classname + "'";
openDb o = new openDb(sqlValidate);
validate = !o.haveRows();
if (validate)
{
string sql = "insert into tbanji (college,comeyear,classname,adminuserid) values (";
sql += "'" + college + "'," + comeyear + ",'" + classname + "'," + adminuserid + ")";
openDb o1 = new openDb(sql);
string msg = o1.update();
//將創建班級者添加到班級中
string sqlFindCid = "select cid from tbanji where adminuserid=" + adminuserid + " order by cid desc";
openDb o2 = new openDb(sqlFindCid);
int cid = Convert.ToInt32(o2.getValue());
string sqladdUser = " insert into tidcid (tid,cid) values(" + adminuserid + "," + cid + ")";
openDb o3 = new openDb(sqladdUser);
o3.update();
myfunc m1 = new myfunc("創建班級成功!");
Response.Write(m1.JavaMsg("index.aspx"));
}
else
{
myfunc m1 = new myfunc("班級已存在");
Response.Write(m1.JavaMsg("myclass.aspx"));
}
}
protected void btnListClassName_Click(object sender, EventArgs e)
{
string college = ddlxuexiao.SelectedValue;
string comeyear = ddlnian.SelectedValue;
string sql;
sql = "select * from tbanji where college='" + college + "' and comeyear=" + comeyear;
sql+=" order by comeyear desc,cid desc";
string strconn = ConfigurationManager.ConnectionStrings["dsn"].ToString();
SqlConnection cn = new SqlConnection(strconn);
cn.Open();
SqlCommand cm = new SqlCommand(sql, cn);
SqlDataReader dr = cm.ExecuteReader();
while (dr.Read())
{
listclass.InnerHtml = "<li>" + dr["college"].ToString()+"__";
listclass.InnerHtml += dr["comeyear"].ToString() +"__"+ dr["classname"].ToString();
listclass.InnerHtml += " ";
listclass.InnerHtml +="<a href=myclass.aspx?action=join&";
listclass.InnerHtml += "cid="+dr["cid"].ToString ()+">";
listclass.InnerHtml += "申請加入</a></li>";
}
cn.Close();
}
protected void ddlxuexiao_SelectedIndexChanged(object sender, EventArgs e)
{
ddlnian.DataBind();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -