Esempio n. 1
0
 private void retrieveinfo()
 {
     if (IsBidExist() && txtBookNameUpdate.Text != string.Empty)
     {
         var         bid   = txtBookNameUpdate.Text;
         BookListing nbook = context.BookListings.Where(x => x.BookID == bid).First();
         txtISBNUpdate.Text                = nbook.ISBN.ToString();
         txtBookTitleUpdate.Text           = nbook.BookTitle.ToString();
         cboBoxBookTypeUpdate.SelectedItem = nbook.BookType.ToString();
         cboBoxLanguageUpdate.SelectedItem = nbook.Language.ToString();
         txtCallNoUpdate.Text              = nbook.CallNumber.ToString();
         cboBoxSectionUpdate.SelectedItem  = nbook.Section.ToString();
         txtNoteUpdate.Text                = nbook.Notes.ToString();
         var    aid    = nbook.AuthorID;
         Author author = context.Authors.Where(x => x.AuthorID == aid).First();
         cboBoxAuthorUpdate.SelectedItem = author.AuthorName.ToString();
         var       pid       = nbook.PublisherID;
         Publisher publisher = context.Publishers.Where(x => x.PublisherID == pid).First();
         cboBoxPublisherUpdate.SelectedItem = publisher.PublisherName.ToString();
     }
     else if (txtBookNameUpdate.Text == string.Empty)
     {
         MessageBox.Show("Please input a Book ID.");
     }
 }
Esempio n. 2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            //Update booklisting table
            if (!UpdateGotEmptyField())
            {
                var         bid   = txtBookNameUpdate.Text;
                BookListing nbook = context.BookListings.Where(x => x.BookID == bid).First();
                nbook.ISBN       = txtISBNUpdate.Text;
                nbook.BookTitle  = txtBookTitleUpdate.Text;
                nbook.BookType   = cboBoxBookTypeUpdate.SelectedItem.ToString();
                nbook.Language   = cboBoxLanguageUpdate.SelectedItem.ToString();
                nbook.CallNumber = txtCallNoUpdate.Text;
                nbook.Section    = cboBoxSectionUpdate.SelectedItem.ToString();
                nbook.Notes      = txtNoteUpdate.Text;
                Author author = context.Authors.Where(x => x.AuthorName == cboBoxAuthorUpdate.SelectedItem.ToString()).First();
                nbook.AuthorID = author.AuthorID;
                Publisher publisher = context.Publishers.Where(x => x.PublisherName == cboBoxPublisherUpdate.SelectedItem.ToString()).First();
                nbook.PublisherID = publisher.PublisherID;
                //Update adjustment table
                BookAdjustment adjust = new BookAdjustment();
                adjust.BookID     = nbook.BookID;
                adjust.DateAdjust = DateTime.Now;
                adjust.WhoAdjust  = Convert.ToInt32("4000");

                if (UpdatedataType())
                {
                    int quantity   = Convert.ToInt32(txtQuantityUpdate.Text);
                    int totalStock = nbook.TotalStock;
                    int noLoaned   = nbook.NumberLoaned;
                    if (quantity > 0 || (quantity < 0 && Math.Abs(quantity) < totalStock - noLoaned))
                    {
                        nbook.TotalStock     = Convert.ToInt32(txtQuantityUpdate.Text) + nbook.TotalStock;
                        adjust.AdjustmentQty = Convert.ToInt32(txtQuantityUpdate.Text);
                        MessageBox.Show("Update book Successfully.");
                    }
                    else if (quantity < 0 && Math.Abs(quantity) > totalStock - noLoaned)
                    {
                        MessageBox.Show("Number of books in library is not enough");
                    }
                }
                if (adjust.AdjustmentQty > 0)
                {
                    adjust.AdjustmentReason = "Buy new books";
                }
                else if (adjust.AdjustmentQty < 0)
                {
                    adjust.AdjustmentReason = "Book damaged";
                }
                else
                {
                    adjust.AdjustmentReason = "Update book information";
                }
                //Update ControlNumber
                //Save Changes
                context.BookAdjustments.Add(adjust);
                context.SaveChanges();
            }
        }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            lblMIDWarning.Visible = false;
            if (hasFieldEmpty() == true)
            {
                MessageBox.Show("All fields must be filled/selected. Please indicate NA if no remarks to be made. ");
            }
            else
            {
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IssueTran IT = context.IssueTrans.Where(x => x.TransactionID == TransactionID).First();
                        IT.DateActualReturn  = DateActualReturn;
                        IT.LoanStatus        = "IN";
                        IT.Remarks           = txtRemark.Text;
                        IT.OverdueFine       = fineAmount;
                        IT.FinePaymentStatus = cboBoxPaymentStatus.SelectedItem.ToString();
                        IT.BookID            = bookID;

                        Member      ML = context.Members.Where(x => x.MemberID == MemberID).First();
                        BookListing BL = context.BookListings.Where(x => x.BookID == bookID).First();

                        if (BL.NumberLoaned > 0 && ML.CurrentNumberOnLoan > 0)
                        {
                            BL.NumberLoaned--;
                            ML.CurrentNumberOnLoan--;

                            MessageBox.Show("Book Return is successful.");
                        }
                        else
                        {
                            MessageBox.Show("There is an error in the number of books on loan. Please check on transaction record.");
                        }

                        context.SaveChanges();
                        ts.Complete();
                    }
                    catch (TransactionException ex)
                    {
                        ts.Dispose();
                        MessageBox.Show("Transaction Exception Occured");
                    }
                }
            }
        }
        private void CommitTransaction()
        {
            using (TransactionScope ts = new TransactionScope())
            {
                // 3. Update IssueTrans table
                IssueTran it = new IssueTran();
                it.MemberID          = Int32.Parse(txtBoxMemberID.Text);
                it.BookID            = txtBoxBookID.Text;
                it.DateBorrow        = dtpBorrow.Value.Date;
                it.DateDue           = dtpDue.Value.Date;
                it.LoanStatus        = "OUT";
                it.Remarks           = "NIL";
                it.OverdueFine       = 0;
                it.FinePaymentStatus = "NA";
                context.IssueTrans.Add(it);

                //4. Update Member table : CurentNumberOnLoan
                Member m = context.Members
                           .Where(x => x.MemberID.ToString() == txtBoxMemberID.Text)
                           .First();

                int newNumberOnLoan = context
                                      .Members
                                      .Where(x => x.MemberID.ToString() == txtBoxMemberID.Text)
                                      .Select(x => x.CurrentNumberOnLoan).First() + 1;

                m.CurrentNumberOnLoan = newNumberOnLoan;


                //5. Update Book Listing table: NumberLoaned ++
                BookListing b = context.BookListings
                                .Where(x => x.BookID.ToString() == txtBoxBookID.Text)
                                .First();
                b.NumberLoaned++;

                //Commit Changes
                context.SaveChanges();

                ts.Complete();
            }
        }
