private void btnAddNew_Click(object sender, EventArgs e)
        {
            Book book = new Book();

            book.BookModelID = book_model_id;
            book.BookStatus  = 1;
            int i = EntityBroker.createNewBook(book);

            if (i == 0)
            {
                return;
            }
            //refreshing book list
            //MessageBox.Show(book_model_id.ToString());
            ucDetailsBook ucdb = new ucDetailsBook(book_model_id);

            ucdb.setMainWindowRefrence(MainWindowObject);
            ucdb.setParentWindowRefrence(ParentWindowObject);
            ParentWindowObject.RequestContentChange(ucdb);

            //refreshing min window list
            ucListBooks booklist = new ucListBooks();

            booklist.setMainWindowRefrence(MainWindowObject);
            MainWindowObject.RequestContentChange(booklist);
        }
        private void pnlMain_Paint(object sender, PaintEventArgs e)
        {
            ucListBooks booklist = new ucListBooks();

            booklist.setMainWindowRefrence(this);
            panelMain.Controls.Add(booklist);
        }
        private void btnReturn_Click(object sender, EventArgs e)
        {
            //update book status
            book.BookStatus = 1;
            int i = EntityBroker.updateBook(book);

            if (i == 1)
            {
                //transaction
                transaction.ReturnDate   = DateTime.Today.Date;
                transaction.ChargeAmount = (decimal)charge;
                int j = EntityBroker.updateTransaction(transaction);
                if (j != 1)
                {
                    MessageBox.Show("Error Saving in Book Transaction Update. Please Contact to Programmer");
                }
            }
            else
            {
                MessageBox.Show("Error Saving in Book Status Change. Please Contact to Programmer");
            }

            ucListBooks booklist = new ucListBooks();

            booklist.setMainWindowRefrence(MainWindowObject);
            MainWindowObject.RequestContentChange(booklist);

            this.Close();
        }
        private void llbClearSearchBookByTitle_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            txtSearchByBookTitle.Text = "";
            try
            {
                ucListBooks booklist = new ucListBooks();
                booklist.setMainWindowRefrence(MainWindowObject);

                MainWindowObject.RequestContentChange(booklist);
            }
            catch { }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            int i = 0;

            if (txtBookTitle.Text == "")
            {
                MessageBox.Show("Book Title shouldn't be empty.");
                return;
            }
            if (txtRentalPricePerDay.Text == "")
            {
                MessageBox.Show("Rental Price shouldn't be empty.");
                return;
            }
            if (maxAvaiableDaysToRent.Text == "")
            {
                MessageBox.Show("Max Avaiable Days To Rent shouldn't be empty.");
                return;
            }

            if (book_model_id > 0)
            {
                bookmodel.BookTitle             = lblBookTitlePageTitle.Text;
                bookmodel.BookTitle             = txtBookTitle.Text;
                bookmodel.BookDescription       = (string)txtBookDescription.Text;
                bookmodel.Author                = txtAuthor.Text;
                bookmodel.BookCategory          = txtBookCategory.Text;
                bookmodel.PublisherName         = txtPublisherName.Text;
                bookmodel.PublishDate           = dtpPublishDate.Value;
                bookmodel.RentalPricePerDay     = (decimal)Convert.ToDouble(txtRentalPricePerDay.Text);
                bookmodel.MaxAvailableDayToRent = (short)Convert.ToInt32(maxAvaiableDaysToRent.Text);

                i = EntityBroker.updateBookModel(bookmodel);
            }
            else
            {
                BooksModel bm = new BooksModel();

                bm.BookTitle             = (string)txtBookTitle.Text;
                bm.BookDescription       = (string)txtBookDescription.Text;
                bm.Author                = (string)txtAuthor.Text;
                bm.BookCategory          = (string)txtBookCategory.Text;
                bm.PublisherName         = (string)txtPublisherName.Text;
                bm.PublishDate           = dtpPublishDate.Value;
                bm.RentalPricePerDay     = (decimal)Convert.ToDouble(txtRentalPricePerDay.Text);
                bm.MaxAvailableDayToRent = (short)Convert.ToDouble(maxAvaiableDaysToRent.Text);

                i = EntityBroker.createNewBookModel(bm);
            }


            if (i == 1)
            {
                MessageBox.Show("Book Information Saved");

                ucListBooks booklist = new ucListBooks();
                booklist.setMainWindowRefrence(MainWindowObject);
                MainWindowObject.RequestContentChange(booklist);

                ParentWindowObject.Close();
            }
            else
            {
                MessageBox.Show("Error in updating. Error code :: {0}", i.ToString());
            }
        }
        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();
        }