private void btnReturn_Click(object sender, EventArgs e)
        {
            try
            {
                // Validate Book ID
                if (txBookID.Text.Length == 5 && txBookID.Text.Substring(0, 1) == "G" && Convert.ToInt32(txBookID.Text.Substring(1, 4)) >= 1 && Convert.ToInt32(txBookID.Text.Substring(1, 4)) <= context.Books.Count())
                {
                    //Check if member has borrowed this book
                    if (context.Transactions.Where(x => (x.BookID == txBookID.Text) && (x.MemberID == txMemberID.Text) && (x.LoanStatus == "Borrowed")).FirstOrDefault() == null)
                    {
                        throw new NoTransactionException();
                    }

                    Transaction r = context.Transactions.Where(x => (x.BookID == txBookID.Text) && (x.MemberID == txMemberID.Text) && (x.LoanStatus == "Borrowed")).FirstOrDefault();
                    MessageBox.Show(r.TransactionID.ToString());


                    // Indentify transaction record and update return date, loanstatus and remarks
                    Transaction t = context.Transactions.Where(x => x.MemberID == txMemberID.Text && x.BookID == txBookID.Text && x.LoanStatus == "Borrowed").First();
                    t.ReturnDate        = DateTime.Today.Date;
                    t.LoanStatus        = "Returned";
                    t.Remarks           = txRemarks.Text;
                    gvReturn.DataSource = context.Transactions.Where(x => x.LoanStatus == "Borrowed" && x.MemberID == txMemberID.Text).Select(x => new { x.TransactionID, x.BookID, x.MemberID, x.LoanStatus, x.IssueDate, x.DueDate, }).ToList();

                    // Identify member record
                    Member m = context.Members.Where(x => x.MemberID == txMemberID.Text).First();
                    CalculateFine();                                    // Update fine amount in member record
                    txFineAmount.Text = Convert.ToString(m.FineAmount); // Display fine amount to user

                    // Identify book record
                    Book b = context.Books.Where(x => x.BookID == txBookID.Text).First();
                    b.NumberBorrowed -= 1; // decrease book borrowed
                    context.SaveChanges();
                }
                else
                {
                    MessageBox.Show("This book is not existing! You may input the wrong BookID, please check and input again!");
                }
            }
            catch (NoTransactionException ex)
            {
                ex = new NoTransactionException("Member did not borrow this book.");
                MessageBox.Show(ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Invalid MemberId" + ex.ToString());
            }
        }
        private void btnUpfM_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();
            Member         c   = new Member();

            try
            {
                // Validate ID to be existing
                if (txmemberID.Text.Length == 5 && txmemberID.Text.Substring(0, 1) == "M")
                {
                    if (Convert.ToInt32(txmemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToInt32(txmemberID.Text.Substring(1, 4)) <= ctx.Members.Count() + 999)
                    {
                        // Identify member record
                        c            = ctx.Members.Where(x => x.MemberID == txmemberID.Text).First();
                        c.FineAmount = Convert.ToDouble(txFine.Text);
                        ctx.SaveChanges();
                        MessageBox.Show("Successful update!");
                        btnclr_Click(sender, e);
                    }
                }
                else
                {
                    MessageBox.Show("Not an existing MemberID!");
                }
            }
            catch (Exception a)
            {
                a = new InvalidInputException("Please ensure that details of member is correct.");
                MessageBox.Show(a.Message);
            }
        }
Пример #3
0
 private void btnUpdate_Click(object sender, EventArgs e)
 {
     try
     {
         Staff s = context.Staffs.Where(x => x.Username == txtUserName.Text && x.EmailAddress == txtEmailId.Text).First();
         if (txtNewPassword.Text != txtRetypePassword.Text)
         {
             MessageBox.Show("Password does'nt match");
         }
         else
         {
             s          = context.Staffs.Where(x => x.Username == txtUserName.Text).First();
             s.Password = txtNewPassword.Text;
             context.SaveChanges();
             MessageBox.Show("Password Changed");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Invalid Details. Please check the details entered                       " + ex.Message);
     }
     //this.Hide();
     //f = new frm2Login();
     //f.Location = this.Location;
     //f.ShowDialog();
     //this.Close();
     btnBack_Click(sender, e);
 }
Пример #4
0
        private void Extension(GalaxyEntities context)
        {
            Transaction t = context.Transactions.Where(x => x.BookID == txBookID.Text && x.MemberID == txMemberID.Text).FirstOrDefault();

            t.IssueDate       = DateTime.Today.Date;
            t.DueDate         = DateTime.Now.AddDays(10);
            t.ExtensionCount += 1;
            context.SaveChanges();
        }
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try {
                if (choose == "Update")
                {
                    groupBoxReadOnly(true);
                    m = context.Members.Where(x => x.MemberID == txCustomerID.Text.ToUpper()).First();
                    updateMember(m);
                    m.Status = cbxStatus.Text;


                    context.SaveChanges();
                    MessageBox.Show("Customer information successfully updated!");

                    btnAdd.Enabled     = true;
                    btnConfirm.Enabled = false;
                    resetCustomerDetails();
                }
                if (choose == "Add")
                {
                    if (txCustomerName.Text == "" || txPhoneNumber.Text == "" || txEmailAddress.Text == "")
                    {
                        throw new ErrorException("Please ensure fill in all the necessary details.");
                    }
                    updateMember(m);
                    m.CurrentBorrowing = 0;
                    m.FineAmount       = 0;
                    context.Members.Add(m);

                    context.SaveChanges();
                    MessageBox.Show("Customer successfully added!");

                    resetCustomerDetails();
                }
            }
            catch (Exception a) {
                a = new ErrorException("Please ensure valid format for all the details.");
                MessageBox.Show(a.Message);
            }
        }
Пример #6
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();
            Staff          c   = ctx.Staffs.Where(x => x.StaffID == txID.Text).First();

            c.Name         = txName.Text;
            c.Password     = txPassword.Text;
            c.PhoneNumber  = txPhoneNo.Text;
            c.Position     = txPosition.Text;
            c.Username     = txUserName.Text;
            c.Address      = txAddress.Text;
            c.EmailAddress = txEmail.Text;
            ctx.SaveChanges();

            MessageBox.Show("Information successfully updated!");
        }
