Ejemplo n.º 1
0
    /// <summary>
    /// Sends a query to insert an entry
    /// this is done if a status of the user is red
    /// </summary>
    /// @author Rasmus Rosenkjær
    /// @status Done
    /// @date 25/05/2020
    /// <param name="currentLocationDTO"></param>
    public static string SendRedEntry(CurrentLocationDTO currentLocationDTO)
    {
        using (MySqlConnection conn = new MySqlConnection("Server=172.16.21.169;port=3306;Database=AppData;UiD=root;Pwd=rd2020"))
        {
            try
            {
                if (conn.State != System.Data.ConnectionState.Open)
                {
                    conn.Open();
                }

                string query = "INSERT INTO CurrentLocation(UserID, status, latitude, longitude, currentTime, act) VALUES (";

                query += currentLocationDTO.UserID + ",'" +
                         currentLocationDTO.Status + "'," +
                         currentLocationDTO.Latitude + "," +
                         currentLocationDTO.Longitude + ",'" +
                         currentLocationDTO.CurrentTime + "'," +
                         currentLocationDTO.Act + ")";
                query += ";";


                MySqlCommand cmd = new MySqlCommand(query, conn);

                cmd.ExecuteNonQuery();

                return("Red Entry was sent");
            }
            catch (System.Exception e)
            {
                return(e.ToString());
            }
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// A Enumerator to save the location of the user
    /// this is done every 2 minutes
    /// </summary>
    /// @author Rasmus Rosenkjær
    /// @status Done
    /// @date 20/05/2020
    /// <returns></returns>
    IEnumerator SaveCurrentLocation()
    {
        yield return(new WaitForSecondsRealtime(120));

        if (locationStatus.Equals("Yellow"))
        {
            yellowCounter++;
            if (yellowCounter >= 3)
            {
                locationStatus = "Red";
                this.GetComponent <SpriteRenderer>().color = new Color(255, 0, 0);
            }
        }

        CurrentLocationDTO location = new CurrentLocationDTO();

        location.UserID = DatabaseManager.userID;

        location.Status = locationStatus;

        location.Latitude = latitude;

        location.Longitude = longitude;

        location.CurrentTime = DateTime.Now.ToString();

        location.Act = false;

        currentLocationDTOs[entryCounter] = location;

        if (locationStatus.Equals("Red"))
        {
            status.text = DatabaseManager.SendRedEntry(currentLocationDTOs[entryCounter]);
        }


        entryCounter++;

        StartCoroutine(SaveCurrentLocation());
    }