Beispiel #1
0
        /// <summary>
        /// Search for all the borrow record accord to the input conditions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                LibraryEntity context = new LibraryEntity();
                if (String.IsNullOrEmpty(tbBookID.Text))
                {
                    var q = from x in context.Borrow
                            where x.NRIC.Contains(tbNRIC.Text) &&
                            (x.DateIssue >= dtpIssueDate.Value.Date && x.DateDue <= dtpDueDate.Value.Date) &&
                            x.RentalStatus == "out"
                            select new { x.TransactionID, x.Books.Title, x.Member.NRIC, x.Member.MemberName };
                    dvwMemberBorrows.DataSource = q.ToList();
                }
                else
                {
                    int bookid = Convert.ToInt32(tbBookID.Text);

                    var q = from x in context.Borrow
                            where x.BookID == bookid &&
                            x.NRIC.Contains(tbNRIC.Text) &&
                            (x.DateIssue >= dtpIssueDate.Value.Date && x.DateDue <= dtpDueDate.Value.Date) &&
                            x.RentalStatus == "out"
                            select new { x.TransactionID, x.Books.Title, x.Member.NRIC, x.Member.MemberName };
                    dvwMemberBorrows.DataSource = q.ToList();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please input booksid!");
            }
        }
Beispiel #2
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();

            try
            {
                Member m = context.Member.Where(x => x.NRIC == tbNRIC.Text).First();
                if (tbName.Text != "" && tbContact.Text != "" && tbEmail.Text != "" && m.Address != "")
                {
                    m.MemberName = tbName.Text;
                    m.Phone      = tbContact.Text;
                    m.Email      = tbEmail.Text;
                    m.Address    = tbAddress.Text;
                    context.SaveChanges();
                    MessageBox.Show("Update successfully!");
                }
                else
                {
                    MessageBox.Show("Fill in the all the details");
                }
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                MessageBox.Show("Fill in the all the details");
            }
            catch (System.InvalidOperationException)
            {
                MessageBox.Show("Invalid NRIC");
            }
        }
Beispiel #3
0
        /// <summary>
        /// Quotq plus 1
        /// </summary>
        private void AddQuota()
        {
            LibraryEntity context = new LibraryEntity();
            Member        mem     = context.Member.Where(x => x.NRIC == txtNRIC.Text).First();

            mem.Quota = mem.Quota + 1;
            context.SaveChanges();
        }
Beispiel #4
0
        /// <summary>
        /// Search for all the borrow record for a given member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCheckMember_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();
            var           q       = from x in context.Borrow
                                    where x.NRIC == tbNRIC.Text
                                    select new { x.TransactionID, x.Books.Title, x.Member.NRIC, x.Member.MemberName, x.DateIssue, x.DateDue };

            dvwMemberBorrows.DataSource = q.ToList();
        }
Beispiel #5
0
        /// <summary>
        /// Total stock plus 1
        /// </summary>
        private void Addtotalstock()
        {
            LibraryEntity context = new LibraryEntity();
            string        BokID   = dvwBooks.CurrentRow.Cells["BookID"].Value.ToString();
            int           BookID  = Convert.ToInt32(BokID);
            Books         bok     = context.Books.Where(x => x.BookID == BookID).First();

            bok.TotalStock = (short)(bok.TotalStock + 1);
            context.SaveChanges();
        }
Beispiel #6
0
        private void btnSearch_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();
            var           q       = from x in context.vw_min_book
                                    where x.Title.Contains(tbTitle.Text) && x.Author.Contains(tbAuthor.Text) && x.Genre.Contains(cmbGenre.Text)
                                    select x;

            dvwBooks.DataSource        = q.ToList();
            toolStripStatusLabel1.Text = q.Count().ToString() + " books found";
        }
Beispiel #7
0
        /// <summary>
        /// Set status to 'in'
        /// </summary>
        private void BookReturn()
        {
            LibraryEntity context = new LibraryEntity();
            string        TranID  = dvwBooks.CurrentRow.Cells["TransactionID"].Value.ToString();
            int           TransID = Convert.ToInt32(TranID);
            Borrow        bor     = context.Borrow.Where(x => x.TransactionID == TransID).First();

            bor.RentalStatus     = "in";
            bor.DateActualReturn = DateTime.Now;
            context.SaveChanges();
        }
