Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.09 KB | None | 0 0
  1. private void timer1_Tick(object sender, EventArgs e)
  2. {
  3. if (timerExec)
  4. {
  5. timerExec = false;
  6. selectStatusRobos();
  7.  
  8. }
  9. //timer1.Enabled = false;
  10. }
  11. public async void selectStatusRobos()
  12. {
  13. String Configuracao = "server=midas.heliohost.org;user=midas_Client;password=SPNSf0V$&zo0;database=midas_Midas;port=3306";
  14. 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";
  15. MySqlConnection conexao = new MySqlConnection(Configuracao);
  16. try
  17. {
  18. await conexao.OpenAsync();
  19. MySqlCommand COMANDO = new MySqlCommand(query, conexao);
  20. MySqlDataAdapter adapter = new MySqlDataAdapter(COMANDO);
  21. DataTable status = new DataTable();
  22. await adapter.FillAsync(status);
  23. bool flag_find = false;
  24. for (int i = 0; i < dataGridView1.RowCount; i++)
  25. {
  26. flag_find = false;
  27. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_exclamation_red_46014;
  28. dataGridView1.Rows[i].Cells["Operacao"].Value = Properties.Resources.if_op_null;
  29. dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_op_null;
  30. for (int b = 0; b < status.Rows.Count; b++)
  31. {
  32.  
  33. if (dataGridView1.Rows[i].Cells["Id"].Value.ToString() == status.Rows[b]["Id"].ToString()
  34. && dataGridView1.Rows[i].Cells["Usuario_meta"].Value.ToString() == status.Rows[b]["Usuario_meta"].ToString()
  35. && dataGridView1.Rows[i].Cells["Corretora"].Value.ToString() == status.Rows[b]["Corretora"].ToString()
  36. && dataGridView1.Rows[i].Cells["Nome_robo"].Value.ToString() == status.Rows[b]["Nome_robo"].ToString()
  37. && dataGridView1.Rows[i].Cells["Simbolo"].Value.ToString() == status.Rows[b]["Simbolo"].ToString().Substring(0, 3)
  38. && dataGridView1.Rows[i].Cells["Periodo"].Value.ToString() == status.Rows[b]["Periodo"].ToString())
  39. {
  40. flag_find = true;
  41. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
  42. dataGridView1.Rows[i].Cells["Hora_ultima"].Value = status.Rows[b]["Hora_criacao"].ToString();
  43. if (status.Rows[b]["Operacao"].ToString() == "1") // Compra
  44. {
  45. dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_Raise_32535_16;
  46. dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
  47. }
  48. else if (status.Rows[b]["Operacao"].ToString() == "2") // Venda
  49. {
  50. dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_Fall_32468_16;
  51. dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
  52. }
  53. else
  54. {
  55. dataGridView1.Rows[i].Cells["Operacao_img"].Value = Properties.Resources.if_op_null;
  56. dataGridView1.Rows[i].Cells["Operacao"].Value = status.Rows[b]["Operacao"].ToString();
  57. }
  58.  
  59. if (status.Rows[b]["Status_op"].ToString() == "2") // Off
  60. {
  61. dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_power_off_10214;
  62. dataGridView1.Rows[i].Cells["Status_op"].Value = status.Rows[b]["Status_op"].ToString();
  63. }
  64. else if (status.Rows[b]["Status_op"].ToString() == "1") // On
  65. {
  66. dataGridView1.Rows[i].Cells["Status_op_img"].Value = Properties.Resources.if_power_on_10215;
  67. dataGridView1.Rows[i].Cells["Status_op"].Value = status.Rows[b]["Status_op"].ToString();
  68. }
  69. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
  70. //query = "DELETE FROM `int00` WHERE Usuario_meta = @usuario_meta AND Nome_robo = @nome_robo AND Simbolo = @simbolo AND Periodo = @periodo";
  71. //COMANDO.CommandText = query;
  72. //COMANDO.Parameters.Clear();
  73. //COMANDO.Parameters.Add("@usuario_meta", MySqlDbType.VarChar).Value = status.Rows[b]["Usuario_meta"].ToString();
  74. //COMANDO.Parameters.Add("@nome_robo", MySqlDbType.VarChar).Value = status.Rows[b]["Nome_robo"].ToString();
  75. //COMANDO.Parameters.Add("@simbolo", MySqlDbType.VarChar).Value = status.Rows[b]["Simbolo"].ToString();
  76. //COMANDO.Parameters.Add("@periodo", MySqlDbType.VarChar).Value = status.Rows[b]["Periodo"].ToString();
  77. //COMANDO.ExecuteNonQuery();
  78. //break;
  79. }
  80. if (dataGridView1.Rows[i].Cells["Hora_ultima"].Value != null)
  81. {
  82. DateTime t = Convert.ToDateTime(dataGridView1.Rows[i].Cells["Hora_ultima"].Value.ToString());
  83.  
  84. // if (dataGridView1.Rows[i].Cells["Hora_ultima"].Value.ToString() != status.Rows[b]["Hora_criacao"].ToString())
  85. if (flag_find)
  86. {
  87. DateTime t1 = DateTime.Now;
  88. DateTime t2 = DateTime.Now.AddSeconds(-30);
  89. System.TimeSpan diff2 = t1.Subtract(t);
  90. if (diff2.TotalSeconds >= 15 && diff2.TotalSeconds <= 45)
  91. {
  92. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_58_62715;
  93. }
  94. else if (diff2.TotalSeconds < 15 && diff2.TotalSeconds >= 0)
  95. {
  96. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_tick_circle_frame_27247;
  97. }
  98. else
  99. {
  100. dataGridView1.Rows[i].Cells["Status"].Value = Properties.Resources.if_exclamation_red_46014;
  101. }
  102.  
  103. }
  104. }
  105. }
  106.  
  107. }
  108.  
  109. //frm = this.MdiParent as frmPrincipal;
  110. //SendMessage send = new SendMessage(frm.SetLabel);
  111. //send(DateTime.Now.ToString("HH:mm :ss") + " - Dados Atualizados...", null, null);
  112. conexao.Close();
  113. }
  114. catch (MySqlException ex)
  115. {
  116.  
  117. frm = this.MdiParent as frmPrincipal;
  118. SendMessage send = new SendMessage(frm.SetLabel);
  119. 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);
  120. //MessageBox.Show(ex.Message + ex.StackTrace, "Detalhes Exception");
  121. timerExec = true;
  122. }
  123. catch (TimeoutException ex)
  124. {
  125. frm = this.MdiParent as frmPrincipal;
  126. SendMessage send = new SendMessage(frm.SetLabel);
  127. 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);
  128. timerExec = true;
  129. }
  130. finally
  131. {
  132. frm = this.MdiParent as frmPrincipal;
  133. SendMessage send = new SendMessage(frm.SetLabel);
  134. send(DateTime.Now.ToString("HH:mm :ss") + " - Dados Atualizados...", null, null, 15000);
  135. conexao.Close();
  136. timerExec = true;
  137. }
  138.  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement