public static void BorrowOut(bookborrowModel model) { try { //string sqlstring = "select * from bookborrow where BooID='" + bookid + "'"; //SqlDataReader datareader = CommonDB.ExecuteReader(CommonDB.CONN_STRING, CommandType.Text, sqlstring, null); //int borrowtimes = -1; //datareader.Read(); //int.TryParse(datareader["BorrowTimes"].ToString(), out borrowtimes); //borrowtimes++; //sqlstring = "update [bookborrow] set BorrowTimes='" + borrowtimes + "' where BooID='" + bookid + "' AND ReaderID='" + accontname + "'"; //CommonDB.ExecuteNonQuery(CommonDB.CONN_STRING, CommandType.Text, sqlstring, null); string sqlstring = "insert into bookborrow (BookID,BookName,ReaderID,BorrowDate,BorrowTimes) values (@bookid,@bookname,@readerid,@borrowdate,@borrowtimes)"; SqlParameter[] sqlpara = new SqlParameter[]{ new SqlParameter("@bookid", SqlDbType.VarChar), new SqlParameter("@bookname", SqlDbType.VarChar) , new SqlParameter("@readerid", SqlDbType.VarChar), new SqlParameter("@borrowdate", SqlDbType.DateTime), new SqlParameter("@borrowtimes", SqlDbType.Int)}; sqlpara[0].Value = model.BookId; sqlpara[1].Value = model.BookName; sqlpara[2].Value = model.ReaderId; sqlpara[3].Value = model.DateTime; sqlpara[4].Value = model.BorrowTimes; CommonDB.ExecuteNonQuery(CommonDB.CONN_STRING, CommandType.Text, sqlstring, sqlpara); } catch (Exception ex) { Console.WriteLine("AdminloanLogic BorrowOut error!"); } }
public static List<bookborrowModel> GetModelList() { List<bookborrowModel> modellist = new List<bookborrowModel>(); string sqlstring = "select * from bookborrow"; SqlDataReader datareader = CommonDB.ExecuteReader(CommonDB.CONN_STRING, CommandType.Text, sqlstring, null); while (datareader.Read()) { DateTime time; DateTime.TryParse(datareader["BorrowDate"].ToString(), out time); int times=-1; int.TryParse(datareader["BorrowTimes"].ToString(), out times); bookborrowModel model = new bookborrowModel(datareader["BookID"].ToString(), datareader["BookName"].ToString(), datareader["ReaderID"].ToString(), time, times); modellist.Add(model); } return modellist; }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "借出" && readername != "") { int rownum = Convert.ToInt32(e.CommandArgument); ReaderReverse.Remove(readername, modellist[rownum].BookId); bookborrowModel bmodel = new bookborrowModel(modellist[rownum].BookId, modellist[rownum].BookName, readername, System.DateTime.Now, 1); AdminloanLogic.BorrowOut(bmodel); //ButtonField bf = GridView1.Columns[4] as ButtonField; //bf.Text = "借出成功"; modellist = AdminloanLogic.GetModelList(readername); if (modellist != null) { IList<bookloanModel> ilist = modellist; GridView1.DataSource = ilist; GridView1.DataBind(); } Response.Write("<script type='text/javascript'>alert('" + "借出成功!" + "');</script>"); } }