Monitoring the last Row from a table

Asked

Viewed 70 times

1

I’m trying to monitor the latest row bank MySQL and when this is changed I will display a message, however I am having doubts on how to monitor with C code#.

I’ve managed to requisition the last row from time to time, but I would like to display it only if it is different from the previous one.

This first part starts my counter along with the Load form:

private void AnteSala_Load(object sender, EventArgs e)
{
    var timer = new System.Timers.Timer
    {
        Interval = 2 * 60 * 1000,
        SynchronizingObject = this
    };
    timer.Elapsed += delegate
    {
        //MessageBox.Show(@"tentou update check 1");
        ReadInformationFromeMessage();
        //MessageBox.Show(@"passou 1");
    };
    timer.Start();
}

This second half takes my last row bank message:

private void ReadInformationFromeMessage()
{
    try
    {
        const string mySelectQuery =
            "select * from send_eMessages order by id desc limit 1";
        var myCommand = new MySqlCommand(mySelectQuery, ConexaoBancoMySql.GetConexao());
        var reader = myCommand.ExecuteReader();

        while (reader.Read())
        {
            var eMessage = (reader.GetString("eMessage"));

            Invoke((MethodInvoker)delegate
            {

               var pop = new PopupNotifier
               {
                   //escopo de mensagem
                   TitleText = "*  Informativo de Segurança  *",
                   ContentText = "" + eMessage,
                   //fim do escopo de mensagem
                   TitleFont = new Font("Tahoma", 12),
                   //cor do titulo do form
                   TitleColor = Color.White,
                   BodyColor = System.Drawing.Color.FromArgb(0, 75, 0),
                   //contorno do form
                   BorderColor = System.Drawing.Color.FromArgb(0, 255, 0),
                   //cor da fonte do aviso
                   ContentColor = System.Drawing.Color.FromArgb(255, 255, 255),
                   //tamanho da fonte
                   ContentFont = new System.Drawing.Font("Tahoma", 12F),
                   //cor da fonte do aviso quando mouse em cima
                   ContentHoverColor = System.Drawing.Color.FromArgb(255, 255, 255),
                   //centralizacao da mensagem no form 
                   ImagePadding = new Padding(0),
                   ContentPadding = new Padding(10),
                   Delay = 15000,
                   GradientPower = 150,
                   //tamanho da borda superior
                   HeaderHeight = 1,
                   Scroll = true,
                   ShowCloseButton = true,
                   ShowGrip = true,
                   ShowOptionsButton = false,                      
               };
                pop.Popup();
           });
        }
    }
    catch (MySqlException ex)
    {
        MessageBox.Show(ex.ToString());
    }
    finally
    {
        ConexaoBancoMySql.FecharConexao();
    }
}

1 answer

0

The question was not clear to me, but I have no score to comment on. So I will answer based on what I understood.

In this case I would make a DataTable history cache, where every time you query saved the data in this cache table, and then compare the data return of the current query with the cache data.

public void sample(){

    DataTable cache = /* sua tabela de cache */;
    DataTable consultaAtual = /* retorno da sua consulta atual */;

    foreach(DataRow rowCache in cache.Rows){
        foreach(DataRow rowConsultaAtual in consultaAtual.Rows){
            /* abaixo você vai comparar todas as colunas da linha da consulta atual com as colunas da linha do cache */
            if(rowCache["column1"].toString().Equals(rowConsultaAtual["column1"])){
                /* os valores das colunas da consulta atual e do cache estão iguais, então não houve modificação */
            }
        }
    }
}

I don’t know if this is what you wanted, if not delete the answer. I’m beginner and I’m trying to learn helping, hope it helps you :)

  • 1

    All right @caio porem ja tive respostas no overflow , even so thanks

Browser other questions tagged

You are not signed in. Login or sign up in order to post.