Esempio n. 5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            PGPLibraryEntities context = new PGPLibraryEntities();
            BookListing        nbook   = new BookListing();
            BookAdjustment     adjust  = new BookAdjustment();

            if (!GotEmptyField() && AdddataType() && IsAddMore())
            {
                //Update Booklisting Table
                nbook.ISBN       = txtISBNAdd.Text;
                nbook.BookTitle  = txtBookTitleAdd.Text;
                nbook.CallNumber = txtCallNoAdd.Text;
                nbook.Notes      = txtNoteAdd.Text;
                nbook.BookType   = cboBoxBookTypeAdd.SelectedItem.ToString();
                nbook.Language   = cboBoxLanguageAdd.SelectedItem.ToString();
                Author author = context.Authors.Where(x => x.AuthorName == cboBoxAuthorAdd.SelectedItem.ToString()).First();
                nbook.AuthorID = author.AuthorID;
                Publisher publisher = context.Publishers.Where(x => x.PublisherName == cboBoxPublisherAdd.SelectedItem.ToString()).First();
                nbook.PublisherID  = publisher.PublisherID;
                nbook.Section      = cboBoxSectionAdd.SelectedItem.ToString();
                nbook.BookID       = "B00" + context.ControlTables.Where(x => x.NumberType == "BookID").Select(x => x.FirstFreeNo).First();
                nbook.NumberLoaned = 0;

                //Update BookAdjustment Table
                adjust.BookID     = "B00" + context.ControlTables.Where(x => x.NumberType == "BookID").Select(x => x.FirstFreeNo).First();
                adjust.DateAdjust = DateTime.Now;
                //Librarian librarian = context.Librarians.Where(x => x.Username == lblUser.Text).First();
                //adjust.WhoAdjust = librarian.LibrarianID;
                adjust.WhoAdjust        = Convert.ToInt32("4000");
                adjust.AdjustmentReason = "Buy new books";
                adjust.AdjustmentQty    = Convert.ToInt32(txtQuantityAdd.Text);
                nbook.TotalStock        = Convert.ToInt32(txtQuantityAdd.Text);
                ////Update ControlNumber
                //ControlTable control = context.ControlTables.Where(x => x.NumberType == "BookID").First();
                //control.FirstFreeNo += 1;
                MessageBox.Show("Add book successfully.");
                context.BookAdjustments.Add(adjust);
                context.BookListings.Add(nbook);
                context.SaveChanges();
            }
        }