public static int Delete(Borrow borrow) { int rows = 0; string sql = "deaete from Borrow where BorrowID=@BorrowID"; SqlParameter[] parameters = { new SqlParameter("@BorrowID", borrow.BorrowId) }; try { rows = SqlHelper.ExecuteNonQuery(sql, parameters); } catch (SqlException ex) { throw new Exception(ex.Message); } return rows; }
//添加复制函数 public Borrow(Borrow rt) { this.BorrowId = rt.BorrowId; this.rdID = rt.rdID; this.bkID = rt.bkID; this.IdContinueTimes = rt.IdContinueTimes; this.IdDateOut = rt.IdDateOut; this.IdDateRetPlan = rt.IdDateRetPlan; this.IdDateRetAct = rt.IdDateRetAct; this.IdOverDay = rt.IdOverDay; this.IdOverMoney = rt.IdOverMoney; this.IdPunishMoney = rt.IdPunishMoney; this.IsHasReturn = rt.IsHasReturn; this.OperatorLend = rt.OperatorLend; this.OperatorRet = rt.OperatorRet; }
//续借时更新borrow表记录 public int UpdateContinue(Borrow borrow) { return (BorrowDAL.UpdateContinue(borrow)); }
//借书时更新图书信息 public int UpdateBook(Borrow borrow) { return (BorrowDAL.UpdateBook(borrow)); }
//借书 public int Insert(Borrow borrow) { return (BorrowDAL.Insert(borrow)); }
//借书 private void btnBorrowBook_Click(object sender, EventArgs e) { int rdID,rdType,bkID; int CanLendQty,CanLendDay,rdBorrowQty; string rdStatus,bkStatus; Borrow borrow = new Borrow(); Reader reader = new Reader(); DataRow dr=null; DataRow ds = null; for(int i=0;i<dgvBook.SelectedRows.Count;i++) { dr = (dgvBook.SelectedRows[i].DataBoundItem as DataRowView).Row; } for (int j = 0; j < dgvReader.SelectedRows.Count; j++) { ds = (dgvReader.SelectedRows[j].DataBoundItem as DataRowView).Row; } rdID = Convert.ToInt32(txtrdID.Text); rdType = Convert.ToInt32(ds.ItemArray[3]); dt = borrowBLL.GetReaderType(rdType); CanLendQty=Convert.ToInt32(dt.Rows[0][0]); CanLendDay = Convert.ToInt32(dt.Rows[0][1]); dm = borrowBLL.GetrdStatus(rdID); rdStatus = Convert.ToString(dm.Rows[0][0]); rdBorrowQty=Convert.ToInt32(dm.Rows[0][1]); bkStatus = Convert.ToString(dr.ItemArray[15]); if (rdStatus != "有效") { MessageBox.Show("借书证无效,无法借书,无法借书!"); } else { if (bkStatus != "在馆") { MessageBox.Show("对不起,该书已不在馆!!"); } else { if (rdBorrowQty >= CanLendQty) { MessageBox.Show("已借书数超出最大可借书量,无法借书!"); } else { borrow.rdID = rdID; borrow.bkID = Convert.ToInt32(dr.ItemArray[0]); borrow.IdContinueTimes = 0; borrow.IdDateOut = DateTime.Now; borrow.IdDateRetPlan = DateTime.Now.AddDays(CanLendDay); borrow.IdDateRetAct = DateTime.Now; borrow.IdOverDay = 0; borrow.IdOverMoney = 0; borrow.IdPunishMoney = 0; borrow.IsHasReturn = false; borrow.OperatorLend = Convert.ToString(ds.ItemArray[1]); borrow.OperatorRet = Convert.ToString(ds.ItemArray[1]); borrowBLL.Insert(borrow); txtbkName.Text = Convert.ToString(borrow.rdID); borrowBLL.UpdateBook(borrow); reader.rdID = rdID; borrowBLL.UpdateBorrowNum(reader); MessageBox.Show("借书成功!!!"); } } } }
//还书 private void btnRetBook_Click(object sender, EventArgs e) { int rdType,CanLendDay; int OverDay;//超期天数 float PunishRate; //罚款率 float OverMoney; //超出金额 Borrow borrow = new Borrow(); DataRow dr = null; DataRow ds = null; for (int i = 0; i < dgvBorrow.SelectedRows.Count; i++)// 指定行操作 { dr = (dgvBorrow.SelectedRows[i].DataBoundItem as DataRowView).Row; } for (int j = 0; j < dgvReader.SelectedRows.Count; j++) { ds = (dgvReader.SelectedRows[j].DataBoundItem as DataRowView).Row; } rdType = Convert.ToInt32(ds.ItemArray[3]); dt = borrowBLL.GetReaderType(rdType); PunishRate = Convert.ToSingle(dt.Rows[0][3]); CanLendDay=Convert.ToInt32(dt.Rows[0][1]); DateTime d1 = Convert.ToDateTime(dr.ItemArray[6]); DateTime d2 = DateTime.Now; System.TimeSpan d3 = d2 - d1; OverDay = d3.Days; if (OverDay >= CanLendDay) { OverMoney = (float)(OverDay) * PunishRate; } else { OverMoney = 0; } borrow.BorrowId = Convert.ToInt32(dr.ItemArray[0]);//根据BorrowId确定更新哪条信息 borrow.bkID = Convert.ToInt32(dr.ItemArray[1]); borrow.IdDateRetAct = DateTime.Now; borrow.IdOverDay = OverDay; borrow.IdOverMoney = OverMoney; borrowBLL.UpdateBack(borrow); borrowBLL.UpdateBk(borrow); MessageBox.Show("还书成功!"); }
//续借 private void btnConBorrow_Click(object sender, EventArgs e) { int rdType, CanLendDay,CanContinueTimes; Borrow borrow = new Borrow(); DataRow dr = null; DataRow ds = null; for (int i = 0; i < dgvBorrow.SelectedRows.Count; i++)// 指定行操作 { dr = (dgvBorrow.SelectedRows[i].DataBoundItem as DataRowView).Row; } for (int j = 0; j < dgvReader.SelectedRows.Count; j++) { ds = (dgvReader.SelectedRows[j].DataBoundItem as DataRowView).Row; } rdType = Convert.ToInt32(ds.ItemArray[3]); dt = borrowBLL.GetReaderType(rdType); CanLendDay = Convert.ToInt32(dt.Rows[0][1]); CanContinueTimes = Convert.ToInt32(dt.Rows[0][2]); //根据续借次数判断是否可续借 if (Convert.ToInt32(dr.ItemArray[4]) >=CanContinueTimes) { MessageBox.Show("对不起,您的续借次数已超出最大可续借次数!"); } else { borrow.BorrowId= Convert.ToInt32(dr.ItemArray[0]); borrow.IdContinueTimes = Convert.ToInt32(dr.ItemArray[4]); borrow.IdDateOut = DateTime.Now; borrow.IdDateRetPlan = DateTime.Now.AddDays(CanLendDay); borrowBLL.UpdateContinue(borrow); MessageBox.Show("续借成功!"); } }
//续借时更新借书信息 public static int UpdateContinue(Borrow borrow) { int rows = 0; string sql = "update Borrow set " + "IdContinueTimes=@IdContinueTimes+1," + "IdDateOut=@IdDateOut," + "IdDateRetPlan=@IdDateRetPlan " + "where BorrowId=@BorrowId"; SqlParameter[] parameters ={ new SqlParameter("@BorrowId",borrow.BorrowId), new SqlParameter("@IdContinueTimes",borrow.IdContinueTimes), new SqlParameter("@IdDateOut",borrow.IdDateOut), new SqlParameter ("@IdDateRetPlan",borrow.IdDateRetPlan) }; try { rows = SqlHelper.ExecuteNonQuery(sql, parameters); } catch (SqlException ex) { throw new Exception(ex.Message); } return rows; }
//借书后更新图书馆书籍数量和状态 public static int UpdateBook(Borrow borrow) { int rows = 0; string sql="update Book set bkNum=bkNum-1,bkStatus='借出' where bkID=@bkID"; SqlParameter [] parameters={ new SqlParameter("@bkID",borrow.bkID) }; try { rows = SqlHelper.ExecuteNonQuery(sql, parameters); } catch (SqlException ex) { throw new Exception(ex.Message); } return rows; }
//还书时更新借书信息 public static int UpdateBack(Borrow borrow) { int rows = 0; string sql = "update Borrow set " + "IdContinueTimes=0," + "IdDateRetAct=@IdDateRetAct, " + "IdOverDay=@IdOverDay," + "IdOverMoney=@IdOverMoney," + "IsHasReturn=1 " + " where BorrowId=@BorrowId"; SqlParameter[] parameters ={ new SqlParameter("@BorrowId",borrow.BorrowId), new SqlParameter("@IdDateRetAct",borrow.IdDateRetAct), new SqlParameter("@IdOverDay",borrow.IdOverDay), new SqlParameter("@IdOverMoney",borrow.IdOverMoney) }; try { rows = SqlHelper.ExecuteNonQuery(sql, parameters); } catch (SqlException ex) { throw new Exception(ex.Message); } return rows; }
//借书时在Borrow表内插入一条记录 public static int Insert(Borrow borrow) { int rows = 0; string sql = "insert into Borrow(rdID,bkID,IdContinueTimes,IdDateOut,IdDateRetPlan,IdDateRetAct,IdOverDay,IdOverMoney,IdPunishMoney,IsHasReturn,OperatorLend,OperatorRet)" + " values (@rdID,@bkID,@IdContinueTimes,@IdDateOut,@IdDateRetPlan,@IdDateRetAct,@IdOverDay,@IdOverMoney,@IdPunishMoney,@IsHasReturn,@OperatorLend,@OperatorRet)"; SqlParameter[] parameters ={ new SqlParameter("@rdID",borrow.rdID), new SqlParameter("@bkID",borrow.bkID), new SqlParameter("@IdContinueTimes",borrow.IdContinueTimes), new SqlParameter("@IdDateOut",borrow.IdDateOut), new SqlParameter("@IdDateRetPlan",borrow.IdDateRetPlan), new SqlParameter("@IdDateRetAct",borrow.IdDateRetAct), new SqlParameter("@IdOverDay",borrow.IdOverDay), new SqlParameter("@IdOverMoney",borrow.IdOverMoney), new SqlParameter("@IdPunishMoney",borrow.IdPunishMoney), new SqlParameter("@IsHasReturn",borrow.IsHasReturn), new SqlParameter("@OperatorLend",borrow.OperatorLend), new SqlParameter("@OperatorRet",borrow.OperatorRet) }; try { rows = SqlHelper.ExecuteNonQuery(sql, parameters); } catch (SqlException ex) { throw new Exception(ex.Message); } return rows; }