⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 logonform.cs

📁 wince开发的订购系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Reflection;

namespace Book_Admin
{
	/// <summary>
	/// LogonForm 的摘要说明。
	/// </summary>
	public class LogonForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button btnCancel;
		private System.Windows.Forms.TextBox txtUsername;
		private System.Windows.Forms.TextBox txtPassword;
		private System.Windows.Forms.Button btnLogon;

		private System.Data.DataSet dsAdmins;
		private System.Data.DataTable dtAdmins;

		public string Username
		{
			get
			{
				return txtUsername.Text;
			}
		}

		public LogonForm()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.txtUsername = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtPassword = new System.Windows.Forms.TextBox();
			this.btnLogon = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			// 
			// txtUsername
			// 
			this.txtUsername.Location = new System.Drawing.Point(80, 8);
			this.txtUsername.Size = new System.Drawing.Size(120, 21);
			this.txtUsername.Text = "";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 8);
			this.label1.Size = new System.Drawing.Size(48, 16);
			this.label1.Text = "用户名";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 40);
			this.label2.Size = new System.Drawing.Size(48, 16);
			this.label2.Text = "密  码";
			// 
			// txtPassword
			// 
			this.txtPassword.Location = new System.Drawing.Point(80, 40);
			this.txtPassword.PasswordChar = '*';
			this.txtPassword.Size = new System.Drawing.Size(120, 21);
			this.txtPassword.Text = "";
			// 
			// btnLogon
			// 
			this.btnLogon.Location = new System.Drawing.Point(32, 72);
			this.btnLogon.Size = new System.Drawing.Size(64, 24);
			this.btnLogon.Text = "登录";
			this.btnLogon.Click += new System.EventHandler(this.btnLogon_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.Location = new System.Drawing.Point(128, 72);
			this.btnCancel.Size = new System.Drawing.Size(64, 24);
			this.btnCancel.Text = "取消";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
			// 
			// LogonForm
			// 
			this.BackColor = System.Drawing.Color.Silver;
			this.ClientSize = new System.Drawing.Size(218, 103);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnLogon);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.txtPassword);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtUsername);
			this.Location = new System.Drawing.Point(12, 50);
			this.Text = "登录";
			this.Load += new System.EventHandler(this.LogonForm_Load);

		}
		#endregion

		private bool CheckUser(string username)
		{
			return dtAdmins.Rows.Find(username) != null;
		}

		private bool CheckPassword(string username,string password)
		{
            DataRow row = dtAdmins.Rows.Find(username);
			if(row ==  null) return false;
			return row["password"].ToString() == password;
		}

		private void LogonForm_Load(object sender, System.EventArgs e)
		{
			string path = Assembly.GetExecutingAssembly().GetName().CodeBase;
			dsAdmins = new DataSet();
			dsAdmins.ReadXml(new FileInfo(path).DirectoryName + @"\" + "administrators.xml");
			dtAdmins = dsAdmins.Tables[0];

			DataColumn[] pkey = new DataColumn[1];
			pkey[0] = dtAdmins.Columns["username"];
			dtAdmins.PrimaryKey = pkey;
		}

		private void btnLogon_Click(object sender, System.EventArgs e)
		{
			if (!CheckUser(txtUsername.Text))
			{
				MessageBox.Show("用户名不存在,请重新输入。","登录错误");
			}
			else if (!CheckPassword(txtUsername.Text, txtPassword.Text))
			{
				MessageBox.Show("口令不正确,请重新输入。","登录错误");
			}
			else
				this.DialogResult = DialogResult.OK;
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			this.DialogResult = DialogResult.Cancel;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -