protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { this.hfbookid.Value = Request.QueryString["bookid"]; libraryEntities db = new libraryEntities(); int bookid = Convert.ToInt32(this.hfbookid.Value); book book = db.books.Where <book>(x => x.id == bookid).FirstOrDefault(); this.lblbooktitle.Text = book.title; this.imgbook.ImageUrl = book.cover_picture; borrowhistory objBorrowHistory = db.borrowhistories.OrderByDescending(u => u.id).FirstOrDefault(); // get the last borrower from history. if (objBorrowHistory != null && book.status == "checkout") { this.txtCheckOutDate.Text = objBorrowHistory.checkout_date.ToShortDateString(); this.txtCheckInDate.Text = objBorrowHistory.checkin_date.ToShortDateString(); this.txtReturnDate.Text = DateTime.Now.ToShortDateString(); this.txtBorrower.Text = objBorrowHistory.borrower; this.txtMobile.Text = objBorrowHistory.mobile; int bDays = Rules.GetBusinessDays(objBorrowHistory.checkout_date, DateTime.Now); if (bDays > 15) { this.lblMessage.Text = "Penalty of 5 Dhs will be charged for over days." + "\n" + "You need to pay: " + Math.Abs(bDays - 15) * 5 + " Dhs"; } } else { this.lblMessage.Text = "Book Information Not Found."; this.btnCheckIn.Enabled = false; } } }
/// <summary> /// Create a new borrowhistory object. /// </summary> /// <param name="id">Initial value of the id property.</param> /// <param name="bookid">Initial value of the bookid property.</param> /// <param name="borrower">Initial value of the borrower property.</param> /// <param name="mobile">Initial value of the mobile property.</param> /// <param name="nationalid">Initial value of the nationalid property.</param> /// <param name="checkout_date">Initial value of the checkout_date property.</param> /// <param name="checkin_date">Initial value of the checkin_date property.</param> public static borrowhistory Createborrowhistory(global::System.Int32 id, global::System.Int32 bookid, global::System.String borrower, global::System.String mobile, global::System.String nationalid, global::System.DateTime checkout_date, global::System.DateTime checkin_date) { borrowhistory borrowhistory = new borrowhistory(); borrowhistory.id = id; borrowhistory.bookid = bookid; borrowhistory.borrower = borrower; borrowhistory.mobile = mobile; borrowhistory.nationalid = nationalid; borrowhistory.checkout_date = checkout_date; borrowhistory.checkin_date = checkin_date; return(borrowhistory); }
protected void btnCheckOut_Click(object sender, EventArgs e) { libraryEntities db = new libraryEntities(); lockbook objLockBook; int bookid = Convert.ToInt32(this.hfbookid.Value); objLockBook = db.lockbooks.Where <lockbook>(x => x.bookid == bookid).FirstOrDefault(); if (objLockBook == null) { objLockBook = new lockbook(); objLockBook.bookid = bookid; objLockBook.username = User.Identity.Name; db.lockbooks.AddObject(objLockBook); db.SaveChanges(); } else { lblMessage.Text = "Book not available"; return; } book objBook = db.books.Where <book>(x => x.id == bookid).FirstOrDefault(); if (objBook.status == "checkout") { lblMessage.Text = "Book not available"; } else { borrowhistory bh = new borrowhistory(); bh.bookid = bookid; bh.borrower = this.txtBorrower.Text; bh.checkin_date = Rules.AddBusinessDays(DateTime.Now, 14); bh.checkout_date = DateTime.Now; bh.nationalid = this.txtNationalID.Text; bh.mobile = this.txtMobile.Text; db.borrowhistories.AddObject(bh); objBook.status = "checkout"; lblMessage.Text = "CheckOut Successfull"; db.SaveChanges(); } db.lockbooks.DeleteObject(objLockBook); db.SaveChanges(); }
protected void btnCheckIn_Click(object sender, EventArgs e) { libraryEntities db = new libraryEntities(); int bookid = Convert.ToInt32(this.hfbookid.Value); book objBook = db.books.Where <book>(x => x.id == bookid).FirstOrDefault(); if (objBook.status == "checkout") { objBook.status = "checkin"; borrowhistory bh = new borrowhistory(); bh = db.borrowhistories.OrderByDescending(u => u.id).FirstOrDefault(); // get the last borrower from history. bh.checkin_date_return = DateTime.Now; db.SaveChanges(); lblMessage.Text = "CheckIn Successfull"; } else { lblMessage.Text = "Book CheckIn Failed"; } }
/// <summary> /// Deprecated Method for adding a new object to the borrowhistories EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToborrowhistories(borrowhistory borrowhistory) { base.AddObject("borrowhistories", borrowhistory); }