Example #1
0
        private void chamarChatToolStripMenuItem_Click(object sender, EventArgs e)
        {
            tela_conversa   tela = new tela_conversa();
            MySqlDataReader dr;
            Conexao         con = new Conexao();
            MySqlCommand    cmd = new MySqlCommand("select * from tb_conversa where destinatario = @destinatario  and remetente =@remetente or destinatario =@remetente and remetente=@destinatario", con.ConectarBD());

            cmd.Parameters.Add("@destinatario", MySqlDbType.VarChar).Value = msg;
            cmd.Parameters.Add("@remetente", MySqlDbType.VarChar).Value    = Variaveis_globais.usuario;
            dr = cmd.ExecuteReader();
            if (dr.HasRows == false)
            {
                tela.Show();
                tela.cbbDesti.Text = msg;
            }
            else
            {
                tela.Show();
            }
            while (dr.Read())
            {
                tela.cbbDesti.Text     = dr[2].ToString();
                tela.richTextBox1.Text = dr[3].ToString();
            }
            con.DesconectarBD();
            con.ConectarBD();
            con.DesconectarBD();
        }
        private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            tela_conversa   tela = new tela_conversa();
            MySqlDataReader dr;
            Conexao         con = new Conexao();
            MySqlCommand    cmd = new MySqlCommand("select * from tb_conversa where destinatario = @destinatario and lido ='n' and remetente =@remetente or destinatario=@remetente and remetente=@destinatario and lido='n'", con.ConectarBD());

            cmd.Parameters.Add("@destinatario", MySqlDbType.VarChar).Value = Variaveis_globais.usuario;
            cmd.Parameters.Add("@remetente", MySqlDbType.VarChar).Value    = msg;
            dr = cmd.ExecuteReader();
            string remet;

            if (dr.HasRows == false)
            {
                MessageBox.Show("Erro ao buscar !");
            }
            else
            {
                tela.Show();
                while (dr.Read())
                {
                    remet = dr[1].ToString();
                    if (Variaveis_globais.usuario == remet)
                    {
                        tela.cbbDesti.Text     = dr[1].ToString();
                        tela.richTextBox1.Text = dr[3].ToString();
                    }
                    else if (Variaveis_globais.usuario != remet)
                    {
                        tela.cbbDesti.Text     = dr[2].ToString();
                        tela.richTextBox1.Text = dr[3].ToString();
                    }
                    this.Close();
                }
                con.DesconectarBD();
                con.ConectarBD();
                con.DesconectarBD();
            }

            Conexao      co = new Conexao();
            MySqlCommand cm = new MySqlCommand("update tb_conversa set lido='s' where destinatario = @destinatario and lido ='n' and remetente =@remetente or destinatario=@remetente and remetente=@destinatario", co.ConectarBD());

            cm.Parameters.Add("@destinatario", MySqlDbType.VarChar).Value = Variaveis_globais.usuario;
            cm.Parameters.Add("@remetente", MySqlDbType.VarChar).Value    = msg;
            cm.ExecuteNonQuery();
            try
            {
                MessageBox.Show("LIDO COM SUCESSO !");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }