Exemple #1
0
        public static LibTran getLastTransationByBookID(int _book_id)
        {
            LibraryDBEntities entity = new LibraryDBEntities();

            var q = from t in entity.LibTrans
                    where t.BookID == _book_id
                    group t by t.BookID into g
                    select new
            {
                Max = g.Max(b => b.TransactionID),
            };

            int i = 0;

            foreach (var data in q)
            {
                i = data.Max;
                break;
            }
            LibTran tranObj = new LibTran();

            if (i > 1)
            {
                tranObj = entity.LibTrans.Where(x => x.TransactionID == i).First();
            }

            return(tranObj);
        }
        /// <summary>
        /// Create a new LibTran object.
        /// </summary>
        /// <param name="transactionID">Initial value of the TransactionID property.</param>
        /// <param name="bookID">Initial value of the BookID property.</param>
        /// <param name="memberID">Initial value of the MemberID property.</param>
        /// <param name="lendDate">Initial value of the LendDate property.</param>
        /// <param name="returnDate">Initial value of the ReturnDate property.</param>
        /// <param name="chargeAmount">Initial value of the ChargeAmount property.</param>
        public static LibTran CreateLibTran(global::System.Int32 transactionID, global::System.Int32 bookID, global::System.Int32 memberID, global::System.DateTime lendDate, global::System.DateTime returnDate, global::System.Decimal chargeAmount)
        {
            LibTran libTran = new LibTran();

            libTran.TransactionID = transactionID;
            libTran.BookID        = bookID;
            libTran.MemberID      = memberID;
            libTran.LendDate      = lendDate;
            libTran.ReturnDate    = returnDate;
            libTran.ChargeAmount  = chargeAmount;
            return(libTran);
        }
Exemple #3
0
        public static int updateTransaction(LibTran tran)
        {
            LibraryDBEntities entity = new LibraryDBEntities();

            var tran_row = entity.LibTrans.Where(x => x.TransactionID == tran.TransactionID).SingleOrDefault();

            tran_row.ReturnDate   = tran.ReturnDate;
            tran_row.ChargeAmount = tran.ChargeAmount;

            int i = entity.SaveChanges();

            return(i);
        }
        public void fillBookList()
        {
            try
            {
                lblBookTitlePageTitle.Text = bookmodel.BookTitle;
                txtBookTitle.Text          = bookmodel.BookTitle;
                txtBookDescription.Text    = bookmodel.BookDescription;
                txtAuthor.Text             = bookmodel.Author;
                txtBookCategory.Text       = bookmodel.BookCategory;
                txtPublisherName.Text      = bookmodel.PublisherName;
                dtpPublishDate.Value       = bookmodel.PublishDate.Value;
                txtRentalPricePerDay.Text  = bookmodel.RentalPricePerDay.ToString();
                maxAvaiableDaysToRent.Text = bookmodel.MaxAvailableDayToRent.ToString();
            }
            catch { }
            dt.Rows.Clear();

            var books = EntityBroker.getBooksByBookModelID(bookmodel.BookModelId);

            dgvListOfCopies.DataSource = null;
            foreach (Book book in books)
            {
                string lend_date_str = "-";
                string due_date_str  = "-";

                string status = (book.BookStatus == 0) ? "Rented" : (book.BookStatus == 1) ? "Avaiable" : "Not Avaiable";

                LibTran t = EntityBroker.getLastTransationByBookID(book.BookID);

                if (book.BookStatus == 0)
                {
                    lend_date_str = t.LendDate.ToString("dd MM yyyy");
                    DateTime DueDate = t.LendDate.AddDays(Convert.ToDouble(bookmodel.MaxAvailableDayToRent));
                    due_date_str = DueDate.ToString("dd MM yyyy");
                }

                dt.Rows.Add(
                    book.BookID,
                    status,
                    lend_date_str,
                    due_date_str
                    );
            }
        }
        public Window_Popup_ReturnBook(int _book_id)
        {
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle; //make unresizable

            transaction = EntityBroker.getLastTransationByBookID(_book_id);
            book        = EntityBroker.getBookByBookID(_book_id);
            member      = EntityBroker.getMemberByMemberID(transaction.MemberID);
            bookmodel   = EntityBroker.getBookModelByID(book.BookModelID);

            calculateCharge();

            lblBookTitle.Text = bookmodel.BookTitle;

            lblBookIDValue.Text     = book.BookID.ToString();
            lblMemberNameValue.Text = member.MemberName;
            lblMemberIDValue.Text   = member.MemberID.ToString();
            lblRentDateValue.Text   = transaction.LendDate.ToString("dd MM, yyyy");
            lblChargeValue.Text     = charge.ToString();
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the LibTrans EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToLibTrans(LibTran libTran)
 {
     base.AddObject("LibTrans", libTran);
 }
        private void btnRent_Click(object sender, EventArgs e)
        {
            //#TODO::ExceptionHandle
            LibraryDBEntities entity = new LibraryDBEntities();
            LibTran           t      = new LibTran();

            int member_id = 0;
            int book_id   = 0;

            try
            {
                book_id = Convert.ToInt32(txtBookID.Text);
            }
            catch
            {
                MessageBox.Show("BookID you entered is not valid type.");
                return;
            }

            try
            {
                member_id = Convert.ToInt32(txtMemberID.Text);
            }
            catch
            {
                MessageBox.Show("MemberID you entered is not valid type.");
                return;
            }

            Book book = EntityBroker.getBookByBookID(book_id);

            if (book == null)
            {
                MessageBox.Show("BookID doesn't exit.");
                return;
            }
            if (book.BookStatus != 1)
            {
                MessageBox.Show("Book is not avaiable to rent.");
                return;
            }

            Member member;

            member = EntityBroker.getMemberByMemberID(member_id);
            if (member == null)
            {
                MessageBox.Show("MemberID doesn't exit.");
                return;
            }

            t.MemberID = member_id;
            t.BookID   = book_id;
            t.LendDate = DateTime.Now;

            entity.AddToLibTrans(t);
            try
            {
                entity.SaveChanges();
            }catch {
                MessageBox.Show("User not exit");
            }
            Book b = entity.Books.Where(x => x.BookID == t.BookID).SingleOrDefault();

            b.BookStatus = 0;

            int i = entity.SaveChanges();

            if (i == 1)
            {
                try
                {
                    ucListBooks booklist = new ucListBooks();
                    booklist.setMainWindowRefrence(MainWindowObject);
                    MainWindowObject.RequestContentChange(booklist);
                }
                catch {
                    MessageBox.Show("Exception. Please close the window manually. Sorry for inconvenience");
                }
            }
            this.Close();
        }