Ejemplo n.º 1
0
        private void addTransaction()
        {
            BookTransaction bt = new BookTransaction();

            bt.DateIssue       = DateTime.Today.Date;
            bt.OriginalDateDue = DateTime.Today.AddDays(21).Date;
            bt.MemberID        = memberID;
            context.BookTransactions.Add(bt);
            context.SaveChanges();
            B.transactionNo = bt.TransactionID;
        }
Ejemplo n.º 2
0
        private void txtReturnBookID_TextChanged(object sender, EventArgs e)
        {
            if (txtReturnBookID.TextLength == 10)
            {
                try
                {
                    returnBookID = Convert.ToInt32(txtReturnBookID.Text);
                    //next check if book has already been returned.
                    if (context.books.Where(x => x.BookID == returnBookID).First().LoanStatus == true)
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            updateBookInventory();
                            updateBookLoanstatus();
                            updateTransactionDetailsAndFine();

                            context.SaveChanges();
                            ts.Complete();
                            txtReturnSuccess.Visible = true;
                            txtReturnSuccess.Text    = returnBookID.ToString() + " has been returned successfully";
                            txtReturnBookID.Text     = "";

                            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
                            timer.Interval = 5000;
                            timer.Tick    += (source, m) =>
                            {
                                txtReturnSuccess.Visible = false;
                                timer.Stop();
                            };
                            timer.Start();
                        }
                    }
                    else
                    {
                        txtReturnError.Text  = "Item has already been returned. Please check";
                        txtReturnBookID.Text = "";
                    }
                }
                //catch (InvalidOperationException)
                //{
                //    txtReturnError.Text = "Book not found. Please try again.";
                //    txtReturnBookID.Text = "";
                //}
                catch (FormatException)
                {
                    txtReturnError.Text  = "Wrong Input. Please try again.";
                    txtReturnBookID.Text = "";
                }
            }
        }
Ejemplo n.º 3
0
        private void ExtendButton_Click(object sender, EventArgs e)
        {
            DateTime datedue = Convert.ToDateTime(dataGridView1.CurrentRow.Cells[3].Value.ToString());
            int      TrID    = Convert.ToInt32(dataGridView1.CurrentRow.Cells[0].Value.ToString());
            int      BID     = Convert.ToInt32(dataGridView1.CurrentRow.Cells[1].Value.ToString());

            context = new LibrarySevenAEntities();
            var             QBT = context.BookTransactions.Where(x => x.TransactionID == TrID);
            BookTransaction bk  = QBT.First();

            if (bk.OriginalDateDue == datedue)
            {
                var             QBTD = context.BookTransDetails.Where(x => x.TransactionID == TrID && x.BookID == BID);
                BookTransDetail btd  = QBTD.First();
                btd.DateDue = datedue.AddDays(21);
                context.SaveChanges();
                //refresh
                context = new LibrarySevenAEntities();
                List <BookTransaction> lbt = new List <BookTransaction>();
                lbt = context.BookTransactions.Where(x => x.MemberID == memberID).ToList();
                if (lbt.Count > 0)
                {
                    List <object> lbtd = new List <object>();

                    for (int i = 0; i < lbt.Count; i++)
                    {
                        int temp = Convert.ToInt32(lbt[i].TransactionID.ToString());
                        var q    = from x in context.BookTransDetails
                                   where x.TransactionID == temp && x.RentalStatus == false
                                   select new { x.TransactionID, x.BookID, x.book.BookTitle, x.DateDue };
                        if (q.ToList().Count > 0)
                        {
                            object bktd = q.ToList().First();
                            lbtd.Add(bktd);
                        }
                    }
                    dataGridView1.DataSource = lbtd;
                    this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                }
            }
            else
            {
                MessageBox.Show("Unable to extend, this book has previously been extended");
            }
        }
Ejemplo n.º 4
0
        private void EditButton_Click(object sender, EventArgs e)
        {
            int error = 0;

            if (Name1.Text == string.Empty)
            {
                lblNameError.Text = "Name cannot be empty";
                error++;
            }
            else if (!noNumSpecialChar(Name1.Text))
            {
                lblNameError.Text = "Please only input alphabetical characters";
                error++;
            }
            else
            {
                m.MemberName      = Name1.Text;
                lblNameError.Text = "";
            }


            m.Address      = Address.Text;
            m.PostalCode   = Postalcode.Text;
            m.EmailAddress = EmaiAddress.Text;
            if (!isDigitOnly(ContactNum.Text))
            {
                lblContactError.Text = "Please only enter numbers for contact number";
                error++;
            }
            else
            {
                m.ContactNumber      = ContactNum.Text;
                lblContactError.Text = "";
            }
            m.Remarks      = Remark.Text;
            m.ContactTitle = cBTitle.Text;

            if (error > 0)
            {
                return;
            }
            context.SaveChanges();
            MessageBox.Show("Edit Successful");
        }
