📄 m_userinfo.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;
namespace e_librarys
{
/// <summary>
/// M_UserInfo 的摘要说明。
/// </summary>
public partial class M_UserInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
Conn.Open();
SqlDataAdapter Da = new SqlDataAdapter("select * from User_Info ", Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds);
//设置数据库中主键字段
DataGrid_M_UserInfo.DataKeyField = "U_ID";
DataGrid_M_UserInfo.DataSource = Ds.Tables[0];
if (!Page.IsPostBack)
{ DataGrid_M_UserInfo.DataBind(); }
DataGrid_M_UserInfo.DataBind();
Conn.Close();
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
}
#endregion
protected void Button_Select_Click(object sender, System.EventArgs e)
{
SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
Conn.Open();
string StrSql = "select * from User_Info";
//方法1判断选择查询类型
if (Request.Form["Select"].ToString() != "")
{
switch (Request.Form["Select"].ToString())
{
case "ID": StrSql = StrSql + " where U_ID='" + TextBox.Text.ToString() + "'"; break;
case "Name": StrSql = StrSql + " where U_Name like '%" + TextBox.Text.ToString() + "%'"; break;
case "QQ": StrSql = StrSql + " where U_QQ='" + TextBox.Text.ToString() + "'"; break;
case "Email": StrSql = StrSql + " where U_Email like '%" + TextBox.Text.ToString() + "%'"; break;
case "Telephone": StrSql = StrSql + " where U_Telephone like '%" + TextBox.Text.ToString() + "%'"; break;
case "Birthday": StrSql = StrSql + " where U_Birthday='" + TextBox.Text.ToString() + "'"; break;
case "Adimin": StrSql = StrSql + " where U_IsAdimin='" + TextBox.Text.ToString() + "'"; break;
case "RentCount": StrSql = StrSql + " where U_RentCount='" + TextBox.Text.ToString() + "'"; break;
default: Response.Write("<Script Language='JavaScript'>alert('你没有选择类型')</Script>"); break;
}
}
//方法2判断选择查询类型
// if(Request.Form["Select"].ToString()=="ID")
// { StrSql=StrSql+" where U_ID='"+TextBox.Text.ToString()+"'";}
//
// if(Request.Form["Select"].ToString()=="Name")
// { StrSql=StrSql+" where U_Name like '%"+TextBox.Text.ToString()+"%'";}
//
// if(Request.Form["Select"].ToString()=="QQ")
// { StrSql=StrSql+" where U_QQ='"+TextBox.Text.ToString()+"'";}
//
// if(Request.Form["Select"].ToString()=="Email")
// { StrSql=StrSql+" where U_Email like '%"+TextBox.Text.ToString()+"%'";}
//
// if(Request.Form["Select"].ToString()=="Telephone")
// { StrSql=StrSql+" where U_Telephone like '%"+TextBox.Text.ToString()+"%'";}
//
// if(Request.Form["Select"].ToString()=="Birthday")
// { StrSql=StrSql+" where U_Birthday='"+TextBox.Text.ToString()+"'";}
//
// if(Request.Form["Select"].ToString()=="Adimin")
// { StrSql=StrSql+" where U_IsAdimin='"+TextBox.Text.ToString()+"'";}
//
// if(Request.Form["Select"].ToString()=="RentCount")
// { StrSql=StrSql+" where U_RentCount='"+TextBox.Text.ToString()+"'";}
SqlDataAdapter Da = new SqlDataAdapter(StrSql, Conn);
DataSet Ds = new DataSet();
Da.Fill(Ds);
DataGrid_M_UserInfo.DataSource = Ds.Tables[0];
DataGrid_M_UserInfo.DataBind();
Conn.Close();
}
//取消
protected void Button_Blank_Click(object sender, EventArgs e)
{
TextBox_Name.Text = "";
TextBox_Pswd.Text = "";
TextBox_Email.Text = "";
TextBox_QQ.Text = "";
TextBox_Telephone.Text = "";
TextBox_Sex.Text = "";
TextBox_Birthday.Text = "";
TextBox_IsAdmine.Text = "";
TextBox_Tenancy.Text = "";
}
//修改
protected void Button_Modify_Click(object sender, EventArgs e)
{
string StrConn = "server=(local);database=e_library;uid=sa;pwd=";
SqlConnection Conn = new SqlConnection(StrConn);
Conn.Open();
string StrSql = "update User_Info set U_Name='" + TextBox_Name.Text.ToString() + "',U_Pswd='" + TextBox_Pswd.Text.ToString() + "',U_Email='" + TextBox_Email.Text.ToString() + "'," +
"U_Telephone='" + TextBox_Telephone.Text.ToString() + "',U_Dirthday='" + TextBox_Birthday.Text.ToString() + "',U_QQ='" + TextBox_QQ.Text.ToString() + "'," +
"U_Sex='" + TextBox_Sex.Text.ToString() + "', U_IsAdimin='" + TextBox_IsAdmine.Text + "', U_RentCount='" + TextBox_Tenancy.Text + "' where U_ID='" + TextBox_ID.Text + "'";
SqlCommand Comm = new SqlCommand(StrSql, Conn);
Comm.ExecuteNonQuery();
Conn.Close();
Response.Write("<script language='javascript'>alert('修改信息成功')</script>");
////清空
//TextBox_Name.Text = "";
//TextBox_ID.Text = "";
//TextBox_Pswd.Text = "";
//TextBox_Email.Text = "";
//TextBox_QQ.Text = "";
//TextBox_Telephone.Text = "";
//TextBox_Sex.Text = "";
//TextBox_Birthday.Text = "";
//TextBox_IsAdmine.Text = "";
//TextBox_Tenancy.Text = "";
}
//选择 把选中的数据绑定到表中相应字段
protected void DataGrid_M_UserInfo_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox_Name.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[2].Text;
TextBox_ID.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[3].Text;
TextBox_Pswd.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[4].Text;
TextBox_Email.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[6].Text;
TextBox_QQ.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[5].Text;
TextBox_Telephone.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[8].Text;
TextBox_Sex.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[7].Text;
TextBox_Birthday.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[9].Text;
TextBox_IsAdmine.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[10].Text;
TextBox_Tenancy.Text = this.DataGrid_M_UserInfo.SelectedItem.Cells[11].Text;
}
//取消
protected void DataGrid_M_UserInfo_CancelCommand1(object source, DataGridCommandEventArgs e)
{
//DataGrid_M_UserInfo.EditItemIndex = -1;
//DataGrid_M_UserInfo.DataBind();
}
//删除
protected void DataGrid_M_UserInfo_DeleteCommand1(object source, DataGridCommandEventArgs e)
{
//得到主键值
string UserID = DataGrid_M_UserInfo.DataKeys[e.Item.ItemIndex].ToString();
string StrSql = "delete from User_Info where U_ID='" + UserID + "'";
SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
Conn.Open();
SqlCommand Comm = new SqlCommand(StrSql, Conn);
Comm.ExecuteNonQuery();
Conn.Close();
Response.Write("<script language='javascript'>alert('删除信息成功!')</script>");
}
//编辑
protected void DataGrid_M_UserInfo_EditCommand(object source, DataGridCommandEventArgs e)
{
//DataGrid_M_UserInfo.EditItemIndex = e.Item.ItemIndex;
//DataGrid_M_UserInfo.DataBind();
}
//更新
protected void DataGrid_M_UserInfo_UpdateCommand1(object source, DataGridCommandEventArgs e)
{
//if (!Page.IsPostBack)
//{
// string UserID = DataGrid_M_UserInfo.DataKeys[e.Item.ItemIndex].ToString();
// string UName = ((TextBox)e.Item.Cells[2].Controls[0]).Text;
// string UPswd = ((TextBox)e.Item.Cells[4].Controls[0]).Text;
// string UQQ = ((TextBox)e.Item.Cells[5].Controls[0]).Text;
// string UEmail = ((TextBox)e.Item.Cells[6].Controls[0]).Text;
// string USex = ((TextBox)e.Item.Cells[7].Controls[0]).Text;
// string UTelephone = ((TextBox)e.Item.Cells[8].Controls[0]).Text;
// string UDirthday = ((TextBox)e.Item.Cells[9].Controls[0]).Text;
// int UIsAdimin = Convert.ToInt32(((TextBox)e.Item.Cells[11].Controls[0]).Text);
// int URentCount = Convert.ToInt32(((TextBox)e.Item.Cells[12].Controls[0]).Text);
// string StrSql = "update User_Info set U_Name='" + UName.ToString() + "',U_Pswd='" + UPswd.ToString() + "',U_QQ='" + UQQ.ToString() + "'" +
// ",U_Email='" + UEmail.ToString() + "',U_Sex='" + USex.ToString() + "',U_Telephone='" + UTelephone.ToString() + "'" +
// ",U_Dirthday='" + UDirthday.ToString() + "',U_IsAdimin=" + UIsAdimin + ",U_RentCount=" + URentCount + " where U_ID='" + UserID + "'";
// SqlConnection Conn = new SqlConnection("server=(local);database=e_library;uid=sa;pwd=");
// Conn.Open();
// SqlCommand Comm = new SqlCommand(StrSql, Conn);
// Comm.ExecuteNonQuery();
// Conn.Close();
// DataGrid_M_UserInfo.EditItemIndex = -1;
// DataGrid_M_UserInfo.DataBind();
// Response.Write("<script language='javascript'>alert('修改信息成功!')</script>");
//}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -