dataGridView2.DataSource = bs; }
private void button5_Click(object sender, EventArgs e) {
string sql = \;
ada.SelectCommand = new SqlCommand(sql, con); ds.Clear();
ada.Fill(ds, \); bs.DataSource = ds; bs.DataMember = \; dataGridView1.DataSource = bs; }
private void button6_Click(object sender, EventArgs e) {
string sql = \;
ada.SelectCommand = new SqlCommand(sql, con); ds.Clear();
ada.Fill(ds, \); bs.DataSource = ds; bs.DataMember = \; dataGridView1.DataSource = bs; }
private void button7_Click(object sender, EventArgs e) {
string sql = \ + textBox1.Text.Trim() + \;
SqlCommand cmd = new SqlCommand(sql, con); int a = cmd.ExecuteScalar(); if(a=0) {
MessageBox.Show(\借书数量已满,请还书后再借!\); return; }
string _sql = \ + textBox3.Text.Trim() + \; SqlCommand cmd = new SqlCommand(_sql, con); int b = cmd.ExecuteScalar(); if(b=0) {
MessageBox.Show(\此书已全部被借出,不能借阅\); } else {
string sql = \@user_name, @book_id, @jstime)\;
SqlCommand sqlcmd = new SqlCommand(sql, con);
sqlcmd.Parameters.AddWithValue(\, textBox1.Text); sqlcmd.Parameters.AddWithValue(\, textBox2.Text); sqlcmd.Parameters.AddWithValue(\, textBox3.Text); sqlcmd.Parameters.AddWithValue(\, dateTimePicker1.Value);
string sqlstr=\; string _sql=\; SqlCommand cmd = new SqlCommand(sqlstr, con); SqlCommand ddd = new SqlCommand(_sql,con);
cmd.Parameters.AddWithValue(\, textBox1.Text); ddd.Parameters.AddWithValue(\, textBox3.Text); try {
con.Open();
sqlcmd.ExecuteNonQuery(); cmd.ExecuteNonQuery(); ddd.ExecuteNonQuery(); con.Close();
MessageBox.Show(\借阅成功\); }
catch (DataException ex) { MessageBox.Show(ex.Message); } finally {
dataGridView3.DataSource = bs; } } }
private void button8_Click(object sender, EventArgs e) {
this.Close(); }
private void button9_Click(object sender, EventArgs e) {
string sql = \ + textBox4.Text.Trim() + \; ada.SelectCommand = new SqlCommand(sql, con); dataGridView2.DataSource = null; ada.Fill(ds, \); bs.DataSource = ds; bs.DataMember = \; if (bs.Count <= 0)
MessageBox.Show(\表中无此书籍\);
else
dataGridView2.DataSource = bs; }
} }
5.1归还图书模块设计 5.1.1界面设计
5.1.2算法设计
在“更新”按钮的Click事件代码中编写代码,采用ADO.Net技术实现数据库的访问,在数据库的jhbook表中查询读者信息记录,用SqlDataReader对象读取,然后显
示出所有的读者借阅图书信息记录。
在“查询”按钮的Click事件代码中编写代码,采用ADO.Net技术实现数据库的访问,在数据库的jhbook表中查询读者信息记录,用SqlDataReader对象读取,然后显示出查询的读者借阅图书信息记录。
在“归还图书”按钮的Click事件代码中编写代码,将读者要借的图书信息与读者的信息绑定写入数据库借阅图书表(jHbook表)中 。 5.1.3代码实现
using System;
using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;
using System.Windows.Forms; using System.Data.SqlClient;
namespace WindowsApplication1 {
public partial class 归还图书 : Form {
public 归还图书() {
InitializeComponent(); }
private void 归还图书_Load(object sender, EventArgs e) {
// TODO: 这行代码将数据加载到表“tsglxtDataSet.borrower_reader”中。您可以根据需要移动或移除它。
this.borrower_readerTableAdapter.Fill(this.tsglxtDataSet.borrower_reader);
// TODO: 这行代码将数据加载到表“tsglxtDataSet.book”中。您可以根据需要移动或移除它。 this.bookTableAdapter.Fill(this.tsglxtDataSet.book);
// TODO: 这行代码将数据加载到表“tsglxtDataSet.JHbook”中。您可以根据需要移动或移除它。 this.jHbookTableAdapter.Fill(this.tsglxtDataSet.JHbook); }
SqlConnection con = new SqlConnection(\Security=True\);
DataSet ds = new DataSet();
SqlDataAdapter ada = new SqlDataAdapter(); BindingSource bs = new BindingSource();
private void button1_Click(object sender, EventArgs e)
相关推荐: