internal void CreateMeasurement(Activity activity, string MeasurementResult, string insertedDateOfMeasurement)
 {
     DateTime dateOfMeasurement = Convert.ToDateTime(insertedDateOfMeasurement);
     Double result = Double.Parse(MeasurementResult);
     Measurement newMeasurement = new Measurement(activity.Id, result, dateOfMeasurement);
     dataQualityAssurance.AddNewMeasurement(activity, newMeasurement);
 }
        internal void CreateActivity(string name, string location, string reason, string measurementMethod, Employee measurementEmployee, string insertedMeasurementDate,
            string insertedMeasurementNumber, string frequencyMeasurementType, string expectedResultMin, string expectedResultMax, string failureAction, Employee failureActionEmployee, string productName)
        {
            int frequencyMeasurementNumber = Convert.ToInt32(insertedMeasurementNumber);
            
            DateTime measurementDate = Convert.ToDateTime(insertedMeasurementDate);
            //public Activity(string name, string location, string reason, string measurementMethod, Employee measurementEmployee, DateTime measurementDate, int frequencyMeasurementNumber,
            //string frequencyMeasurementType, double expectedResultMin, double expectedResultMax, string failureAction, string failureActionEmployeeName, double measureMent, string productName)

            Activity newActivity = new Activity(name, location, reason, measurementMethod, measurementEmployee, measurementDate,
                frequencyMeasurementNumber, frequencyMeasurementType, expectedResultMin, expectedResultMax, failureAction, failureActionEmployee, productName);
            dataQualityAssurance.AddNewActivity(newActivity);
        }
 public string AddNewMeasurement(Activity activity, Measurement newMeasurement)
 {
     try
     {
         SqlCommand sqlcmd = new SqlCommand("CreateNewMeasurement", conn);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.Add(new SqlParameter("@fk_ActivityID", activity.Id));
         sqlcmd.Parameters.Add(new SqlParameter("@Result", newMeasurement.Result));
         sqlcmd.Parameters.Add(new SqlParameter("@DateOfMeasurement", newMeasurement.DateOfMeasurement));
         conn.Open();
         sqlcmd.ExecuteNonQuery();
         conn.Close();
         return "Activity created!";
     }
     catch (SqlException e)
     {
         return e.Message;
     }
     finally
     {
         conn.Close();
     }
 }
 public string AddNewActivity(Activity activity)
 {
     try
     {
         
         if (conn.State != ConnectionState.Open)
             conn.Open();
         SqlCommand sqlcmd = new SqlCommand("createNewActivity", conn);
         sqlcmd.CommandType = CommandType.StoredProcedure;
         sqlcmd.Parameters.Add(new SqlParameter("@Name", activity.Name));
         sqlcmd.Parameters.Add(new SqlParameter("@Location", activity.Location));
         sqlcmd.Parameters.Add(new SqlParameter("@Reason", activity.Reason));
         sqlcmd.Parameters.Add(new SqlParameter("@MeasurementMethod", activity.MeasurementMethod));
         sqlcmd.Parameters.Add(new SqlParameter("@fk_MeasurementEmployeeID", activity.MeasurementEmployee.Id));
         sqlcmd.Parameters.Add(new SqlParameter("@MeasurementDate", activity.MeasurementDate));
         sqlcmd.Parameters.Add(new SqlParameter("@FrequencyMeasurementNumber", activity.FrequencyMeasurementNumber));
         sqlcmd.Parameters.Add(new SqlParameter("@FrequencyMeasurementType", activity.FrequencyMeasurementType));
         sqlcmd.Parameters.Add(new SqlParameter("@ExpectedMinResult", activity.ExpectedResultMin));
         sqlcmd.Parameters.Add(new SqlParameter("@ExpectedMaxResult", activity.ExpectedResultMax));
         sqlcmd.Parameters.Add(new SqlParameter("@FailureAction", activity.FailureAction));
         sqlcmd.Parameters.Add(new SqlParameter("@fk_FailureActionEmployeeID", activity.FailureActionEmployee.Id));
         sqlcmd.Parameters.Add(new SqlParameter("@ProductName", activity.ProductName));
         
         sqlcmd.ExecuteNonQuery();
         conn.Close();
         return "Activity created!";
     }
     catch (SqlException e)
     {
         return e.Message;
     }
     finally
     {
         conn.Close();
     }
 }
        public List<Activity> ReadScheduledActivities()
        {
            List<Activity> activityList = new List<Activity>();
            try
            {
                if (conn.State != ConnectionState.Open)
                    conn.Open();
                SqlCommand sqlcmd = new SqlCommand("GetScheduledActivities", conn);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                DataTable table = new DataTable();
                SqlDataAdapter adapter = new SqlDataAdapter(sqlcmd);
                adapter.Fill(table);
                SqlDataReader reader = sqlcmd.ExecuteReader();
                reader.Read();
                foreach (DataRow row in table.Rows)
                {
                    Activity newActivity = new Activity(
                        row["Name"].ToString(),
                        row["Location"].ToString(),
                        row["Reason"].ToString(),
                        row["MeasurementMethod"].ToString(),
                        ReadEmployeeFromId(int.Parse(row["fk_MeasurementEmployeeID"].ToString()))[0],
                        DateTime.Parse(row["MeasurementDate"].ToString()),
                        int.Parse(row["FrequencyMeasurementNumber"].ToString()),
                        row["FrequencyMeasurementType"].ToString(),
                        row["ExpectedMinResult"].ToString(),
                        row["ExpectedMaxResult"].ToString(),
                        row["FailureAction"].ToString(),
                        ReadEmployeeFromId(int.Parse(row["fk_FailureActionEmployeeID"].ToString()))[0],
                        row["ProductName"].ToString());
                    newActivity.Id = int.Parse(row["pk_ActivityID"].ToString());
                    activityList.Add(newActivity);
                }
                conn.Close();
                return activityList;
            }
            catch (SqlException e)
            {
                throw e;
            }
            finally
            {
                conn.Close();
            }

        }