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

📄 login.cs

📁 物业管理系统
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace WindowsApplication1
{
	/// <summary>
	/// login 的摘要说明。
	/// </summary>
	public class login : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Panel panel1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		public System.Windows.Forms.TextBox textBox1;
		public System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		public System.Windows.Forms.Button button3;
		public static bool flag=false;
		public static int i=0;
		private System.Windows.Forms.Label label3;

		
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public login()
		{
			//
		
			// 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()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(login));
			this.panel1 = new System.Windows.Forms.Panel();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.label3 = new System.Windows.Forms.Label();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// panel1
			// 
			this.panel1.BackColor = System.Drawing.Color.Transparent;
			this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
			this.panel1.Controls.Add(this.textBox2);
			this.panel1.Controls.Add(this.textBox1);
			this.panel1.Controls.Add(this.label2);
			this.panel1.Controls.Add(this.label1);
			this.panel1.Location = new System.Drawing.Point(24, 40);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(248, 112);
			this.panel1.TabIndex = 0;
			this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(80, 64);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.Size = new System.Drawing.Size(128, 21);
			this.textBox2.TabIndex = 3;
			this.textBox2.Text = "";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(80, 16);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(128, 21);
			this.textBox1.TabIndex = 2;
			this.textBox1.Text = "";
			this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label2.Location = new System.Drawing.Point(11, 60);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(74, 32);
			this.label2.TabIndex = 1;
			this.label2.Text = "密  码:";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("宋体", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.Location = new System.Drawing.Point(16, 18);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(63, 22);
			this.label1.TabIndex = 0;
			this.label1.Text = "用户名:";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// button1
			// 
			this.button1.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button1.BackgroundImage")));
			this.button1.Location = new System.Drawing.Point(32, 168);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 24);
			this.button1.TabIndex = 1;
			this.button1.Text = "登录";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.BackColor = System.Drawing.Color.Transparent;
			this.button2.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button2.BackgroundImage")));
			this.button2.Location = new System.Drawing.Point(120, 168);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(56, 24);
			this.button2.TabIndex = 2;
			this.button2.Text = "取消";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.BackColor = System.Drawing.Color.Transparent;
			this.button3.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("button3.BackgroundImage")));
			this.button3.Location = new System.Drawing.Point(216, 168);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(56, 24);
			this.button3.TabIndex = 3;
			this.button3.Text = "注册";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.BackColor = System.Drawing.Color.Transparent;
			this.label3.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.Location = new System.Drawing.Point(80, 8);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(151, 26);
			this.label3.TabIndex = 4;
			this.label3.Text = "用  户  登  录";
			// 
			// login
			// 
			this.AcceptButton = this.button1;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
			this.ClientSize = new System.Drawing.Size(296, 200);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.panel1);
			this.MaximizeBox = false;
			this.Name = "login";
			this.Text = "用户登录窗体";
			this.Load += new System.EventHandler(this.login_Load);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void button1_Click(object sender, System.EventArgs e)
		{
										OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Application.StartupPath + "\\xqwy.mdb");				conn.Open();				OleDbCommand cmd = new OleDbCommand("select * from user1", conn);
				OleDbDataReader myreader=cmd.ExecuteReader();
				while (myreader.Read())
				{
					if(myreader.GetString(0)==this.textBox1.Text)
					{
						flag=true;
						break;
					}
				}
				if(flag==false)
				{
					MessageBox.Show("不存在该用户名,请重新输入!");
					this.textBox1.Text="";
					this.textBox1.Focus();
					return;
				}
				else if(myreader.GetString(1)!=this.textBox2.Text)
				{
					MessageBox.Show("密码错误,请重新输入!");
					this.textBox2.Text="";
					this.textBox2.Focus();
					return;
				}
				else
				{
					main m=new main(this);
					m.Show();
					this.Hide();
				}
				conn.Close();
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void login_Load(object sender, System.EventArgs e)
		{
			i++;
			if(i==1)
			{
				this.button3.Enabled=false;
			}
			else
			{
				this.button3.Enabled=true;
			}
			}

		private void button3_Click(object sender, System.EventArgs e)
		{
			/*OleDbConnection conn1=new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data source=" + Application.StartupPath + "\\xqwy.mdb");
			conn1.Open();

			string sqlstr="select * from user1";

			OleDbDataAdapter da=new OleDbDataAdapter(sqlstr,conn1);

			DataSet ds =new DataSet();

			da.Fill(ds);
			DataTable dt=new DataTable();
			dt=ds.Tables[0];
			

			
			
			//DataTable dt=new DataTable(user1);
			
			DataRow dr=dt.NewRow();
			dr[0]=this.textBox1.Text;
			dr[1]=this.textBox2.Text;
			
			//dr.Item("Name")=this.textBox1.Text;
			//dr.Item("Passwd")=this.textBox2.Text;
			
			dt.Rows.Add(dr);

			OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);

			da.Update(dt);*/
			OleDbConnection conn1=new OleDbConnection(@"provider=Microsoft.jet.oledb.4.0;data source="+Application.StartupPath+ "\\xqwy.mdb");
			conn1.Open();
			OleDbDataAdapter da=new OleDbDataAdapter("select * from user1",conn1);
			DataSet ds=new DataSet();
			da.Fill(ds);
			DataTable dt=new DataTable();
			dt=ds.Tables[0];
			DataRow dr=dt.NewRow();
			dr[0]=this.textBox1.Text;
			dr[1]=this.textBox2.Text;
			dt.Rows.Add(dr);
			OleDbCommandBuilder cmdbld=new OleDbCommandBuilder(da);
			da.Update(dt);

		}

		private void panel1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
		
		}

		private void textBox1_TextChanged(object sender, System.EventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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