📄 frmuser.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace OES
{
/// <summary>
/// Summary description for frmUser.
/// </summary>
public class frmUser : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnSave;
private System.Windows.Forms.Label lblUsername;
private System.Windows.Forms.TextBox txtUsername;
private System.Windows.Forms.Label lblPassword;
private System.Windows.Forms.TextBox txtPassword;
private System.Windows.Forms.Label lblConfirmPwd;
private System.Windows.Forms.TextBox txtConfirmPwd;
private System.Windows.Forms.Label lblCreateUser;
private System.Windows.Forms.GroupBox grpPersonalDetails;
private System.Windows.Forms.GroupBox grpStatus;
private System.Windows.Forms.RadioButton radInactive;
private System.Windows.Forms.RadioButton radActive;
private System.Windows.Forms.GroupBox grpGender;
private System.Windows.Forms.RadioButton radFemale;
private System.Windows.Forms.RadioButton radMale;
private System.Windows.Forms.TextBox txtEmail;
private System.Windows.Forms.Label lblEmail;
private System.Windows.Forms.TextBox txtPhone;
private System.Windows.Forms.Label lblPhone;
public System.Windows.Forms.ComboBox cboUserType;
private System.Windows.Forms.Label lblUserType;
private System.Windows.Forms.Button btnHelp;
private System.Windows.Forms.TextBox txtAddress;
private System.Windows.Forms.Label lblAddress;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.TextBox txtName;
//error message variable for validation
private string errorMsg;
//variable for validation
private bool allValidated=true;
private static int count=0;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public static DataTable dtUpdate;
private static int index=0;
private int localflag=0;
private frmUserSearch objUserSearch;
//private static DataTable dtUser;
private DataTable dtUserTable;
private bool status, gender;
private System.Windows.Forms.ErrorProvider errUser;
private System.Windows.Forms.Button btnCancel;
//记录要修改的行
private DataRow drBefore;
//记录最初表的数据
private DataTable dtIniTable;
//数据即将被修改的表
private DataTable tdModifTable;
//定义要修改数据的行号
int intModifRowNumber;
public frmUser(int flag,object user)
{
//CreateTable();
localflag = flag;
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// 获取要修改的整个表,然后根据要修改的行号,显示要修改的相应数据
/// </summary>
/// <param name="flag" >标识</param>
/// <param name="user" >用户</param>
/// <param name="intModifRow" >要修改的行号</param>
/// <param name="tbModyTable" >用户列表</param>
public frmUser(int flag,object user,int intModifRow,DataTable tbModyTable)
{
localflag = flag;
//记录要修改的行号
this.intModifRowNumber =intModifRow;
//记录修改之前的行的数据
drBefore=tbModyTable.NewRow ();
drBefore[1]="a";
this.CopyRow (tbModyTable.Rows[intModifRow],drBefore);
//记录要修改的表
this.dtIniTable =tbModyTable;
//数据即将被修改的表
tdModifTable=tbModyTable;
// 初始化窗体
InitializeComponent();
if(localflag == 3)//确定用户的管理员身份
{
this.btnSave.Enabled=true;
this.objUserSearch = (frmUserSearch)user;
this.lblCreateUser.Font = new System.Drawing.Font("Century Gothic", 21.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblCreateUser.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(192)), ((System.Byte)(192)), ((System.Byte)(255)));
this.lblCreateUser.Location = new System.Drawing.Point(144, 8);
lblCreateUser.Text="修 改 用 户";
this.btnSave.Text = "确认(&O)";
this.lblConfirmPwd .Visible =false;
this.txtConfirmPwd.Visible =false;
this.txtUsername.ReadOnly = true;
//以下显示将要修改行的数据显示到相应的输入框
this.txtUsername.Text = tdModifTable.Rows[intModifRow][0].ToString();
this.txtName.Text = tdModifTable.Rows[intModifRow][1].ToString ();
this.txtPassword.Text = tdModifTable.Rows[intModifRow][2].ToString ();
if (Convert.ToBoolean(tdModifTable.Rows[intModifRow][3]))
{
this.radActive.Checked=true ;
}
else
{
this.radInactive.Checked = true;
}
this.cboUserType.Text = tdModifTable.Rows[intModifRow][4].ToString() ;
if (Convert.ToBoolean (tdModifTable.Rows[intModifRow][5]))
{
this.radMale.Checked = true;
}
else
{
this.radFemale.Checked = true;
}
this.txtAddress.Text = tdModifTable.Rows[intModifRow][6].ToString();
this.txtEmail.Text = tdModifTable.Rows[intModifRow][7].ToString();
this.txtPhone.Text = tdModifTable.Rows[intModifRow][8].ToString();
}
else
{
MessageBox.Show ("您不是管理员,没有修改用户的权力!");
}
}
//拷贝第一行的数据到第二行
private DataRow CopyRow(DataRow drBef,DataRow drAft)
{
for(int colIndex=0;colIndex<drBef.ItemArray .Length ;colIndex++)
{
drAft[colIndex]=drBef[colIndex];
}
return drAft;
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmUser));
this.lblUsername = new System.Windows.Forms.Label();
this.txtUsername = new System.Windows.Forms.TextBox();
this.lblPassword = new System.Windows.Forms.Label();
this.txtPassword = new System.Windows.Forms.TextBox();
this.lblConfirmPwd = new System.Windows.Forms.Label();
this.txtConfirmPwd = new System.Windows.Forms.TextBox();
this.lblCreateUser = new System.Windows.Forms.Label();
this.btnSave = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.grpPersonalDetails = new System.Windows.Forms.GroupBox();
this.grpStatus = new System.Windows.Forms.GroupBox();
this.radInactive = new System.Windows.Forms.RadioButton();
this.radActive = new System.Windows.Forms.RadioButton();
this.grpGender = new System.Windows.Forms.GroupBox();
this.radFemale = new System.Windows.Forms.RadioButton();
this.radMale = new System.Windows.Forms.RadioButton();
this.txtEmail = new System.Windows.Forms.TextBox();
this.lblEmail = new System.Windows.Forms.Label();
this.txtPhone = new System.Windows.Forms.TextBox();
this.lblPhone = new System.Windows.Forms.Label();
this.txtAddress = new System.Windows.Forms.TextBox();
this.lblAddress = new System.Windows.Forms.Label();
this.txtName = new System.Windows.Forms.TextBox();
this.lblName = new System.Windows.Forms.Label();
this.cboUserType = new System.Windows.Forms.ComboBox();
this.lblUserType = new System.Windows.Forms.Label();
this.btnHelp = new System.Windows.Forms.Button();
this.errUser = new System.Windows.Forms.ErrorProvider();
this.grpPersonalDetails.SuspendLayout();
this.grpStatus.SuspendLayout();
this.grpGender.SuspendLayout();
this.SuspendLayout();
//
// lblUsername
//
this.lblUsername.AutoSize = true;
this.lblUsername.BackColor = System.Drawing.Color.Transparent;
this.lblUsername.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblUsername.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblUsername.Location = new System.Drawing.Point(173, 112);
this.lblUsername.Name = "lblUsername";
this.lblUsername.Size = new System.Drawing.Size(45, 18);
this.lblUsername.TabIndex = 0;
this.lblUsername.Text = "用户名";
//
// txtUsername
//
this.txtUsername.BackColor = System.Drawing.SystemColors.Info;
this.txtUsername.Font = new System.Drawing.Font("Times New Roman", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.txtUsername.Location = new System.Drawing.Point(269, 112);
this.txtUsername.Name = "txtUsername";
this.txtUsername.Size = new System.Drawing.Size(163, 20);
this.txtUsername.TabIndex = 1;
this.txtUsername.Text = "";
this.txtUsername.Leave += new System.EventHandler(this.txtUsername_Leave);
//
// lblPassword
//
this.lblPassword.AutoSize = true;
this.lblPassword.BackColor = System.Drawing.Color.Transparent;
this.lblPassword.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblPassword.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblPassword.Location = new System.Drawing.Point(451, 112);
this.lblPassword.Name = "lblPassword";
this.lblPassword.Size = new System.Drawing.Size(32, 18);
this.lblPassword.TabIndex = 2;
this.lblPassword.Text = "密码";
//
// txtPassword
//
this.txtPassword.BackColor = System.Drawing.SystemColors.Info;
this.txtPassword.Location = new System.Drawing.Point(595, 112);
this.txtPassword.Name = "txtPassword";
this.txtPassword.PasswordChar = '*';
this.txtPassword.Size = new System.Drawing.Size(163, 21);
this.txtPassword.TabIndex = 3;
this.txtPassword.Text = "";
this.txtPassword.Leave += new System.EventHandler(this.txtPassword_Leave);
//
// lblConfirmPwd
//
this.lblConfirmPwd.AutoSize = true;
this.lblConfirmPwd.BackColor = System.Drawing.Color.Transparent;
this.lblConfirmPwd.Font = new System.Drawing.Font("Century Gothic", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.lblConfirmPwd.ForeColor = System.Drawing.SystemColors.ActiveCaptionText;
this.lblConfirmPwd.Location = new System.Drawing.Point(451, 146);
this.lblConfirmPwd.Name = "lblConfirmPwd";
this.lblConfirmPwd.Size = new System.Drawing.Size(59, 18);
this.lblConfirmPwd.TabIndex = 4;
this.lblConfirmPwd.Text = "确认密码";
//
// txtConfirmPwd
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -