Beispiel #1
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();
            }
        }
Beispiel #2
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();
            }
        }