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

📄 form2.cs

📁 只做了一部分,希望以后能向各位高手学习,好学就是我咯!
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data ;using System.Data.SqlClient ;

using drawmenu;
using System.Net;
namespace lzl061111152357good5
{
	/// <summary>
	/// Form2 的摘要说明。
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.ErrorProvider errorProvider1;
		DialogResult result;
		private System.Windows.Forms.PictureBox pictureBox1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.PictureBox pictureBox2;
		private System.ComponentModel.IContainer components;

		public string text;

		public Form2()
		{
			//
			// 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form2));
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			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.errorProvider1 = new System.Windows.Forms.ErrorProvider();
			this.pictureBox1 = new System.Windows.Forms.PictureBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.pictureBox2 = new System.Windows.Forms.PictureBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// textBox2
			// 
			this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox2.Location = new System.Drawing.Point(8, 88);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.Size = new System.Drawing.Size(160, 21);
			this.textBox2.TabIndex = 4;
			this.textBox2.Text = "";
			this.textBox2.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// textBox1
			// 
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox1.Location = new System.Drawing.Point(8, 40);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(160, 21);
			this.textBox1.TabIndex = 3;
			this.textBox1.Text = "";
			this.textBox1.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(176, 16);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 16);
			this.label3.TabIndex = 2;
			this.label3.Text = "lzlgood5";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.Image = ((System.Drawing.Image)(resources.GetObject("label2.Image")));
			this.label2.Location = new System.Drawing.Point(48, 72);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(80, 16);
			this.label2.TabIndex = 1;
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.Image = ((System.Drawing.Image)(resources.GetObject("label1.Image")));
			this.label1.Location = new System.Drawing.Point(48, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(80, 16);
			this.label1.TabIndex = 0;
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// button1
			// 
			this.button1.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button1.Location = new System.Drawing.Point(8, 16);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 24);
			this.button1.TabIndex = 5;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
			this.button2.Location = new System.Drawing.Point(8, 48);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(56, 24);
			this.button2.TabIndex = 6;
			this.button2.Text = "退出";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// errorProvider1
			// 
			this.errorProvider1.ContainerControl = this;
			// 
			// pictureBox1
			// 
			this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
			this.pictureBox1.Location = new System.Drawing.Point(16, 24);
			this.pictureBox1.Name = "pictureBox1";
			this.pictureBox1.Size = new System.Drawing.Size(240, 96);
			this.pictureBox1.TabIndex = 1;
			this.pictureBox1.TabStop = false;
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.groupBox2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.textBox2);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(176, 120);
			this.groupBox1.TabIndex = 7;
			this.groupBox1.TabStop = false;
			this.groupBox1.Visible = false;
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.button1);
			this.groupBox2.Controls.Add(this.button2);
			this.groupBox2.Location = new System.Drawing.Point(176, 32);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(72, 80);
			this.groupBox2.TabIndex = 5;
			this.groupBox2.TabStop = false;
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// pictureBox2
			// 
			this.pictureBox2.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox2.Image")));
			this.pictureBox2.Location = new System.Drawing.Point(184, 24);
			this.pictureBox2.Name = "pictureBox2";
			this.pictureBox2.Size = new System.Drawing.Size(88, 96);
			this.pictureBox2.TabIndex = 8;
			this.pictureBox2.TabStop = false;
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(274, 136);
			this.Controls.Add(this.pictureBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.pictureBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Name = "Form2";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "登陆界面";
			this.Load += new System.EventHandler(this.Form2_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		String userpws;
		String userid;

		private void Form2_Load(object sender, System.EventArgs e)
		{
			pictureBox2.Visible=false;
			timer1.Interval=800;
			timer1.Start();
			/*SqlConnection conn=new SqlConnection();
			conn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=enter;Data Source=USER-11E41ED98B;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=USER-11E41ED98B;Use Encryption for Data=False;Tag with column collation when possible=False";
			conn.Open();*/
		}
		private void button1_Click(object sender, System.EventArgs e)
		{
			userpws=textBox2.Text.Trim();
			userid=textBox1.Text.Trim();
			string SelectCom="select * from enter where id='"+userid+"' and passwd='"+userpws+"'";
			searchall a=new searchall();
            string ConStr=a.connstr;
			//string ConStr="Data Source=172.17.88.6;Initial Catalog=enter;password=lzl520;User id=linzling;";
			SqlConnection myConn=new SqlConnection(ConStr); 
			SqlDataReader myReader;       
			SqlCommand myCom; 
			myCom=new SqlCommand(SelectCom,myConn); 
			myConn.Open(); 
			myReader=myCom.ExecuteReader(); 
			if(textBox1.Text==""&&textBox2.Text=="")
			{
				this.errorProvider1.SetError(this.label1,"对不起,无法识别!!!");
				this.errorProvider1.SetError(this.label2,"对不起,无法识别!!!");
				result=MessageBox.Show(this,"输入错误!","错误提示",
					MessageBoxButtons.RetryCancel,MessageBoxIcon.Question);
			}
			else if(textBox1.Text=="")
			{
				this.errorProvider1.SetError(this.label1,"用户名字不能为空!");
				result=MessageBox.Show(this,"用户名字输入错误","错误提示",
					MessageBoxButtons.RetryCancel,MessageBoxIcon.Information); 
			}
			else if(textBox2.Text=="")
			{ 
				this.errorProvider1.SetError(this.label2,"用户密码不能为空!");
				result=MessageBox.Show(this,"用户密码输入错误","错误提示",
					MessageBoxButtons.RetryCancel,MessageBoxIcon.Information); 
			} 
			else
			{
				if(myReader.Read()) 
				{   
					//引用类库
                   //drawmenu.DataConn dc =new drawmenu.DataConn();
					//引用类库




					//获取主机名称
					string HostName=Dns.GetHostName();
					string d=System.DateTime.Now.ToString();
					//获取本机IP地址
					IPHostEntry MyEntry=Dns.GetHostByName(Dns.GetHostName());
					IPAddress MyAddress=new IPAddress(MyEntry.AddressList[0].Address);
		            searchall upd=new searchall();
					upd.change1("UPDATE enter SET ip='"+MyAddress.ToString()+" 'WHERE lzl='linzling '","enter");
					upd.change1("UPDATE enter SET comp='"+HostName+" 'WHERE lzl='linzling '","enter");
					upd.change1("UPDATE enter SET dtime='"+d+" 'WHERE lzl='linzling '","enter");
			
					upd.change1("update enter set times=times+1 where id='"+userid+"'","enter");
					upd.change1("update enter set user_type=(select name  from enter where id='"+userid+"'),times=times+1 where lzl='linzling'","enter");
					upd.change1("update enter set name=(select user_type  from enter where id='"+userid+"')where lzl='linzling'","enter");

					this.Hide();
					Form aaa=new Form3();
					aaa.Show(); 
				} 
				else
				{
					this.errorProvider1.SetError(this.label1,"用户名字错误!");
					this.errorProvider1.SetError(this.label2,"用户密码错误!");
					result=MessageBox.Show(this,"用户名字或用户密码错误!!!","错误提示",
						MessageBoxButtons.RetryCancel,MessageBoxIcon.Error);
					textBox1.Text="";
					textBox2.Text="";
				}
			}
			myConn.Close(); 
			myReader.Close();
			switch(result)
			{
				case DialogResult.Retry:
					this.textBox1.Text="";
					this.textBox2.Text="";
					this.errorProvider1.Dispose();
					break;
				case DialogResult.Cancel:
					this.Close();
					break;				
			}

		}

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

		private void timer1_Tick(object sender, System.EventArgs e)
		{
			pictureBox1.Visible=false;
			pictureBox2.Visible=true;
			groupBox1.Visible=true;
			if(textBox1.Text.Length>0||textBox2.Text.Length>0)
			{
				//this.Size = new System.Drawing.Size(280, 168);
				pictureBox2.Visible=false;
				this.groupBox1.Size = new System.Drawing.Size(256, 120);
				groupBox2.Visible=true;
			}
			else
			{
				//this.Size="200, 168";
				pictureBox2.Visible=true;
				this.groupBox1.Size = new System.Drawing.Size(176, 120);
				groupBox2.Visible=false;
			}
               
		}
	}
}

⌨️ 快捷键说明

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