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

📄 主窗口.cs

📁 图书管理系统,.net2003+sql2000,分为三个模块,用户端,操作员端,系统管理员端.基本上是用自定义控件dll来完成,内含完整sql语句,包括存储过程.
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace 系统管理员
{
	/// <summary>
	/// 主窗口 的摘要说明。
	/// </summary>
	public class 主窗口 : System.Windows.Forms.Form
	{
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem menuItem2;
		private 读者信息dll.UserControl1 userControl11;
		private System.Windows.Forms.MenuItem menuItem3;
		private System.Windows.Forms.MenuItem menuItem4;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.MenuItem menuItem5;
		private System.Windows.Forms.MenuItem menuItem6;
		private 书目管理dll.UserControl1 userControl12;
		public Form1 p;

		public 主窗口()
		{
			//
			// 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.mainMenu1 = new System.Windows.Forms.MainMenu();
			this.menuItem1 = new System.Windows.Forms.MenuItem();
			this.menuItem3 = new System.Windows.Forms.MenuItem();
			this.menuItem4 = new System.Windows.Forms.MenuItem();
			this.menuItem2 = new System.Windows.Forms.MenuItem();
			this.menuItem5 = new System.Windows.Forms.MenuItem();
			this.menuItem6 = new System.Windows.Forms.MenuItem();
			this.userControl11 = new 读者信息dll.UserControl1();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.label1 = new System.Windows.Forms.Label();
			this.userControl12 = new 书目管理dll.UserControl1();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// mainMenu1
			// 
			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem1,
																					  this.menuItem2});
			// 
			// menuItem1
			// 
			this.menuItem1.Index = 0;
			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem3,
																					  this.menuItem4});
			this.menuItem1.Text = "读者管理";
			// 
			// menuItem3
			// 
			this.menuItem3.Index = 0;
			this.menuItem3.Text = "增加读者";
			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
			// 
			// menuItem4
			// 
			this.menuItem4.Index = 1;
			this.menuItem4.Text = "读者管理";
			this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
			// 
			// menuItem2
			// 
			this.menuItem2.Index = 1;
			this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
																					  this.menuItem5,
																					  this.menuItem6});
			this.menuItem2.Text = "书目管理";
			// 
			// menuItem5
			// 
			this.menuItem5.Index = 0;
			this.menuItem5.Text = "增加书目";
			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
			// 
			// menuItem6
			// 
			this.menuItem6.Index = 1;
			this.menuItem6.Text = "书目管理";
			this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
			// 
			// userControl11
			// 
			this.userControl11.Location = new System.Drawing.Point(0, -16);
			this.userControl11.Name = "userControl11";
			this.userControl11.Size = new System.Drawing.Size(752, 432);
			this.userControl11.TabIndex = 0;
			this.userControl11.Load += new System.EventHandler(this.userControl11_Load);
			this.userControl11.textBox1.KeyDown+=new KeyEventHandler(textBox1_KeyDown);
			
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(384, 248);
			this.button1.Name = "button1";
			this.button1.TabIndex = 1;
			this.button1.Text = "确定";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(480, 248);
			this.button2.Name = "button2";
			this.button2.TabIndex = 2;
			this.button2.Text = "取消";
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(24, 288);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(712, 88);
			this.dataGrid1.TabIndex = 3;
			// 
			// label1
			// 
			this.label1.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label1.ForeColor = System.Drawing.Color.Crimson;
			this.label1.Location = new System.Drawing.Point(216, 80);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 32);
			this.label1.TabIndex = 4;
			this.label1.Text = "*输入证件号回车可查询";
			// 
			// userControl12
			// 
			this.userControl12.Location = new System.Drawing.Point(8, 0);
			this.userControl12.Name = "userControl12";
			this.userControl12.Size = new System.Drawing.Size(728, 440);
			this.userControl12.TabIndex = 5;
			this.userControl12.Load += new System.EventHandler(this.userControl12_Load);
			// 
			// 主窗口
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(744, 425);
			this.Controls.Add(this.userControl12);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.button2);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.userControl11);
			this.Menu = this.mainMenu1;
			this.Name = "主窗口";
			this.Text = "主窗口";
			this.Closed += new System.EventHandler(this.主窗口_Closed);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void 主窗口_Closed(object sender, System.EventArgs e)
		{
			this.p.Close();
		}

		private void menuItem3_Click(object sender, System.EventArgs e)
		{
			this.userControl11.Visible=true;
			this.userControl12.Visible=false;
			this.userControl11.button1.Visible=false;
			this.userControl11.button2.Visible=false;
			this.button1.Visible=true;
			this.button2.Visible=true;
			公共数据dll.Store.ds.Clear();
			this.userControl11.textBox4.Text="";
			this.userControl11.textBox2.Text="";
			this.userControl11.textBox1.Text="";
			this.userControl11.textBox3.Text="";
			this.userControl11.textBox5.Text="";



		}

		private void userControl11_Load(object sender, System.EventArgs e)
		{
			this.userControl11.button1.Enabled=false;
			this.userControl11.button2.Enabled=false;
			this.button1.Visible=false;
			this.button2.Visible=false;
		
		}

		private void button1_Click(object sender, System.EventArgs e)//增加读者
		{
			公共数据dll.Store.cn.Open();
			公共数据dll.Store.sqlStr="insert into readerinfo(密码,证件号,姓名,年龄,性别,出生日期,文化程度,工作单位,职业,电话,[E-MAIL],最大借书量) values ('"+this.userControl11.textBox2.Text+"','"+this.userControl11.textBox1.Text+"','"+this.userControl11.textBox4.Text+"','"+this.userControl11.numericUpDown1.Value+"','"+this.userControl11.comboBox3.Text+"','"+this.userControl11.dateTimePicker1.Value+"','"+this.userControl11.comboBox1.Text+"','"+this.userControl11.comboBox6.Text+"','"+this.userControl11.comboBox4.Text+"','"+this.userControl11.textBox3.Text+"','"+this.userControl11.textBox5.Text+"','"+this.userControl11.comboBox5.Text+"')";
			MessageBox.Show(公共数据dll.Store.sqlStr);
			公共数据dll.Store.cmd=new System.Data.SqlClient.SqlCommand(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
			try
			{
				if(公共数据dll.Store.cmd.ExecuteNonQuery()==1)
				{
					公共数据dll.Store.ds.Clear();
					公共数据dll.Store.sqlStr="select * from readerinfo where 证件号='"+this.userControl11.textBox1.Text+"'";
					公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
					公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"onlyonerecord");
					this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"onlyonerecord");
				}
			}
			catch(Exception E)
			{
				MessageBox.Show(E.Message);
			}
			公共数据dll.Store.cn.Close();
		}

		private void menuItem4_Click(object sender, System.EventArgs e)//修改/删除读者
		{
			this.userControl11.Visible=true;
			this.userControl12.Visible=false;
			this.userControl11.button1.Visible=true;
			this.userControl11.button2.Visible=true;
			this.userControl11.button1.Enabled=true;
			this.userControl11.button2.Enabled=true;
			this.button1.Visible=false;
			this.button2.Visible=false;
			公共数据dll.Store.str_temp=this.userControl11.textBox1.Text;
			
		}

		private void userControlbutton1_Click(object sender, EventArgs e)
		{
			公共数据dll.Store.str_temp=this.userControl11.textBox1.Text;

		}


		private void textBox1_KeyDown(object sender, KeyEventArgs e)//在第一个自定义控件中回车的响应///注意,每次更新容易造成代码修改器里的textBox1回车事件失效.
		{
			if(e.KeyValue==13)
			{
				公共数据dll.Store.ds.Clear();
				公共数据dll.Store.sqlStr="select * from readerinfo where 证件号='"+this.userControl11.textBox1.Text+"'";
				公共数据dll.Store.myDataAdapter=new System.Data.SqlClient.SqlDataAdapter(公共数据dll.Store.sqlStr,公共数据dll.Store.cn);
				公共数据dll.Store.myDataAdapter.Fill(公共数据dll.Store.ds,"inquirereader");
				this.dataGrid1.SetDataBinding(公共数据dll.Store.ds,"inquirereader");
				////////////////////////////////////////////////////////////////////
				foreach(DataRow dr in 公共数据dll.Store.ds.Tables["inquirereader"].Rows)
				{
					this.userControl11.textBox4.Text=dr["姓名"].ToString();
					this.userControl11.textBox2.Text=dr["密码"].ToString();//////////////////
					this.userControl11.textBox1.Text=dr["证件号"].ToString();
					this.userControl11.comboBox1.Text=dr["文化程度"].ToString();
					this.userControl11.dateTimePicker1.Text=dr["出生日期"].ToString();
					decimal year=(decimal)int.Parse(dr["年龄"].ToString());
					this.userControl11.numericUpDown1.Value=year;
					this.userControl11.comboBox6.Text=dr["工作单位"].ToString();
					this.userControl11.comboBox3.Text=dr["性别"].ToString();
					this.userControl11.comboBox4.Text=dr["职业"].ToString();
					this.userControl11.comboBox5.Text=dr["最大借书量"].ToString();
					this.userControl11.textBox3.Text=dr["电话"].ToString();////////////////////////////
					this.userControl11.textBox5.Text=dr["E-MAIL"].ToString();/////////////////////////
				}
				公共数据dll.Store.cn.Close();
			}

		}

		private void menuItem5_Click(object sender, System.EventArgs e)//书目新增时的外观
		{
			/////////////////////////////////////自定义控件可见
			this.userControl11.Visible=false;
			this.userControl12.Visible=true;
			/////////////////////////////////////按钮的可见
			this.userControl12.button1.Enabled=true;
			this.userControl12.button4.Enabled=true;
			this.userControl12.button5.Enabled=false;
			this.userControl12.button6.Enabled=false;
			this.userControl12.button7.Enabled=false;
			this.userControl12.button8.Enabled=false;




		}

		private void userControl12_Load(object sender, System.EventArgs e)
		{
			公共数据dll.Store.cn.Close();
			this.userControl12.Visible=false;
		}

		private void menuItem6_Click(object sender, System.EventArgs e)//书目管理时的外观
		{
			/////////////////////////////////////自定义控件可见
			this.userControl11.Visible=false;
			this.userControl12.Visible=true;
			/////////////////////////////////////按钮的可见
			this.userControl12.button1.Enabled=false;
			this.userControl12.button4.Enabled=false;
			this.userControl12.button5.Enabled=true;
			this.userControl12.button6.Enabled=true;
			this.userControl12.button7.Enabled=true;
			this.userControl12.button8.Enabled=true;

		}
	}
}

⌨️ 快捷键说明

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