Esempio n. 1
0
        public void SaveConfigChanges()
        {
            double bedX;
            double bedY;
            double toiletX;
            double toiletY;
            double showerAreaX;
            double showerAreaY;
            double diningTableX;
            double diningTableY;
            double basinX;
            double basinY;
            double sofaX;
            double sofaY;
            double entranceX;
            double entranceY;
            double doorsY;

            char[] separator = new char[] { ';' };
            if (string.IsNullOrEmpty(BedCoords) || string.IsNullOrEmpty(ToiletCoords) || string.IsNullOrEmpty(ShowerCoords) || string.IsNullOrEmpty(DiningCoords) || string.IsNullOrEmpty(BasinCoords) || string.IsNullOrEmpty(SofaCoords) || string.IsNullOrEmpty(EntranceCoords) || string.IsNullOrEmpty(DoorsCoords))
            {
                ActivityViewModel.ShowMessageBox("All coordinate textboxes must be filled", "Error!");
            }
            else
            {
                AddActivityLocations();
                bedX         = Convert.ToDouble(BedCoords.Split(separator)[0]);
                bedY         = Convert.ToDouble(BedCoords.Split(separator)[1]);
                toiletX      = Convert.ToDouble(ToiletCoords.Split(separator)[0]);
                toiletY      = Convert.ToDouble(ToiletCoords.Split(separator)[1]);
                showerAreaX  = Convert.ToDouble(ShowerCoords.Split(separator)[0]);
                showerAreaY  = Convert.ToDouble(ShowerCoords.Split(separator)[1]);
                diningTableX = Convert.ToDouble(DiningCoords.Split(separator)[0]);
                diningTableY = Convert.ToDouble(DiningCoords.Split(separator)[1]);
                basinX       = Convert.ToDouble(BasinCoords.Split(separator)[0]);
                basinY       = Convert.ToDouble(BasinCoords.Split(separator)[1]);
                sofaX        = Convert.ToDouble(SofaCoords.Split(separator)[0]);
                sofaY        = Convert.ToDouble(SofaCoords.Split(separator)[1]);
                entranceX    = Convert.ToDouble(EntranceCoords.Split(separator)[0]);
                entranceY    = Convert.ToDouble(EntranceCoords.Split(separator)[1]);
                doorsY       = Convert.ToDouble(DoorsCoords.Split(separator)[1]);
                AddActivityCoords(bedX, nameof(bedX));
                AddActivityCoords(bedY, nameof(bedY));
                AddActivityCoords(toiletX, nameof(toiletX));
                AddActivityCoords(toiletY, nameof(toiletY));
                AddActivityCoords(showerAreaX, nameof(showerAreaX));
                AddActivityCoords(showerAreaY, nameof(showerAreaY));
                AddActivityCoords(diningTableX, nameof(diningTableX));
                AddActivityCoords(diningTableY, nameof(diningTableY));
                AddActivityCoords(basinX, nameof(basinX));
                AddActivityCoords(basinY, nameof(basinY));
                AddActivityCoords(sofaX, nameof(sofaX));
                AddActivityCoords(sofaY, nameof(sofaY));
                AddActivityCoords(entranceX, nameof(entranceX));
                AddActivityCoords(entranceY, nameof(entranceY));
                DatabaseHandler dbHandler = new DatabaseHandler();
                dbHandler.SaveDoorsLocationToDatabase(doorsY, 1);
                dbHandler.SaveConfigLocationToDatabase(configPositionList, 1);
            }
        }
        public List <string> GetRoomList()
        {
            string        Room;
            string        connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
            List <string> roomList         = new List <string>();
            SqlConnection con       = new SqlConnection(connectionString);
            string        selectSQL = "SELECT Room FROM Room";

            try
            {
                con.Open();
                SqlCommand    cmd = new SqlCommand(selectSQL, con);
                SqlDataReader dr  = cmd.ExecuteReader();
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        Room = Convert.ToString(dr["Room"]);

                        roomList.Add(Room);
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
            return(roomList);
        }
        public double GetDoorVerticalPosition(int configId)
        {
            double        doorVerticalPosition = 0;
            string        connectionString     = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
            SqlConnection con       = new SqlConnection(connectionString);
            string        selectSQL = string.Format("SELECT VerticalPosition FROM DoorsPosition WHERE ConfigId = {0}", configId);

            try
            {
                con.Open();
                SqlCommand    cmd = new SqlCommand(selectSQL, con);
                SqlDataReader dr  = cmd.ExecuteReader();
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        doorVerticalPosition = Convert.ToDouble(dr["VerticalPosition"]);
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
            return(doorVerticalPosition);
        }
        public List <DataTypes> GetRoomActivityCombo()
        {
            string           connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
            List <DataTypes> roomActivityList = new List <DataTypes>();
            SqlConnection    con       = new SqlConnection(connectionString);
            string           selectSQL = "SELECT Room.Room, Activity.Activity FROM Room_Activity_Mapping INNER JOIN Room ON Room_Activity_Mapping.RoomId = Room.RoomId INNER JOIN Activity ON Room_Activity_Mapping.ActivityId = Activity.ActivityId";

            try
            {
                con.Open();
                SqlCommand    cmd = new SqlCommand(selectSQL, con);
                SqlDataReader dr  = cmd.ExecuteReader();
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        DataTypes dataTypes = new DataTypes();

                        dataTypes.Room     = Convert.ToString(dr["Room"]);
                        dataTypes.Activity = Convert.ToString(dr["Activity"]);

                        roomActivityList.Add(dataTypes);
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
            return(roomActivityList);
        }
        public List <ConfigPositions> GetConfigPositions(int configId)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
            List <ConfigPositions> configPositionList = new List <ConfigPositions>();
            SqlConnection          con = new SqlConnection(connectionString);
            string selectSQL           = String.Format("SELECT Activity.Activity, XPos, YPos FROM ActivityPosition INNER JOIN Activity ON ActivityPosition.ActivityId = Activity.ActivityId");

            try
            {
                con.Open();
                SqlCommand    cmd = new SqlCommand(selectSQL, con);
                SqlDataReader dr  = cmd.ExecuteReader();
                if (dr != null)
                {
                    while (dr.Read())
                    {
                        ConfigPositions configPosition = new ConfigPositions();

                        configPosition.Activity = Convert.ToString(dr["Activity"]);
                        configPosition.XPos     = Convert.ToDouble(dr["XPos"]);
                        configPosition.YPos     = Convert.ToDouble(dr["YPos"]);

                        configPositionList.Add(configPosition);
                    }
                }
                con.Close();
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
            return(configPositionList);
        }
        public List <Dataset> GetDatasetInfo()
        {
            {
                string         connectionString = ConfigurationManager.ConnectionStrings["DatabaseConnectionString"].ConnectionString;
                List <Dataset> datasetList      = new List <Dataset>();
                SqlConnection  con       = new SqlConnection(connectionString);
                string         selectSQL = "SELECT * FROM DataSet";
                try
                {
                    con.Open();
                    SqlCommand    cmd = new SqlCommand(selectSQL, con);
                    SqlDataReader dr  = cmd.ExecuteReader();
                    if (dr != null)
                    {
                        while (dr.Read())
                        {
                            Dataset dataSet = new Dataset();

                            dataSet.DataSetIndex = Convert.ToInt16(dr["DataSetIndex"]);
                            dataSet.StartTime    = Convert.ToDateTime(dr["StartTime"]);
                            dataSet.EndTime      = Convert.ToDateTime(dr["EndTime"]);

                            datasetList.Add(dataSet);
                        }
                    }
                    con.Close();
                }
                catch (Exception ex)
                {
                    ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
                }
                return(datasetList);
            }
        }
Esempio n. 7
0
        public void ImportFromCSV(int previousDatasetIndex)
        {
            DatabaseHandler  dbHandler    = new DatabaseHandler();
            List <DataTypes> importedList = new List <DataTypes>();

            SelectFilePath();
            try
            {
                using (var reader = new StreamReader(filePath))
                {
                    while (!reader.EndOfStream)
                    {
                        DataTypes dataTypes = new DataTypes();
                        var       line      = reader.ReadLine();
                        var       values    = line.Split(';');
                        dataTypes.StartTime = Convert.ToDateTime(values[0]);
                        dataTypes.EndTime   = Convert.ToDateTime(values[1]);
                        dataTypes.Location  = Convert.ToString(values[2]);
                        dataTypes.Room      = Convert.ToString(values[3]);
                        dataTypes.Activity  = Convert.ToString(values[4]);

                        importedList.Add(dataTypes);
                    }
                }
                dbHandler.SaveStartTimeAndEndTime(importedList, previousDatasetIndex);
                dbHandler.SaveActivityData(importedList, previousDatasetIndex);
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
        }
Esempio n. 8
0
        public void ExportToCSV(int dataSetIndex, List <DataTypes> activityList, string exportFileName)
        {
            if (!activityList.Any())
            {
                DatabaseHandler dbHandler = new DatabaseHandler();
                activityList = dbHandler.GetActivityData(dataSetIndex);
            }
            SelectFolderPath();
            string csv = "";

            for (int i = 0; i < activityList.Count; i++)
            {
                csv = csv + string.Format("{0:yyyy/MM/dd hh:mm:ss};{1:yyyy/MM/dd hh:mm:ss};{2};{3};{4}" + "\n",
                                          Convert.ToString(activityList[i].StartTime), Convert.ToString(activityList[i].EndTime),
                                          Convert.ToString(activityList[i].Location),
                                          Convert.ToString(activityList[i].Room), Convert.ToString(activityList[i].Activity));
            }
            try
            {
                System.IO.File.WriteAllText(string.Format(@"{0}" + "\\{1}.csv", folderName, exportFileName), csv);
            }
            catch (Exception ex)
            {
                ActivityViewModel.ShowMessageBox(ex.ToString(), "Error!");
            }
        }
Esempio n. 9
0
 public void StartSimulationThread()
 {
     if (simulationThreadFinished)
     {
         simulationThreadFinished = false;
         simulationCaller         = new Thread(new ThreadStart(StartSimulation));
         simulationCaller.Start();
     }
     else
     {
         ActivityViewModel.ShowMessageBox("Simulation already running", "Error!");
     }
 }
Esempio n. 10
0
 /*
  * 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 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");
            }
        }
        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!");
            }
        }
Esempio n. 13
0
 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);
        }