Пример #7
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();

            if (txID.Text.Length == 3 && txID.Text.Substring(0, 1) == "S" && Convert.ToInt32(txID.Text.Substring(1, 2)) >= 1 && Convert.ToInt32(txID.Text.Substring(1, 2)) <= ctx.Staffs.Count())
            {
                Staff c = ctx.Staffs.Where(x => x.StaffID == txID.Text).First();
                ctx.Staffs.Remove(c);
                ctx.SaveChanges();

                MessageBox.Show("Staff successfully deleted!");
            }
            else
            {
                MessageBox.Show("This staff is not existing! You may input the wrong StaffID, please check and input again!");
            }
        }
Пример #8
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            GalaxyEntities ctx = new GalaxyEntities();


            if (txID.Text.Length == 3 && txID.Text.Substring(0, 1) == "S" && Convert.ToInt32(txID.Text.Substring(1, 2)) >= 1 && Convert.ToInt32(txID.Text.Substring(1, 2)) <= ctx.Staffs.Count())
            {
                bool check = false;
                foreach (Staff x in ctx.Staffs.ToList())
                {
                    if (txID.Text == x.StaffID)
                    {
                        check = true;
                        break;
                    }
                }
                if (check == false)
                {
                    Staff c = new Staff();
                    c.StaffID      = txID.Text;
                    c.Name         = txName.Text;
                    c.Password     = txPassword.Text;
                    c.PhoneNumber  = txPhoneNo.Text;
                    c.Position     = txPosition.Text;
                    c.Username     = txUserName.Text;
                    c.Address      = txAddress.Text;
                    c.EmailAddress = txEmail.Text;
                    ctx.Staffs.Add(c);
                    ctx.SaveChanges();

                    MessageBox.Show("Staff successfully added!");
                }
                else
                {
                    MessageBox.Show("Existed Member ID, please set other ID!!");
                }
            }
            else
            {
                MessageBox.Show("You may input the wrong StaffID, please check and input again!");
            }
        }
Пример #9
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (txTitle.Text == "" || txPublisher.Text == "" || txAuthor.Text == "" || txShelf.Text == "" || txPrice.Text == "" || txStock.Text == "")
                {
                    throw new InvalidInputException();
                }

                //Create book record
                b                = new Book();
                b.BookID         = newBookID;
                b.Title          = txTitle.Text;
                b.Publisher      = txPublisher.Text;
                b.Author         = txAuthor.Text;
                b.BookCategory   = cbxCategory.SelectedItem.ToString();
                b.Location       = "F" + cbxFloor.SelectedItem.ToString() + "-L" + txShelf.Text;
                b.Price          = Convert.ToDouble(txPrice.Text);
                b.TotalStock     = Convert.ToInt32(txStock.Text);
                b.NumberBorrowed = 0;
                b.Availability   = "yes";

                //Store book record to database
                context.Books.Add(b);
                context.SaveChanges();

                // Inform user and clear page
                MessageBox.Show("Book successfully added!");
                ResetValues();
            }

            catch (Exception a)
            {
                a = new InvalidInputException("Please fill in all fields.");
                MessageBox.Show(a.Message);
            }
        }
