初学者,帮忙看一下是什么意思吧!很长,谢谢喽
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 PIS
{
/// <summary>
/// users 的摘要说明。
/// </summary>
public partial class users : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
//判断用户是否为合法用户
try
{
if(Session["userpower"].ToString ()=="1");
else
{
Response.End ();
}
}
catch
{
Response.Write ("您不是合法用户,请登录后再操作,<a href='default.aspx'>返回</a>");
Response.End ();
}
// 在此处放置用户代码以初始化页面
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn=new SqlConnection(strconn);
cn.Open();
if(!IsPostBack)
{
Bindgrid();
}
cn.Close();
}
#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()
{
}
#endregion
public void DataGrid_cancel(object sender,DataGridCommandEventArgs e)
{
Dgd_userinformation.EditItemIndex=-1;
Bindgrid();
}
public void DataGrid_edit(object sender,DataGridCommandEventArgs e)
{
Dgd_userinformation.EditItemIndex=(int)e.Item.ItemIndex;
Bindgrid();
}
public void DataGrid_update(object sender,DataGridCommandEventArgs e)
{
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn=new SqlConnection(strconn);
cn.Open();
string strsql="update users set UID=@uid,UPassword=@password,UPower=@kind where ID=@userid";
SqlCommand cm=new SqlCommand(strsql,cn);
cm.Parameters.Add(new SqlParameter("@uid",SqlDbType.VarChar,50));
cm.Parameters.Add(new SqlParameter("@password",SqlDbType.VarChar,50));
cm.Parameters.Add(new SqlParameter("@kind",SqlDbType.Int,4));
cm.Parameters.Add(new SqlParameter("@userid",SqlDbType.BigInt,8));
string colvalue=((TextBox)e.Item.Cells[3].Controls[0]).Text;
cm.Parameters["@uid"].Value=colvalue;
colvalue=((TextBox)e.Item.Cells[4].Controls[0]).Text;
cm.Parameters["@password"].Value=colvalue;
colvalue=((TextBox)e.Item.Cells[5].Controls[0]).Text;
cm.Parameters["@kind"].Value=colvalue;
cm.Parameters["@userid"].Value=Dgd_userinformation.DataKeys[(int)e.Item.ItemIndex];
try
{
cm.ExecuteNonQuery();
Lbl_show.Text="编辑成功";
Dgd_userinformation.EditItemIndex=-1;
}
catch(SqlException)
{
Lbl_show.Text="编辑失败,请检查输入!";
Lbl_show.Style["color"]="red";
}
cm.Connection.Close();
Bindgrid();
}
public void DataGrid_delete(object sender,DataGridCommandEventArgs e)
{
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn=new SqlConnection(strconn);
cn.Open();
string strsql="delete from users where ID=@userid";
SqlCommand cm=new SqlCommand(strsql,cn);
cm.Parameters.Add(new SqlParameter("@userid",SqlDbType.BigInt,8));
cm.Parameters["@userid"].Value=Dgd_userinformation.DataKeys[(int)e.Item.ItemIndex];
try
{
cm.ExecuteNonQuery();
Lbl_show.Text="删除成功";
}
catch(SqlException)
{
Lbl_show.Text="删除失败";
Lbl_show.Style["color"]="red";
}
cm.Connection.Close();
Bindgrid();
}
public void Bindgrid()
{
string uID = Session["userid"].ToString();;
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn=new SqlConnection(strconn);
cn.Open();
SqlDataAdapter da=new SqlDataAdapter("select * from users where UID != '"+uID+"'",cn);
DataSet ds=new DataSet();
da.Fill(ds);
Dgd_userinformation.DataSource=ds;
Dgd_userinformation.DataBind();
cn.Close();
}
protected void Btn_search_Click(object sender, System.EventArgs e)
{
string strconn= ConfigurationSettings.AppSettings["dsn"];
SqlConnection cn=new SqlConnection(strconn);
cn.Open();
string strsql="select * from users where UID=@uid";
SqlCommand cm=new SqlCommand(strsql,cn);
cm.Parameters.Add(new SqlParameter("@uid",SqlDbType.VarChar,50));
cm.Parameters["@uid"].Value=Tbx_uid.Text;
SqlDataReader dr=cm.ExecuteReader();
Dgd_userinformation.DataSource=dr;
Dgd_userinformation.DataBind();
cn.Close();
}
protected void Btn_add_Click(object sender, System.EventArgs e)
{
Response.Redirect("addusers.aspx");
}
protected void Button1_Click(object sender, System.EventArgs e)
{
Response.Redirect("default.aspx");
}
}
}
--------------------编程问答-------------------- 一个用户操作页面,更新\搜索\删除\编辑用户的操作
补充:.NET技术 , C#