Beispiel #8
0
        private void btnBooksSearch_Click(object sender, EventArgs e)
        {
            LibraryEntity context    = new LibraryEntity();
            string        title      = tbTitle.Text;
            string        author     = tbAuthor.Text;
            string        callNumber = tbCallNumber.Text;
            var           q          = from x in context.Books
                                       where x.Title.Contains(title) && x.Author.Contains(author) && x.CallNumber.Contains(callNumber) && x.Genre.Contains(cmbGenre.Text)
                                       select x;

            dvwBooks.DataSource        = q.ToList();
            toolStripStatusLabel1.Text = q.Count().ToString() + " books found";
        }
Beispiel #9
0
 /// <summary>
 /// Search for all the borrow record for a given member
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnCheckBook_Click_1(object sender, EventArgs e)
 {
     try
     {
         LibraryEntity context = new LibraryEntity();
         int           bookid  = Convert.ToInt32(tbBookID.Text);
         dvwMemberBorrows.DataSource = context.Borrow.Where(x => x.BookID == bookid).ToList();
     }
     catch (System.FormatException)
     {
         MessageBox.Show("Please select a book!");
     }
 }
Beispiel #10
0
        private void SearchMember()
        {
            LibraryEntity context = new LibraryEntity();
            string        name    = tbName.Text;
            string        phone   = tbPhone.Text;
            string        email   = tbEmail.Text;
            string        address = tbAddress.Text;
            string        NRIC    = this.value;
            var           q       = from x in context.Member
                                    where x.NRIC.Contains(NRIC) && x.MemberName.Contains(name) && x.Phone.Contains(phone) && x.Email.Contains(email) && x.Address.Contains(address)
                                    select x;

            dvwMember.DataSource = q.ToList();
        }
Beispiel #11
0
        private void btnSearchMember_Click(object sender, EventArgs e)
        {
            LibraryEntity        context      = new LibraryEntity();
            SearchMemberDialogue searchMember = new SearchMemberDialogue();

            searchMember.ShowDialog();
            if (searchMember.DialogResult == DialogResult.OK)
            {
                Member member = context.Member.Where(x => x.NRIC == searchMember.NRIC).First();
                tbNRIC.Text    = member.NRIC.ToString();
                tbName.Text    = member.MemberName.ToString();
                tbEmail.Text   = member.Email.ToString();
                tbContact.Text = member.Phone.ToString();
                tbAddress.Text = member.Address.ToString();
            }
        }
Beispiel #12
0
        /// <summary>
        /// Total stock in book table minus 1
        /// </summary>
        private void TotalStockminus()
        {
            LibraryEntity context = new LibraryEntity();
            int           bookID  = Convert.ToInt32(txtBookID.Text);

            try
            {
                Books bok = context.Books.Where(x => x.BookID == bookID).First();
                bok.TotalStock = (short)(bok.TotalStock - 1);
                context.SaveChanges();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
        }
Beispiel #13
0
        /// <summary>
        /// Insert a record into borrow table
        /// </summary>
        private void Borrow()
        {
            LibraryEntity context = new LibraryEntity();
            Borrow        bo      = new Borrow();
            Member        me      = context.Member.Where(x => x.NRIC == txtNRIC.Text).First();
            int           bookID  = Convert.ToInt32(txtBookID.Text);
            Books         bok     = context.Books.Where(x => x.BookID == bookID).First();

            bo.Member       = me;
            bo.Books        = bok;
            bo.BookID       = bok.BookID;
            bo.NRIC         = me.NRIC;
            bo.RentalStatus = "out";
            bo.DateIssue    = dtpDOI.Value;
            bo.DateDue      = dtpDueDate.Value;
            bo.Remarks      = txtRemarks.Text;
            context.Borrow.Add(bo);
            context.SaveChanges();
        }
Beispiel #14
0
        /// <summary>
        /// Delete the member
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();

            try
            {
                Member member = context.Member.Where(x => x.NRIC == tbNRIC.Text).First();
                context.Member.Remove(member);
                context.SaveChanges();
                MessageBox.Show("successful");
                tbNRIC.Text    = null;
                tbName.Text    = null;
                tbEmail.Text   = null;
                tbContact.Text = null;
                tbAddress.Text = null;
            }
            catch (Exception)
            {
                MessageBox.Show("Invalid NRIC");
            }
        }
