private void reserveBookToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveMdiChild != null) { this.ActiveMdiChild.Close(); } ReserveForm frm = new ReserveForm(); frm.Show(); frm.MdiParent = this; }
private void btnIssue_Click(object sender, EventArgs e) { try { if (ValidateInputs() == false) { return; } Book issuedBook = new Book(); issuedBook.BookID = int.Parse(txtBookID.Text); DataTable BookRequired = ConnectionManager.GetTable("select noOfAvailableBooks from Book where bookID=(" + int.Parse(txtBookID.Text) + ")"); IssueBook newIssue = new IssueBook(); newIssue.BookID = int.Parse(txtBookID.Text); newIssue.StudentID = int.Parse(txtStudentID.Text); newIssue.DoI = DateTime.Parse(txtDoI.Text); newIssue.DoR = DateTime.Parse(txtDoR.Text); newIssue.LibrarianID = int.Parse(txtLibrarianID.Text); DataTable BookAlreadyIssued = ConnectionManager.GetTable("select * from BookIssue where bookID=(" + int.Parse(txtBookID.Text) + ") and studentID=(" + int.Parse(txtStudentID.Text) + ")"); if (BookAlreadyIssued.Rows.Count >= 1) { MessageBox.Show("This student is currently in possess of one of this book already." + Environment.NewLine + "Please check again that all the Details inserted are correct.", "Sorry NOT ALLOWED"); txtBookID.Focus(); } else if (newIssue.DoR <= newIssue.DoI) { MessageBox.Show(" Date inserted must be wrong, as return date is previous or same to the date of issue.", "Sorry NOT POSSIBLE"); } else if (BookAlreadyIssued.Rows.Count == 0) { string ConditionQuery; ConditionQuery = "select noOfAvailableBooks from Book where bookID=(" + int.Parse(txtBookID.Text) + ")"; SqlConnection conn = ConnectionManager.DBConnection(); SqlDataReader rdr = null; try { conn.Open(); SqlCommand cmd = new SqlCommand(ConditionQuery, conn); rdr = cmd.ExecuteReader(); while (rdr.Read()) { Book booksDetails = new Book(); booksDetails.AvailableBooks = int.Parse(rdr["noOfAvailableBooks"].ToString()); if (booksDetails.AvailableBooks <= 0) { DialogResult dialogResult = MessageBox.Show("Book Requested is not available at moment." + Environment.NewLine + "Do you want Reserve this book?", "Sorry,Not Available.", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { this.Hide(); ReserveForm Procede = new ReserveForm(); Procede.Show(); } else if (dialogResult == DialogResult.No) { txtBookID.Text = ""; txtStudentID.Text = ""; txtDoI.Text = ""; txtDoR.Text = ""; txtLibrarianID.Text = ""; txtBookID.Focus(); MessageBox.Show("Issue Resetted."); } } else { newIssue.AddNewIssue(); issuedBook.updateBookQtyOnIssue(); MessageBox.Show("Book Issue Complete."); } } } catch { MessageBox.Show("Please make sure the follow details are inserted in the right format as in this example:" + Environment.NewLine + "BookiD : 1" + Environment.NewLine + "Student ID : 1001" + Environment.NewLine + "Date of Issue: MM-DD-YYYY" + Environment.NewLine + "Date of Return: 12-31-2018" + Environment.NewLine + "LibrarianID : 2"); } } }catch { MessageBox.Show("Please make sure the follow details are inserted in the right format as in this example:" + Environment.NewLine + "BookiD : 1" + Environment.NewLine + "Student ID : 1001" + Environment.NewLine + "Date of Issue: DD-MM-YYYY" + Environment.NewLine + "Date of Return: 31-12-2018" + Environment.NewLine + "LibrarianID : 2"); } }