Пример #10
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                if (txTitle.Text == "" || txPublisher.Text == "" || txAuthor.Text == "" || txShelf.Text == "" || txPrice.Text == "" || txStock.Text == "")
                {
                    throw new InvalidInputException();
                }

                // Update book details in database
                b.Title        = txTitle.Text;
                b.Publisher    = txPublisher.Text;
                b.Author       = txAuthor.Text;
                b.BookCategory = cbxCategory.SelectedItem.ToString();
                b.Location     = "F" + cbxFloor.SelectedItem.ToString() + "-L" + txShelf.Text;
                b.Price        = Convert.ToDouble(txPrice.Text);
                b.TotalStock   = Convert.ToInt32(txStock.Text);
                if (rbtnYes.Checked)
                {
                    b.Availability = "yes";
                }
                else
                {
                    b.Availability = "no";
                }

                context.SaveChanges();
                MessageBox.Show("Book information successfully updated!");
                ResetValues();
                readOnlyFields();
            }
            catch (Exception a)
            {
                a = new InvalidInputException("Please fill in all fields.");
                MessageBox.Show(a.Message);
            }
        }
Пример #11
0
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            using (GalaxyEntities context = new GalaxyEntities()) {
                txMemberID.Text.Trim();
                txBookID.Text.Trim();

                if (txMemberID.Text.Length == 5 && txMemberID.Text.Substring(0, 1) == "M" &&
                    Convert.ToDouble(txMemberID.Text.Substring(1, 4)) >= 1000 && Convert.ToDouble(txMemberID.Text.Substring(1, 4)) <= context.Members.Count() + 999)
                {
                    if (txBookID.Text.Length == 5 && txBookID.Text.Substring(0, 1) == "G" && Convert.ToDouble(txBookID.Text.Substring(1, 4)) >= 1 && Convert.ToDouble(txBookID.Text.Substring(1, 4)) <= context.Books.Count())
                    {
                        int i = TotalBookStockValidation(context);

                        if (i > 0)
                        {
                            var count    = context.Transactions.Where(x => x.MemberID == txMemberID.Text && x.LoanStatus == "Borrowed").Count();
                            var Lecturer = context.Members.Where(x => x.MemberID == txMemberID.Text && x.MemberCategory == "Lecturer");

                            if (count <= 3)
                            {
                                Transaction t = new Transaction();
                                t.TransactionID = (context.Transactions.Count() + 1);
                                t.BookID        = txBookID.Text;
                                t.MemberID      = txMemberID.Text;
                                t.IssueDate     = DateTime.Today.Date;
                                t.DueDate       = DateTime.Now.AddDays(10);
                                t.LoanStatus    = "";
                                context.Transactions.Add(t);
                                context.SaveChanges();

                                DateTime r = DateTime.Today;

                                Transaction t1 = context.Transactions.Where
                                                     (x => x.MemberID == txMemberID.Text && x.BookID == txBookID.Text).First();
                                if (Lecturer != null) //Lecturers loan duration is 20 compared to 10
                                {
                                    t1.DueDate = DateTime.Today.Date.AddDays(20);
                                }
                                else
                                {
                                    t1.DueDate = DateTime.Now.AddDays(10);
                                }
                                Book b1 = new Book();
                                b1 = context.Books.Where(x => x.BookID == txBookID.Text).First();
                                b1.NumberBorrowed += 1;
                                b1.TotalStock     -= 1;
                                Member a = new Member();
                                a = context.Members.Where(x => x.MemberID == txMemberID.Text).First();
                                a.CurrentBorrowing += 1;
                                t.LoanStatus        = "Borrowed";
                                context.SaveChanges();
                                GV.DataSource = context.Transactions.Where(x => x.LoanStatus == "Borrowed" && x.MemberID == txMemberID.Text).
                                                Select(x => new { x.TransactionID, x.BookID, x.MemberID, x.ReturnDate, x.IssueDate, x.DueDate, x.ExtensionCount, x.LoanStatus, x.Remarks }).
                                                ToList();
                            }
                            else
                            {
                                txSuccess.Text = "Borrowing Limit Reached";
                            }
                        }
                        else
                        {
                            txSuccess.Text = "Book Currently Unavailable!";
                        }
                    }
                    else
                    {
                        txSuccess.Text = "Wrong input!";
                    }
                }
                else
                {
                    txSuccess.Text = "Wrong Input!";
                }
            }
        }