public void SaveStartTimeAndEndTime(List <DataTypes> importedList, int datasetIndex) { string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); string insertSQL = string.Format("INSERT INTO DataSet (DataSetIndex, StartTime, EndTime) VALUES ({0}, '{1:u}', '{2:u}')", datasetIndex + 1, importedList[0].StartTime, importedList[importedList.Count - 1].EndTime); try { con.Open(); SqlCommand cmd = new SqlCommand(insertSQL, con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { ActivityViewModel.ShowMessageBox(ex.ToString(), "Error"); } }
/* * The method randomizes the sequence textboxes. * New start time: (current simulation time) + (random amount of minutes between 5 and 120) * New end time: (New start time) + (random amount of minutes between 5 and 120) * New room and activity: random selection from database where the new room and activity are compatible with each other */ public void RandomizeSequence() { try { int randomIndex; NewStartTime = CurrentTime.AddMinutes(rnd.Next(5, 120)); NewEndTime = NewStartTime.AddMinutes(rnd.Next(5, 120)); List <DataTypes> RoomActivityList = new List <DataTypes>(); RoomActivityList = dbHandler.GetRoomActivityCombo(); randomIndex = rnd.Next(RoomActivityList.Count); NewRoom = RoomActivityList[randomIndex].Room; NewActivity = RoomActivityList[randomIndex].Activity; } catch (ArgumentOutOfRangeException) { ActivityViewModel.ShowMessageBox("Simulator must be running", "Error"); } }
public void SaveDoorsLocationToDatabase(double doorsY, int configId) { string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); string insertSQL = string.Format("UPDATE DoorsPosition SET VerticalPosition = {0} WHERE ConfigId = {1}", Math.Round(doorsY), configId); try { con.Open(); SqlCommand cmd = new SqlCommand(insertSQL, con); cmd.ExecuteNonQuery(); con.Close(); } catch (Exception ex) { ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!"); } }
public void UpdateActivityList() { if (NewStartDate.Date + NewStartTime.TimeOfDay < CurrentTime) { ActivityViewModel.ShowMessageBox("Start time must be later than current time", "Error entering sequence"); } else if (NewStartDate.Date + NewStartTime.TimeOfDay > NewEndDate.Date + NewEndTime.TimeOfDay) { ActivityViewModel.ShowMessageBox("Start time can not be later than end time", "Error entering sequence"); } else if (NewActivity == "" || NewRoom == "") { ActivityViewModel.ShowMessageBox("Enter a room and activity combo", "Error entering sequence"); } else { activityList = sequence.AddSequenceToList(activityList, listIndex, NewStartDate, NewEndDate, NewStartTime, NewEndTime, NewRoom, NewActivity); ShowNextActivity(); ActivityViewModel.ShowMessageBox("Sequence added to list", "Success!"); } }
public void SaveActivityData(List <DataTypes> importedList, int previousDatasetIndex) { string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); try { con.Open(); for (int i = 0; i < importedList.Count; i++) { string insertSQL = string.Format("INSERT INTO ActivityData (StartTime, EndTime, SensorLocationId, ActivityId, DatasetIndex) VALUES ('{0:u}', '{1:u}', (SELECT SensorLocationId FROM SensorLocation WHERE Location = '{2}'), (SELECT ActivityId FROM Activity WHERE Activity = '{3}'), {4})", importedList[i].StartTime, importedList[i].EndTime, importedList[i].Location, importedList[i].Activity, previousDatasetIndex + 1); SqlCommand cmd = new SqlCommand(insertSQL, con); cmd.ExecuteNonQuery(); } con.Close(); ActivityViewModel.ShowMessageBox("Activity data saved to database", "Success!"); } catch (Exception ex) { ActivityViewModel.ShowMessageBox(ex.ToString(), "Error"); } }
public void SaveConfigLocationToDatabase(List <ConfigPositions> configPositionList, int configId) { string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(connectionString); try { con.Open(); for (int i = 0; i < configPositionList.Count; i++) { string insertSQL = string.Format("UPDATE ActivityPosition SET XPos = {0}, YPos = {1} WHERE ActivityId = (SELECT ActivityId FROM Activity WHERE Activity = '{2}') AND ConfigId = {3}", Math.Round(configPositionList[i].XPos), Math.Round(configPositionList[i].YPos), configPositionList[i].Activity, configId); SqlCommand cmd = new SqlCommand(insertSQL, con); cmd.ExecuteNonQuery(); } con.Close(); ActivityViewModel.ShowMessageBox("Config locations saved to database", "Success!"); } catch (Exception ex) { ActivityViewModel.ShowMessageBox(ex.ToString(), "Error"); } }
public List <DataTypes> GetActivityData(int DataSetIndex) { string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString; List <DataTypes> activityDataList = new List <DataTypes>(); SqlConnection con = new SqlConnection(connectionString); string selectSQL = String.Format("SELECT ActivityData.StartTime, ActivityData.EndTime, SensorLocation.Location, " + "Room.Room, Activity.Activity FROM ActivityData LEFT JOIN SensorLocation " + "ON ActivityData.SensorLocationId = SensorLocation.SensorLocationId INNER JOIN Room ON " + "SensorLocation.RoomId = Room.RoomId LEFT JOIN Activity ON ActivityData.ActivityId = Activity.ActivityId " + "WHERE ActivityData.DataSetIndex = {0}", DataSetIndex); try { con.Open(); SqlCommand cmd = new SqlCommand(selectSQL, con); SqlDataReader dr = cmd.ExecuteReader(); if (dr != null) { while (dr.Read()) { DataTypes dataTypes = new DataTypes(); dataTypes.StartTime = Convert.ToDateTime(dr["StartTime"]); dataTypes.EndTime = Convert.ToDateTime(dr["EndTime"]); dataTypes.Location = Convert.ToString(dr["Location"]); dataTypes.Room = Convert.ToString(dr["Room"]); dataTypes.Activity = Convert.ToString(dr["Activity"]); activityDataList.Add(dataTypes); } } con.Close(); } catch (Exception ex) { ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!"); } return(activityDataList); }