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

📄 form1.cs

📁 学生管理系统(学生信息的管理、添加、删除、编辑
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace winform1
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtSearch;
		private System.Windows.Forms.ComboBox Cmbtype;
		private System.Windows.Forms.Button BtSearch;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.TextBox txtSearchID;
		private System.Windows.Forms.Button BtSearchID;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.TextBox TxtBookID;
		private System.Windows.Forms.TextBox TxtBookName;
		private System.Windows.Forms.TextBox TxtState;
		private System.Windows.Forms.Button BtAdd;
		private System.Windows.Forms.Button BtDel;
		private System.Windows.Forms.Button BtEdit;
		private System.Windows.Forms.Button BtSave;
		private System.Windows.Forms.ToolBar toolBar1;
		private System.Windows.Forms.ToolBarButton TBfirst;
		private System.Windows.Forms.ToolBarButton TBpre;
		private System.Windows.Forms.ToolBarButton TBNext;
		private System.Windows.Forms.ToolBarButton TBlast;
		private System.Windows.Forms.ToolBarButton toolBarButton5;
		private System.Windows.Forms.ToolBarButton TBExit;
		private System.ComponentModel.IContainer components;
		OleDbConnection myConnection;
		OleDbDataAdapter myAdapter;
		OleDbCommand myCmd;
		DataSet ds;
		DataTable mytable;
		DataRow myrow;
		private System.Windows.Forms.DataGrid GRDbooks;
		private System.Windows.Forms.ImageList imageList1;
		int rownumber;
        
		public bool OpenDb()
		{
			String SQLstr="";
			SQLstr="select * from tblbooks";
			try
			{
				myConnection=new OleDbConnection("Provider=" +"Microsoft.Jet.OLEDB.4.0;Data Source=D:\\lib.mdb");
				myAdapter=new OleDbDataAdapter(SQLstr,myConnection);
				ds=new DataSet();
				myAdapter.Fill(ds,"tblbooks");
				mytable=ds.Tables[0];
				rownumber=0;
				myrow=mytable.Rows[rownumber];
			}
			catch(Exception e)
			{
				MessageBox.Show(e.ToString(),"错误",MessageBoxButtons.OK);
				return false;
			}
			return true;
		}


		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			OpenDb();
			TxtBookID.Text=myrow[0].ToString();
			TxtBookName.Text=myrow[1].ToString();
			TxtState.Text=myrow[2].ToString();

			//
			// 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(Form1));
			this.GRDbooks = new System.Windows.Forms.DataGrid();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.BtSearch = new System.Windows.Forms.Button();
			this.Cmbtype = new System.Windows.Forms.ComboBox();
			this.txtSearch = new System.Windows.Forms.TextBox();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.BtSearchID = new System.Windows.Forms.Button();
			this.txtSearchID = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.TxtState = new System.Windows.Forms.TextBox();
			this.TxtBookName = new System.Windows.Forms.TextBox();
			this.TxtBookID = new System.Windows.Forms.TextBox();
			this.label6 = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.groupBox4 = 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.groupBox5 = new System.Windows.Forms.GroupBox();
			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.TBExit = new System.Windows.Forms.ToolBarButton();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			((System.ComponentModel.ISupportInitialize)(this.GRDbooks)).BeginInit();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.groupBox5.SuspendLayout();
			this.SuspendLayout();
			// 
			// GRDbooks
			// 
			this.GRDbooks.DataMember = "";
			this.GRDbooks.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.GRDbooks.Location = new System.Drawing.Point(192, 392);
			this.GRDbooks.Name = "GRDbooks";
			this.GRDbooks.Size = new System.Drawing.Size(216, 120);
			this.GRDbooks.TabIndex = 0;
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.BtSearch);
			this.groupBox1.Controls.Add(this.Cmbtype);
			this.groupBox1.Controls.Add(this.txtSearch);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(8, 256);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(296, 128);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			// 
			// BtSearch
			// 
			this.BtSearch.ForeColor = System.Drawing.Color.Indigo;
			this.BtSearch.Location = new System.Drawing.Point(104, 88);
			this.BtSearch.Name = "BtSearch";
			this.BtSearch.TabIndex = 4;
			this.BtSearch.Text = "查询";
			this.BtSearch.Click += new System.EventHandler(this.BtSearch_Click);
			// 
			// Cmbtype
			// 
			this.Cmbtype.Items.AddRange(new object[] {
														 "图书编号",
														 "图书名称",
														 "图书总数量"});
			this.Cmbtype.Location = new System.Drawing.Point(16, 40);
			this.Cmbtype.Name = "Cmbtype";
			this.Cmbtype.Size = new System.Drawing.Size(121, 20);
			this.Cmbtype.TabIndex = 3;
			this.Cmbtype.Text = "图书编号";
			// 
			// txtSearch
			// 
			this.txtSearch.Location = new System.Drawing.Point(152, 40);
			this.txtSearch.Name = "txtSearch";
			this.txtSearch.Size = new System.Drawing.Size(120, 21);
			this.txtSearch.TabIndex = 2;
			this.txtSearch.Text = "";
			// 
			// label2
			// 
			this.label2.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label2.Location = new System.Drawing.Point(152, 16);
			this.label2.Name = "label2";
			this.label2.TabIndex = 1;
			this.label2.Text = "查询条件";
			// 
			// label1
			// 
			this.label1.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label1.Location = new System.Drawing.Point(8, 16);
			this.label1.Name = "label1";
			this.label1.TabIndex = 0;
			this.label1.Text = "查询类型";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.BtSearchID);
			this.groupBox2.Controls.Add(this.txtSearchID);
			this.groupBox2.Controls.Add(this.label3);
			this.groupBox2.Location = new System.Drawing.Point(8, 400);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(168, 104);
			this.groupBox2.TabIndex = 2;
			this.groupBox2.TabStop = false;
			// 
			// BtSearchID
			// 
			this.BtSearchID.ForeColor = System.Drawing.Color.Indigo;
			this.BtSearchID.Location = new System.Drawing.Point(16, 72);
			this.BtSearchID.Name = "BtSearchID";
			this.BtSearchID.TabIndex = 2;
			this.BtSearchID.Text = "查询";
			this.BtSearchID.Click += new System.EventHandler(this.button1_Click);
			// 
			// txtSearchID
			// 
			this.txtSearchID.Location = new System.Drawing.Point(16, 40);
			this.txtSearchID.Name = "txtSearchID";
			this.txtSearchID.Size = new System.Drawing.Size(120, 21);
			this.txtSearchID.TabIndex = 1;
			this.txtSearchID.Text = "";
			// 
			// label3
			// 
			this.label3.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label3.Location = new System.Drawing.Point(8, 16);
			this.label3.Name = "label3";
			this.label3.TabIndex = 0;
			this.label3.Text = "按图书编号";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.TxtState);
			this.groupBox3.Controls.Add(this.TxtBookName);
			this.groupBox3.Controls.Add(this.TxtBookID);
			this.groupBox3.Controls.Add(this.label6);
			this.groupBox3.Controls.Add(this.label5);
			this.groupBox3.Controls.Add(this.label4);
			this.groupBox3.Location = new System.Drawing.Point(8, 96);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(232, 152);
			this.groupBox3.TabIndex = 3;
			this.groupBox3.TabStop = false;
			// 
			// TxtState
			// 
			this.TxtState.Location = new System.Drawing.Point(88, 112);
			this.TxtState.Name = "TxtState";
			this.TxtState.Size = new System.Drawing.Size(128, 21);
			this.TxtState.TabIndex = 5;
			this.TxtState.Text = "";
			// 
			// TxtBookName
			// 
			this.TxtBookName.Location = new System.Drawing.Point(88, 72);
			this.TxtBookName.Name = "TxtBookName";
			this.TxtBookName.Size = new System.Drawing.Size(128, 21);
			this.TxtBookName.TabIndex = 4;
			this.TxtBookName.Text = "";
			this.TxtBookName.TextChanged += new System.EventHandler(this.textBox2_TextChanged);
			// 
			// TxtBookID
			// 
			this.TxtBookID.Location = new System.Drawing.Point(88, 32);
			this.TxtBookID.Name = "TxtBookID";
			this.TxtBookID.Size = new System.Drawing.Size(128, 21);
			this.TxtBookID.TabIndex = 3;
			this.TxtBookID.Text = "";
			// 
			// label6
			// 
			this.label6.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label6.Location = new System.Drawing.Point(16, 112);
			this.label6.Name = "label6";
			this.label6.TabIndex = 2;
			this.label6.Text = "图书状态";
			// 
			// label5
			// 
			this.label5.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label5.Location = new System.Drawing.Point(16, 72);
			this.label5.Name = "label5";
			this.label5.TabIndex = 1;
			this.label5.Text = "图书名称";
			// 
			// label4
			// 
			this.label4.ForeColor = System.Drawing.Color.DodgerBlue;
			this.label4.Location = new System.Drawing.Point(16, 32);
			this.label4.Name = "label4";
			this.label4.TabIndex = 0;
			this.label4.Text = "图书编号";
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.Add(this.BtSave);
			this.groupBox4.Controls.Add(this.BtEdit);
			this.groupBox4.Controls.Add(this.BtDel);
			this.groupBox4.Controls.Add(this.BtAdd);
			this.groupBox4.Location = new System.Drawing.Point(256, 88);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(96, 152);
			this.groupBox4.TabIndex = 4;
			this.groupBox4.TabStop = false;
			// 
			// BtSave
			// 
			this.BtSave.ForeColor = System.Drawing.Color.Indigo;
			this.BtSave.Location = new System.Drawing.Point(8, 120);
			this.BtSave.Name = "BtSave";
			this.BtSave.TabIndex = 3;
			this.BtSave.Text = "保存";
			this.BtSave.Click += new System.EventHandler(this.BtSave_Click);
			// 
			// BtEdit
			// 
			this.BtEdit.ForeColor = System.Drawing.Color.Indigo;
			this.BtEdit.Location = new System.Drawing.Point(8, 88);
			this.BtEdit.Name = "BtEdit";
			this.BtEdit.TabIndex = 2;
			this.BtEdit.Text = "编辑";
			this.BtEdit.Click += new System.EventHandler(this.BtEdit_Click);

⌨️ 快捷键说明

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