《系统源代码.doc》由会员分享,可在线阅读,更多相关《系统源代码.doc(18页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、namespace BookManage public partial class frmLogin : Form public frmLogin() InitializeComponent(); private void btnLogin_Click(object sender, EventArgs e) /验证通过 if (Validate() string state = this.cboUserType.Text; int num; if (state.Equals(管理员)/判断用户角色 num = 1; else if (state.Equals(后台管理) num = 2; el
2、se num = 3; /定义查询语句 string sql = string.Format(select * from userinfo where uname=0and upwd=1 and ustate=2, this.txName.Text.Trim(),this.txtPwd.Text.Trim(),num); DataSet ds = DataAccess.GetDataSetBySql(sql); if (ds.Tables0.Rows.Count 0) MessageBox.Show(登录成功); Constans.UserBookID = ds.Tables0.Rows0UB
3、ookID.ToString(); Constans.UserName = ds.Tables0.Rows0UName.ToString(); Constans.UserState = ds.Tables0.Rows0UState.ToString(); if(num=1) frmMain.result = DialogResult.OK; this.Hide(); frmMain main = new frmMain(); main.ShowDialog(); else if (num = 2) frmBookInStore store = new frmBookInStore(); sto
4、re.ShowDialog(); else frmBookJY jy = new frmBookJY(); jy.ShowDialog(); else MessageBox.Show(用户名或密码错误); private void frmLogin_Load(object sender, EventArgs e) this.cboUserType.SelectedIndex = 0; /验证方法 private bool Vaildate() if (this.txName.Text != string.Empty & this.txtPwd.Text != string.Empty) ret
5、urn true; else MessageBox.Show(用户名或密码不能为空); return false; private void btnCancle_Click(object sender, EventArgs e) this.Close(); namespace BookManage public partial class frmMain : Form public static DialogResult result; public frmMain() InitializeComponent(); /查询子窗体是否存在 public bool checkchildfrm(st
6、ring childfrmname) foreach (Form childFrm in this.MdiChildren) if (childFrm.Name = childfrmname) if (childFrm.WindowState = FormWindowState.Minimized) childFrm.WindowState = FormWindowState.Normal; childFrm.Activate(); return true; return false; /用户登录菜单的事件处理 private void 用户登录ToolStripMenuItem_Click(
7、object sender, EventArgs e) /检测该窗口是否处于打开状态 if (this.checkchildfrm(frmLogin) = true) return; /窗口已经打开,返回 frmLogin user = new frmLogin();/实例化登录窗体 user.ShowDialog(); /登录窗体以模式对话框的方式的打开 /判断是否登录成功,登录成功则启用相应的菜单和按钮 if (result = DialogResult.OK) this.tsbtnAddBook.Enabled = true; this.mnuUpdateBook.Enabled = t
8、rue; this.mnuAddBook.Enabled = true; /登录按钮事件处理 private void tsbtnLogin_Click(object sender, EventArgs e) if (this.checkchildfrm(frmLogin) = true) return; frmLogin user = new frmLogin(); user.ShowDialog(); if (result = DialogResult.OK) this.tsbtnAddBook.Enabled = true; this.mnuUpdateBook.Enabled = tr
9、ue; this.mnuAddBook.Enabled = true; /图书查询按钮Click事件处理 private void tsbtnSearch_Click(object sender, EventArgs e) frmBookSearch frmbs = new frmBookSearch(); frmbs.ShowDialog(); /图书检索菜单Click事件处理 private void 图书检索ToolStripMenuItem_Click(object sender, EventArgs e) frmBookSearch frmbs = new frmBookSearch
10、(); frmbs.ShowDialog(); /图书入库菜单Click事件处理 private void 图书入库ToolStripMenuItem1_Click(object sender, EventArgs e) frmBookInStore bookinstore = new frmBookInStore(); bookinstore.ShowDialog(); /图书入库按钮Click事件处理 private void tsbtnAddBook_Click(object sender, EventArgs e) frmTsgx tsgx = new frmTsgx(); tsgx.
11、ShowDialog(); /图书更新菜单Click事件处理 private void 图书修改ToolStripMenuItem_Click(object sender, EventArgs e) frmTsgx tsgx = new frmTsgx(); tsgx.ShowDialog(); /图书借阅按钮事件处理 private void tsbtnIssue_Click(object sender, EventArgs e) frmBookJY bookjy = new frmBookJY(); bookjy.ShowDialog(); private void tsbtnExit_C
12、lick(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.t
13、sbtnAddBook.Enabled = false; /this.mnuAddBook.Enabled = false; /this.mnuUpdateBook.Enabled = false; /在关闭主窗体的同时,关闭整个系统 private void frmMain_FormClosed(object sender, FormClosedEventArgs e) Application.Exit(); private void 图书借阅ToolStripMenuItem_Click(object sender, EventArgs e) frmBookJY bookJy = new
14、frmBookJY(); bookJy.ShowDialog(); private void 图书归还ToolStripMenuItem_Click(object sender, EventArgs e) frmBookReturn frmreturn = new frmBookReturn(); frmreturn.ShowDialog(); private void 注册ToolStripMenuItem_Click(object sender, EventArgs e) frmUserZC zc = new frmUserZC(); zc.ShowDialog(); namespace
15、BookManage public partial class frmBookInStore : Form public frmBookInStore() InitializeComponent(); private void BookInStore_Load(object sender, EventArgs e) DataSet Myds = DataAccess.GetDataSetBySql(select * from BookInfo); DataTable table = Myds.Tables0; this.dataGridView1.DataSource = table; pri
16、vate void btnExit_Click(object sender, EventArgs e) this.Close(); private void btnInsert_Click(object sender, EventArgs e) string bookname = this.txtBookName.Text; string booktype = this.txtBookType.Text; string author = this.txtAuthor.Text; string cbs = this.txtCBS.Text;/出版商 int kc =Convert.ToInt32
17、( this.txtKC.Text);/库存 int kjysl =Convert.ToInt32( this.txtKJY.Text);/可借阅数量 string sql = string.Format(insert into BookInfo values(0,1,2,3,4,5), booktype,bookname, author, cbs, kc, kjysl); if (DataAccess.UpdateDataTable(sql) MessageBox.Show(添加成功!, 提示); else MessageBox.Show(添加失败!,提示,MessageBoxButtons
18、.OK); DataSet Myds = DataAccess.GetDataSetBySql(select * from BookInfo); DataTable table=Myds.Tables0; this.dataGridView1.DataSource = table; public bool Validate() return true; namespace BookManage public partial class frmTsgx : Form public frmTsgx() InitializeComponent(); private void btnClose_Cli
19、ck(object sender, EventArgs e) this.Close(); private void frmTsgx_Load(object sender, EventArgs e) DataSet Myds = DataAccess.GetDataSetBySql(select * from BookInfo); DataTable table = Myds.Tables0; dataGridView1.DataSource = table; private void dataGridView1_CellContentClick(object sender, DataGridV
20、iewCellEventArgs e) int index = dataGridView1.CurrentCell.RowIndex; this.textBox1.Text = this.dataGridView1.Rowsindex.Cells0.Value.ToString().Trim();/图书编号 this.textBox2.Text = this.dataGridView1.Rowsindex.Cells2.Value.ToString().Trim();/图书名称 this.textBox3.Text = this.dataGridView1.Rowsindex.Cells1.V
21、alue.ToString().Trim();/图书类型 this.textBox4.Text = this.dataGridView1.Rowsindex.Cells3.Value.ToString().Trim();/图书作者 this.textBox5.Text = this.dataGridView1.Rowsindex.Cells4.Value.ToString().Trim();/出版商 this.textBox6.Text = this.dataGridView1.Rowsindex.Cells5.Value.ToString().Trim();/库存 this.textBox7
22、.Text = this.dataGridView1.Rowsindex.Cells6.Value.ToString().Trim();/可借阅的数量 private void btnUpdate_Click(object sender, EventArgs e) string bookname = textBox2.Text.ToString().Trim(); string booktype = textBox3.Text.ToString().Trim(); string bookauthor = textBox4.Text.ToString().Trim(); string bookp
23、ublish = textBox5.Text.ToString().Trim(); int bookkc = Convert.ToInt32(textBox6.Text.Trim(); int bookjysl = Convert.ToInt32(textBox7.Text.Trim(); string sql = string.Format(update BookInfo set BookName=0,BookType=1,BookAuthor=2,BookPublish=3,BookKC=4,BookJYSL=5 where BookID=6,bookname,booktype,booka
24、uthor,bookpublish,bookkc,bookjysl,Convert.ToInt32(textBox1.Text); if (DataAccess.UpdateDataTable(sql) MessageBox.Show(更新成功!, 提示, MessageBoxButtons.OK); else MessageBox.Show(更新失败!,提示,MessageBoxButtons.OK); private void btnSaveEdit_Click(object sender, EventArgs e) string sql = select * from BookInfo;
25、 DataSet ds = DataAccess.GetDataSetBySql(sql); DialogResult result = MessageBox.Show(您确实要将修改保存到数据库中吗?,操作提示,MessageBoxButtons.OKCancel,MessageBoxIcon.Question); if(result=DialogResult.OK) DataAccess.UpdateDataSet(ds,sql); MessageBox.Show(保存成功!); dataGridView1.DataSource = DataAccess.GetDataSetBySql(s
26、ql).Tables0; namespace BookManage public partial class frmBookSearch : Form public frmBookSearch() InitializeComponent(); private void btnClose_Click(object sender, EventArgs e) this.Close(); private void btnSearch_Click(object sender, EventArgs e) /string cbo1 = this.cboBookType.Text; string bookty
27、pe = this.cboType2.Text; string bookname = this.txtBookName.Text; string sql=select * from BookInfo where BookType=+booktype+and BookName like %+bookname+%; DataSet Myds = DataAccess.GetDataSetBySql(sql); DataTable table = Myds.Tables0; this.dataGridView1.DataSource = table; private void frmBookSear
28、ch_Load(object sender, EventArgs e) DataSet Myds = DataAccess.GetDataSetBySql(select distinct BookType from BookInfo); DataTable table = Myds.Tables0; for (int i = 0; i table.Rows.Count; i+) /this.cboBookType.Items.Add(table.Rowsi0.ToString().Trim(); this.cboType2.Items.Add(table.Rowsi0.ToString().T
29、rim(); / this.cboBookType.SelectedIndex = 0; this.cboType2.SelectedIndex = 0; namespace BookManage public partial class frmBookReturn : Form public frmBookReturn() InitializeComponent(); private void button2_Click(object sender, EventArgs e) this.Close(); private void btnSearch_Click(object sender,
30、EventArgs e) string userbookid = textBox1.Text; string sql=string.Format(select * from IssueInfo where UserBookID=0,userbookid); DataSet Myds = DataAccess.GetDataSetBySql(sql); DataTable table = Myds.Tables0; dataGridView1.DataSource = table; private void button1_Click(object sender, EventArgs e) Da
31、teTime time = Convert.ToDateTime(this.textBox9.Text); string bo = boBox2.Text.ToString(); string sql =string.Format( update IssueInfo set ghDateTime=0,Bool=1 where IssID=2,time,bo,Convert.ToInt32(textBox15.Text); if (DataAccess.UpdateDataTable(sql) MessageBox.Show(还书成功!, 提示, MessageBoxButtons.OK); s
32、tring sql2 = string.Format(update BookInfo set BookKC=BookKC+1 where BookID=0,Convert.ToInt32( this.textBox14.Text.ToString().Trim(); string sq = string.Format(update UserIssue set BookKC=BookKC-1 where UserBookID=0, this.textBox15.Text.ToString(); DataAccess.UpdateDataTable(sql2); DataAccess.UpdateDataTable(sq); else MessageBox.Show(还书失败!,提示,MessageBoxButtons.OK);