예제 #1
0
 /// <summary>
 /// Use to retrieve the list of available lab tests.
 /// </summary>
 /// <returns>All available lab tests</returns>
 public static List<LabTest> GetAllLabTests()
 {
     List<LabTest> labTestList = new List<LabTest>();
     try
     {
         using (SqlConnection connection = HealthCareDBConnection.GetConnection())
         {
             string selectStatement =
                     "SELECT * from LabTest";
             using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
             {
                 connection.Open();
                 using (SqlDataReader reader = selectCommand.ExecuteReader())
                 {
                     while (reader.Read())
                     {
                         LabTest labTest = new LabTest();
                         labTest.TestId = (int) reader["testID"];
                         labTest.TestType = reader["testType"].ToString();
                         labTestList.Add(labTest);
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
     }
     return labTestList;
 }
예제 #2
0
        /// <summary>
        /// Use to retrieve a specific lab tests.
        /// </summary>
        /// <returns>the lab test with the given id</returns>
        public static LabTest GetLabTestByID(int id)
        {
            LabTest test = new LabTest();
            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string selectStatement =
                            "SELECT * from LabTest where testID = @TESTID";
                    using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                    {
                        selectCommand.Parameters.AddWithValue("@TESTID", id);
                        connection.Open();

                        using (SqlDataReader reader = selectCommand.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                test.TestId = (int)reader["testID"];
                                test.TestType = reader["testType"].ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
            return test;
        }
예제 #3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            bool edited = false;

            try
            {
                LabTest newTest = new LabTest();
                newTest.TestId = oldTest.TestId;
                if(Validator.IsPresent(tbTestType))
                {
                    newTest.TestType = tbTestType.Text;
                    edited = LabTestController.UpdateLabTest(oldTest, newTest);
                }

                if (!edited)
                {
                    throw new Exception("The lab test was not updated.");
                }

                MessageBox.Show("The lab test was updated successfully.", "Update Successful!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Close();   
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #4
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            //Validates required fields.
            if (Validator.AreAllPresent(controls))
            {
                newTest = new LabTest();
                newTest.TestType = tbTestType.Text;

                try
                {
                    int newTestID = LabTestController.AddLabTest(newTest);
                    MessageBox.Show("Success!", "Lab Test successfully added.", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    ClearAllControls();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);

                }
            }
        }
예제 #5
0
        public static bool UpdateLabTest(LabTest oldLabTest, LabTest newLabTest)
        {
            bool success = false;

            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string updateStatement =
                          "UPDATE LabTest SET " +
                            "testType = @NewTestType " +
                          "WHERE testID = @OldTestID " +
                            "AND testType = @OldTestType";

                    using (SqlCommand updateCommand = new SqlCommand(updateStatement, connection))
                    {
                        updateCommand.Parameters.AddWithValue("@NewTestType", newLabTest.TestType);
                        updateCommand.Parameters.AddWithValue("@OldTestID", oldLabTest.TestId);
                        updateCommand.Parameters.AddWithValue("@OldTestType", oldLabTest.TestType);

                        connection.Open();
                        int count = updateCommand.ExecuteNonQuery();
                        if (count > 0)
                        {
                            success = true;
                        }
                        else
                        {
                            success = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }
            return success;
        }
예제 #6
0
        public static int InsertLabTest(LabTest labTest)
        {
            int testID = -1;
            try
            {
                using (SqlConnection connection = HealthCareDBConnection.GetConnection())
                {
                    string insertStatement =
                        "INSERT LabTest " +
                        "(testType) " +
                        "VALUES (@TestType)";
                    using (SqlCommand insertCommand = new SqlCommand(insertStatement, connection))
                    {
                        insertCommand.Parameters.AddWithValue("@TestType", labTest.TestType);

                        connection.Open();
                        insertCommand.ExecuteNonQuery();

                        string selectStatement =
                            "SELECT IDENT_CURRENT('LabTest') FROM LabTest";

                        using (SqlCommand selectCommand = new SqlCommand(selectStatement, connection))
                        {
                            testID = Convert.ToInt32(selectCommand.ExecuteScalar());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK);
            }

            return testID;
        
        }
예제 #7
0
 public static bool UpdateLabTest(LabTest oldLabTest , LabTest newLabTest)
 {
     return LabTestDB.UpdateLabTest(oldLabTest, newLabTest);
 }
예제 #8
0
 public static int AddLabTest(LabTest labTest)
 {
     return LabTestDB.InsertLabTest(labTest);
 }
예제 #9
0
 public frmEditTest(int testID)
 {
     InitializeComponent();
     oldTest = LabTestController.GetLabTestByID(testID);
     tbTestID.Text = "" + testID;
 }