using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
namespace Jh.UserControls
{
public delegate void PasswordInEvent(object sender,PasswordInArgs e);
/// <summary>
/// PasswordIn 的摘要说明。
/// </summary>
public class PasswordIn : System.Windows.Forms.UserControl
{
/// <summary>
/// 输入完成事件
/// </summary>
public event PasswordInEvent OnAllInput;
/// <summary>
/// 输入完成事件
/// </summary>
public event PasswordInEvent OnOldInput;
/// <summary>
/// 输入完成事件
/// </summary>
public event PasswordInEvent OnNewInput;
/// <summary>
/// 输入完成事件
/// </summary>
public event PasswordInEvent OnNewConfirmInput;
public System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbOld;
public System.Windows.Forms.Label label2;
public System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tbNew2;
private System.Windows.Forms.TextBox tbNew1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public PasswordIn()
{
// 该调用是 Windows.Forms 窗体设计器所必需的。
InitializeComponent();
// TODO: 在 InitializeComponent 调用后添加任何初始化
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器
/// 修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.tbOld = new System.Windows.Forms.TextBox();
this.tbNew1 = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.tbNew2 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(4, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(66, 23);
this.label1.TabIndex = 0;
this.label1.Text = "旧密码 :";
//
// tbOld
//
this.tbOld.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbOld.Location = new System.Drawing.Point(80, 11);
this.tbOld.Name = "tbOld";
this.tbOld.PasswordChar = '*';
this.tbOld.Size = new System.Drawing.Size(159, 23);
this.tbOld.TabIndex = 1;
this.tbOld.Text = "";
this.tbOld.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbOld_KeyPress);
this.tbOld.Enter += new System.EventHandler(this.tbOld_Enter);
//
// tbNew1
//
this.tbNew1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbNew1.Location = new System.Drawing.Point(80, 41);
this.tbNew1.Name = "tbNew1";
this.tbNew1.PasswordChar = '*';
this.tbNew1.Size = new System.Drawing.Size(159, 23);
this.tbNew1.TabIndex = 3;
this.tbNew1.Text = "";
this.tbNew1.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbNew1_KeyPress);
this.tbNew1.Enter += new System.EventHandler(this.tbNew1_Enter);
//
// label2
//
this.label2.Location = new System.Drawing.Point(5, 44);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(66, 23);
this.label2.TabIndex = 2;
this.label2.Text = "新密码:";
//
// tbNew2
//
this.tbNew2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.tbNew2.Location = new System.Drawing.Point(80, 71);
this.tbNew2.Name = "tbNew2";
this.tbNew2.PasswordChar = '*';
this.tbNew2.Size = new System.Drawing.Size(159, 23);
this.tbNew2.TabIndex = 5;
this.tbNew2.Text = "";
this.tbNew2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.tbNew2_KeyPress);
this.tbNew2.Enter += new System.EventHandler(this.tbNew2_Enter);
//
// label3
//
this.label3.Location = new System.Drawing.Point(5, 73);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(77, 23);
this.label3.TabIndex = 4;
this.label3.Text = "确认密码:";
//
// PasswordIn
//
this.Controls.Add(this.tbNew2);
this.Controls.Add(this.label3);
this.Controls.Add(this.tbNew1);
this.Controls.Add(this.label2);
this.Controls.Add(this.tbOld);
this.Controls.Add(this.label1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "PasswordIn";
this.Size = new System.Drawing.Size(244, 101);
this.ResumeLayout(false);
}
#endregion
private void tbOld_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 0x0d)
{
tbNew1.Focus();
if (OnOldInput != null)
{
OnOldInput(this,new PasswordInArgs(this.OldPassword,this.NewPassword,this.NewPasswordConfirm));
}
}
}
private void tbNew1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 0x0d)
{
tbNew2.Focus();
if (OnNewInput != null)
{
OnNewInput(this,new PasswordInArgs(this.OldPassword,this.NewPassword,this.NewPasswordConfirm));
}
}
}
private void tbNew2_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (e.KeyChar == 0x0d)
{
tbOld.Focus();
if (OnNewConfirmInput != null)
{
OnNewConfirmInput(this,new PasswordInArgs(this.OldPassword,this.NewPassword,this.NewPasswordConfirm));
}
if (OnAllInput != null)
{
OnAllInput(this,new PasswordInArgs(tbOld.Text,tbNew1.Text,tbNew2.Text));
}
}
}
private void tbOld_Enter(object sender, System.EventArgs e)
{
tbOld.SelectAll();
}
private void tbNew1_Enter(object sender, System.EventArgs e)
{
tbNew1.SelectAll();
}
private void tbNew2_Enter(object sender, System.EventArgs e)
{
tbNew2.SelectAll();
}
/// <summary>
/// 旧密码
/// </summary>
public string OldPassword
{
get
{
return tbOld.Text;
}
}
/// <summary>
/// 新密码
/// </summary>
public string NewPassword
{
get
{
return tbNew1.Text;
}
}
/// <summary>
/// 新密码确认
/// </summary>
public string NewPasswordConfirm
{
get
{
return tbNew2.Text;
}
}
/// <summary>
/// 输入控件枚举
/// </summary>
public enum PasswordInTextBoxs
{
Old,
New,
NewConfirm
}
/// <summary>
/// 设置输入焦点
/// </summary>
/// <param name="tb">输入控件枚举</param>
public void SetFocus(PasswordInTextBoxs tb)
{
if (tb == PasswordInTextBoxs.Old)
{
tbOld.Focus();
}
if (tb == PasswordInTextBoxs.New)
{
tbNew1.Focus();
}
if (tb == PasswordInTextBoxs.NewConfirm)
{
tbNew2.Focus();
}
}
/// <summary>
/// 密码掩码
/// </summary>
public char PasswordChar
{
get
{
return tbOld.PasswordChar;
}
set
{
tbOld.PasswordChar = value;
tbNew1.PasswordChar = value;
tbNew2.PasswordChar = value;
}
}
}
/// <summary>
/// 传输事件处理类
/// </summary>
public class PasswordInArgs : EventArgs
{
public PasswordInArgs(string old,string new1,string new2) : base()
{
OldPassword = old;
NewPassword = new1;
NewPasswordConfirm = new2;
}
string oldPassword;
/// <summary>
/// 旧密码
/// </summary>
public string OldPassword
{
get
{
return oldPassword;
}
set
{
oldPassword = value;
}
}
string newPassword;
/// <summary>
/// 新密码
/// </summary>
public string NewPassword
{
get
{
return newPassword;
}
set
{
newPassword = value;
}
}
string newPasswordConfirm;
/// <summary>
/// 新密码确认
/// </summary>
public string NewPasswordConfirm
{
get
{
return newPasswordConfirm;
}
set
{
newPasswordConfirm = value;
}
}
}
}
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Drawing.Imaging;
using Jh.UserControls;
namespace Jh.UtilForms
{
/// <summary>
/// 登录窗口
/// </summary>
public class JhLogin : BmpWnd
{
private Jh.UserControls.JhLogon jhLogon1;
private Jh.UserControls.BmpLabel bmpLabel3;
private Jh.UserControls.BmpLabel bmpLabel1;
private Jh.UserControls.BmpLabel bmpLabel2;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
/// <summary>
/// 开始传输事件
/// </summary>
public event PasswordInEvent OnLogin;
/// <summary>
/// 数字ID标志
/// </summary>
bool numericID = true;
/// <summary>
/// 数字ID标志
/// </summary>
public bool NumericID
{
get
{
return numericID;
}
set
{
numericID = value;
}
}
public JhLogin()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
jhLogon1.OnInput += new Jh.UserControls.PasswordInEvent(OnInput);
}
/// <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(JhLogin));
this.jhLogon1 = new Jh.UserControls.JhLogon();
this.bmpLabel3 = new Jh.UserControls.BmpLabel();
this.bmpLabel1 = new Jh.UserControls.BmpLabel();
this.bmpLabel2 = new Jh.UserControls.BmpLabel();
this.SuspendLayout();
//
// jhLogon1
//
this.jhLogon1.BackColor = System.Drawing.SystemColors.Control;
this.jhLogon1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("jhLogon1.BackgroundImage")));
this.jhLogon1.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.jhLogon1.Location = new System.Drawing.Point(128, 261);
this.jhLogon1.Name = "jhLogon1";
this.jhLogon1.Size = new System.Drawing.Size(140, 63);
this.jhLogon1.TabIndex = 0;
//
// bmpLabel3
//
this.bmpLabel3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("bmpLabel3.BackgroundImage")));
this.bmpLabel3.Location = new System.Drawing.Point(114, 60);
this.bmpLabel3.Name = "bmpLabel3";
this.bmpLabel3.Size = new System.Drawing.Size(140, 54);
this.bmpLabel3.TabIndex = 3;
//
// bmpLabel1
//
this.bmpLabel1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("bmpLabel1.BackgroundImage")));
this.bmpLabel1.Location = new System.Drawing.Point(33, 264);
this.bmpLabel1.Name = "bmpLabel1";
this.bmpLabel1.Size = new System.Drawing.Size(61, 23);
this.bmpLabel1.TabIndex = 4;
//
// bmpLabel2
//
this.bmpLabel2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("bmpLabel2.BackgroundImage")));
this.bmpLabel2.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.bmpLabel2.Location = new System.Drawing.Point(28, 294);
this.bmpLabel2.Name = "bmpLabel2";
this.bmpLabel2.Size = new System.Drawing.Size(107, 23);
this.bmpLabel2.TabIndex = 5;
//
// JhLogin
//
this.AutoScaleBaseSize = new System.Drawing.Size(7, 16);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(383, 386);
this.Controls.Add(this.bmpLabel2);
this.Controls.Add(this.bmpLabel1);
this.Controls.Add(this.bmpLabel3);
this.Controls.Add(this.jhLogon1);
this.Font = new System.Drawing.Font("宋体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.Name = "JhLogin";
this.ResumeLayout(false);
}
#endregion
private bool OnInput(object sender, PasswordInArgs e)
{
if (e.OldPassword == "")
{
MessageBox.Show("ID can not be empty!");
this.jhLogon1.Focus();
return false;
}
if (NumericID == true )
{
string s = "0000000000000000" + int.Parse(e.OldPassword).ToString();
s = s.Substring(s.Length - e.OldPassword.Length);
if (s != e.OldPassword)
{
MessageBox.Show("ID must be composed by 0-9!");
this.jhLogon1.Focus();
return false;
}
}
if (e.NewPassword == "")
{
MessageBox.Show("Password can not be empty!");
this.jhLogon1.Focus();
return false;
}
if (OnLogin != null)
{
OnLogin(this,e);
}
this.DialogResult = DialogResult.OK;
Close();
return true;
}
}
}