www.pudn.com > HttpProxy.rar > Login.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using HttpProxy.Component;
namespace HttpProxy.UI
{
///
/// Login 类
///
public class Login : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtName;
private System.Windows.Forms.TextBox txtPwd1;
private System.Windows.Forms.Label lblName;
private System.Windows.Forms.Label lblPwd1;
private System.Windows.Forms.Button btnOk;
private System.Windows.Forms.Button btnCancel;
///
/// 必需的设计器变量。
///
private System.ComponentModel.Container components = null;
public Login()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
///
/// 清理所有正在使用的资源。
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
///
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
///
private void InitializeComponent()
{
this.txtName = new System.Windows.Forms.TextBox();
this.txtPwd1 = new System.Windows.Forms.TextBox();
this.lblName = new System.Windows.Forms.Label();
this.lblPwd1 = new System.Windows.Forms.Label();
this.btnOk = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtName
//
this.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtName.Location = new System.Drawing.Point(112, 24);
this.txtName.MaxLength = 10;
this.txtName.Name = "txtName";
this.txtName.Size = new System.Drawing.Size(112, 21);
this.txtName.TabIndex = 5;
this.txtName.Text = "";
//
// txtPwd1
//
this.txtPwd1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.txtPwd1.Location = new System.Drawing.Point(112, 64);
this.txtPwd1.MaxLength = 10;
this.txtPwd1.Name = "txtPwd1";
this.txtPwd1.PasswordChar = '*';
this.txtPwd1.Size = new System.Drawing.Size(112, 21);
this.txtPwd1.TabIndex = 6;
this.txtPwd1.Text = "";
this.txtPwd1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtPwd1_KeyDown);
//
// lblName
//
this.lblName.Location = new System.Drawing.Point(32, 24);
this.lblName.Name = "lblName";
this.lblName.Size = new System.Drawing.Size(56, 24);
this.lblName.TabIndex = 3;
this.lblName.Text = "用户名:";
//
// lblPwd1
//
this.lblPwd1.Location = new System.Drawing.Point(32, 64);
this.lblPwd1.Name = "lblPwd1";
this.lblPwd1.Size = new System.Drawing.Size(56, 24);
this.lblPwd1.TabIndex = 4;
this.lblPwd1.Text = "密 码:";
//
// btnOk
//
this.btnOk.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnOk.Location = new System.Drawing.Point(56, 104);
this.btnOk.Name = "btnOk";
this.btnOk.Size = new System.Drawing.Size(64, 25);
this.btnOk.TabIndex = 7;
this.btnOk.Text = "登 录";
this.btnOk.Click += new System.EventHandler(this.btnOk_Click);
//
// btnCancel
//
this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnCancel.Location = new System.Drawing.Point(160, 104);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(64, 25);
this.btnCancel.TabIndex = 7;
this.btnCancel.Text = "取 消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// Login
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(274, 144);
this.ControlBox = false;
this.Controls.Add(this.btnOk);
this.Controls.Add(this.txtName);
this.Controls.Add(this.txtPwd1);
this.Controls.Add(this.lblName);
this.Controls.Add(this.lblPwd1);
this.Controls.Add(this.btnCancel);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
this.MaximizeBox = false;
this.Name = "Login";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统登录";
this.ResumeLayout(false);
}
#endregion
///
/// Handles the Click event of the btnCancel control.
///
/// The source of the event.
/// The instance containing the event data.
private void btnCancel_Click(object sender, System.EventArgs e)
{
this.Close();
}
///
/// Handles the Click event of the btnOk control.
///
/// The source of the event.
/// The instance containing the event data.
private void btnOk_Click(object sender, System.EventArgs e)
{
User user=new User();
if(this.txtName.Text.Trim().Length!=0 && this.txtPwd1.Text.Trim().Length!=0)
{
user.Retrieve(this.txtName.Text.Trim(),this.txtPwd1.Text.Trim());
if(user!=null && user.Id>0)
{
ProxyMain.LoginSucceed=true;
ProxyMain.ProxyUser=user;
ProxyMain.UserId=user.Id;
ProxyMain.UserName=user.Name;
this.Close();
}
else
MessageBox.Show("登录信息错误!","Proxy登录",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
else
{
MessageBox.Show("请完整登陆信息","Proxy登录",MessageBoxButtons.OK,MessageBoxIcon.Information);
}
}
///
/// Handles the KeyDown event of the txtPwd1 control.
///
/// The source of the event.
/// The instance containing the event data.
private void txtPwd1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
{
if(e.KeyCode==Keys.Enter)
this.btnOk.PerformClick();
}
}
}