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

📄 form1.cs

📁 小型图书馆管理系统能够实现图书馆用户信息和图书的存储以及查询。
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
//引入数据库操作类命名空间
using System.Data.OleDb;
//引入ADO.NET操作命名空间

namespace 图书管理系统
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		internal System.Windows.Forms.GroupBox GroupBox1;
		internal System.Windows.Forms.TextBox TxtBookName;
		internal System.Windows.Forms.TextBox TxtState;
		internal System.Windows.Forms.TextBox TxtBookID;
		internal System.Windows.Forms.Label Label3;
		internal System.Windows.Forms.Label Label2;
		internal System.Windows.Forms.Label Label1;
		internal System.Windows.Forms.ToolBar ToolBar1;
		internal System.Windows.Forms.ToolBarButton TBfirst;
		internal System.Windows.Forms.ToolBarButton TBpre;
		internal System.Windows.Forms.ToolBarButton TBNext;
		internal System.Windows.Forms.ToolBarButton TBlast;
		internal System.Windows.Forms.ToolBarButton ToolBarButton5;
		internal System.Windows.Forms.ToolBarButton ToolBarButton6;
		internal System.Windows.Forms.ToolBarButton TBExit;
		internal System.Windows.Forms.ImageList ImageList1;
		internal System.Windows.Forms.GroupBox GroupBox2;
		internal System.Windows.Forms.Button BtSave;
		internal System.Windows.Forms.Button BtEdit;
		internal System.Windows.Forms.Button BtDel;
		internal System.Windows.Forms.Button BtAdd;
		internal System.Windows.Forms.GroupBox GroupBox3;
		internal System.Windows.Forms.GroupBox GroupBox5;
		internal System.Windows.Forms.DataGrid GRDbooks;
		internal System.Windows.Forms.GroupBox GroupBox6;
		internal System.Windows.Forms.Button BtSearchID;
		internal System.Windows.Forms.TextBox txtSearchID;
		internal System.Windows.Forms.Label Label6;
		internal System.Windows.Forms.GroupBox GroupBox4;
		internal System.Windows.Forms.Label Label5;
		internal System.Windows.Forms.Label Label4;
		internal System.Windows.Forms.Button BtSearch;
		internal System.Windows.Forms.TextBox txtSearch;
		internal System.Windows.Forms.ComboBox Cmbtype;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			OpenDb();
			//应用数据库连接函数,打开数据连接
			TxtBookID.Text = myrow[0].ToString();
			//显示图书编号
			TxtBookName.Text = myrow[1].ToString();
			//显示图书名称
			TxtState.Text = myrow[2].ToString();
			//显示图书当前状态
		}

		OleDbConnection myConnection;       
		//建立OleDbConnection连接对象
		OleDbDataAdapter myAdapter;
		//建立OleDbDataAdapter对象 
		OleDbCommand myCmd;
		//建立OleDbCommand对象
		DataSet ds;
		//建立DataSet对象 
		DataTable mytable ;
		//建立表单对象
		DataRow myrow;
		//建立数据行对象
		int rownumber;
		//定义一个整型变量来存放当前行数
		public bool OpenDb()
		{
			String SQLstr = "";
			//定义SQL查询字符串
			SQLstr = "select * from tblbooks";
			//建立SQL查询语句
			try
			{
				myConnection=new OleDbConnection("Provider="
					+"Microsoft.Jet.OLEDB.4.0;Data Source=lib.mdb");
				//建立连接对象
				myAdapter = new OleDbDataAdapter(SQLstr,myConnection);
				//建立ADODataSetCommand对象
				ds=new DataSet();
				//创建数据集
				myAdapter.Fill(ds, "tblbooks");
				//取得表单
				mytable = ds.Tables[0];
				//取得tblbooks表
				rownumber = 0;
				//设置为起始行
				myrow = mytable.Rows[rownumber];
				//取得第1行数据
			}
			catch(Exception e)
			{
				MessageBox.Show(e.ToString(),"错误",MessageBoxButtons.OK);
				return false;
			}
			return true;
		}

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

		#region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
            this.components = new System.ComponentModel.Container();
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.GroupBox1 = new System.Windows.Forms.GroupBox();
            this.TxtBookName = new System.Windows.Forms.TextBox();
            this.TxtState = new System.Windows.Forms.TextBox();
            this.TxtBookID = 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.ToolBar1 = new System.Windows.Forms.ToolBar();
            this.TBfirst = new System.Windows.Forms.ToolBarButton();
            this.TBpre = new System.Windows.Forms.ToolBarButton();
            this.TBNext = new System.Windows.Forms.ToolBarButton();
            this.TBlast = new System.Windows.Forms.ToolBarButton();
            this.ToolBarButton5 = new System.Windows.Forms.ToolBarButton();
            this.ToolBarButton6 = new System.Windows.Forms.ToolBarButton();
            this.TBExit = new System.Windows.Forms.ToolBarButton();
            this.ImageList1 = new System.Windows.Forms.ImageList(this.components);
            this.GroupBox2 = new System.Windows.Forms.GroupBox();
            this.BtSave = new System.Windows.Forms.Button();
            this.BtEdit = new System.Windows.Forms.Button();
            this.BtDel = new System.Windows.Forms.Button();
            this.BtAdd = new System.Windows.Forms.Button();
            this.GroupBox3 = new System.Windows.Forms.GroupBox();
            this.GroupBox5 = new System.Windows.Forms.GroupBox();
            this.GRDbooks = new System.Windows.Forms.DataGrid();
            this.GroupBox6 = new System.Windows.Forms.GroupBox();
            this.BtSearchID = new System.Windows.Forms.Button();
            this.txtSearchID = new System.Windows.Forms.TextBox();
            this.Label6 = new System.Windows.Forms.Label();
            this.GroupBox4 = new System.Windows.Forms.GroupBox();
            this.Label5 = new System.Windows.Forms.Label();
            this.Label4 = new System.Windows.Forms.Label();
            this.BtSearch = new System.Windows.Forms.Button();
            this.txtSearch = new System.Windows.Forms.TextBox();
            this.Cmbtype = new System.Windows.Forms.ComboBox();
            this.GroupBox1.SuspendLayout();
            this.GroupBox2.SuspendLayout();
            this.GroupBox3.SuspendLayout();
            this.GroupBox5.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.GRDbooks)).BeginInit();
            this.GroupBox6.SuspendLayout();
            this.GroupBox4.SuspendLayout();
            this.SuspendLayout();
            // 
            // GroupBox1
            // 
            this.GroupBox1.Controls.Add(this.TxtBookName);
            this.GroupBox1.Controls.Add(this.TxtState);
            this.GroupBox1.Controls.Add(this.TxtBookID);
            this.GroupBox1.Controls.Add(this.Label3);
            this.GroupBox1.Controls.Add(this.Label2);
            this.GroupBox1.Controls.Add(this.Label1);
            this.GroupBox1.Location = new System.Drawing.Point(8, 40);
            this.GroupBox1.Name = "GroupBox1";
            this.GroupBox1.Size = new System.Drawing.Size(272, 120);
            this.GroupBox1.TabIndex = 2;
            this.GroupBox1.TabStop = false;
            this.GroupBox1.Enter += new System.EventHandler(this.GroupBox1_Enter);
            // 
            // TxtBookName
            // 
            this.TxtBookName.Location = new System.Drawing.Point(112, 48);
            this.TxtBookName.Name = "TxtBookName";
            this.TxtBookName.Size = new System.Drawing.Size(96, 21);
            this.TxtBookName.TabIndex = 1;
            // 
            // TxtState
            // 
            this.TxtState.Location = new System.Drawing.Point(112, 80);
            this.TxtState.Name = "TxtState";
            this.TxtState.Size = new System.Drawing.Size(96, 21);
            this.TxtState.TabIndex = 1;
            // 
            // TxtBookID
            // 
            this.TxtBookID.Location = new System.Drawing.Point(112, 16);
            this.TxtBookID.Name = "TxtBookID";
            this.TxtBookID.Size = new System.Drawing.Size(96, 21);
            this.TxtBookID.TabIndex = 1;
            // 
            // Label3
            // 
            this.Label3.Location = new System.Drawing.Point(32, 80);
            this.Label3.Name = "Label3";
            this.Label3.Size = new System.Drawing.Size(56, 16);
            this.Label3.TabIndex = 0;
            this.Label3.Text = "图书状态";
            // 
            // Label2
            // 
            this.Label2.Location = new System.Drawing.Point(32, 56);
            this.Label2.Name = "Label2";
            this.Label2.Size = new System.Drawing.Size(56, 16);
            this.Label2.TabIndex = 0;
            this.Label2.Text = "图书名称";
            // 
            // Label1
            // 
            this.Label1.Location = new System.Drawing.Point(32, 24);
            this.Label1.Name = "Label1";
            this.Label1.Size = new System.Drawing.Size(56, 16);
            this.Label1.TabIndex = 0;
            this.Label1.Text = "图书编号";
            // 
            // ToolBar1
            // 
            this.ToolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
            this.TBfirst,
            this.TBpre,
            this.TBNext,
            this.TBlast,
            this.ToolBarButton5,
            this.ToolBarButton6,
            this.TBExit});
            this.ToolBar1.DropDownArrows = true;
            this.ToolBar1.ImageList = this.ImageList1;
            this.ToolBar1.Location = new System.Drawing.Point(0, 0);
            this.ToolBar1.Name = "ToolBar1";
            this.ToolBar1.ShowToolTips = true;
            this.ToolBar1.Size = new System.Drawing.Size(330, 28);
            this.ToolBar1.TabIndex = 3;
            this.ToolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.ToolBar1_ButtonClick);
            // 
            // TBfirst
            // 
            this.TBfirst.ImageIndex = 0;
            this.TBfirst.Name = "TBfirst";
            this.TBfirst.ToolTipText = "显示第一条";
            // 
            // TBpre
            // 
            this.TBpre.ImageIndex = 1;
            this.TBpre.Name = "TBpre";
            this.TBpre.ToolTipText = "显示上一条";
            // 
            // TBNext
            // 
            this.TBNext.ImageIndex = 2;
            this.TBNext.Name = "TBNext";
            this.TBNext.ToolTipText = "显示下一条";
            // 
            // TBlast
            // 
            this.TBlast.ImageIndex = 3;
            this.TBlast.Name = "TBlast";
            // 
            // ToolBarButton5
            // 
            this.ToolBarButton5.Name = "ToolBarButton5";

⌨️ 快捷键说明

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