private void button6_Click_run() { if_get_bookid = 0; if_can_borrow = true; do_huanshu = false; //是否执行还书按钮 //int people = 1; //有该借阅证号的人数 int text8moder = 0; //textBox8显示的内容 textBox1.Text = get_number_llm.borrow_cardnum; //获得节约证号 textBox2.Text = ""; textBox3.Text = ""; try { int booknum = 0; //借书的数量 open_mysql_llm.conn.Open(); String cardnum = textBox1.Text.Trim(); // String ID = ""; //String last_data = ""; DataSet dslibrary = new DataSet(); String str1 = "图书ID 借阅证号 借阅日期 图书名" + "\r\n\r\n"; String str2 = "您有书逾期没还,不能够借书。信息如下:\r\n\r\n"; //不能借书,以及未归还书籍信息 str2 = str2 + "书名 " + "还书日期 " + "当前日期" + "\r\n\r\n"; System.DateTime now = new System.DateTime(); //获取系统时间 now = System.DateTime.Now; String strmy_recorder = "Select * From recorder Where CardNum = '" + cardnum + "'"; MySqlDataAdapter darecorder = new MySqlDataAdapter(strmy_recorder, open_mysql_llm.conn); MySqlCommandBuilder bdrecorder = new MySqlCommandBuilder(darecorder); darecorder.Fill(dslibrary, "recorder"); foreach (DataRow row1 in dslibrary.Tables["recorder"].Rows) { text8moder = 1; //textBox8.Text = "无借阅信息!"; str1 = str1 + row1["BookID"].ToString() + " " + row1["CardNum"].ToString() + " " + row1["BorrowDate"].ToString() + " " + row1["BookName"].ToString() + "\r\n\r\n"; booknum += 1; //借的书的数量 System.DateTime borrowdate = Convert.ToDateTime(row1["BorrowDate"]); //获取借阅时间 borrowdate = borrowdate.AddDays(mouth_max); //截止日期 if (System.DateTime.Compare(now, borrowdate) > 0) { str2 = str2 + row1["BookName"].ToString() + " " + borrowdate.ToString() + " " + now.ToString() + "\r\n"; if_can_borrow = false; do_huanshu = true; } } if (text8moder == 0) { textBox8.Text = "无借阅信息!"; if_get_bookid = 1; } else { textBox8.Text = str1; if_get_bookid = 1; } textBox2.Text = booknum.ToString(); textBox3.Text = num_book_max.ToString(); //最多可借书数 //判断是否可以借书,,查看是否有欠费记录。 if (if_can_borrow == true) { int t = 0; String arr = "是"; String strmy_returnedbook = "Select * From returnedbook Where CardNum = '" + cardnum + "' and Arrearage = '" + arr + "'"; MySqlDataAdapter dareturnedbook = new MySqlDataAdapter(strmy_returnedbook, open_mysql_llm.conn); MySqlCommandBuilder bdreturnedbook = new MySqlCommandBuilder(dareturnedbook); dareturnedbook.Fill(dslibrary, "returnedbook"); foreach (DataRow row in dslibrary.Tables["returnedbook"].Rows) { t++; } if (t != 0) { if_can_borrow = false; str2 = "您有费用没交,不能够借书哦!"; } } if (do_huanshu == true) { MessageBox.Show(str2 + "\r\n" + " 请先还书后再缴费!"); } else { if (if_can_borrow == false) //显示不能借书原因 { //MessageBox.Show(str2); get_number_llm.str_message = str2; if_message_1 f1 = new if_message_1(); f1.Show(); //if_message_pay f2 = new if_message_pay(); //f2.Show(); } } if (booknum >= num_book_max) // 判断是否超过最多借书量 { MessageBox.Show("不能够借书,原因:已达到最大借书量!"); max_book_num = false; } open_mysql_llm.conn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString() + "打开数据库失败!"); } }
private void button1_Click(object sender, EventArgs e) //借书按钮 { try { if (do_huanshu == false) { if (max_book_num == true) { if (butten1_times == 0) { butten1_times++; if (textBox1.Text.Count() != 0 && textBox4.Text.Count() != 0) { if (if_can_borrow == true) { if (maxmouth == 0) { MessageBox.Show("不能借,因为该书预定在" + mouth_max.ToString() + "天以内!"); } else { open_mysql_llm.conn.Open(); String cardnum = textBox1.Text.Trim(); String bookid = textBox4.Text.Trim(); DataSet dsmydata = new DataSet(); String strmy_bookinformation = "Select * From bookinformation Where BookID = '" + bookid + "'"; MySqlDataAdapter dabookinformation = new MySqlDataAdapter(strmy_bookinformation, open_mysql_llm.conn); MySqlCommandBuilder bdbookinformation = new MySqlCommandBuilder(dabookinformation); dabookinformation.Fill(dsmydata, "bookinformation"); //删除预定书的记录 if (delet_booking == 1) { String strmy_booking = "Select * From booking Where BookID = '" + bookid + "'"; MySqlDataAdapter dabooking = new MySqlDataAdapter(strmy_booking, open_mysql_llm.conn); MySqlCommandBuilder bdbooking = new MySqlCommandBuilder(dabooking); dabooking.Fill(dsmydata, "booking"); dsmydata.Tables["booking"].Rows[0].Delete(); dabooking.Update(dsmydata, "booking"); dsmydata.Tables["booking"].AcceptChanges(); } //到此结束 String bookclassid = ""; //获得编码 foreach (DataRow row5 in dsmydata.Tables["bookinformation"].Rows) { row5["SendFlag"] = "1"; bookclassid = row5["BookClassID"].ToString().Trim(); } dabookinformation.Update(dsmydata, "bookinformation"); dsmydata.Tables["bookinformation"].AcceptChanges(); //打开tbookclass获得图书名 String strmy_tbookclass = "Select * From tbookclass Where BookClassID = '" + bookclassid + "'"; MySqlDataAdapter datbookclass = new MySqlDataAdapter(strmy_tbookclass, open_mysql_llm.conn); MySqlCommandBuilder bdtbookclass = new MySqlCommandBuilder(datbookclass); datbookclass.Fill(dsmydata, "tbookclass"); String name = ""; foreach (DataRow row6 in dsmydata.Tables["tbookclass"].Rows) { name = row6["BookName"].ToString().Trim(); } //打开recoreder表 String strmy_recorder = "Select * From recorder"; MySqlDataAdapter darecorder = new MySqlDataAdapter(strmy_recorder, open_mysql_llm.conn); MySqlCommandBuilder bdrecorder = new MySqlCommandBuilder(darecorder); darecorder.Fill(dsmydata, "recorder"); System.DateTime now = new System.DateTime(); //获取系统时间 now = System.DateTime.Now; //为recorder添加借阅信息。 DataRow newrow = dsmydata.Tables["recorder"].NewRow(); newrow["BookID"] = bookid; newrow["BorrowDate"] = now; newrow["CardNum"] = cardnum; //name = "名"; newrow["BookName"] = name; newrow["BorrowingStatus"] = "在借"; dsmydata.Tables["recorder"].Rows.Add(newrow); darecorder.Update(dsmydata, "recorder"); dsmydata.Tables["recorder"].AcceptChanges(); //#################################### returnedbook,添加 increase_returnedbook(bookid, cardnum, name, "借阅", "否", ref dsmydata); MessageBox.Show("借书成功!"); textBox4.Text = ""; textBox9.Text = ""; open_mysql_llm.conn.Close(); //******************日志代码****************** //******************************************************************************************** String str_log = ""; str_log = " 借阅ID为:" + bookid.ToString() + " 的图书,"; Log.WriteLog(str_log); //******************************************** button6_Click_run(); //再次执行该函数,进行刷新。 } } else { //MessageBox.Show("不能够借书!"); textBox4.Text = ""; textBox9.Text = ""; get_number_llm.str_message = "要交完费用,才能借书哦!"; if_message_1 f1 = new if_message_1(); f1.Show(); } } else { MessageBox.Show("不能执行该操作!"); } } } else { MessageBox.Show("已达到最大借数量,不能借书!"); } } else { MessageBox.Show("同学,请先还书啊!不然我不借给你!啊!"); textBox4.Text = ""; textBox9.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString() + "打开数据库失败!"); } }