コード例 #1
0
 private void btnPrice_Click(object sender, EventArgs e)
 {
     try
     {
         if (txMemberID == null || txBookID == null || txRemarks == null)
         {
             throw new InvalidInputException();
         }
         Transaction t = context.Transactions.Where(x => x.MemberID == txMemberID.Text && x.BookID == txBookID.Text).First();
         if (t.LoanStatus == "Borrowed")
         {
             gvReturn.DataSource = context.Books.Select(x => new { x.BookID, x.Title, x.Price }).Where(x => x.BookID == txBookID.Text).ToList();
             Book b = context.Books.Where(x => x.BookID == txBookID.Text).First();
             b.TotalStock -= 1;
             float  fine;
             Member m  = context.Members.Where(x => x.MemberID == txMemberID.Text).First();
             Book   b1 = context.Books.Where(x => x.BookID == txBookID.Text).First();
             fine              = (float)Convert.ToDouble(m.FineAmount + b.Price);
             m.FineAmount      = fine;
             txFineAmount.Text = Convert.ToString(fine);
             context.SaveChanges();
             MessageBox.Show("Total stock value is deducted");
         }
         else
         {
             MessageBox.Show("The book is already returned");
         }
     }
     catch (Exception a)
     {
         a = new InvalidInputException("Please fill in all fields.");
         MessageBox.Show(a.Message);
     }
 }
        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 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);
            }
        }
コード例 #4
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);
            }
        }
        public void search()
        {
            try
            {
                // Perform SQL query with condition indicated by user has input search text
                if (txInput.Text != "")
                {
                    switch (cbxSearchBy.SelectedItem.ToString())
                    {
                    case "Book ID":
                        gv.DataSource = context.Books.Where(x => x.BookID.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Title":
                        gv.DataSource = context.Books.Where(x => x.Title.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Publisher":
                        gv.DataSource = context.Books.Where(x => x.Publisher.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Author":
                        gv.DataSource = context.Books.Where(x => x.Author.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Book Category":
                        gv.DataSource = context.Books.Where(x => x.BookCategory.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Location":
                        gv.DataSource = context.Books.Where(x => x.Location.Contains(txInput.Text)).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Price":
                        amount        = double.Parse(txInput.Text);
                        gv.DataSource = context.Books.Where(x => x.Price == amount).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Total Stock":
                        amount        = int.Parse(txInput.Text);
                        gv.DataSource = context.Books.Where(x => x.TotalStock == amount).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Number Borrowed":
                        amount        = int.Parse(txInput.Text);
                        gv.DataSource = context.Books.Where(x => x.NumberBorrowed == amount).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;

                    case "Availability":
                        gv.DataSource = context.Books.Where(x => x.Availability == txInput.Text).
                                        Select(x => new {
                            x.BookID,
                            x.Title,
                            x.Publisher,
                            x.Author,
                            x.BookCategory,
                            x.Location,
                            x.Price,
                            x.TotalStock,
                            x.NumberBorrowed,
                            x.Availability
                        }).ToList(); break;
                    }
                }
            }
            catch (Exception a)
            {
                a = new InvalidInputException("Invalid number.");
                MessageBox.Show(a.Message);
            }
        }