mardi 19 janvier 2016

When checkbox is checked changes button behavior

I'm having troubles with my program, that requires a checkbox to see which values are archived. When the checkbox is checked my datagrid only shows the data that is "archived" (corresponding to 1 and 0 for "non-archived" values). With that in mind i want to be able to use the same button to revert the archived value and if the checkbox is not checked it could be able to archive the data value.

Example:

I got a company that it must be archived in the database, with that in mind i have to press the button to give on the table "archive" the value of 1. After that the value disapears because the checkbox isn't checked, but when i check it, the same company that i early on archived shows up. But if i want to change the value of the company from 1 to 0, i have to press the same button (and that's my problem at the moment, i can't figure out a way to make a button have 2 diferent behaviors)

private void chkVerArq_CheckedChanged(object sender, EventArgs e)
    {
        MySqlDataAdapter sda = new MySqlDataAdapter();

        if (chkVerArq.Checked == true)
        {
            string Connection = "server=localhost;user id=root; password = 12345; persistsecurityinfo=True;database=portaria";
            string Query = "SELECT nome_empresa, id_empresa from empresas WHERE arquivo= 1;";
            MySqlConnection Con = new MySqlConnection(Connection);
            MySqlCommand Command = new MySqlCommand(Query, Con);
            DataTable dt = new DataTable();
            sda.SelectCommand = Command;
            sda.Fill(dt);
            DgvGerirEmp.DataSource = dt;



        }
        else
        {
            string Connection = "server=localhost;user id=root; password = 12345; persistsecurityinfo=True;database=portaria";
            string Query = "SELECT nome_empresa, id_empresa from empresas WHERE arquivo= 0 ";
            MySqlConnection Con = new MySqlConnection(Connection);
            MySqlCommand Command = new MySqlCommand(Query, Con);
            DataTable dt = new DataTable();
            sda.SelectCommand = Command;
            sda.Fill(dt);
            DgvGerirEmp.DataSource = dt;
        }

Aucun commentaire:

Enregistrer un commentaire