Ejemplo n.º 5
0
        private void button1_Click(object sender, EventArgs e)
        {
            Member k     = new Member();
            int    error = 0;

            if (MemberNametext.Text == "")
            {
                lblNameError.Text = "This field is required";
                error++;
            }
            else
            {
                k.MemberName = MemberNametext.Text;
            }
            if (txtMemberType.Text == "")
            {
                lblMemberTypeError.Text = "This field is required";
                error++;
            }
            else
            {
                k.MemberType = txtMemberType.Text;
            }
            k.MemberType = txtMemberType.Text;
            if (GenderText.Text == "")
            {
                lblGenderError.Text = "This field is required";
                error++;
            }
            else
            {
                k.Gender = GenderText.Text;
            }
            k.Country = Countrytext.Text;
            if (!isDigitOnly(PostalCodetext.Text))
            {
                lblPostalCodeError.Text = "Postal code must be numerical";
                error++;
            }
            else
            {
                k.PostalCode = PostalCodetext.Text;
            }
            if (!isDigitOnly(Agetext.Text))
            {
                lblAgeError.Text = "Age must be numerical";
                error++;
            }
            else
            {
                Int16 age = Convert.ToInt16(Agetext.Text);
                k.Age = age;
            }

            if (!isDigitOnly(ContactNumbertext.Text))
            {
                lblContactError.Text = "Contact must be numerical";
                error++;
            }
            else
            {
                k.ContactNumber = ContactNumbertext.Text;
            }

            k.Address      = Addresstext.Text;
            k.EmailAddress = EmailAddresstext.Text;
            k.Remarks      = Remarkstext.Text;
            k.Password     = Passwordtext.Text;
            k.ContactTitle = txtTitle.Text;
            if (error == 0)
            {
                context.Members.Add(k);
                context.SaveChanges();
                MessageBox.Show("Member Added");
            }
        }
Ejemplo n.º 6
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                if (BookTitletext.Text == "" || Authortext.Text == "" || Publishertext.Text == "" || BookCategorycomboBox.Text == "" || BookTypetext.Text == "" || ISBNtext.Text == "" || Editiontext.Text == "")
                {
                    MessageBox.Show("Please input all fields");
                    return;
                }

                else
                {
                    DateTime PublishedYear;
                    DateTime.TryParse(PublishedYeartext.Text, out PublishedYear);
                    PublishedYear.ToString();



                    var q = context.BkCategories.Where(x => x.BookCategory == BookCategorycomboBox.Text && x.BookType == BookTypetext.Text).ToList();
                    if (q.Count == 0)
                    {
                        BkCategory bcategory = new BkCategory();
                        bcategory.BookCategory = BookCategorycomboBox.Text;
                        bcategory.BookType     = BookTypetext.Text;
                        context.BkCategories.Add(bcategory);
                        context.SaveChanges();
                    }

                    var m = context.BookInventories.Where(x => x.ISBN == ISBNtext.Text).ToList();
                    if (m.Count == 0)
                    {
                        BookInventory BInventory = new BookInventory();
                        BInventory.ISBN             = ISBNtext.Text;
                        BInventory.InventoryLibrary = 1;
                        BInventory.InventoryLoan    = 0;
                        context.BookInventories.Add(BInventory);
                        context.SaveChanges();
                    }
                    else
                    {
                        BookInventory J = m.First();
                        J.InventoryLibrary++;
                    }



                    book b = new book();


                    b.BookTitle     = BookTitletext.Text;
                    b.Author        = Authortext.Text;
                    b.Publisher     = Publishertext.Text;
                    b.BookCategory  = BookCategorycomboBox.Text;
                    b.BookType      = BookTypetext.Text;
                    b.LoanStatus    = false;
                    b.ISBN          = ISBNtext.Text;
                    b.Edition       = Editiontext.Text;
                    b.Language      = Languagetext.Text;
                    b.PublishedYear = PublishedYear;
                    context.books.Add(b);
                    context.SaveChanges();



                    //insert/update book inventory



                    //insert book category



                    ts.Complete();
                    MessageBox.Show("Book Record Added Successfully");
                }
                //this.Close();
            }
        }