Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     if (!UpdateGotEmptyField())
     {
         var    mid     = Convert.ToInt32(txtMIDUpdate.Text);
         Member nMember = context.Members.Where(x => x.MemberID == mid).First();
         nMember.FirstName      = txtBoxFnameUpdate.Text;
         nMember.LastName       = txtBoxLNameUpdate.Text;
         nMember.MemberCategory = cboBoxMCategoryUpdate.SelectedItem.ToString();
         nMember.NRIC           = cboBoxNRICUpdate.SelectedItem.ToString();
         nMember.Salutation     = txtSalutationUpdate.Text;
         nMember.Address        = txtAddressUpdate.Text;
         nMember.DateOfBirth    = cboBoxDOBUpdate.Value;
         nMember.Postcode       = Convert.ToInt32(txtPostCodeUpdate.Text);
         nMember.Email          = txtEmailUpdate.Text;
         nMember.Phone          = Convert.ToInt32(txtPhoneUpdate.Text);
         nMember.Username       = txtUserNameUpdate.Text;
         nMember.Password       = txtPasswordUpdate.Text;
         MessageBox.Show("Update Successfully.");
     }
     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())
            {
                Member m             = new Member();
                var    MemberIDToUse = context.ControlTables.Where(x => x.NumberType == "MemberID").First();
                m.MemberID            = MemberIDToUse.FirstFreeNo;
                m.FirstName           = firstName;
                m.LastName            = lastName;
                m.MemberCategory      = memberCategory;
                m.NRIC                = NRIC;
                m.Salutation          = salutation;
                m.Address             = address;
                m.DateOfBirth         = dateOfBirth;
                m.Postcode            = postCode;
                m.Email               = email;
                m.Phone               = phoneNumber;
                m.CurrentNumberOnLoan = currentNumberOnLoan;
                m.Remarks             = remarks;
                m.Username            = UserName;

                //For password, store the Hashed version

                //1. Generate salt, and store salt
                m.Salt = LoginHashing.CreateSalt(50);
                //2. Hash(salt+password), Store hashed password + salt
                m.Password = LoginHashing.CreatePasswordHash(Password, m.Salt);

                //Commit Changes
                context.Members.Add(m);

                ControlTable c = MemberIDToUse;
                c.FirstFreeNo++;

                context.SaveChanges();

                ts.Complete();
            }

            //Show notification, go back LogIn Page
            //txtUsername.Text = "";
            //        txtPassword.Text = "";
            //        txtPasswordCheck.Text = "";
            //        MessageBox.Show("User created! Next page!");
        }
        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();
            }
        }
Ejemplo n.º 6
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();
            }
        }