您好,欢迎光临本网站![请登录][注册会员]  
文件名称: 图书管理系统
  所属分类: C/C++
  开发工具:
  文件大小: 7mb
  下载次数: 0
  上传时间: 2015-11-13
  提 供 者: a18936******
 详细说明: namespace LibraryManager { public partial class MainForm : Form { public MainForm() { InitializeComponent(); } private void MainForm_Load(object sender, EventArgs e) { Tool.InitCategoryData(cbCategoy); } #region 数据初始化 private void tsbCategory_Click(object sender, EventArgs e) { CategoryForm cf = new CategoryForm(); cf.ShowDialog(); } private void ShowData(int categoryID) { ///创建LibraryManagerDB数据库的数据上下文 LibraryManagerDBDataContext db = new LibraryManagerDBDataContext(LibraryManager.Properties.Settings.Default.LibraryManagerDBConnectionString); ///查询数据 var result = from b in db.Book join bc in db.BookCategory on b.ID equals bc.BookID where bc.CategoryID == categoryID orderby b.PublishDate descending select b; ///设置dgvBook控件的数据源 dgvBook.DataSource = result; dgvBook.AutoGenerateColumns = false; ///排列列显示的顺序 int index = 0; dgvBook.Columns["cName"].DisplayIndex = index++; dgvBook.Columns["cISBN"].DisplayIndex = index++; dgvBook.Columns["cAuthor"].DisplayIndex = index++; dgvBook.Columns["cPublish"].DisplayIndex = index++; dgvBook.Columns["cPublishDate"].DisplayIndex = index++; dgvBook.Columns["cStore"].DisplayIndex = index++; dgvBook.Columns["cBorrowNumber"].DisplayIndex = index++; dgvBook.Columns["cUpdate"].DisplayIndex = index++; dgvBook.Columns["cDelete"].DisplayIndex = index++; ///设置列的可见性 for (int i = 0; i < dgvBook.Columns.Count; i++) { DataGridViewColumn c = dgvBook.Columns[i]; if (c.DisplayIndex > index - 1) c.Visible = false; c.SortMode = DataGridViewColumnSortMode.NotSortable; } dgvBook.Columns["cUpdate"].Width = 40; dgvBook.Columns["cDelete"].Width = 40; ///设置行显示的值 foreach (DataGridViewRow row in dgvBook.Rows) { row.HeaderCell.Value = (row.Index + 1).ToString(); if (Int32.Parse(row.Cells["cBorrowNumber"].Value.ToString()) > 0) { row.Cells["cDelete"].Value = string.Empty; } else { row.Cells["cDelete"].Value = "删除"; } } ///设置按钮的可用性 if (dgvBook.CurrentRow != null) { Book book = result.ToList()[dgvBook.CurrentRow.Index]; btnLend.Enabled = (book.Status.Value == 2 || book.Store <= 0) ? false : true; } } private void dgvBook_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void dgvBook_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e) { ///设置借阅书籍按钮的可用性 if (e.RowIndex < 0 || e.RowIndex > dgvBook.Rows.Count - 1) return; Book book = ((IQueryable)dgvBook.DataSource).ToList()[e.RowIndex]; btnLend.Enabled = (book.Status.Value == 2 || book.Store <= 0) ? false : true; } #endregion #region 按钮事件设计 private void pbCategory_Click(object sender, EventArgs e) { ///打开分类管理的对话框 CategoryForm cf = new CategoryForm(); cf.ShowDialog(); } private void cbCategoy_SelectedIndexChanged_1(object sender, EventArgs e) { ///显示书籍的数据 try { ShowData(((Category)cbCategoy.SelectedItem).ID); } catch (Exception ex) { Console.WriteLine(ex); } } private void btnLend_Click(object sender, EventArgs e) { ///打开借阅书籍的对话框 LendForm lf = new LendForm(); IQueryable books = ((IQueryable)dgvBook.DataSource); lf.BookID = books.ToList()[dgvBook.CurrentRow.Index].ID; if (lf.ShowDialog() == DialogResult.OK) { ShowData(((Category)cbCategoy.SelectedItem).ID); } } private void btnAdd_Click_1(object sender, EventArgs e) { ///打开添加书籍的对话框 BookForm bf = new BookForm(); if (bf.ShowDialog() == DialogResult.OK) { ShowData(((Category)cbCategoy.SelectedItem).ID); } } private void MainForm_FormClosed(object sender, FormClosedEventArgs e) { ///退出应用程序 Application.Exit(); } #endregion private void pLeft_Paint_1(object sender, PaintEventArgs e) { ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle, Border3DStyle.Etched, Border3DSide.Right); } private void pBottom_Paint_1(object sender, PaintEventArgs e) { ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle, Border3DStyle.Etched, Border3DSide.Top); } private void label1_Click(object sender, EventArgs e) { } private void pbCategory_Click_1(object sender, EventArgs e) { ///打开分类管理的对话框 CategoryForm cf = new CategoryForm(); cf.ShowDialog(); } private void dgvBook_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { ///判断列索引是否合法 if (e.ColumnIndex < 0 || e.ColumnIndex > dgvBook.Columns.Count - 1) return; if (dgvBook.Columns[e.ColumnIndex].Name == "cBorrowNumber") { ///打开查看借阅书籍用户的对话框 LendUserInfoForm luif = new LendUserInfoForm(); IQueryable books = ((IQueryable)dgvBook.DataSource); luif.BookID = books.ToList()[e.RowIndex].ID; luif.ShowDialog(); } if (dgvBook.Columns[e.ColumnIndex].Name == "cUpdate") { ///打开修改书籍的对话框 BookForm bf = new BookForm(); IQueryable books = ((IQueryable)dgvBook.DataSource); bf.BookID = books.ToList()[e.RowIndex].ID; if (bf.ShowDialog() == DialogResult.OK) { ///更新数据 ShowData(((Category)cbCategoy.SelectedItem).ID); } } if (dgvBook.Columns[e.ColumnIndex].Name == "cDelete") { if (MessageBox.Show("确定要删除该书籍吗?", "删除书籍询问对话框", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { ///创建LibraryManagerDB数据库的数据上下文 LibraryManagerDBDataContext db = new LibraryManagerDBDataContext(LibraryManager.Properties.Settings.Default.LibraryManagerDBConnectionString); ///查询被删除的书籍 IQueryable books = ((IQueryable)dgvBook.DataSource); var deleteBooks = db.Book.Where(b => b.ID == books.ToList()[e.RowIndex].ID); ///删除数据,并提交到数据库中 db.Book.DeleteAllOnSubmit(deleteBooks); db.SubmitChanges(); MessageBox.Show("恭喜您,删除书籍成功!"); } } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)

下载文件列表

相关说明

  • 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
  • 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度
  • 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
  • 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
  • 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
  • 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.
 相关搜索: 图书管理系统 vs
 输入关键字,在本站1000多万海量源码库中尽情搜索: