📄 accountmodule.ascx.cs
字号:
namespace JdglWeb.Modules
{
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
/// <summary>
/// AccountModule 的摘要说明。
/// </summary>
public class AccountModule : ModuleBase
{
protected System.Web.UI.WebControls.Label CreateLabel;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator5;
protected System.Web.UI.WebControls.Label ShowMsg;
protected System.Web.UI.WebControls.TextBox NameTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator4;
protected System.Web.UI.WebControls.RadioButtonList GenderList;
protected System.Web.UI.WebControls.TextBox EmailTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator Requiredfieldvalidator5;
protected System.Web.UI.WebControls.RegularExpressionValidator RegularExpressionValidator1;
protected System.Web.UI.WebControls.TextBox AddrTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator6;
protected System.Web.UI.WebControls.TextBox PhoneTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator7;
protected System.Web.UI.WebControls.TextBox DepartmentTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator8;
protected System.Web.UI.WebControls.DropDownList TypeList;
protected System.Web.UI.WebControls.TextBox PasswordTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.CompareValidator CompareValidator1;
protected System.Web.UI.WebControls.TextBox ConfirmPasswordTextBox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator3;
protected System.Web.UI.WebControls.CompareValidator CompareValidator2;
protected System.Web.UI.WebControls.TextBox UserIdTextbox;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RegularExpressionValidator Regularexpressionvalidator2;
protected System.Web.UI.WebControls.CustomValidator IdUniqueCustomValidator;
protected System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
}
//验证编号是否已被注册
public void IsIdValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args){
//从文件Web.config中读取连接字符串
string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//连接JdglSys数据库
SqlConnection Conn= new SqlConnection (sqldb);
Conn.Open ();
//构造SQL语句,该语句在UsersInfo表中检查用户名是否已存在
string checksql= "select * from UsersInfo where UserId='"+UserIdTextbox.Text.Trim() +"'";
//创建Command对象
SqlCommand mycommand=new SqlCommand (checksql,Conn);
//执行ExecuteReader ()方法
SqlDataReader dr=mycommand.ExecuteReader ();
if(dr.Read ())
{
args.IsValid =false;//编号已被注册
}
else
{
args.IsValid =true;//编号尚未被注册
}
//关闭连接
Conn.Close();
}
public void ProcessChanges()
{
if(Page.IsValid){
//从文件Web.config中读取连接字符串
string sqldb= ConfigurationSettings.AppSettings["ConnectionString"];
//连接JdglSys数据库
SqlConnection Conn= new SqlConnection (sqldb);
Conn.Open ();
//利用Command对象调用存储过程
SqlCommand mycommand=new SqlCommand ("sp_InsertUser",Conn);
//将命令类型转为存储类型
mycommand.CommandType =CommandType.StoredProcedure ;
//往存储过程中添加参数
mycommand.Parameters .Add ("@Id",SqlDbType.Int);
mycommand.Parameters .Add ("@Name",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Pwd",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Gender",SqlDbType.Int);
mycommand.Parameters .Add ("@Email",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Address",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Telephone",SqlDbType.VarChar);
mycommand.Parameters .Add ("@Department",SqlDbType.VarChar );
mycommand.Parameters .Add ("@Type",SqlDbType.Int );
//给存储过程的参数赋值
mycommand.Parameters ["@Id"].Value =int.Parse(UserIdTextbox.Text.Trim());
mycommand.Parameters ["@Name"].Value =NameTextBox.Text.Trim();
mycommand.Parameters ["@Pwd"].Value =PasswordTextBox.Text.Trim();
mycommand.Parameters ["@Gender"].Value =GenderList.SelectedIndex;
mycommand.Parameters ["@Email"].Value =EmailTextBox.Text.Trim();
mycommand.Parameters ["@Address"].Value =AddrTextBox.Text.Trim();
mycommand.Parameters ["@Telephone"].Value =PhoneTextBox.Text.Trim();
mycommand.Parameters ["@Department"].Value =DepartmentTextBox.Text.Trim();
mycommand.Parameters ["@Type"].Value =TypeList.SelectedItem.Value;
try
{
mycommand.ExecuteNonQuery();
ShowMsg.Text="新员工注册成功";
ShowMsg.Style["color"]="green";}
catch(SqlException error)
{
ShowMsg.Text="注册未成功,请稍后再试。原因:"+error.Message;
ShowMsg.Style["color"]="red";
}
//关闭连接
Conn.Close();
}
}
#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -