示例#1
0
        private void toolStripButton1_Click(object sender, EventArgs e) // Borrow button
        {
            if (textBox2.Text == "")                                    // validate: check for no selected customer
            {
                MessageBox.Show("No customer account selected");
            }
            else if (dataGridView1.DataSource == null) // validate: check for no selected books
            {
                MessageBox.Show("No books are selected for borrowing");
            }
            else
            {
                try
                {
                    Boolean IssueSucess = false;
                    using (System.Transactions.TransactionScope ts = new System.Transactions.TransactionScope())
                    {
                        // update IssueTrans
                        IssueTran IT = new IssueTran();

                        IT.CustomerID = Convert.ToInt32(textBox1.Text);
                        context.IssueTrans.Add(IT);
                        context.SaveChanges();

                        // update booklist and BookIssued
                        foreach (BookList b in bL)
                        {
                            b.Loaned++;

                            BookIssued BI = new BookIssued();
                            BI.TransactionNo = IT.TransactionNo;
                            BI.ISBN          = b.ISBN;
                            BI.BookTitle     = b.BookTitle;
                            BI.DateBorrow    = DateTime.Now.Date;
                            BI.DateDue       = DateTime.Now.Date.AddDays(14);
                            context.BookIssueds.Add(BI);
                            BorrowSucessfulMessage += string.Format("{0}\t\t{1}\n", b.BookTitle.PadRight(20).Substring(0, 20), BI.DateDue);
                        }
                        context.SaveChanges();
                        ts.Complete();

                        MessageBox.Show(BorrowSucessfulMessage);

                        IssueSucess = true;
                    }

                    if (IssueSucess)
                    {
                        new TransReceiptForm().ShowDialog();
                    }

                    this.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 private void Confirm_Click(object sender, EventArgs e)
 {
     if (textBox2.Text == "" || textBox4.Text == "" || textBox6.Text == "" || comboBox1.Text == "" || textBox3.Text == "")
     {
         MessageBox.Show("Error!Please fill the blanks with (*).");
     }
     else
     {
         context = new SA45Team13bLibraryEntities();
         int           i  = Int32.Parse(textBox1.Text);
         LibraryMember lb = new LibraryMember();
         lb = context.LibraryMembers.Where(x => x.CustomerID == i).First();
         lb.CustomerName   = textBox2.Text;
         lb.Age            = Int16.Parse(textBox3.Text);
         lb.Address        = textBox4.Text;
         lb.PostalCode     = textBox5.Text;
         lb.DocumentNo     = textBox6.Text;
         lb.DocumentType   = comboBox1.Text;
         lb.PhoneNumber    = textBox8.Text;
         lb.EmailAddress   = textBox9.Text;
         lb.AltPhoneNumber = textBox10.Text;
         context.SaveChanges();
         MessageBox.Show("Submit success!");
         this.Close();
     }
 }
 private void Confirm_Click_1(object sender, EventArgs e)
 {
     m       = new LibraryMember();
     context = new SA45Team13bLibraryEntities();
     if (CustomerNameBox.Text == "" || AddressBox.Text == "" || DocumentNoBox.Text == "" || DocumentTypeBox.Text == "" || AgeBox.Text == "")
     {
         MessageBox.Show("Error!Please fill the blanks with (*).");
     }
     else if (System.Text.RegularExpressions.Regex.IsMatch(AgeBox.Text, "[^0-9]"))
     {
         MessageBox.Show("Please enter correct age.");
     }
     else
     {
         m.CustomerName   = CustomerNameBox.Text;
         m.Age            = Int16.Parse(AgeBox.Text);
         m.Address        = AddressBox.Text;
         m.PostalCode     = PostalCodeBox.Text;
         m.DocumentNo     = DocumentNoBox.Text;
         m.DocumentType   = DocumentTypeBox.Text;
         m.PhoneNumber    = PhoneNumberBox.Text;
         m.EmailAddress   = EmailAddressBox.Text;
         m.AltPhoneNumber = AltPhoneNumberBox.Text;
         context.LibraryMembers.Add(m);
         context.SaveChanges();
         MessageBox.Show("Submit success!");
         Refresh();
         this.Close();
     }
 }
示例#4
0
        private void Confirm_Click(object sender, EventArgs e)
        {
            m = new LibraryMember();
            using (TransactionScope ts = new TransactionScope())
            {
                context = new SA45Team13bLibraryEntities();

                m.CustomerName = textBox2.Text;
                var k = Int16.Parse(textBox3.Text);
                m.Age            = Int16.Parse(textBox3.Text);
                m.Address        = textBox4.Text;
                m.PostalCode     = textBox5.Text;
                m.DocumentNo     = textBox6.Text;
                m.DocumentType   = comboBox1.Text;
                m.PhoneNumber    = textBox8.Text;
                m.EmailAddress   = textBox9.Text;
                m.AltPhoneNumber = textBox10.Text;

                context.LibraryMember.Add(m);
                context.SaveChanges();
                ts.Complete();
                MessageBox.Show("Submit success!");
                this.Close();
            }
        }
示例#5
0
        private void DeleteBookToolStripButton_Click(object sender, EventArgs e)
        {
            SA45Team13bLibraryEntities context = new SA45Team13bLibraryEntities();
            BookList bookToBeDeleted;

            int    loaned;
            String selectedISBN;

            // Get the Selected Row, if any
            if (BooksDataGridView.SelectedRows.Count != 0)
            {
                // Get the selected Row (There's only one)
                loaned       = Convert.ToInt32(BooksDataGridView.SelectedRows[0].Cells["LoanedColumn"].Value.ToString());
                selectedISBN = BooksDataGridView.SelectedRows[0].Cells["ISBNColumn"].Value.ToString();

                // Can't delete book which is still loaned out
                if (loaned == 0)
                {
                    // Confirm Deletion, otherwise cancel
                    if (MessageBox.Show("Are you sure you want to delete?", "Confirm", MessageBoxButtons.YesNo)
                        == DialogResult.No)
                    {
                        return;
                    }

                    // Delete the book
                    bookToBeDeleted = context.BookLists.Where(book => book.ISBN == selectedISBN).First();
                    context.BookLists.Remove(bookToBeDeleted);

                    context.SaveChanges();

                    // Refresh the display
                    RefreshDisplay();
                }
                else
                {
                    MessageBox.Show("Please Return All Loaned Books First");
                    return;
                }
            }
            else
            {
                MessageBox.Show("Please Select a Book First");
                return;
            }
        }
        private void AddButton_Click(object sender, EventArgs e)
        {
            String errorMessage;

            // Get Entity Context
            SA45Team13bLibraryEntities context = new SA45Team13bLibraryEntities();

            // Display error if values are invalid
            if (!ValidateValues(out errorMessage))
            {
                MessageBox.Show(errorMessage, "Unable to add new Book", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            // Continue to add book
            BookList book = new BookList();

            book.BookTitle  = TitleTextBox.Text;
            book.Author     = AuthorTextBox.Text;
            book.Publisher  = PublisherTextBox.Text;
            book.ISBN       = ISBNTextBox.Text;
            book.Loaned     = 0;
            book.TotalStock = (short)StockNumericUpDown.Value;
            book.Language   = LanguageTextBox.Text;
            book.Genre      = GenreTextBox.Text;
            book.BookCost   = (float)Double.Parse(BookCostTextBox.Text);
            if (ShelfComboBox.SelectedValue != null)
            {
                book.Shelf = ShelfComboBox.SelectedValue.ToString();
            }
            else
            {
                book.Shelf = "1";
            }

            context.BookLists.Add(book);
            context.SaveChanges();

            // Display message
            MessageBox.Show("Book Added Sucessfully");
            DialogResult = DialogResult.OK;
            this.Close();
        }
        private void Delete_Click(object sender, System.EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                string        xx = dataGridView1.CurrentRow.Cells[1].Value.ToString();
                LibraryMember lb = context.LibraryMembers.Where(x => x.CustomerName == xx).First();
                context.LibraryMembers.Remove(lb);

                DialogResult result = MessageBox.Show("Are you sure to delete?", "Confirm", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    MessageBox.Show("Delete Success!");
                    context.SaveChanges();
                    refresh();
                }
            }
            else
            {
                MessageBox.Show("Please Search Member First");
                return;
            }
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            BookIssued bookissue;
            BookList   blist;
            DueTran    dtran;

            String SelectedISBN;
            String SelectedTitle;

            // Get the Selected Row, if any
            if (dataGridView1.SelectedRows.Count != 0)
            {
                // Get the selected Row (There's only one)
                SelectedISBN  = dataGridView1.SelectedRows[0].Cells["ISBNColumn"].Value.ToString();
                SelectedTitle = dataGridView1.SelectedRows[0].Cells["TitleColumn"].Value.ToString();
            }
            else
            {
                MessageBox.Show("Please Search a Book First");
                return;
            }


            //Assign bookissue to the selected book in datagrid view
            string returnbook = dataGridView1.CurrentRow.Cells[0].Value.ToString();

            var selectedISBN = from x in context.BookIssueds where x.ISBN == returnbook select x;

            bookissue = selectedISBN.First();

            //Over Due Date
            if (bookissue.DateDue < DateTime.Now)
            {
                var duetranupdate = from x in context.DueTrans
                                    where x.CustomerID.ToString() == textBox1.Text
                                    select x;
                dtran = duetranupdate.First();

                int payamount = 0;
                dtran.CustomerID = Int32.Parse(textBox1.Text);

                bookissue.DateActualReturn = DateTime.Now;

                TimeSpan noofDue = (DateTime.Now) - bookissue.DateDue;
                double   noofDay = noofDue.TotalDays;

                //TimeSpan duedate = DateTime.Today - bookissue.DateDue;
                //MessageBox.Show(duedate.ToString());

                int overdate = (int)noofDay;
                if (overdate > 1)
                {
                    payamount       = overdate;
                    dtran.DueAmount = payamount;
                }

                dtran.Remarks = "Find new; You are " + noofDay + "day late.";
                context.DueTrans.Add(dtran);

                var        dateupdate = from x in context.BookIssueds where x.ISBN == returnbook select x;
                BookIssued bi         = dateupdate.First();
                bi.DateActualReturn = DateTime.Now;

                MessageBox.Show("You are " + overdate + "days over due date!.. Pay Amount is: $" + payamount + "!");
                context.SaveChanges();
                refresh();
            }

            else
            {
                string returnbook1 = dataGridView1.CurrentRow.Cells[0].Value.ToString();
                var    q           = from x in context.BookLists where x.ISBN == returnbook1 select x;
                blist = q.ToList().First();
                blist.Loaned--;

                var        dateupdate = from x in context.BookIssueds where x.ISBN == returnbook1 select x;
                BookIssued bi         = dateupdate.First();
                bi.DateActualReturn = DateTime.Now;
                context.SaveChanges();
                MessageBox.Show("Thank You for Returning Your Book.");
                refresh();
            }
        }