/// <summary>
    /// Queries the database for a Users Personal Information
    /// </summary>
    /// @Author Dennis Dupont
    /// @Status Done
    /// @Date 02/5/2020
    /// <returns>Returns a CitizenTemplate containing the Users Information</returns>
    public static CitizenTemplate QueryDatabaseForUserInfo(int userId)
    {
        //Opens the Connection to the Database, while we're in the production phase we're using the Root Login
        //Which will later be replaced with a safe user.
        using (MySqlConnection conn = new MySqlConnection("Server=172.16.21.168;port=3306;Database=UserLogin;UiD=root;Pwd=rd2020"))
        {
            if (conn.State != System.Data.ConnectionState.Open)
            {
                conn.Open();
            }


            string query = $"SELECT UserID, Firstname, Lastname, Zipcode FROM User WHERE UserID='{userId}'";

            MySqlCommand cmd = new MySqlCommand(query, conn);

            MySqlDataReader reader = cmd.ExecuteReader();
            if (reader.Read())
            {
                CitizenTemplate citizen = new CitizenTemplate();
                citizen.UserID    = reader.GetInt32(0);
                citizen.FirstName = reader.GetString(1);
                citizen.LastName  = reader.GetString(2);
                citizen.ZipCode   = reader.GetString(3);
                return(citizen);
            }
            return(null);
        }
    }
Exemplo n.º 2
0
    /// <summary>
    /// Queries the server though the DatabaseManager to get the
    /// user information to spawns the bars showing users in the system
    /// </summary>
    /// @Author Dennis Dupont
    /// @Status Done
    public void SpawnUserbars()
    {
        GameObject parent = barHolder;

        for (int i = 1; i <= 5; i++)
        {
            //Queries the Database for User Data, to display on the Bars
            CitizenTemplate user = DatabaseManager.QueryDatabaseForUserInfo(i);

            if (user != null)
            {
                //Creates a User Bar
                GameObject currentUserBar = Instantiate(userbarPrefab, parent.transform);

                //Manually sets up this GameObject as a button
                currentUserBar.GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => SpawnDetailWindow(user.UserID));

                //Adds the Bar to the list of Bars
                instance.userBars.Add(currentUserBar);

                //Makes the Bar a child of the BarHolder Object
                currentUserBar.transform.SetParent(parent.transform);

                //Gets the text Object in the Bar and updates it according to the user Information
                currentUserBar.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = user.FirstName + " " + user.LastName;

                //Checks the Status of the User Created
                string status = DatabaseManager.GetUserStatus(user.UserID);

                //Updates his Dashboard Status in accordance with his personal Status
                if (status == "Green")
                {
                    currentUserBar.transform.GetChild(2).GetComponent <UnityEngine.UI.Image>().color = new Color(0, 255, 0);
                }
                if (status == "Yellow")
                {
                    currentUserBar.transform.GetChild(2).GetComponent <UnityEngine.UI.Image>().color = new Color(255, 255, 0);
                }
                if (status == "Red")
                {
                    currentUserBar.transform.GetChild(2).GetComponent <UnityEngine.UI.Image>().color = new Color(255, 0, 0);
                }
            }
            else
            {
                print("Was null?!");
                break;
            }
        }
    }
Exemplo n.º 3
0
    /// <summary>
    /// Queries the server though the DatabaseManager to get the
    /// user information to spawn in the Detail Windows for a specific User
    /// </summary>
    /// @Author Dennis Dupont
    /// @Status Done
    public void SpawnDetailWindow(int barId)
    {
        GameObject parent = GameObject.FindGameObjectWithTag("Canvas");

        CitizenTemplate user = DatabaseManager.QueryDatabaseForUserInfo(barId);

        GameObject detailWindow = Instantiate(detailInfoPrefab, transform.parent);

        //Manually sets up this GameObject as a button
        detailWindow.transform.GetChild(6).GetComponent <UnityEngine.UI.Button>().onClick.AddListener(() => PerformCall(user.UserID));

        //If a details windows is already displayed, it will be removed
        if (instance.currentDetailInfo != null)
        {
            Destroy(currentDetailInfo.gameObject);
        }

        //The Details Windows is set as the Current Details Window
        //And is set to a child of the Canvas object
        instance.currentDetailInfo = detailWindow;
        instance.currentDetailInfo.transform.SetParent(parent.transform, false);

        //Gets the text Object in the Details Window and updates it according to the user Information
        instance.currentDetailInfo.transform.GetChild(1).GetComponent <TextMeshProUGUI>().text = "Name: " + user.FirstName + " " + user.LastName;
        instance.currentDetailInfo.transform.GetChild(3).GetComponent <TextMeshProUGUI>().text = "Zipcode: " + user.ZipCode;

        //Queries the Database for his latest 60 entries
        CurrentLocationTemplate[] userEntries = DatabaseManager.GetUserDataEntries(barId);

        //Clears the Log
        instance.currentDetailInfo.transform.GetChild(4).transform.GetChild(0).transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = "";

        //Displays the users Log Entries on the Dashboard
        foreach (CurrentLocationTemplate entry in userEntries)
        {
            instance.currentDetailInfo.transform.GetChild(4).transform.GetChild(0).transform.GetChild(0).GetComponent <TextMeshProUGUI>().text += "Status: " + entry.Status + "\n" +
                                                                                                                                                  "Latitude: " + entry.Latitude + "\n" +
                                                                                                                                                  "Longitude: " + entry.Longitude + "\n" +
                                                                                                                                                  "Current Time: " + entry.CurrentTime + "\n\n";
        }
    }