private void borrow_btn_Click(object sender, EventArgs e) { fill_borrow(); if (rb_borrow_bk.Checked == false) { rb_borrow_bk.Checked = true; MessageBox.Show("请重新选择读者和书本", "qoq", MessageBoxButtons.OK); } DialogResult br_power = DialogResult.Cancel; if (rd.rdStatus.Equals("有效") && bk.bkStatus.Equals("在馆")) { br_power = MessageBox.Show("可以借书,确定借阅?(Y?N)", "lol", MessageBoxButtons.OKCancel); } else if (rd.rdStatus.Equals("有效")) { MessageBox.Show("很抱歉书本不在馆,不能借阅", "qoq", MessageBoxButtons.OK); } else if (bk.bkStatus.Equals("在馆")) { MessageBox.Show("很抱歉读者证已失效,不能借阅", "qoq", MessageBoxButtons.OK); } if (br_power == DialogResult.OK) { string sql_canlendbk = string.Format("select dbo.ReaderType.CanLendQty from dbo.ReaderType where ReaderType.rdType = (select rdType from dbo.Reader where rdID = '{0}')", rd.rdID); int rd_canlendbk = Convert.ToInt32(Reader_ad.rd_sel(sql_canlendbk)); string sql_allendbk = string.Format("select rdBorrowQty from dbo.reader where rdID = '{0}'", rd.rdID); int rd_allendbk = Convert.ToInt32(Reader_ad.rd_sel(sql_allendbk)); if (rd_allendbk < rd_canlendbk) { bk.bkStatus = "借出"; //Book对象状态 rd.rdBorrowQty = string.Format("{0}", ++rd_allendbk); //Reader对象更改后书籍数量 if (Borrow_ad.run_insql(br, 0)) { Reader_ad.run_insql(rd, 2); //更新读者已借书本数 Book_ad.run_insql(bk, 1); //更新Reader rd书本状态 MessageBox.Show(string.Format("\"{0}\"借阅\"{1}\"成功!", rd.rdName, bk.bkName), "lol", MessageBoxButtons.OK); } rd_refresh_Click(null, null); bk_refresh_Click(null, null); } else { MessageBox.Show(string.Format("\"{0}\"借阅\"{1}\"失败!", rd.rdName, bk.bkName), "lol", MessageBoxButtons.OK, MessageBoxIcon.Error); } } br = new Borrow();// 清空borrow对象数据 }
private void return_btn_Click(object sender, EventArgs e) { if (rb_return_bk.Checked == false) { rb_return_bk.Checked = true; MessageBox.Show("请重新选择读者和书本", "qoq", MessageBoxButtons.OK); } else { fill_borrow_b(); if (br.BorrowID.Equals("") || br.bkID.Equals("") || br.rdID.Equals("")) { MessageBox.Show("请输入(借阅号 或 书本号 或 读者号)", "qoq", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); return; } DialogResult rt_power = DialogResult.Cancel; rt_power = MessageBox.Show("可以还书,确定退还?(Y?N)", "lol", MessageBoxButtons.OKCancel); if (rt_power == DialogResult.OK) { if (Borrow_ad.run_insql(br, 1)) { bk.bkStatus = "在馆"; string sql_allendbk = string.Format("select rdBorrowQty from dbo.reader where rdID = '{0}'", rd.rdID); int rd_allendbk = Convert.ToInt32(Reader_ad.rd_sel(sql_allendbk)); rd.rdBorrowQty = string.Format("{0}", --rd_allendbk); Console.WriteLine(string.Format("{0}", --rd_allendbk)); Book_ad.run_insql(bk, 1); //更新Reader rd书本状态 Reader_ad.run_insql(rd, 2); //更新读者已借书本数 MessageBox.Show(string.Format("\"{0}\"退还\"{1}\"成功!", rd.rdName, bk.bkName), "lol", MessageBoxButtons.OK); rd_refresh_Click(null, null); bk_refresh_Click(null, null); } else { MessageBox.Show(string.Format("\"{0}\"退还\"{1}\"失败!", rd.rdName, bk.bkName), "lol", MessageBoxButtons.OK, MessageBoxIcon.Error); } } br = new Borrow();// 清空borrow对象数据 } }
//执行按钮 private void r_btn_Click(object sender, EventArgs e) { tbox2rd(); string choose = rd_choose.Text; try { switch (choose) { case "插入": Reader_ad.run_insql(rd, 0); rd_refresh_btn_Click(null, null); MessageBox.Show("Success", "lol", MessageBoxButtons.OK); break; case "删除": Reader_ad.run_insql(rd, 1); rd_refresh_btn_Click(null, null); MessageBox.Show("Success", "lol", MessageBoxButtons.OK); break; case "更新": Reader_ad.run_insql(rd, 2); rd_refresh_btn_Click(null, null); MessageBox.Show("Success", "lol", MessageBoxButtons.OK); break; case "查询": r_select(string.Format("select * from dbo.reader where {0} like '{1}'", rd_select_choose.Text, rd_select_text.Text)); break; } } catch (SqlException ex) { MessageBox.Show(ex.Message, "qoq", MessageBoxButtons.OK); } }