public static CentralLogTipo Get(ECentralLogTipo idLog) { int id = (int)idLog; CentralLogTipo tipoLog; using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString)) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM central_log_tipo WHERE central_log_tipo_ID = @Id"; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@Id", id); connection.Open(); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { // Si ya está en el Diccionario, obtiene el objeto, de lo contrario, lo crea if (!TiposLog.TryGetValue(id, out tipoLog)) { tipoLog = new CentralLogTipo(); TiposLog[id] = tipoLog; } // Actualiza los datos del tipo de log (sea nuevo o recien creado en memoria) tipoLog.TipoLogId = id; tipoLog.Nombre = reader["nombre"].ToString(); tipoLog.Descripción = reader["descripcion"].ToString(); } else { return(null); } } } return(tipoLog); }
public static List <CentralLog> GetAll(string centralId) { List <CentralLog> logs = new List <CentralLog>(); using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString)) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM central_log WHERE central_ID = @IdCentral ORDER BY fecha DESC LIMIT 20"; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@IdCentral", centralId); connection.Open(); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { int id = Convert.ToInt32(reader["central_log_ID"]); CentralLog log = new CentralLog(CentralMonitoreo.Get(reader["central_ID"].ToString()), CentralLogTipo.Get((ECentralLogTipo)Convert.ToInt32(reader["central_log_tipo_ID"]))); log.LogId = id; log.Fecha = Convert.ToDateTime(reader["fecha"]); // Agrego el log a la lista de retorno logs.Add(log); } } } return(logs); }
/* * Obtiene el log más reciente */ public static CentralLog GetLast(string centralId) { CentralLog log = null; using (MySqlConnection connection = new MySqlConnection(DbAccess.Instance.ConnectionString)) { MySqlCommand cmd = new MySqlCommand(); cmd.Connection = connection; cmd.CommandText = "SELECT * FROM central_log WHERE central_ID = @IdCentral ORDER BY fecha DESC LIMIT 1"; cmd.CommandType = System.Data.CommandType.Text; cmd.Parameters.AddWithValue("@IdCentral", centralId); connection.Open(); using (MySqlDataReader reader = cmd.ExecuteReader()) { if (reader.Read()) { log = new CentralLog(CentralMonitoreo.Get(reader["central_ID"].ToString()), CentralLogTipo.Get((ECentralLogTipo)Convert.ToInt32(reader["central_log_tipo_ID"]))); log.LogId = Convert.ToInt32(reader["central_log_ID"]); log.Fecha = Convert.ToDateTime(reader["fecha"]); } else { return(null); } } } return(log); }
public CentralLog(CentralMonitoreo central, CentralLogTipo tipoLog) { Central = central; TipoLog = tipoLog; }