lundi 21 août 2017

Floorplan of users status

I'm currently starting to develop a floorplan of my working place to show if the users are Online, Offline or Away. The best way that I know is making buttons, because when the user clicks it, it need to show some information about the PC.

Now, the way to show the status of the users in the buttons is changing the color of the button like Online->Green, Offline->Red, Away->Yellow

I can determine the color thanks to a mysql table that stores the status of each user, but my problem is that I don't know how to link each button to its status in the table.

    protected void Page_Load(object sender, EventArgs e)
    {
        foreach (Button b in this.Controls.OfType<Button>())
        {
            string MyConString ="SERVER=000.000.000.00;" + "DB=fakedb;" + "User=fakeuser;" + "Password=fakepass;";


            SqlConnection con = new SqlConnection(MyConString);
            SqlCommand command = con.CreateCommand();

            con.Open();

            string str = "Select Status from  Ustatus where Username = @user";
                command = new SqlCommand(str, con);
            command.CommandType = System.Data.CommandType.Text;
            command.Parameters.AddWithValue("@user", b.Text);
            object obj = command.ExecuteScalar();

            string statuser = obj.ToString();

            if (statuser == "ONLINE")
            {
                b.ForeColor = Color.Green;
                b.BackColor = Color.Green;
            }
            else if (statuser == "OFFLINE")
            {
                b.ForeColor = Color.Red;
                b.BackColor = Color.Red;
            }
            else
            {
                b.ForeColor = Color.Yellow;
                b.BackColor = Color.Yellow;
            }


        }
    }

I'm using that, without luck. Am I taking the right path or there is another way to do it? Thank you in advance!




Aucun commentaire:

Enregistrer un commentaire