private void btnSubmit_Click(object sender, EventArgs e) { int rV = 0; foreach (DataGridViewRow dg in dataGridView1.Rows) { if (Convert.ToBoolean(dg.Cells[0].Value) == true) { rV++; } } if (rV > 0 && (txtName.Text.Length > 0)) { DialogResult result = new DialogResult(); result = MessageBox.Show("Proceed with borrowing?", "Borrowing books", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { SA45TEAM01ALibraryEntities context = new SA45TEAM01ALibraryEntities(); using (TransactionScope ts = new TransactionScope()) { foreach (DataGridViewRow dgRow in dataGridView1.Rows) { if (dgRow.Cells[0].Value != null) { int selected1 = Convert.ToInt32(dgRow.Cells[3].Value.ToString()); int newIssueID = context.Issue_Details.Select(x => x.Issue_ID).Max() + 1; Issue_Details id = new Issue_Details(); id.Issue_ID = newIssueID; id.Issue_Date = DateTime.Today.ToString(); id.Due_Date = DateTime.Today.AddDays(20).ToString(); id.Book_ID = selected1; id.User_ID = Convert.ToInt32(txtID.Text.ToString()); id.Rental_Status = "OUT"; id.Return_Date = null; context.Issue_Details.Add(id); string uid = txtID.Text; User m = context.Users.Where(x => x.User_ID.ToString() == uid).First(); m.Book_due++; context.SaveChanges(); } } ts.Complete(); } FormBorrow(); } } else if (rV > 0) { MessageBox.Show("Please input a valid user id"); } else { MessageBox.Show("Please select checkboxes for books to borrow"); } }
private void btnReceive_Click(object sender, EventArgs e) { bool isBlank = true; foreach (DataGridViewRow dgRow in dataGridView1.Rows) { DataGridViewCheckBoxCell CbxCell = (DataGridViewCheckBoxCell)dgRow.Cells[0]; if (Convert.ToBoolean(CbxCell.Value) == false) { isBlank = true; } else { isBlank = false; break; } } if (isBlank == true) { MessageBox.Show("Select books first"); } else { DialogResult result = new DialogResult(); result = MessageBox.Show("Are Books received?", "Receiving Books", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { foreach (DataGridViewRow dgRow1 in dataGridView1.Rows) { if (Convert.ToBoolean(dgRow1.Cells[0].Value)) { using (TransactionScope ts = new TransactionScope()) { string sID = dgRow1.Cells[1].Value.ToString(); string uID = dgRow1.Cells[4].Value.ToString(); Issue_Details id = context.Issue_Details.Where(x => x.Issue_ID.ToString() == sID && x.User_ID.ToString() == uID).First(); id.Rental_Status = "IN"; id.Return_Date = DateTime.Today.ToString(); User u = context.Users.Where(x => x.User_ID.ToString() == uID).First(); u.Book_due--; context.SaveChanges(); ts.Complete(); } } toolStripStatusLabel2.Text = "Changes Updated."; } } else { FormRefresh(); } } }