public static void Run() { Conection_Information.Load(); List <Customer> customers = new List <Customer>(); Conection_Information.Load(); Console.WriteLine("Collecting informations from CUSTOMER"); Console.WriteLine("Conection state: " + Conection.Open()); MySqlCommand command = new MySqlCommand("select distinct idcustomer, tecnical_visits, forms_answereds from customer", Conection.Connection); using (MySqlDataReader data = command.ExecuteReader()) { while (data.Read()) { customers.Add(new Customer(int.Parse(data["idcustomer"].ToString()), int.Parse(data["tecnical_visits"].ToString()), int.Parse(data["forms_answereds"].ToString()))); } } Console.WriteLine("Coletado " + customers.Count + " suarios"); foreach (Customer customer in customers) { Console.WriteLine("Atualizando informações do cliente: " + customer.Id); Console.WriteLine("Visitas técnicas: " + customer.Visitas); Console.WriteLine("Formulários respondidos: " + customer.Forms_respondidos); Console.WriteLine("Média: " + customer.CalculateMedia()); Console.WriteLine(""); if (customer.Id == 0) { command.CommandText = "update customer set tecnical_visits = 1 where v11_id = " + customer.Id; } else { command.CommandText = "update customer set effectiviness = " + customer.CalculateMedia() + " where idcustomer = " + customer.Id; } command.Connection = Conection.Connection; command.ExecuteNonQuery(); } Console.WriteLine("Atualização finalizada."); }
public static void Run() { List <string> ids = new List <string>(); Conection_Information.Load(); Console.WriteLine("Collecting informations from CUSTOMER"); Console.WriteLine("Conection state: " + Conection.Open()); MySqlCommand command = new MySqlCommand("select distinct idcustomer from form", Conection.Connection); using (MySqlDataReader data = command.ExecuteReader()) { while (data.Read()) { ids.Add(data["idcustomer"].ToString()); } } Console.WriteLine("Coletado " + ids.Count + " suarios"); foreach (string id in ids) { Console.WriteLine("Coletando informações para o id " + id); Conection.Close(); Conection.Open(); command.CommandText = "select ROUND(avg(evaluation_value), 1) from form where idcustomer = " + id; command.Connection = Conection.Connection; string val = command.ExecuteScalar().ToString(); if (val == null || val == "") { val = "0"; } val = val.Replace(',', '.'); Console.WriteLine("id " + id + " possui uma média de " + val + ". Atualizando registro..."); Conection.Close(); Conection.Open(); command.CommandText = "update customer set avaliation_avarage = " + val + " where v11_id = " + id; command.Connection = Conection.Connection; command.ExecuteNonQuery(); } }