private void button1_Click(object sender, EventArgs e) { textBox2.Clear(); try { dt.Rows.Clear(); int memberid = int.Parse(textBox1.Text); MembersDetail mb = ctx.MembersDetails.Single(x => x.MemberID == memberid); if (mb == null) { toolStripStatusLabel1.Text = "Invalid ID"; } else { textBox2.Text = mb.MemberName; } var transactionInfos = ctx.LoanRecords.Where(x => x.MemberID.ToString() == textBox1.Text) .Select(x => new { TransactionID = x.TransactionID, DateIssue = x.DateIssue, DateDue = x.DateDue }).ToList(); foreach (var info in transactionInfos) { var bookIDs = ctx.LoanTransDetails.Where(x => x.TransactionID == info.TransactionID && x.LoanStatus == "out").Select(x => x.BookID).ToList(); var books = ctx.BooksDetails.Where(x => bookIDs.Contains(x.BookID)).Select(x => new { BookID = x.BookID, BookTitle = x.BookTitle, Author = x.Author, BookType = x.BookType }); foreach (var b in books) { DataRow r = dt.NewRow(); r["TransactionID"] = info.TransactionID; r["BookID"] = b.BookID; r["BookTitle"] = b.BookTitle; r["Author"] = b.Author; r["BookType"] = b.BookType; r["DateIssue"] = info.DateIssue; r["DateDue"] = info.DateDue; dt.Rows.Add(r); } } dataGridView1.DataSource = dt; if (dataGridView1.RowCount == 0) //for members who have no books to return currently { toolStripStatusLabel1.Text = "There is no book pending return currently."; } else { toolStripStatusLabel1.Text = "Please select one or more books to return."; //clear message if members have books to return } } catch (Exception obj) { toolStripStatusLabel1.Text = "Please input the correct MemberID"; textBox2.Text = ""; } }
private void buttonDelete_Click(object sender, EventArgs e) { int CurRec = posn; MembersDetail m = memberLst[CurRec]; ctx.MembersDetails.Remove(m); ctx.SaveChanges(); if (posn > 0) { posn--; } PopulateText(posn); }
private void txtMemberID_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { try { if (e.KeyData == Keys.Tab) { MembersDetail md = ctx.MembersDetails.Where(x => x.MemberID.ToString() == txtMemberID.Text).First(); txtMemberName.Text = md.MemberName; } } catch (InvalidOperationException) { txtBookTitle.Text = ""; toolStripLabel1.Text = "Please enter a valid Member ID before pressing tab"; } }
private void buttonAdd_Click(object sender, EventArgs e) { MembersDetail m = new MembersDetail(); txtMemberID.Text = Convert.ToString(" "); txtMemberName.Text = " "; dtpBirthDate.Format = DateTimePickerFormat.Custom; dtpBirthDate.CustomFormat = " "; txtEmailAddress.Text = ""; txtAddress.Text = ""; txtPostalCode.Text = ""; txtPhoneNumber.Text = ""; memberLst.Add(m); ctx.MembersDetails.Add(m); posn = memberLst.Count - 1; PopulateText(posn); dtpBirthDate.Format = DateTimePickerFormat.Long; }
private void buttonFind_Click(object sender, EventArgs e) { int id = Convert.ToInt32(txtFind.Text); MembersDetail md = memberLst.SingleOrDefault(m => m.MemberID == id); if (memberLst.SingleOrDefault(m => m.MemberID == id) == null) { toolStripLabel.Text = "No records exists in table"; } else { for (int i = 0; i < memberLst.Count; i++) { if (txtFind.Text == memberLst[i].MemberID.ToString()) { posn = i; toolStripLabel.Text = "Records: " + posn; break; } PopulateText(posn); } } }