Beispiel #15
0
        /// <summary>
        /// Issue borrow book: Insert a borrow record to the borrow table, the total stock of the book minus 1, the quota for member minus 1
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnIssuebook_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();

            try
            {
                using (TransactionScope transScope = new TransactionScope())
                {
                    int    bookID = Convert.ToInt32(txtBookID.Text);
                    Books  bok    = context.Books.Where(x => x.BookID == bookID).First();
                    Member mem    = context.Member.Where(x => x.NRIC == txtNRIC.Text).First();
                    if (bok.TotalStock > 0 && mem.Quota > 0)
                    {
                        this.Borrow();
                        this.TotalStockminus();
                        this.Quotaminus();
                        toolStripStatusLabel1.Text = "Lend successfully";
                        // Auto increment column, the last record is the newest record
                        int    Count = context.Borrow.Count();
                        Borrow bor   = context.Borrow.ToList()[Count - 1];
                        int    TraID = bor.TransactionID;
                        if (cbPrintReceipt.CheckState == CheckState.Checked)
                        {
                            // The receipt form should given a tranID
                            ReceiptForm rececipt = new ReceiptForm(TraID);
                            rececipt.Show();
                        }
                    }
                    else
                    {
                        MessageBox.Show("Please check the totalstock of " + bok.Title + "or the quota of" + mem.MemberName);
                    }
                    transScope.Complete();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("Please check your NRIC or BookID");
            }
        }
Beispiel #16
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();
            Books         b       = new Books();

            try
            {
                b.Title      = tbTitle.Text;
                b.Author     = tbAuthor.Text;
                b.TotalStock = Convert.ToInt16(tbTotalStock.Text);
                b.Genre      = cmbGenre.SelectedItem.ToString();
                b.CallNumber = tbCallNumber.Text;
                context.Books.Add(b);
                context.SaveChanges();
                MessageBox.Show("Update successfull");
                this.Close();
            }
            catch (System.Data.Entity.Infrastructure.DbUpdateException)
            {
                MessageBox.Show("fill in the all the details");
            }
        }
Beispiel #17
0
 private void btnSignup_Click(object sender, EventArgs e)
 {
     LibraryEntity context = new LibraryEntity();
     Member m = new Member();
     try
     {
         m.NRIC = tbNRIC.Text;
         m.MemberName = tbName.Text;
         m.Phone = tbContact.Text;
         m.Email = tbEmail.Text;
         m.Address = tbAddress.Text;
         ///
         ///The quota for every new member is 4
         ///
         m.Quota = 4;
         context.Member.Add(m);
         context.SaveChanges();
     }
     catch (System.Data.Entity.Infrastructure.DbUpdateException)
     {
         MessageBox.Show("fill in the all the details");
     }
 }
Beispiel #18
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();

            if (tbMemberID.Text == "Venkat")
            {
                if (tbPassword.Text == "P@ssword1")
                {
                    SearchBookForm form = new SearchBookForm();
                    form.ShowDialog(this);
                    this.Close();
                }
                else
                {
                    MessageBox.Show("Incorect password!");
                }
            }
            else
            {
                int    id       = Convert.ToInt32(tbMemberID.Text);
                string password = tbPassword.Text;
                try
                {
                    Staff staff = context.Staff.Where(x => x.StaffID == id && x.Password == password).First();
                    if (staff != null)
                    {
                        SearchBookForm form = new SearchBookForm();
                        form.ShowDialog(this);
                        this.Close();
                    }
                }
                catch (System.InvalidOperationException)
                {
                    MessageBox.Show("Incorect password!", "ERROR");
                }
            }
        }
Beispiel #19
0
        private void btnSearchBook_Click(object sender, EventArgs e)
        {
            LibraryEntity context = new LibraryEntity();

            dvwBooks.DataSource = context.Borrow.Where(x => x.NRIC == txtNRIC.Text && x.RentalStatus == "out").ToList();
        }