?? tec.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
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.Configuration;
namespace class_kinghome
{
/// <summary>
/// stuinfo 的摘要說明。
/// </summary>
public class tec : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox pas;
protected System.Web.UI.WebControls.Label info;
protected System.Web.UI.WebControls.Button find;
protected System.Web.UI.WebControls.Button add;
protected System.Web.UI.WebControls.Button del;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox manager;
protected System.Web.UI.WebControls.Button enter;
protected System.Web.UI.WebControls.TextBox dept;
protected System.Web.UI.WebControls.TextBox stuname;
protected System.Web.UI.WebControls.TextBox stuno;
protected System.Web.UI.WebControls.TextBox stusex;
public string getdept;
public string getstuname;
public string getstusex;
public string getstuno;
protected System.Web.UI.WebControls.Label change;
protected System.Web.UI.WebControls.Button condel;
private void Page_Load(object sender, System.EventArgs e)
{
Session.Timeout=30;
getdept=dept.Text;
getstuname=stuname.Text ;
getstusex=stusex.Text;
getstuno=stuno.Text;
DataGrid1.PagerStyle.Visible=true;
}
public void manaenter(object sender, System.EventArgs e)
{
if (manager.Text==ConfigurationSettings.AppSettings["managername"]&&pas.Text==ConfigurationSettings.AppSettings["password"])
{
Session["ifenter"]="hasenter";
info.Text="歡迎管理員登陸!";
}
else
info.Text="請確認輸入!";
}
public void find_Click(object sender, System.EventArgs e)
{
SqlConnection Con = new SqlConnection("Data Source=(local);Initial Catalog=class;User ID=sa;Pwd=sasasa;");
string sel;
SqlDataAdapter Cmd ;
sel="select * from tea WHERE "+checkstr(getdept,"tdept")+checkstr(getstuname,"tname")+checkstr(getstusex,"tpost")+checkstr(getstuno,"tno");
if(sel.EndsWith("and")==true)
sel=sel.Remove(sel.Length-3,3);
Cmd=new SqlDataAdapter(sel,Con);
DataSet ds=new DataSet();
Cmd.Fill(ds,"stu");
DataGrid1.DataSource=ds.Tables["stu"].DefaultView;
DataGrid1.DataBind();
}
public void addstu(object sender, System.EventArgs e)
{
try
{
if (Session["ifenter"]=="hasenter")
{
if ((getdept=="")||(getstuname=="")||(getstuno==""))
change.Text="必須項沒有填寫!";
else
{
change.Text="正在操作";
SqlConnection Con = new SqlConnection("Data Source=(local);Initial Catalog=class;User ID=sa;Pwd=sasasa;");
string sql = "insert into tea (tno,tname,tdept,tpost) values ('" + getstuno + "','"+getstuname + "','" + getdept + "','" +getstusex +"')";
SqlCommand addCommand =new SqlCommand(sql,Con);
addCommand.Connection.Open();
addCommand.ExecuteNonQuery();
addCommand.Connection.Close();
change.Text="操作成功";
stuno.Text="";
stuname.Text="";
stusex.Text="";
dept.Text="";
}
}
else
change.Text="你還沒登陸!";
}
catch
{change.Text="處理數據時出錯";}
}
public void delstu(object sender, System.EventArgs e)
{
string delsql;
if (Session["ifenter"]=="hasenter")
{
SqlConnection Con = new SqlConnection("Data Source=(local);Initial Catalog=class;User ID=sa;Pwd=sasasa;");
delsql = "DELETE FROM tea WHERE "+checkstr(getdept,"tdept")+checkstr(getstuname,"tname")+checkstr(getstusex,"tpost")+checkstr(getstuno,"tno");
if(delsql.EndsWith("and")==true)
delsql=delsql.Remove(delsql.Length-3,3);
SqlCommand delCommand =new SqlCommand(delsql,Con);
delCommand.Connection.Open();
delCommand.ExecuteNonQuery();
delCommand.Connection.Close();
change.Text="操作成功";
condel.Visible=false;
}
else
change.Text="你還沒登陸!";
}
public string checkstr(string a,string b)
{
if (a!="")
a=" "+b+"='"+a+"' and";
return a;
}
public void showdel(object sender, System.EventArgs e)
{
find_Click(sender,e);
condel.Visible=true;
change.Text="將要刪除以下記錄!";
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN:該調用是 ASP.NET Web 窗體設計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內容。
/// </summary>
private void InitializeComponent()
{
this.find.Click += new System.EventHandler(this.find_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -