/** * 还书 */ private void btnGiveBack_Click(object sender, EventArgs e) { string book_id = ""; string id = ""; try { id = gridBook.SelectedRows[0].Cells[0].Value.ToString(); string give_time = gridBook.SelectedRows[0].Cells[4].Value.ToString(); Console.WriteLine(give_time); if (give_time.Length != 0) { DialogResult box = MessageBox.Show("本书已还,不可重复还~", "Tip", MessageBoxButtons.OK); return; } //book_id = gridBook.SelectedRows[0].Cells[1].Value.ToString(); }catch (Exception ex) { DialogResult box = MessageBox.Show("没有选中任何书籍!", "Tip", MessageBoxButtons.OK); return; } DialogResult dr = MessageBox.Show("确定要归还<<" + gridBook.SelectedRows[0].Cells[1].Value.ToString() + ">>这本书?", "Tip", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { string updateUserCmd = "update user set num=num+1 where id=" + user_id; string searchBook = "select book_id from user_book where id=" + id; MySqlDataReader reader = MysqlUtil.search(searchBook); if (reader.Read()) { book_id = reader[0].ToString(); } else { DialogResult d = MessageBox.Show("发生未知错误", "Tip", MessageBoxButtons.OK); return; } string updateBookCmd = "update book set ramined=ramined+1 where id=" + book_id; string updateUserBookCmd = "update user_book set give_time = '{0}' where id=" + id; DateTime give_time = DateTime.Now; updateUserBookCmd = string.Format(updateUserBookCmd, give_time); Console.WriteLine(updateBookCmd); Console.WriteLine(updateUserCmd); Console.WriteLine(updateUserBookCmd); //修改数据库 if (MysqlUtil.operation(updateUserCmd) != -1 && MysqlUtil.operation(updateBookCmd) != -1 && MysqlUtil.operation(updateUserBookCmd) != -1) { MessageBox.Show("还书成功", "Tip", MessageBoxButtons.OK); this.Reload(); } } }
private void btnChange_Click(object sender, EventArgs e) { string sqlcmd = "update book set title='{0}',author='{1}',press='{2}',num='{3}',ramined='{4}',place='{5}' where id='{6}'"; sqlcmd = string.Format(sqlcmd, txtName.Text.ToString(), txtAuthor.Text.ToString(), txtPress.Text.ToString(), txtNum.Text.ToString(), txtRemained.Text.ToString() , txtPlace.Text.ToString(), id); Console.WriteLine(sqlcmd); if (MysqlUtil.operation(sqlcmd) == -1) { MessageBox.Show("更新时发生了未知错误,请重试", "error", MessageBoxButtons.OK); } else { MessageBox.Show("修改成功"); this.DialogResult = DialogResult.OK; this.Close(); superForm.Reload(); } }
private void btnDel_Click(object sender, EventArgs e) { DialogResult res = MessageBox.Show("确定删除此条记录?", "删除", MessageBoxButtons.YesNo); if (res == DialogResult.Yes) { string id = gridBook.SelectedRows[0].Cells[0].Value.ToString(); string sqlcmd = "delete from book where id=" + id; Console.WriteLine(sqlcmd); if (MysqlUtil.operation(sqlcmd) == -1) { MessageBox.Show("删除失败,请重试!", "error", MessageBoxButtons.OK); } else { MessageBox.Show("删除成功!", "Tip", MessageBoxButtons.OK); this.Reload(); } } }
private void borrow_Click(object sender, EventArgs e) { string book_id = ""; string ramined = ""; int remained = 0; try { book_id = gridBook.SelectedRows[0].Cells[0].Value.ToString(); ramined = gridBook.SelectedRows[0].Cells[5].Value.ToString(); remained = int.Parse(ramined); }catch (Exception ex) { DialogResult dr = MessageBox.Show("没有选中任何书籍!", "Tip", MessageBoxButtons.OK); return; } if (remained == 0) { DialogResult dr = MessageBox.Show("余量不足,暂时无法借阅!", "Tip", MessageBoxButtons.OK); } else { DialogResult dr = MessageBox.Show("确定要借阅<<" + gridBook.SelectedRows[0].Cells[1].Value.ToString() + ">>这本书?", "Tip", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { string updateUserCmd = "update user set num=num-1 where id=" + id; string updateBookCmd = "update book set ramined=ramined-1 where id=" + book_id; string insertCmd = "INSERT INTO user_book (user_id, book_id, borrow_time, revert_time) VALUES ('{0}', '{1}', '{2}', '{3}')"; DateTime borrow_time = DateTime.Now; DateTime revert_time = borrow_time.AddMonths(1); insertCmd = string.Format(insertCmd, id, book_id, borrow_time, revert_time); //修改数据库 if (MysqlUtil.operation(updateUserCmd) != -1 && MysqlUtil.operation(updateBookCmd) != -1 && MysqlUtil.operation(insertCmd) != -1) { MessageBox.Show("借阅成功", "Tip", MessageBoxButtons.OK); this.Reload(); } } } }
private void btnChange_Click(object sender, EventArgs e) { string title = txtName.Text.ToString(); string author = txtAuthor.Text.ToString(); string press = txtPress.Text.ToString(); string num = txtNum.Text.ToString(); string remained = txtRemained.Text.ToString(); string place = txtPlace.Text.ToString(); string sqlcmd = "INSERT INTO book (title, author, press, num, ramined, place) VALUES ('{0}','{1}','{2}','{3}','{4}','{5}')"; sqlcmd = string.Format(sqlcmd, title, author, press, num, remained, place); Console.WriteLine(sqlcmd); if (MysqlUtil.operation(sqlcmd) == -1) { MessageBox.Show("插入时发生了未知错误,请重试", "error", MessageBoxButtons.OK); } else { MessageBox.Show("插入成功"); this.DialogResult = DialogResult.OK; this.Close(); superForm.Reload(); } }