private void btnReturnToCriteriaForm_Click(object sender, EventArgs e) { var criteria = new frmCriteria(); this.Hide(); criteria.Show(); }
private void btnLoadDecision_Click(object sender, EventArgs e) { //Handle attempts at loading a created decision try { var connection = ConfigurationManager.ConnectionStrings["DecisionsServer"].ConnectionString; using (SqlConnection conn = new SqlConnection(connection.ToString())) { conn.Open(); if (lstDecisionDisplay.SelectedIndex == -1) { //Below SQL Command is for a situation where the program closed before setting the "IsCurrentDecision" field of the decision being used to 0 //and the user accidentally attempts to load no decision using (SqlCommand cmd = new SqlCommand("UPDATE Decision SET IsCurrentDecision = 0 WHERE IsCurrentDecision = 1")) { cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.ExecuteNonQuery(); } MessageBox.Show("Please select the decision you wish to load."); } else if (lstDecisionDisplay.SelectedIndex != -1) { //Ensure that only one decision is set to be the current decision at a time by resetting the "IsCurrentDecision" value of all other decisions //back to 0 if there are any. using (SqlCommand cmd = new SqlCommand("UPDATE Decision SET IsCurrentDecision = 0 WHERE DecisionName <> '" + lstDecisionDisplay.SelectedItems[0].ToString() + "' AND IsCurrentDecision = 1")) { cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.ExecuteNonQuery(); } using (SqlCommand cmd = new SqlCommand("UPDATE Decision SET IsCurrentDecision = 1 WHERE DecisionName = '" + lstDecisionDisplay.SelectedItems[0].ToString() + "'")) { cmd.CommandType = CommandType.Text; cmd.Connection = conn; cmd.ExecuteNonQuery(); } var criteria = new frmCriteria(); this.Hide(); criteria.Show(); } conn.Close(); } } catch (Exception E) { MessageBox.Show(E.ToString()); } }