C#课程设计图书馆信息管理系统 下载本文

frmIssueBook issuebook = new frmIssueBook(); issuebook.MdiParent= this; issuebook.Show(); }

private void tsbtnExit_Click(object sender, EventArgs e) { Application.Exit(); }

private void 退出ToolStripMenuItem1_Click(object sender, EventArgs e)

{ Application.Exit(); }

private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)

{ Application.Exit(); }

//窗体载入时事件处理

private void FrmMain_Load(object sender, EventArgs e) { this.tsbtnAddBook.Enabled = false; this.mnuAddBook.Enabled = false;

this.mnuUpdateBook.Enabled = false;}}}

附录B 图书查询实现代码

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; namespace BookManage

{ public partial class frmSearchBook : Form { public frmSearchBook()

{ InitializeComponent(); }

private void btnSerch_Click(object sender, EventArgs e) { string cbo1 = this.cboOR.Text; string cbo2 = this.cboAnd.Text; string booktype = cboType.Text;

string bookname = this.txtName.Text;

string bookcontent = this.txtContent.Text; //定义sql语句

string sql = \ +

20

booktype + \ + cbo1 + \ + bookname + \ + cbo2 + \ + bookcontent + \; //调用DataAccess.GetDataSetBySql方法

DataSet Myds = DataAccess.GetDataSetBySql(sql); DataTable table = Myds.Tables[0]; //指定数据源

this.dgvSearchBook.DataSource = table; }

private void frmSearchBook_Load(object sender, EventArgs e) { //图书类别组合框初始化

DataSet Myds = DataAccess.GetDataSetBySql(\BookType from bookInfo\);

DataTable table = Myds.Tables[0];

for (int i = 0; i < table.Rows.Count; i++)

{ this.cboType.Items.Add(table.Rows[i][0].ToString().Trim()); }

cboType.SelectedIndex = 0; this.cboOR.SelectedIndex = 0; this.cboAnd.SelectedIndex = 0; }

private void btnClose_Click(object sender, EventArgs e) { this.Close(); }}}

附录C 图书更新实现代码

using System;

using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text;

using System.Windows.Forms; using System.Data.SqlClient; namespace BookManage

{ public partial class frmUpdateBook : Form { DataSet ds = new DataSet(); public frmUpdateBook()

{ InitializeComponent(); }

private void frmUpdateBook_Load(object sender, EventArgs e) { string sql = \; ds = DataAccess.GetDataSetBySql(sql);

21

this.dgvBookInfo.DataSource=ds.Tables[0]; this.txtbID.Enabled = false; }

private void txtbPic_TextChanged(object sender, EventArgs e) { }

private void btnUpdate_Click(object sender, EventArgs e) { string booktype = this.txtbType.Text.ToString(); string bookname = this.txtbName.Text.ToString(); string bookauthor = this.txtAuthor.Text.ToString();

Double bookprice = Convert.ToDouble(this.txtbPrice.Text); string bookpic = this.txtbPic.Text.ToString();

string bookcontent = this.txtbContent.Text.ToString(); int bookissue = Convert.ToInt32(this.txtIssueID.Text); string sql = string.Format(\

BookType='{0}',BookName='{1}',BookAuthor='{2}',BookPrice={3},BookPic='{4}',BookContent='{5}',BookIssue={6} where BookID={7}\, booktype, bookname, bookauthor, bookprice, bookpic, bookcontent, bookissue,Convert.ToInt32(this.txtbID.Text)); if (DataAccess.UpdateDataTable(sql)) { MessageBox.Show(\更新成功\, \提示\, MessageBoxButtons.OK); } else

{ MessageBox.Show(\更新失败\, \提示\, MessageBoxButtons.OK); } }

private void btnSave_Click(object sender, EventArgs e) { string sql = \;

DialogResult result = MessageBox.Show(\确实要将修改保存到数据库吗?\, \操作提示\, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

if (result == DialogResult.OK)

{ DataAccess.UpdateDataSet(ds, sql); MessageBox.Show(\保存成功\); }

this.dgvBookInfo.DataSource = DataAccess.GetDataSetBySql(sql).Tables[0]; }

private void dgvBookInfo_CellClick(object sender, DataGridViewCellEventArgs e)

{ //获得当前鼠标单击时的行索引号

int index = this.dgvBookInfo.CurrentCell.RowIndex; //通过索引号获得值并赋予相应的文本框显示

22

this.txtbID.Text =

this.dgvBookInfo.Rows[index].Cells[0].Value.ToString().Trim(); this.txtbType.Text =

this.dgvBookInfo.Rows[index].Cells[1].Value.ToString().Trim(); this.txtbName.Text =

this.dgvBookInfo.Rows[index].Cells[2].Value.ToString().Trim(); this.txtAuthor.Text =

this.dgvBookInfo.Rows[index].Cells[3].Value.ToString().Trim(); this.txtbPrice.Text =

this.dgvBookInfo.Rows[index].Cells[4].Value.ToString().Trim(); this.txtbPic.Text =

this.dgvBookInfo.Rows[index].Cells[5].Value.ToString().Trim(); this.txtbContent.Text =

this.dgvBookInfo.Rows[index].Cells[6].Value.ToString(); this.txtIssueID.Text =

this.dgvBookInfo.Rows[index].Cells[7].Value.ToString(); }

private void btnUpdatePic_Click(object sender, EventArgs e) { string pic = this.txtbPic.Text.ToString();

int bookid = Convert.ToInt32(this.txtbID.Text); frmBookPic bookpic = new frmBookPic(); bookpic.ShowContent(bookid,pic); bookpic.ShowDialog(); }

private void btnDel_Click(object sender, EventArgs e) { DataSet ds = DataAccess.GetDataSetBySql(\IssueInfo where BookID=\+Convert.ToInt32(this.txtbID.Text)+\); if (ds.Tables[0].Rows.Count > 0)

{ MessageBox.Show(\此书有借阅,不能删除\); return; } else

{ string sql = \ + this.txtbID.Text + \;

if (DataAccess.UpdateDataTable(sql)) { MessageBox.Show(\删除成功\, \提示\, MessageBoxButtons.OK); } else

{ MessageBox.Show(\删除失败\, \提示\, MessageBoxButtons.OK); }}

this.txtAuthor.Text = \; this.txtbContent.Text = \;

23