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

📄 client.cs

📁 C#制作的小型图书馆管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.txt8);
			this.groupBox2.Controls.Add(this.txt7);
			this.groupBox2.Controls.Add(this.label8);
			this.groupBox2.Controls.Add(this.label7);
			this.groupBox2.Controls.Add(this.label6);
			this.groupBox2.Controls.Add(this.txt6);
			this.groupBox2.Controls.Add(this.btnSearch);
			this.groupBox2.Location = new System.Drawing.Point(8, 152);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(632, 72);
			this.groupBox2.TabIndex = 2;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "图书搜索";
			// 
			// txt8
			// 
			this.txt8.Location = new System.Drawing.Point(504, 32);
			this.txt8.Name = "txt8";
			this.txt8.TabIndex = 6;
			this.txt8.Text = "";
			// 
			// txt7
			// 
			this.txt7.Location = new System.Drawing.Point(320, 32);
			this.txt7.Name = "txt7";
			this.txt7.TabIndex = 5;
			this.txt7.Text = "";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(440, 32);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(56, 23);
			this.label8.TabIndex = 4;
			this.label8.Text = "作者";
			this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(256, 32);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(56, 23);
			this.label7.TabIndex = 3;
			this.label7.Text = "书名";
			this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(80, 32);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(48, 23);
			this.label6.TabIndex = 2;
			this.label6.Text = "书号";
			this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// txt6
			// 
			this.txt6.Location = new System.Drawing.Point(136, 32);
			this.txt6.Name = "txt6";
			this.txt6.TabIndex = 1;
			this.txt6.Text = "";
			// 
			// btnSearch
			// 
			this.btnSearch.Image = ((System.Drawing.Image)(resources.GetObject("btnSearch.Image")));
			this.btnSearch.ImageAlign = System.Drawing.ContentAlignment.BottomLeft;
			this.btnSearch.Location = new System.Drawing.Point(16, 32);
			this.btnSearch.Name = "btnSearch";
			this.btnSearch.Size = new System.Drawing.Size(56, 23);
			this.btnSearch.TabIndex = 0;
			this.btnSearch.Text = "搜索";
			this.btnSearch.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			this.btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionVisible = false;
			this.dataGrid1.DataMember = "图书信息";
			this.dataGrid1.DataSource = this.dataSet11;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(8, 232);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(632, 272);
			this.dataGrid1.TabIndex = 3;
			// 
			// dataSet11
			// 
			this.dataSet11.DataSetName = "DataSet1";
			this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// da1
			// 
			this.da1.SelectCommand = this.sqlSelectCommand1;
			this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																						  new System.Data.Common.DataTableMapping("Table", "图书信息", new System.Data.Common.DataColumnMapping[] {
																																																  new System.Data.Common.DataColumnMapping("书号", "书号"),
																																																  new System.Data.Common.DataColumnMapping("书名", "书名"),
																																																  new System.Data.Common.DataColumnMapping("出版社", "出版社"),
																																																  new System.Data.Common.DataColumnMapping("出版日期", "出版日期"),
																																																  new System.Data.Common.DataColumnMapping("作者", "作者"),
																																																  new System.Data.Common.DataColumnMapping("已借出", "已借出"),
																																																  new System.Data.Common.DataColumnMapping("库存", "库存"),
																																																  new System.Data.Common.DataColumnMapping("内容摘要", "内容摘要")})});
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 书号, 书名, 出版社, 出版日期, 作者, 已借出, 库存, 内容摘要 FROM 图书信息 WHERE (书号 LIKE @Param25) AN" +
				"D (书名 LIKE @Param26) AND (作者 LIKE @Param27)";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param25", System.Data.SqlDbType.VarChar, 10, "书号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param26", System.Data.SqlDbType.VarChar, 100, "书名"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param27", System.Data.SqlDbType.VarChar, 200, "作者"));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=YXK;packet size=4096;integrated security=SSPI;data source=YXK;pers" +
				"ist security info=False;initial catalog=library";
			// 
			// Client
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(648, 510);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.toolBar1);
			this.Controls.Add(this.groupBox1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Client";
			this.Text = "【图书馆管理系统客户端】";
			this.Load += new System.EventHandler(this.Client_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		//------------查询并读入读者信息以及读者已经借书的信息------------
		private void txt1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
		{
			if(e.KeyChar==13&&txt1.Text.Trim()!="")
			{
				this.showInfo();//显示读者信息
			}
			
		}

		//----------根据输入的信息,查询图书信息--------
		private void btnSearch_Click(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.SelectCommand.Parameters[2].Value="%%";
			if(txt6.Text!="")
			{
				da1.SelectCommand.Parameters[0].Value="%"+txt6.Text+"%";
			}
			if(txt7.Text!="")
			{
				da1.SelectCommand.Parameters[1].Value="%"+txt7.Text+"%";
			}
			if(txt8.Text!="")
			{
				da1.SelectCommand.Parameters[2].Value="%"+txt8.Text+"%";
			}
			dataSet11.图书信息.Clear();
			da1.Fill(dataSet11);
		}

		//---------------工具栏事务处理----------------
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.ToolTipText=="修改个人信息")
			{
				txt2.Focus();
				SetModifyMode(true);
				
			}

			//------------------显示个人借书信息--------------------------
			if(e.Button.ToolTipText=="个人借阅情况")
			{
				History newFrm=new History();

				newFrm.Show();
			}
			if(e.Button.ToolTipText=="保存个人信息")
			{
				if(txt2.Text.Trim()=="")
				{
					MessageBox.Show("请输入姓名","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				
				string strConn = "workstation id=localhost;Integrated Security=SSPI;database=library";
				SqlConnection cn=new SqlConnection(strConn);
				cn.Open();
				SqlCommand cmd=cn.CreateCommand();			
				cmd.CommandText="update 读者信息 set 读者姓名='"+txt2.Text.Trim()+"',系名='"+txt4.Text.Trim()+"',年级='"+txt5.Text.Trim()+"' where (证号='"+txt1.Text.Trim()+"')";
				SqlDataReader dr=cmd.ExecuteReader();//执行查询,并读入读者数据
				dr.Close();
				SetModifyMode(false);
				return;
			}
			if(e.Button.ToolTipText=="退出客户程序")
			{
				this.Close();
			}
		}

		//--------------对控件的属性做设置---------------
		private void SetModifyMode(bool blnEdit)
		{
			//设置文本框和下拉列表框属性
			txt1.ReadOnly=blnEdit;	//证号不能更改
			txt2.ReadOnly=!blnEdit;
			txt4.ReadOnly=!blnEdit;
			txt5.ReadOnly=!blnEdit;
		}

		//------------------------------显示读者信息-------------------------------
		private void showInfo()
		{
			string strConn = "workstation id=localhost;Integrated Security=SSPI;database=library";
			SqlConnection cn=new SqlConnection(strConn);
			cn.Open();
			SqlCommand cmd=cn.CreateCommand();			
			cmd.CommandText="select 读者姓名,性别,系名,年级 from 读者信息 where (证号='"+txt1.Text.Trim()+"')";
			SqlDataReader dr=cmd.ExecuteReader();//执行查询,并读入读者数据
			dr.Read();
			if(dr.HasRows==false)//如未能查询到读者信息,则提示重新输入
			{
				MessageBox.Show("无此读者,请检查后重新输入证号","错误",MessageBoxButtons.OK,MessageBoxIcon.Error);
				return;
			}
			else
			{				
				txt2.Text=dr.GetValue(0).ToString().Trim();//显示读者信息
				txt3.Text=dr.GetValue(1).ToString().Trim();
				txt4.Text=dr.GetValue(2).ToString().Trim();
				txt5.Text=dr.GetValue(3).ToString().Trim();
				this.ReaderID=txt1.Text.Trim();
			}
			dr.Close();
		}

		//--------------------------初始化数据区--------------------------------------------
		private void Client_Load(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.SelectCommand.Parameters[2].Value="%%";
			dataSet11.图书信息.Clear();
			da1.Fill(dataSet11);
			cmOrders=(CurrencyManager) BindingContext[dataSet11,"图书信息"];
		}
	}
}

⌨️ 快捷键说明

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