Example #1
0
 private void btnReg_Click(object sender, EventArgs e)
 {
     if (txtAddress.Text == "" || txtFirst.Text == "" || txtLast.Text == "")
     {
         MessageBox.Show("One or more fields are blank.");
     }
     else
     {
         var r  = chxMember.Checked ? 1 : 2;
         var db = new libmanDataClassesDataContext();
         var p  = new Patron
         {
             Address   = txtAddress.Text,
             FirstName = txtFirst.Text,
             LastName  = txtLast.Text,
             Role      = r
         };
         db.Patrons.InsertOnSubmit(p);
         db.SubmitChanges();
         if (r == 1)
         {
             var f = new Fee {
                 Amount = 25m, AssessedDate = DateTime.Today, FeeType = "MEM", PaidDate = DateTime.Today, PatronId = p.Id
             };
             db.Fees.InsertOnSubmit(f);
             db.SubmitChanges();
         }
         MessageBox.Show("Patron registered.");
     }
 }
 private void btnCO_Click(object sender, EventArgs e)
 {
     txtStatus.Clear();
     txtStatus.AppendText($"{DateTime.Now}\r\n- - - - - - - - - -\r\n");
     if (txtBookId.Text == "" || txtPatronId.Text == "")
     {
         txtStatus.AppendText("Book ID and Patron ID cannot be empty.\r\n");
     }
     else
     {
         var db             = new libmanDataClassesDataContext();
         var bookOut        = db.Lendings.Any(l => l.BookId == int.Parse(txtBookId.Text) && l.ReturnDate == null);
         var booksChecked   = db.Lendings.Count(l => l.PatronId == int.Parse(txtPatronId.Text));
         var limit          = db.Patrons.Where(p => p.Id == int.Parse(txtPatronId.Text)).Select(p => p.Role1.Limit).First();
         var chargesPending = db.Fees.Where(f => f.PatronId == int.Parse(txtPatronId.Text) && f.PaidDate == null);
         var totalFees      = chargesPending.Select(f => f.Amount).Sum();
         if (bookOut)
         {
             txtStatus.AppendText("Book has been checked out already.\r\n");
         }
         else if (booksChecked == limit)
         {
             txtStatus.AppendText("Checkout limit reached.\r\n");
         }
         else if (totalFees > 0)
         {
             var mb = MessageBox.Show($"Patron has ${totalFees} in charges which must be paid before further checkouts are made. Pay now?", "LibMan", MessageBoxButtons.YesNo);
             if (mb == DialogResult.Yes)
             {
                 foreach (var cp in chargesPending)
                 {
                     cp.PaidDate = DateTime.Today;
                 }
                 db.SubmitChanges();
             }
         }
         else
         {
             var checkout = new Lending
             {
                 BookId     = int.Parse(txtBookId.Text),
                 PatronId   = int.Parse(txtPatronId.Text),
                 BorrowDate = DateTime.Today
             };
             db.Lendings.InsertOnSubmit(checkout);
             txtStatus.AppendText("Patron successfully checked out book.\r\n");
             db.SubmitChanges();
         }
     }
 }
Example #3
0
        private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (!e.IsSelected)
            {
                return;
            }
            txtStatus.Clear();
            var db = new libmanDataClassesDataContext();
            var b  = db.Books.First(_ => _.Title == e.Item.Text);

            txtStatus.AppendText($"BOOK ID: {b.Id}\r\nLENDING STATUS: ");
            var l = db.Lendings.FirstOrDefault(_ => _.Book == b && _.ReturnDate == null);

            txtStatus.AppendText(l == null ? "AVAILABLE\r\n" : $"CHECKED OUT\r\nTO: {l.Patron.LastName}, {l.Patron.FirstName}\r\nDUE: {l.BorrowDate+TimeSpan.FromDays(7):d}");
        }
Example #4
0
 private void btnSearch_Click(object sender, System.EventArgs e)
 {
     listView1.Items.Clear();
     if (txtSearch.Text == "")
     {
         MessageBox.Show("Search field is blank.");
     }
     else
     {
         var db = new libmanDataClassesDataContext();
         if (rdbTitle.Checked)
         {
             foreach (var b in db.Books.Where(_ => _.Title.Contains(txtSearch.Text)).Select(_ => new { _.Title, Author = $"{_.AuthorLastName}, {_.AuthorFirstName}" }))
             {
                 listView1.Items.Add(new ListViewItem(new[] { b.Title, b.Author }));
             }
         }
         else if (rdbAuthorLast.Checked)
         {
             foreach (var b in db.Books.Where(_ => _.AuthorLastName.Contains(txtSearch.Text)).Select(_ => new { _.Title, Author = $"{_.AuthorLastName}, {_.AuthorFirstName}" }))
             {
                 listView1.Items.Add(new ListViewItem(new[] { b.Title, b.Author }));
             }
         }
         else if (rdbAuthorFirst.Checked)
         {
             foreach (var b in db.Books.Where(_ => _.AuthorFirstName.Contains(txtSearch.Text)).Select(_ => new { _.Title, Author = $"{_.AuthorLastName}, {_.AuthorFirstName}" }))
             {
                 listView1.Items.Add(new ListViewItem(new[] { b.Title, b.Author }));
             }
         }
         else if (rdbID.Checked)
         {
             foreach (var b in db.Books.Where(_ => _.Id == int.Parse(txtSearch.Text)).Select(_ => new { _.Title, Author = $"{_.AuthorLastName}, {_.AuthorFirstName}" }))
             {
                 listView1.Items.Add(new ListViewItem(new[] { b.Title, b.Author }));
             }
         }
     }
 }
 private void btnCI_Click(object sender, EventArgs e)
 {
     txtStatus.Clear();
     txtStatus.AppendText($"{DateTime.Now}\r\n- - - - - - - - - -\r\n");
     if (txtBookId.Text == "")
     {
         txtStatus.AppendText("Book ID cannot be empty.\n");
     }
     else
     {
         var db      = new libmanDataClassesDataContext();
         var bookOut = db.Lendings.Any(l => l.BookId == int.Parse(txtBookId.Text) && l.ReturnDate == null);
         if (!bookOut)
         {
             txtStatus.AppendText("Book has not been checked out.\n");
         }
         else
         {
             var dateOut = db.Lendings.Where(l => l.BookId == int.Parse(txtBookId.Text) && l.ReturnDate == null).Select(l => l.BorrowDate).First();
             if ((DateTime.Today - dateOut).TotalDays > 7)
             {
                 var p = db.Lendings.Where(l => l.BookId == int.Parse(txtBookId.Text) && l.ReturnDate == null).Select(l => l.PatronId).First();
                 var f = new Fee {
                     Amount = 5m, AssessedDate = DateTime.Today, FeeType = "OD", PatronId = p
                 };
                 var mb = MessageBox.Show($"Patron has returned book overdue. Pay now?", "LibMan", MessageBoxButtons.YesNo);
                 if (mb == DialogResult.Yes)
                 {
                     f.PaidDate = DateTime.Today;
                 }
                 db.Fees.InsertOnSubmit(f);
             }
             var checkin = db.Lendings.First(l => l.BookId == int.Parse(txtBookId.Text) && l.ReturnDate == null);
             checkin.ReturnDate = DateTime.Today;
             txtStatus.AppendText($"CHECK IN\r\nPATRON: {checkin.Patron.LastName}, {checkin.Patron.FirstName}\r\nBOOK: {checkin.Book.Title}\r\n");
         }
         db.SubmitChanges();
     }
 }