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(); } } }
private void detach_Lendings(Lending entity) { this.SendPropertyChanging(); entity.Patron = null; }
private void attach_Lendings(Lending entity) { this.SendPropertyChanging(); entity.Patron = this; }
partial void DeleteLending(Lending instance);
partial void UpdateLending(Lending instance);
partial void InsertLending(Lending instance);