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

📄 loginform.cs

📁 关键词:.net Winform C# DataSource
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;

namespace DataServer
{
	/// <summary>
	/// LoginForm 的摘要说明。
	/// </summary>
	public class LoginForm : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btn_ok;
		private System.Windows.Forms.Button btn_close;
		private System.Windows.Forms.TextBox tb_login;
		private System.Windows.Forms.TextBox tb_passwd;
		private System.Windows.Forms.Label lb_login;
		private System.Windows.Forms.Label lb_passwd;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

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

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

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

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.btn_ok = new System.Windows.Forms.Button();
			this.btn_close = new System.Windows.Forms.Button();
			this.lb_login = new System.Windows.Forms.Label();
			this.lb_passwd = new System.Windows.Forms.Label();
			this.tb_login = new System.Windows.Forms.TextBox();
			this.tb_passwd = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// btn_ok
			// 
			this.btn_ok.Location = new System.Drawing.Point(48, 128);
			this.btn_ok.Name = "btn_ok";
			this.btn_ok.Size = new System.Drawing.Size(72, 24);
			this.btn_ok.TabIndex = 3;
			this.btn_ok.Text = "OK(&O)";
			this.btn_ok.Click += new System.EventHandler(this.btn_ok_Click);
			// 
			// btn_close
			// 
			this.btn_close.Location = new System.Drawing.Point(144, 128);
			this.btn_close.Name = "btn_close";
			this.btn_close.Size = new System.Drawing.Size(72, 24);
			this.btn_close.TabIndex = 4;
			this.btn_close.Text = "Close(&C)";
			this.btn_close.Click += new System.EventHandler(this.btn_close_Click);
			// 
			// lb_login
			// 
			this.lb_login.Location = new System.Drawing.Point(32, 32);
			this.lb_login.Name = "lb_login";
			this.lb_login.Size = new System.Drawing.Size(48, 16);
			this.lb_login.TabIndex = 2;
			this.lb_login.Text = "LogID:";
			// 
			// lb_passwd
			// 
			this.lb_passwd.Location = new System.Drawing.Point(32, 80);
			this.lb_passwd.Name = "lb_passwd";
			this.lb_passwd.Size = new System.Drawing.Size(48, 16);
			this.lb_passwd.TabIndex = 3;
			this.lb_passwd.Text = "PassWD:";
			// 
			// tb_login
			// 
			this.tb_login.Location = new System.Drawing.Point(80, 24);
			this.tb_login.Name = "tb_login";
			this.tb_login.Size = new System.Drawing.Size(152, 21);
			this.tb_login.TabIndex = 1;
			this.tb_login.Text = "0000";
			// 
			// tb_passwd
			// 
			this.tb_passwd.Location = new System.Drawing.Point(80, 72);
			this.tb_passwd.Name = "tb_passwd";
			this.tb_passwd.Size = new System.Drawing.Size(152, 21);
			this.tb_passwd.TabIndex = 2;
			this.tb_passwd.Text = "";
			// 
			// LoginForm
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(264, 165);
			this.Controls.Add(this.tb_passwd);
			this.Controls.Add(this.tb_login);
			this.Controls.Add(this.lb_passwd);
			this.Controls.Add(this.lb_login);
			this.Controls.Add(this.btn_close);
			this.Controls.Add(this.btn_ok);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "LoginForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "LoginForm";
			this.Load += new System.EventHandler(this.LoginForm_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void btn_ok_Click(object sender, System.EventArgs e)
		{
			string strSql ="select * from code_operator where oper_code = @oper_code and pwd = @pwd";
			SqlCommand command = new SqlCommand(strSql,DBConnect.Instance().cn);
			command.Parameters.Add("@oper_code",SqlDbType.VarChar ,20) ;
			command.Parameters["@oper_code"].Value = tb_login.Text ;
			command.Parameters.Add("@pwd",SqlDbType.VarChar ,20) ;
			command.Parameters["@pwd"].Value = tb_passwd.Text ;
			SqlDataAdapter sda = new SqlDataAdapter(command) ;
			try
			{
				DataSet dsUser = new DataSet() ;
				sda.Fill(dsUser) ;
				if (dsUser.Tables[0].Rows.Count == 0)
				{
					MessageBox.Show("用户名或密码出错!");
					return;
				}
			}
			catch(Exception)
			{
				MessageBox.Show("系统登陆出错!");
				return;
			}

			DialogResult = DialogResult.OK;
			return;
		}

		private void btn_close_Click(object sender, System.EventArgs e)
		{
			DialogResult = DialogResult.Cancel;
			return;
		}
		private void LoginForm_Load(object sender, System.EventArgs e)
		{
		}
	}
}

⌨️ 快捷键说明

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