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

📄 reader.cs

📁 C#制作的小型图书馆管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.txt4.TabIndex = 6;
			this.txt4.Text = "";
			// 
			// txt3
			// 
			this.txt3.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者信息.证号"));
			this.txt3.Location = new System.Drawing.Point(16, 40);
			this.txt3.Name = "txt3";
			this.txt3.ReadOnly = true;
			this.txt3.Size = new System.Drawing.Size(88, 21);
			this.txt3.TabIndex = 5;
			this.txt3.Text = "";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(376, 16);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(88, 23);
			this.label7.TabIndex = 4;
			this.label7.Text = "年级";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(264, 16);
			this.label6.Name = "label6";
			this.label6.TabIndex = 3;
			this.label6.Text = "系名";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(208, 16);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(32, 23);
			this.label5.TabIndex = 2;
			this.label5.Text = "性别";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(120, 16);
			this.label4.Name = "label4";
			this.label4.TabIndex = 1;
			this.label4.Text = "姓名";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 17);
			this.label3.Name = "label3";
			this.label3.TabIndex = 0;
			this.label3.Text = "证号";
			// 
			// da1
			// 
			this.da1.DeleteCommand = this.sqlDeleteCommand1;
			this.da1.InsertCommand = this.sqlInsertCommand1;
			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("年级", "年级")})});
			this.da1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = @"DELETE FROM 读者信息 WHERE (证号 = @Original_证号) AND (已借书 = @Original_已借书 OR @Original_已借书 IS NULL AND 已借书 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (性别 = @Original_性别 OR @Original_性别 IS NULL AND 性别 IS NULL) AND (系名 = @Original_系名 OR @Original_系名 IS NULL AND 系名 IS NULL) AND (读者姓名 = @Original_读者姓名 OR @Original_读者姓名 IS NULL AND 读者姓名 IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_证号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "证号", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_已借书", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "已借书", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_性别", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "性别", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_系名", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "系名", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_读者姓名", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "读者姓名", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=YXK;packet size=4096;integrated security=SSPI;data source=YXK;pers" +
				"ist security info=False;initial catalog=library";
			this.sqlConnection1.InfoMessage += new System.Data.SqlClient.SqlInfoMessageEventHandler(this.sqlConnection1_InfoMessage);
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO 读者信息(证号, 读者姓名, 已借书, 性别, 系名, 年级) VALUES (@证号, @读者姓名,@已借书, @性别, @系名, @年" +
				"级); SELECT 证号, 读者姓名, 已借书, 性别, 系名, 年级 FROM 读者信息 WHERE (证号 = @证号)";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@证号", System.Data.SqlDbType.VarChar, 10, "证号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@读者姓名", System.Data.SqlDbType.VarChar, 20, "读者姓名"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@已借书", System.Data.SqlDbType.Int, 4, "已借书"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@性别", System.Data.SqlDbType.VarChar, 2, "性别"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@系名", System.Data.SqlDbType.VarChar, 30, "系名"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 证号, 读者姓名, 已借书, 性别, 系名, 年级 FROM 读者信息 WHERE (证号 LIKE @Param3) AND (读者姓名 LIKE" +
				" @Param4)";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param3", System.Data.SqlDbType.VarChar, 10, "证号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 20, "读者姓名"));
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE 读者信息 SET 证号 = @证号, 读者姓名 = @读者姓名, 已借书 = @已借书, 性别 = @性别, 系名 = @系名, 年级 = @年级 WHERE (证号 = @Original_证号) AND (已借书 = @Original_已借书 OR @Original_已借书 IS NULL AND 已借书 IS NULL) AND (年级 = @Original_年级 OR @Original_年级 IS NULL AND 年级 IS NULL) AND (性别 = @Original_性别 OR @Original_性别 IS NULL AND 性别 IS NULL) AND (系名 = @Original_系名 OR @Original_系名 IS NULL AND 系名 IS NULL) AND (读者姓名 = @Original_读者姓名 OR @Original_读者姓名 IS NULL AND 读者姓名 IS NULL); SELECT 证号, 读者姓名, 已借书, 性别, 系名, 年级 FROM 读者信息 WHERE (证号 = @证号)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@证号", System.Data.SqlDbType.VarChar, 10, "证号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@读者姓名", System.Data.SqlDbType.VarChar, 20, "读者姓名"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@已借书", System.Data.SqlDbType.Int, 4, "已借书"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@性别", System.Data.SqlDbType.VarChar, 2, "性别"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@系名", System.Data.SqlDbType.VarChar, 30, "系名"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@年级", System.Data.SqlDbType.VarChar, 4, "年级"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_证号", System.Data.SqlDbType.VarChar, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "证号", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_已借书", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "已借书", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_年级", System.Data.SqlDbType.VarChar, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "年级", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_性别", System.Data.SqlDbType.VarChar, 2, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "性别", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_系名", System.Data.SqlDbType.VarChar, 30, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "系名", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_读者姓名", System.Data.SqlDbType.VarChar, 20, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "读者姓名", System.Data.DataRowVersion.Original, null));
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(432, 48);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(96, 32);
			this.label8.TabIndex = 8;
			this.label8.Text = "使用证号搜索时去掉前面的0";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(472, 16);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(56, 23);
			this.label9.TabIndex = 10;
			this.label9.Text = "已借书";
			// 
			// txt7
			// 
			this.txt7.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "读者信息.已借书"));
			this.txt7.Location = new System.Drawing.Point(472, 40);
			this.txt7.Name = "txt7";
			this.txt7.ReadOnly = true;
			this.txt7.Size = new System.Drawing.Size(56, 21);
			this.txt7.TabIndex = 11;
			this.txt7.Text = "";
			// 
			// Reader
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.AutoScroll = true;
			this.ClientSize = new System.Drawing.Size(584, 414);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.txt2);
			this.Controls.Add(this.txt1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnSearch);
			this.Controls.Add(this.toolBar1);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Reader";
			this.Text = "读者管理";
			this.Load += new System.EventHandler(this.Reader_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion
		
		private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
		
		}
		

		private void Reader_Load(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.Fill(dataSet11);
			//绑定数据导航
			cmOrders=(CurrencyManager) BindingContext[dataSet11,"读者信息"];
		}

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


		//---------------工具栏事务处理----------------
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.ToolTipText=="新增")
			{
				cmOrders.AddNew();
				txt3.Focus();
				txt3.Text=" ";
				txt7.Text="0";
				SetModifyMode(true);
				
			}
			if(e.Button.ToolTipText=="修改")
			{
				SetModifyMode(true);
			}
			if(e.Button.ToolTipText=="删除")
			{	
				int curRow=dataGrid1.CurrentCell.RowNumber;
				if(dataGrid1[curRow,2].Equals(0))
				{
					DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
					if(result==DialogResult.OK)
						if(cmOrders.Count>0)//立即从数据集中删除
						{
							cmOrders.RemoveAt(cmOrders.Position);						
							da1.Update(dataSet11);
						}
						else
							MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				else
				{
					DialogResult result=MessageBox.Show("读者还有图书未归还,不能删除","提示",MessageBoxButtons.OKCancel);
					return;
				}
				}
			if(e.Button.ToolTipText=="保存")
			{
				if(txt3.Text.Trim()=="")
				{
					MessageBox.Show("请输入证号","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				if(txt4.Text.Trim()=="")
				{
					MessageBox.Show("请输入姓名","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				
				cmOrders.EndCurrentEdit();
				if(dataSet11.GetChanges()!=null)
				{
					try
					{
						da1.Update(dataSet11);
						SetModifyMode(false);
					}
					catch(Exception express)
					{
						MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
						dataSet11.RejectChanges();
					}
				}
				SetModifyMode(false);
				return;
			}
			if(e.Button.ToolTipText=="退出")
			{
				this.Close();
			}

		}

		//--------------对控件的属性做设置---------------
		private void SetModifyMode(bool blnEdit)
		{
			//设置文本框和下拉列表框属性
			txt3.ReadOnly=!blnEdit;
			txt4.ReadOnly=!blnEdit;
			txt5.ReadOnly=!blnEdit;
			txt6.ReadOnly=!blnEdit;
			txt7.ReadOnly=!blnEdit;
			cmb1.Enabled=blnEdit;
		}

		private void sqlConnection1_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
		{
		
		}
	}
}

⌨️ 快捷键说明

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