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

📄 book.cs

📁 C#制作的小型图书馆管理系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// 
			this.label9.Location = new System.Drawing.Point(8, 80);
			this.label9.Name = "label9";
			this.label9.TabIndex = 8;
			this.label9.Text = "备注";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(400, 16);
			this.label8.Name = "label8";
			this.label8.TabIndex = 7;
			this.label8.Text = "出版日期";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(296, 16);
			this.label7.Name = "label7";
			this.label7.TabIndex = 6;
			this.label7.Text = "出版社";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(216, 16);
			this.label6.Name = "label6";
			this.label6.TabIndex = 5;
			this.label6.Text = "作者";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(112, 16);
			this.label5.Name = "label5";
			this.label5.TabIndex = 4;
			this.label5.Text = "书名";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(8, 16);
			this.label4.Name = "label4";
			this.label4.TabIndex = 3;
			this.label4.Text = "书号";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(80, 56);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(48, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "书号";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(256, 56);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(48, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "书名";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(432, 56);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(48, 23);
			this.label3.TabIndex = 2;
			this.label3.Text = "作者";
			// 
			// txt2
			// 
			this.txt2.Location = new System.Drawing.Point(312, 56);
			this.txt2.Name = "txt2";
			this.txt2.TabIndex = 6;
			this.txt2.Text = "";
			// 
			// txt3
			// 
			this.txt3.Location = new System.Drawing.Point(480, 56);
			this.txt3.Name = "txt3";
			this.txt3.TabIndex = 7;
			this.txt3.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("已借出", "已借出"),
																																																  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) 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, 20, 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, 100, 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, 200, 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.DateTime, 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, 50, 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.Int, 4, 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";
			// 
			// 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, 20, "书号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@书名", System.Data.SqlDbType.VarChar, 100, "书名"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@出版社", System.Data.SqlDbType.VarChar, 50, "出版社"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@出版日期", System.Data.SqlDbType.DateTime, 4, "出版日期"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@作者", System.Data.SqlDbType.VarChar, 200, "作者"));
			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.Int, 4, "库存"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@内容摘要", System.Data.SqlDbType.NVarChar, 1073741823, "内容摘要"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 书号, 书名, 出版社, 出版日期, 作者, 已借出, 库存, 内容摘要 FROM 图书信息 WHERE (书号 LIKE @Param4) AND" +
				" (书名 LIKE @Param5) AND (作者 LIKE @Param6)";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param4", System.Data.SqlDbType.VarChar, 20, "书号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param5", System.Data.SqlDbType.VarChar, 100, "书名"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Param6", System.Data.SqlDbType.VarChar, 200, "作者"));
			// 
			// 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) 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, 20, "书号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@书名", System.Data.SqlDbType.VarChar, 100, "书名"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@出版社", System.Data.SqlDbType.VarChar, 50, "出版社"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@出版日期", System.Data.SqlDbType.DateTime, 4, "出版日期"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@作者", System.Data.SqlDbType.VarChar, 200, "作者"));
			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.Int, 4, "库存"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@内容摘要", System.Data.SqlDbType.NVarChar, 1073741823, "内容摘要"));
			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));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_书名", System.Data.SqlDbType.VarChar, 100, 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, 200, 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.DateTime, 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, 50, 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.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "库存", System.Data.DataRowVersion.Original, null));
			// 
			// label11
			// 
			this.label11.Location = new System.Drawing.Point(448, 80);
			this.label11.Name = "label11";
			this.label11.Size = new System.Drawing.Size(48, 23);
			this.label11.TabIndex = 17;
			this.label11.Text = "已借出";
			// 
			// txt11
			// 
			this.txt11.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "图书信息.已借出"));
			this.txt11.Location = new System.Drawing.Point(448, 104);
			this.txt11.Name = "txt11";
			this.txt11.ReadOnly = true;
			this.txt11.Size = new System.Drawing.Size(48, 21);
			this.txt11.TabIndex = 18;
			this.txt11.Text = "";
			// 
			// Book
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.AutoScroll = true;
			this.ClientSize = new System.Drawing.Size(592, 478);
			this.Controls.Add(this.txt3);
			this.Controls.Add(this.txt2);
			this.Controls.Add(this.txt1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btnSearch);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.toolBar1);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label3);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.Name = "Book";
			this.Text = "图书管理";
			this.Load += new System.EventHandler(this.Book_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void Book_Load(object sender, System.EventArgs e)
		{
			da1.SelectCommand.Parameters[0].Value="%%";
			da1.SelectCommand.Parameters[1].Value="%%";
			da1.SelectCommand.Parameters[2].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="%%";
			da1.SelectCommand.Parameters[2].Value="%%";
			if(txt1.Text!="")
			{
				da1.SelectCommand.Parameters[0].Value="%"+txt1.Text+"%";
			}
			
			if(txt2.Text!="")
			{
				da1.SelectCommand.Parameters[1].Value="%"+txt2.Text+"%";
			}
			if(txt3.Text!="")
			{
				da1.SelectCommand.Parameters[2].Value="%"+txt3.Text+"%";
			}
			dataSet11.图书信息.Clear();
			da1.Fill(dataSet11);
		}

		//---------------工具栏事务处理----------------
		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.ToolTipText=="新增")
			{

				cmOrders.AddNew();
				txt4.Focus();
				//设置默认值
				txt4.Text =" ";
				txt11.Text ="0";
				SetModifyMode(true);				
			}
			if(e.Button.ToolTipText=="修改")
			{
				SetModifyMode(true);
			}
			if(e.Button.ToolTipText=="删除")
			{		
				int curRow=dataGrid1.CurrentCell.RowNumber;
				if(dataGrid1[curRow,5].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(txt4.Text.Trim()=="")
				{
					MessageBox.Show("请输入书号","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
					return;
				}
				if(txt5.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)
		{
			//设置文本框和下拉列表框属性
			txt4.ReadOnly=!blnEdit;
			txt5.ReadOnly=!blnEdit;
			txt6.ReadOnly=!blnEdit;
			txt7.ReadOnly=!blnEdit;
			txt8.ReadOnly=!blnEdit;
			txt9.ReadOnly=!blnEdit;
			txt10.ReadOnly=!blnEdit;
			txt11.ReadOnly=!blnEdit;
		}
	}
}

⌨️ 快捷键说明

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