} } } }
3.4图书查询窗体设计
图书查询窗体通过输入图书名称查询出作者,出版社,数量。图书查询窗体文件名设计为“Form2.cs”.
3.4.1界面设计
在该窗体上添加5个Label、5个TextBox、3个Button控件,其中图书查询窗体及其主要控件的属性设置如表3-7所示。
图3-7 图书查询
3.4.2代码设计:(关键代码) namespace feng {
public partial class Selectbook : Form {
public Selectbook() {
InitializeComponent(); }
14
private void button1_Click(object sender, EventArgs e) { }
private void button2_Click(object sender, EventArgs e) {
Formmain formmain = new Formmain(); formmain.Show(); this.Hide(); }
private void button1_Click_1(object sender, EventArgs e) {
Borrowbook borrowbook = new Borrowbook(); borrowbook.Show(); }
Private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { }
private void button3_Click(object sender, EventArgs e) {
SqlConnection sqlcon = new SqlConnection(\Source=.;Initial Catalog=图书馆借阅系统;Integrated Security=True\ sqlcon.Open();
string str = \查询 where bookid=@bookid or bookname=@bookname or bookauthor=@bookauthor or bookpub=@bookpub or bookstate=@bookstate\
SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(\ cmd.Parameters.Add(\ cmd.Parameters.Add(\50);
cmd.Parameters.Add(\ cmd.Parameters.Add(\SqlDbType.VarChar, 50); cmd.Parameters[\
15
cmd.Parameters[\ cmd.Parameters[\this.textBox3.Text;
cmd.Parameters[\ cmd.Parameters[\= this.textBox5.Text; this.textBox1.Text = \ this.textBox2.Text = \ this.textBox3.Text = \ this.textBox4.Text = \ this.textBox5.Text = \
SqlDataReader dr = cmd.ExecuteReader(); while (dr.Read()) {
this.textBox1.Text = dr[\ this.textBox2.Text = dr[\ this.textBox3.Text = dr[\ this.textBox4.Text = dr[\ this.textBox5.Text = dr[\ } } } }
3.5图书新增窗体设计
图书新增窗体作为系统的启动窗体,用于对新书入库,其运行界面如图1-13所示。登录窗体文件名设计为“Form3.cs”
16
.
3.5.1界面设计
在该窗体上添加4个Label、4个TextBox、2个Button控件,其中图书增加窗体及其主要控件的属性设置如表3-8所示。
图3-8 图书新增
3.5.2代码设计:(关键代码)
namespace feng {
public partial class Addbook : Form {
public Addbook() {
InitializeComponent(); }
private void button1_Click(object sender, EventArgs e) {
SqlConnection sqlcon = new SqlConnection(\source=.;Initial Catalog=图书馆借阅系统;Integrated Security=True\
String str = \新增 values(@bookid,@bookname,@bookauthor,@bookpub)\ sqlcon.Open();
// SqlCommand cmd = new SqlCommand(\新增
17
(bnum,bname,bauthor,bpub,) values('\textBox2.Text + \sqlcon);
SqlCommand cmd = new SqlCommand(str, sqlcon); cmd.Parameters.Add(\ cmd.Parameters.Add(\ cmd.Parameters.Add(\50);
cmd.Parameters.Add(\
cmd.Parameters[\ cmd.Parameters[\ cmd.Parameters[\ cmd.Parameters[\
cmd.ExecuteNonQuery();
sqlcon.Close();
MessageBox.Show(\——添加成功!——\ this.textBox1.Clear(); this.textBox2.Clear(); this.textBox3.Clear(); this.textBox4.Clear(); }
private void button2_Click(object sender, EventArgs e) {
Formmain formmain = new Formmain(); formmain.Show();
18