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

📄 form2.cs

📁 利用Visual C#建立一个数据库
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
namespace 图书系统设计
{
	/// <summary>
	/// Form2 的摘要说明。
	/// </summary>
	public class Form2 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button6;
		public string aaa="aaa";
		public string bbb="bbb";
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		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.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button4 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(64, 184);
			this.button1.Name = "button1";
			this.button1.TabIndex = 0;
			this.button1.Text = "插入数据";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(64, 224);
			this.button2.Name = "button2";
			this.button2.TabIndex = 1;
			this.button2.Text = "删除数据";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(224, 184);
			this.button3.Name = "button3";
			this.button3.TabIndex = 2;
			this.button3.Text = "更新数据";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(224, 224);
			this.button4.Name = "button4";
			this.button4.TabIndex = 3;
			this.button4.Text = "关闭";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.button5);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(160, 160);
			this.groupBox1.TabIndex = 4;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "登录密码";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.button6);
			this.groupBox2.Controls.Add(this.textBox3);
			this.groupBox2.Controls.Add(this.textBox2);
			this.groupBox2.Location = new System.Drawing.Point(184, 8);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(168, 160);
			this.groupBox2.TabIndex = 5;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "修改密码";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(120, 48);
			this.label1.TabIndex = 0;
			this.label1.Text = "注意:初始密码为空,请经常更改密码!";
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(32, 80);
			this.textBox1.Name = "textBox1";
			this.textBox1.PasswordChar = '*';
			this.textBox1.TabIndex = 1;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Location = new System.Drawing.Point(40, 40);
			this.textBox2.Name = "textBox2";
			this.textBox2.PasswordChar = '*';
			this.textBox2.TabIndex = 0;
			this.textBox2.Text = "";
			this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(40, 80);
			this.textBox3.Name = "textBox3";
			this.textBox3.PasswordChar = '*';
			this.textBox3.TabIndex = 1;
			this.textBox3.Text = "";
			// 
			// button5
			// 
			this.button5.Location = new System.Drawing.Point(40, 120);
			this.button5.Name = "button5";
			this.button5.TabIndex = 2;
			this.button5.Text = "登录";
			this.button5.Click += new System.EventHandler(this.button5_Click);
			// 
			// button6
			// 
			this.button6.Location = new System.Drawing.Point(48, 120);
			this.button6.Name = "button6";
			this.button6.TabIndex = 2;
			this.button6.Text = "确定";
			this.button6.Click += new System.EventHandler(this.button6_Click);
			// 
			// Form2
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(368, 278);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.button4);
			this.Controls.Add(this.button3);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Name = "Form2";
			this.Text = "超级用户";
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
//"登录"按钮的Click事件代码
		private void button5_Click(object sender, System.EventArgs e)
		{
			bbb=textBox1.Text;
			FileStream aa=new FileStream("D:\\林冬权\\图书系统设计\\密码.ddd",FileMode.OpenOrCreate,
				FileAccess.ReadWrite);

			StreamReader sr=new StreamReader(aa);
			aaa=sr.ReadToEnd();
			sr.Close();
			aa.Close();
			if(aaa==bbb)
			{
				MessageBox.Show("登录密码正确,本程序为你服务!");
			}
			if(aaa!=bbb)
			{
				MessageBox.Show("登录密码不正确,请重新登录!");
			}
		}
//"确定"按钮的Click事件代码
		private void button6_Click(object sender, System.EventArgs e)
		{
			if(aaa==bbb)
			{
				if(textBox2.Text == textBox3.Text)
				{

					FileStream aa=new FileStream("D:\\林冬权\\图书系统设计\\密码.ddd",FileMode.OpenOrCreate,
						FileAccess.ReadWrite);
					StreamWriter sw=new StreamWriter(aa);
					sw.Write(textBox2.Text);
					sw.Close();
					aa.Close();

					if(textBox2.Text!="")
					{
						MessageBox.Show("密码已经成功更改!");
					}
					else if(textBox2.Text =="")
					{
						MessageBox.Show("抱歉!你输入的值是空值,修改无效");
					}
					else if(textBox2.Text != textBox3.Text)
					{
						MessageBox.Show("你输入的密码不匹配,重新输入!");
					}

				}
				else if(aaa!=bbb)
				{
					MessageBox.Show("登录密码不正确,请重新登录!");
				}
			}
		}


		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
		
		}
//"插入数据"按钮的Click事件代码
		private void button1_Click(object sender, System.EventArgs e)
		{
			Form3 form3 =new Form3();
			if(aaa==bbb)
			{
				form3.Show();
			}
			else{MessageBox.Show("您输入的密码不正确!请重新登录!");}
		}
//"删除数据"按钮的Click事件代码
		private void button2_Click(object sender, System.EventArgs e)
		{
			
			Form4 form4 =new Form4();
			if(aaa==bbb)
			{
				form4.Show();
			}
			else{MessageBox.Show("您输入的密码不正确!请重新登录!");}
		}
//"更新数据"按钮的Click事件代码
		private void button3_Click(object sender, System.EventArgs e)
		{
		
			Form5 form5 =new Form5();
			if(aaa==bbb)
			{
				form5.Show();
			}
			else{MessageBox.Show("您输入的密码不正确!请重新登录!");}
			}
//"关闭"按钮的Click事件代码
			private void button4_Click(object sender, System.EventArgs e)
			{
				Close();
			}
		}
	}

⌨️ 快捷键说明

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