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

📄 form1.cs

📁 学生管理系统(学生信息的管理、添加、删除、编辑
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// BtDel
			// 
			this.BtDel.ForeColor = System.Drawing.Color.Indigo;
			this.BtDel.Location = new System.Drawing.Point(8, 56);
			this.BtDel.Name = "BtDel";
			this.BtDel.TabIndex = 1;
			this.BtDel.Text = "删除";
			this.BtDel.Click += new System.EventHandler(this.BtDel_Click);
			// 
			// BtAdd
			// 
			this.BtAdd.ForeColor = System.Drawing.Color.Indigo;
			this.BtAdd.Location = new System.Drawing.Point(8, 24);
			this.BtAdd.Name = "BtAdd";
			this.BtAdd.TabIndex = 0;
			this.BtAdd.Text = "添加";
			this.BtAdd.Click += new System.EventHandler(this.BtAdd_Click);
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.Add(this.toolBar1);
			this.groupBox5.Location = new System.Drawing.Point(16, 8);
			this.groupBox5.Name = "groupBox5";
			this.groupBox5.Size = new System.Drawing.Size(224, 72);
			this.groupBox5.TabIndex = 5;
			this.groupBox5.TabStop = false;
			this.groupBox5.Enter += new System.EventHandler(this.groupBox5_Enter);
			// 
			// toolBar1
			// 
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.TBfirst,
																						this.TBpre,
																						this.TBNext,
																						this.TBlast,
																						this.toolBarButton5,
																						this.TBExit});
			this.toolBar1.DropDownArrows = true;
			this.toolBar1.ImageList = this.imageList1;
			this.toolBar1.Location = new System.Drawing.Point(3, 17);
			this.toolBar1.Name = "toolBar1";
			this.toolBar1.ShowToolTips = true;
			this.toolBar1.Size = new System.Drawing.Size(218, 41);
			this.toolBar1.TabIndex = 0;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// TBfirst
			// 
			this.TBfirst.ImageIndex = 0;
			this.TBfirst.Text = "Firs";
			this.TBfirst.ToolTipText = "第一条";
			// 
			// TBpre
			// 
			this.TBpre.ImageIndex = 1;
			this.TBpre.Text = "Pre.";
			this.TBpre.ToolTipText = "显示上一条";
			// 
			// TBNext
			// 
			this.TBNext.ImageIndex = 2;
			this.TBNext.Text = "Next";
			this.TBNext.ToolTipText = "显示下一条";
			// 
			// TBlast
			// 
			this.TBlast.ImageIndex = 3;
			this.TBlast.Text = "Last";
			this.TBlast.ToolTipText = "最后一条";
			// 
			// toolBarButton5
			// 
			this.toolBarButton5.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
			// 
			// TBExit
			// 
			this.TBExit.ImageIndex = 4;
			this.TBExit.Text = "Exit";
			this.TBExit.ToolTipText = "退出";
			// 
			// imageList1
			// 
			this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
			this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
			this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(416, 542);
			this.Controls.Add(this.groupBox5);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.GRDbooks);
			this.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.ForeColor = System.Drawing.Color.MintCream;
			this.Name = "Form1";
			this.Text = "图书管理系统";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.GRDbooks)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox5.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			String SearchSQLStr;
			OleDbDataAdapter Searchcmd;
			DataSet searchds=new DataSet();
			if(txtSearchID.Text.Length==0)
			{
				MessageBox.Show("请在文本框中输入要查询的图书编号","操作失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return;
			}
			SearchSQLStr="select tblborrow.[BookID],tblborrow.[BorrowData]," + "tblborrow.[Number],tblstudents.[Name]" + "from tblborrow inner join " + "tblstudents on tblborrow.[Number]=tblstudents.[Number]" + "group by tblborrow.[BookID],tblborrow.[BorrowData]," + "tblborrow.[Number],tblstudents.[Name]" + "HAVING (tblborrow.[BookID]='" + txtSearchID.Text + "')";
			Searchcmd=new OleDbDataAdapter(SearchSQLStr,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\lib.mdb");
			Searchcmd.Fill(searchds,"tblbooks");
			myAdapter.Fill(searchds,"tblborrow");
			GRDbooks.DataSource=searchds.Tables[0].DefaultView;
		}

		private void textBox2_TextChanged(object sender, System.EventArgs e)
		{
		
		}

		private void groupBox5_Enter(object sender, System.EventArgs e)
		{
		
		}

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button==TBfirst)
			{
				rownumber=0;
				TBNext.Enabled=true;
			}
			else if(e.Button==TBpre)
			{
				rownumber=rownumber-1;
				if(rownumber==-1)
				{
					TBpre.Enabled=false;
					return; 
				}
				TBNext.Enabled=true;
			}
			else if(e.Button==TBNext)
			{
				rownumber=rownumber+1;
				if(rownumber==mytable.Rows.Count)
				{
					TBNext.Enabled=false;
					return;
				}
				TBpre.Enabled=true;
			}
			else if(e.Button==TBlast)
			{
				rownumber=mytable.Rows.Count - 1;
				TBpre.Enabled=true;
			}
			else if(e.Button==TBExit)
			{
				DialogResult myresult;
				myresult=MessageBox.Show("要保存对图书信息的更改操作吗?","保存提示",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
				if(myresult==DialogResult.Yes)
				{
					BtSave.PerformClick();
				}
				Application.Exit();
				return;
			}
			try
			{
				myrow=mytable.Rows[rownumber];
				TxtBookID.Text=myrow[0].ToString();
				TxtBookName.Text=myrow[1].ToString();
				TxtState.Text=myrow[2].ToString();
			}
			catch
			{
				MessageBox.Show("错误","错误信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
		}

		private void BtAdd_Click(object sender, System.EventArgs e)
		{
			String insertSQL="insert into tblbooks(BookID,"+"bookName,"+"State) Values (@bookid,@bookname,@state)";
			myCmd=new OleDbCommand(insertSQL,myConnection);
			myCmd.Parameters.Add(new OleDbParameter("@bookid",OleDbType.Char,10));
			myCmd.Parameters["@bookid"].Value=TxtBookID.Text;
			myCmd.Parameters.Add(new OleDbParameter("@bookname",OleDbType.Char,10));
			myCmd.Parameters["@bookname"].Value=TxtBookName.Text;
			myCmd.Parameters.Add(new OleDbParameter("@state",OleDbType.Char,1));
			myCmd.Parameters["@state"].Value=TxtBookID.Text;
			myCmd.Connection.Open();
			try
			{
				myCmd.ExecuteNonQuery();
				MessageBox.Show("添加成功");
			}
			catch
			{
				MessageBox.Show("添加发生错误,请检查参数是否合法");
				myCmd.Connection.Close();
				return;
			}
			myCmd.Connection.Close();
			TxtBookID.Text="";
			TxtBookName.Text="";
			TxtState.Text="";
			OpenDb();
		}

		private void BtDel_Click(object sender, System.EventArgs e)
		{
			String delSQL="delete from tblbooks where " + "(tblbooks.[BookID]=[@bookID])";
			myCmd=new OleDbCommand(delSQL,myConnection);
			myCmd.Parameters.Add(new OleDbParameter("@bookid",OleDbType.Char,10));
			myCmd.Parameters["@bookid"].Value=TxtBookID.Text;
			myCmd.Connection.Open();
			try
			{
				myCmd.ExecuteNonQuery();
				MessageBox.Show("删除成功");
			}
			catch
			{
				MessageBox.Show("删除发生错误,检查参数是否合法");
				myCmd.Connection.Close();
				return;
			}
			myCmd.Connection.Close();
			TxtBookID.Text="";
			TxtBookName.Text="";
			TxtState.Text="";
			OpenDb();
		}

		private void BtEdit_Click(object sender, System.EventArgs e)
		{
			String updateSQL="up0date tblbooks set tblbooks.[BookID]" + " = [@bookid],tblbooks.[bookName]=[@bookname]," + "tblbooks.[State]=[@state] where tblbooks.[BookID]=[@bookid]";
			myCmd=new OleDbCommand(updateSQL,myConnection);
			myCmd.Parameters.Add(new OleDbParameter("@bookid",OleDbType.Char,10));
			myCmd.Parameters["@bookid"].Value=TxtBookID.Text;
			myCmd.Parameters.Add(new OleDbParameter("@bookname",OleDbType.Char,10));
			myCmd.Parameters["@bookname"].Value=TxtBookName.Text;
			myCmd.Parameters.Add(new OleDbParameter("@state",OleDbType.Char,1));
			myCmd.Parameters["@state"].Value=TxtBookID.Text;
			myCmd.Connection.Open();
			try
			{
				myCmd.ExecuteNonQuery();
				MessageBox.Show("编辑成功");
			}
			catch
			{
				MessageBox.Show("编辑发生错误,请检查参数是否合法");
				myCmd.Connection.Close();
				return;
			}
			myCmd.Connection.Close();
			OpenDb();
		}

		private void BtSave_Click(object sender, System.EventArgs e)
		{
			myAdapter.Update(ds,"tblbooks");
		}

		private void BtSearch_Click(object sender, System.EventArgs e)
		{
			String SearchSQLStr="";
			OleDbDataAdapter Searchcmd;
			DataSet searchds=new DataSet();
			DataTable Searchtable;
			DataRow searchrow;
			switch(Cmbtype.SelectedIndex)
			{
				case -1:
					MessageBox.Show("请先选择查询类型。","查询操作失败",MessageBoxButtons.OK,MessageBoxIcon.Information);
					return;
				case 0:
					if(txtSearch.Text.Length==0)
					{
						MessageBox.Show("请在文本框中输入查询需要的条件","操作失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
						return;
					}
					SearchSQLStr="select BookID,bookName,State " + " from tblbooks " + " where (BookID='" + txtSearch.Text + "')";
					break;
				case 1:
					if(txtSearch.Text.Length==0)
					{
						MessageBox.Show("请在文本框中输入查询需要的条件","操作失败",MessageBoxButtons.OK,MessageBoxIcon.Error);
						return;
					}
					SearchSQLStr="select BookID,BookName,State " + " from tblbooks " + " where (BookName='" + txtSearch.Text + "')";
					break;
				case 2:
					SearchSQLStr="select count(bookName)" + "from tblbooks";
					Searchcmd=new OleDbDataAdapter(SearchSQLStr,"Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=D:\\lib.mdb");
					Searchcmd.Fill(searchds,"tblbooks");
					Searchtable=searchds.Tables[0];
					searchrow=Searchtable.Rows[0];
					MessageBox.Show("图书总数为:" + searchrow[0].ToString(),"信息框",MessageBoxButtons.OK,MessageBoxIcon.Information);
					return;
			}
			Searchcmd=new OleDbDataAdapter(SearchSQLStr,"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\\lib.mdb");
			Searchcmd.Fill(searchds,"tblbooks");
			Searchtable=searchds.Tables[0];
			try
			{
				searchrow=Searchtable.Rows[0];
			}
			catch
			{
				MessageBox.Show("没有查找到该图书的信息。","查询结果",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return;
			}
			TxtBookID.Text=searchrow[0].ToString();
			TxtBookName.Text=searchrow[1].ToString();
			TxtState.Text=searchrow[2].ToString();
		}

		private void Form1_Load(object sender, System.EventArgs e)
		{
		
		}

		}
	}

⌨️ 快捷键说明

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