private void button6_Click(object sender, EventArgs e) { readerresult.Rows.Clear(); if (textBox9.Text != "") { db.query("select from `reader` where `sid`='" + textBox9.Text + "'"); } if (textBox14.Text != "") { db.query("select from `reader` where `name`='" + textBox14.Text + "'"); } //循环读取 while (db.fetchline()) { string id = db.get("sid"); //去找借的书的名字 string booknames = ""; DBcore.DBcore db2 = new DBcore.DBcore(".\\"); db2.query("use DB"); db2.query("select from `lendinfo` where `readerid`='" + id + "'"); while (db2.fetchline()) { string bcd = db2.get("bookid"); DBcore.DBcore db3 = new DBcore.DBcore(".\\"); db3.query("use DB"); db3.query("select from `book` where `id`='" + bcd + "'"); while (db3.fetchline()) { booknames = booknames + db3.get("booktitle") + "||"; } } string booktitle = db.get("name"); string description = db.get("sex"); string writer = db.get("lending"); string publisher = db.get("maxnum"); string type = db.get("owe"); DataGridViewRow row = new DataGridViewRow(); row.CreateCells(readerresult); row.Cells[0].Value = id; row.Cells[1].Value = booktitle; row.Cells[2].Value = description; row.Cells[3].Value = writer; row.Cells[4].Value = publisher; row.Cells[5].Value = type; row.Cells[6].Value = booknames; //添加新行 readerresult.Rows.Add(row); } readerresult.Visible = true; }
private void button7_Click(object sender, EventArgs e) { int nums; try { nums = int.Parse(textBox15.Text); } catch (System.Exception ex) { speaker.speak("请输入正确的数量"); return; } //得到学生资料 string sid = textBox17.Text; db.query("select from `reader` where `sid`='" + sid + "'"); string sname = ""; string ssex = ""; string smaxnum = ""; string slending = ""; string sowe = ""; int slend = 0; if (db.fetchline()) { sname = db.get("name"); ssex = db.get("sex"); smaxnum = db.get("maxnum"); slending = db.get("lending"); sowe = db.get("owe"); slend = int.Parse(slending); int snum = int.Parse(smaxnum); slend = slend - nums; if (slend < 0) { speaker.speak("数量出错"); return; } } else { speaker.speak("此读者不存在"); return; } //得到图书资料 string bid = textBox16.Text; string booktitle = ""; string description = ""; string writer = ""; string publisher = ""; string type = ""; string store = ""; string bnums = ""; int bstore = 0; db.query("select from `book` where `id`='" + bid + "'"); if (db.fetchline()) { booktitle = db.get("booktitle"); description = db.get("description"); writer = db.get("writer"); publisher = db.get("publisher"); type = db.get("type"); store = db.get("store"); bnums = db.get("nums"); bstore = int.Parse(store); bstore = bstore + nums; if (bstore > int.Parse(bnums)) { speaker.speak("数量出错"); return; } } else { speaker.speak("此图书不存在"); return; } //检测图书是否是该读者所借 DBcore.DBcore db2 = new DBcore.DBcore(".\\"); db2.query("use DB"); db2.query("select from `lendinfo` where `readerid`='" + sid + "'"); int isyours = 0; System.Collections.ArrayList lendid = new System.Collections.ArrayList(); while (db2.fetchline()) { if (db2.get("bookid") == bid) { isyours = 1; lendid.Add(db2.get("id")); } } if (isyours == 0) { speaker.speak("该书非该读者拥有"); return; } DateTime t1 = new DateTime(1970, 1, 1); DateTime t2 = DateTime.Now; long a = t2.Ticks - t1.Ticks / 1000; int yy = (int)a; int i = 0; //清理图书借阅单 for (i = 0; i < nums; i++) { db.query("delete from `lendinfo` where `id`='" + lendid[i] + "'"); } db.query("delete from `reader` where `sid`='" + sid + "'"); db.query("insert into `reader` values ('" + sid + "','" + sname + "','" + ssex + "','" + smaxnum + "','" + slend + "','" + sowe + "')"); db.query("delete from `book` where `id`='" + bid + "'"); db.query("insert into `book` values ('" + bid + "','" + booktitle + "','" + description + "','" + writer + "','" + publisher + "','" + type + "','" + bstore.ToString() + "','" + bnums + "')"); speaker.speak("操作成功"); }
private void button7_Click(object sender, EventArgs e) { int nums; try { nums = int.Parse(textBox15.Text); } catch (System.Exception ex) { speaker.speak("请输入正确的数量"); return; } //得到学生资料 string sid = textBox17.Text; db.query("select from `reader` where `sid`='" + sid + "'"); string sname = ""; string ssex = ""; string smaxnum = ""; string slending = ""; string sowe = ""; int slend = 0; if (db.fetchline()) { sname = db.get("name"); ssex = db.get("sex"); smaxnum = db.get("maxnum"); slending = db.get("lending"); sowe = db.get("owe"); slend = int.Parse(slending); int snum = int.Parse(smaxnum); slend = slend - nums; if (slend < 0) { speaker.speak("数量出错"); return; } } else { speaker.speak("此读者不存在"); return; } //得到图书资料 string bid = textBox16.Text; string booktitle = ""; string description = ""; string writer = ""; string publisher = ""; string type = ""; string store = ""; string bnums = ""; int bstore = 0; db.query("select from `book` where `id`='" + bid + "'"); if (db.fetchline()) { booktitle = db.get("booktitle"); description = db.get("description"); writer = db.get("writer"); publisher = db.get("publisher"); type = db.get("type"); store = db.get("store"); bnums = db.get("nums"); bstore = int.Parse(store); bstore = bstore + nums; if (bstore > int.Parse(bnums)) { speaker.speak("数量出错"); return; } } else { speaker.speak("此图书不存在"); return; } //检测图书是否是该读者所借 DBcore.DBcore db2 = new DBcore.DBcore(".\\"); db2.query("use DB"); db2.query("select from `lendinfo` where `readerid`='" + sid + "'"); int isyours=0; System.Collections.ArrayList lendid=new System.Collections.ArrayList(); while(db2.fetchline()) { if(db2.get("bookid")==bid) { isyours=1; lendid.Add(db2.get("id")); } } if(isyours==0) { speaker.speak("该书非该读者拥有"); return; } DateTime t1 = new DateTime(1970, 1, 1); DateTime t2 = DateTime.Now; long a = t2.Ticks - t1.Ticks / 1000; int yy = (int)a; int i = 0; //清理图书借阅单 for (i = 0; i < nums; i++) { db.query("delete from `lendinfo` where `id`='" + lendid[i] + "'"); } db.query("delete from `reader` where `sid`='" + sid + "'"); db.query("insert into `reader` values ('" + sid + "','" + sname + "','" + ssex + "','" + smaxnum + "','" + slend + "','" + sowe + "')"); db.query("delete from `book` where `id`='" + bid + "'"); db.query("insert into `book` values ('" + bid + "','" + booktitle + "','" + description + "','" + writer + "','" + publisher + "','" + type + "','" + bstore.ToString() + "','" + bnums + "')"); speaker.speak("操作成功"); }
private void Form1_Load(object sender, EventArgs e) { db.query("use DB"); //db.query("insert into `book` values ('1','电子电工技术','电子电工类的专业书..优秀的课本','老师','电子工业出版社','电子类','3','5')"); }
private void button6_Click(object sender, EventArgs e) { readerresult.Rows.Clear(); if (textBox9.Text != "") { db.query("select from `reader` where `sid`='" + textBox9.Text + "'"); } if (textBox14.Text != "") { db.query("select from `reader` where `name`='" + textBox14.Text + "'"); } //循环读取 while (db.fetchline()) { string id = db.get("sid"); //去找借的书的名字 string booknames = ""; DBcore.DBcore db2 = new DBcore.DBcore(".\\"); db2.query("use DB"); db2.query("select from `lendinfo` where `readerid`='" + id + "'"); while (db2.fetchline()) { string bcd = db2.get("bookid"); DBcore.DBcore db3 = new DBcore.DBcore(".\\"); db3.query("use DB"); db3.query("select from `book` where `id`='" + bcd + "'"); while (db3.fetchline()) { booknames = booknames +db3.get("booktitle") +"||"; } } string booktitle = db.get("name"); string description = db.get("sex"); string writer = db.get("lending"); string publisher = db.get("maxnum"); string type = db.get("owe"); DataGridViewRow row = new DataGridViewRow(); row.CreateCells(readerresult); row.Cells[0].Value = id; row.Cells[1].Value = booktitle; row.Cells[2].Value = description; row.Cells[3].Value = writer; row.Cells[4].Value = publisher; row.Cells[5].Value = type; row.Cells[6].Value = booknames; //添加新行 readerresult.Rows.Add(row); } readerresult.Visible = true; }