Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (timerExec)
- {
- timerExec = false;
- selectStatusRobos();
- }
- //timer1.Enabled = false;
- }
- public async void selectStatusRobos()
- {
- String Configuracao = "server=midas.heliohost.org;user=midas_Client;password=SPNSf0V$&zo0;database=midas_Midas;port=3306";
- string query = "SELECT i.Usuario_meta, i.Nome_robo, i.Simbolo, i.Periodo, i.Status_op, i.Operacao, i.Hora_criacao, c.Id, i.Corretora FROM int00 AS i INNER JOIN cliente00 AS c ON i.Usuario_meta = c.Usuario_meta AND i.Corretora = c.Corretora";
- MySqlConnection conexao = new MySqlConnection(Configuracao);
- try
- {
- await conexao.OpenAsync();
- MySqlCommand COMANDO = new MySqlCommand(query, conexao);
- MySqlDataAdapter adapter = new MySqlDataAdapter(COMANDO);
- DataTable status = new DataTable();
- await adapter.FillAsync(status);
- bool flag_find = false;
- for (int i = 0; i < dataGridView1.RowCount; i++)
- {
- flag_find = false;
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_exclamation_red_46014;
- dataGridView1.Rows[i].Cells["Operacao"].Value = Properties.Resources.if_op_null;
- dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_op_null;
- for (int b = 0; b < status.Rows.Count; b++)
- {
- if (dataGridView1.Rows[i].Cells["Id"].Value.ToString() == status.Rows[b]["Id"].ToString()
- && dataGridView1.Rows[i].Cells["Usuario_meta"].Value.ToString() == status.Rows[b]["Usuario_meta"].ToString()
- && dataGridView1.Rows[i].Cells["Corretora"].Value.ToString() == status.Rows[b]["Corretora"].ToString()
- && dataGridView1.Rows[i].Cells["Nome_robo"].Value.ToString() == status.Rows[b]["Nome_robo"].ToString()
- && dataGridView1.Rows[i].Cells["Simbolo"].Value.ToString() == status.Rows[b]["Simbolo"].ToString().Substring(0, 3)
- && dataGridView1.Rows[i].Cells["Periodo"].Value.ToString() == status.Rows[b]["Periodo"].ToString())
- {
- flag_find = true;
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
- dataGridView1.Rows[i].Cells["Hora_ultima"].Value = status.Rows[b]["Hora_criacao"].ToString();
- if (status.Rows[b]["Operacao"].ToString() == "1") // Compra
- {
- dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_Raise_32535_16;
- dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
- }
- else if (status.Rows[b]["Operacao"].ToString() == "2") // Venda
- {
- dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_Fall_32468_16;
- dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
- }
- else
- {
- dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_op_null;
- dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
- }
- if (status.Rows[b]["Status_op"].ToString() == "2") // Off
- {
- dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_power_off_10214;
- dataGridView1.Rows[i].Cells["Status_op"].Value = status.Rows[b]["Status_op"].ToString();
- }
- else if (status.Rows[b]["Status_op"].ToString() == "1") // On
- {
- dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_power_on_10215;
- dataGridView1.Rows[i].Cells["Status_op"].Value = status.Rows[b]["Status_op"].ToString();
- }
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
- //query = "DELETE FROM `int00` WHERE Usuario_meta = @usuario_meta AND Nome_robo = @nome_robo AND Simbolo = @simbolo AND Periodo = @periodo";
- //COMANDO.CommandText = query;
- //COMANDO.Parameters.Clear();
- //COMANDO.Parameters.Add("@usuario_meta", MySqlDbType.VarChar).Value = status.Rows[b]["Usuario_meta"].ToString();
- //COMANDO.Parameters.Add("@nome_robo", MySqlDbType.VarChar).Value = status.Rows[b]["Nome_robo"].ToString();
- //COMANDO.Parameters.Add("@simbolo", MySqlDbType.VarChar).Value = status.Rows[b]["Simbolo"].ToString();
- //COMANDO.Parameters.Add("@periodo", MySqlDbType.VarChar).Value = status.Rows[b]["Periodo"].ToString();
- //COMANDO.ExecuteNonQuery();
- //break;
- }
- if (dataGridView1.Rows[i].Cells["Hora_ultima"].Value != null)
- {
- DateTime t = Convert.ToDateTime(dataGridView1.Rows[i].Cells["Hora_ultima"].Value.ToString());
- // if (dataGridView1.Rows[i].Cells["Hora_ultima"].Value.ToString() != status.Rows[b]["Hora_criacao"].ToString())
- if (flag_find)
- {
- DateTime t1 = DateTime.Now;
- DateTime t2 = DateTime.Now.AddSeconds(-30);
- System.TimeSpan diff2 = t1.Subtract(t);
- if (diff2.TotalSeconds >= 15 && diff2.TotalSeconds <= 45)
- {
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_58_62715;
- }
- else if (diff2.TotalSeconds < 15 && diff2.TotalSeconds >= 0)
- {
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
- }
- else
- {
- dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_exclamation_red_46014;
- }
- }
- }
- }
- }
- //frm = this.MdiParent as frmPrincipal;
- //SendMessage send = new SendMessage(frm.SetLabel);
- //send(DateTime.Now.ToString("HH:mm :ss") + " - Dados Atualizados...", null, null);
- conexao.Close();
- }
- catch (MySqlException ex)
- {
- frm = this.MdiParent as frmPrincipal;
- SendMessage send = new SendMessage(frm.SetLabel);
- send(DateTime.Now.ToString("HH:mm :ss") + " - Tempo limite excedido na seleção", ex.Message + ex.StackTrace, Properties.Resources.if_Close_Icon_Dark_1398917, 15000);
- //MessageBox.Show(ex.Message + ex.StackTrace, "Detalhes Exception");
- timerExec = true;
- }
- catch (TimeoutException ex)
- {
- frm = this.MdiParent as frmPrincipal;
- SendMessage send = new SendMessage(frm.SetLabel);
- send(DateTime.Now.ToString("HH:mm :ss") + " - Tempo limite excedido na seleção", ex.Message + ex.StackTrace, Properties.Resources.if_Close_Icon_Dark_1398917, 15000);
- timerExec = true;
- }
- finally
- {
- frm = this.MdiParent as frmPrincipal;
- SendMessage send = new SendMessage(frm.SetLabel);
- send(DateTime.Now.ToString("HH:mm :ss") + " - Dados Atualizados...", null, null, 15000);
- conexao.Close();
- timerExec = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement