private void retrunboat_button_Click(object sender, EventArgs e) { //see if boat is borrowed by someone searchboats_button.PerformClick(); Searchborrowers_button.PerformClick(); if ((accno_textbox.Text != Boat1) && (accno_textbox.Text != Boat2)) { MessageBox.Show("THE INPUTED BORROWER HAS NOT BORRWED THE BOAT INPUTED! \n"); return; } //everything is fine, continue return process //first set the value of boat1 or boat2 as accno of boat being returned try { if (Boat1 == accno_textbox.Text) { //accno must be updated in book1 slot cmd = new SqlCommand("Transact_Update_Boat1_SP", con); } else { //accno must be updated in book2 slot cmd = new SqlCommand("Transact_Update_Boat2_SP", con); } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@accNo", (object)DBNull.Value); cmd.Parameters.AddWithValue("@brId", borrowerid_textbox.Text); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } //now we also update borrower id in boats table cmd = new SqlCommand("Transact_Update_Borrower_SP", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@accNo", accno_textbox.Text); cmd.Parameters.AddWithValue("@brId", (object)DBNull.Value); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); //insert details into transactions table cmd = new SqlCommand("Transactions_Delete_SP", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@boat_num", accno_textbox.Text); cmd.Parameters.AddWithValue("@br_id", borrowerid_textbox.Text); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); //this completes the whole transaction so now we perfom click event on both buttons so user can see the changes made Searchborrowers_button.PerformClick(); searchboats_button.PerformClick(); MessageBox.Show("Successfully returned.\n"); }
private void issueboat_button_Click(object sender, EventArgs e) { //see if boat is borrowed by someone searchboats_button.PerformClick(); if (Borrower != "") { //someone has borrowed the boat MessageBox.Show("Boat is already borrowed by borrower with id: \n" + Borrower); return; } //see if borrower has already taken two boats Searchborrowers_button.PerformClick(); if ((Boat1 != "") && (Boat2 != "")) { //borrower has already borrowed maximum number of boats MessageBox.Show("Borrower has already borrowed maximum number of books. \n"); return; } //everything is fine, continue issue process //first set the value of boat1 or boat2 as accno of boat being issued in borrowers table try { if (Boat1 == "") { //accno must be updated in book1 slot cmd = new SqlCommand("Transact_Update_Boat1_SP", con); } else if (Boat2 == "") { //accno must be updated in book2 slot cmd = new SqlCommand("Transact_Update_Boat2_SP", con); } cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@accNo", accno_textbox.Text); cmd.Parameters.AddWithValue("@brId", borrowerid_textbox.Text); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } //now we also update borrower id in boats table cmd = new SqlCommand("Transact_Update_Borrower_SP", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@accNo", accno_textbox.Text); cmd.Parameters.AddWithValue("@brId", borrowerid_textbox.Text); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); //insert details into transactions table cmd = new SqlCommand("Transactions_Insert_SP", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@boat_num", accno_textbox.Text); cmd.Parameters.AddWithValue("@br_id", borrowerid_textbox.Text); con.Open(); try { cmd.ExecuteNonQuery(); } catch (Exception ex) { MessageBox.Show(" <<<INVALID SQL OPERATION>>> :\n" + ex); } con.Close(); //this completes the whole transaction so now we perfom click event on both buttons so user can see the changes made Searchborrowers_button.PerformClick(); searchboats_button.PerformClick(); MessageBox.Show("Successfully issued.\n"); }