public List<ControlAnimal> ValidarPlaca() { List<ControlAnimal> lista = new List<ControlAnimal>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = BaseDatos.conn; cmd.CommandText = "SELECT Placa FROM ControlAnimal"; BaseDatos.conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ControlAnimal c; while (dr.Read()) { c = new ControlAnimal(); c.Placa = Convert.ToInt32(dr["Placa"].ToString()); //c.Raza = dr["Raza"].ToString(); //c.FechaNacido = Convert.ToDateTime(dr["FechaNacido"].ToString()); lista.Add(c); } BaseDatos.conn.Close(); } catch (Exception ex) { throw ex; } finally { BaseDatos.conn.Close(); } return lista; }
public List<ControlAnimal> ValidaPla(int pla) { List<ControlAnimal> lista = new List<ControlAnimal>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = BaseDatos.conn; cmd.CommandText = "SELECT Placa FROM ControlAnimal WHERE Placa = @Pla"; cmd.Parameters.AddWithValue("@Pla", pla); BaseDatos.conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ControlAnimal c; while (dr.Read()) { c = new ControlAnimal(); c.Placa = Convert.ToInt32(dr["Placa"].ToString()); lista.Add(c); } BaseDatos.conn.Close(); } catch (Exception ex) { throw ex; } finally { BaseDatos.conn.Close(); } return lista; }
public List<ControlAnimal> ObtenerNombreRaza() { List<ControlAnimal> lista = new List<ControlAnimal>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = BaseDatos.conn; cmd.CommandText = "Select distinct raza from controlanimal "; BaseDatos.conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ControlAnimal c; while (dr.Read()) { c = new ControlAnimal(); c.Raza = dr["Raza"].ToString(); lista.Add(c); } BaseDatos.conn.Close(); } catch (Exception ex) { throw ex; } finally { BaseDatos.conn.Close(); } return lista; }
public List<ControlAnimal> ObtenerPorPlaca(int pla) { List<ControlAnimal> lista = new List<ControlAnimal>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = BaseDatos.conn; cmd.CommandText = "SELECT * FROM ControlAnimal WHERE Placa = @Pla Order By Placa"; cmd.Parameters.AddWithValue("@Pla", pla); BaseDatos.conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ControlAnimal c; while (dr.Read()) { c = new ControlAnimal(); c.Placa = Convert.ToInt32(dr["Placa"].ToString()); c.Raza = dr["Raza"].ToString(); c.FechaNacido = Convert.ToDateTime(dr["FechaNacido"].ToString()); c.LugarFoto = dr["Imagen"].ToString(); c.PlacaPadre = Convert.ToInt32(dr["PlacaPadre"].ToString()); c.PlacaMadre = Convert.ToInt32(dr["PlacaMadre"].ToString()); c.Observaciones = dr["Observacion"].ToString(); c.Sexo = dr["Sexo"].ToString(); lista.Add(c); } BaseDatos.conn.Close(); } catch (Exception ex) { throw ex; } finally { BaseDatos.conn.Close(); } return lista; }
public List<ControlAnimal> ObtenerListaPorRaza(string raz) { List<ControlAnimal> lista = new List<ControlAnimal>(); try { SqlCommand cmd = new SqlCommand(); cmd.Connection = BaseDatos.conn; //cmd.CommandText = "SELECT * FROM Controlanimal where Raza like '@Raz+%'"; cmd.CommandText = "SELECT * FROM Controlanimal where Raza LIKE '" + raz + "%' ORDER BY Placa"; cmd.Parameters.AddWithValue("@Raz", raz); BaseDatos.conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); ControlAnimal c; while (dr.Read()) { c = new ControlAnimal(); c.Placa = Convert.ToInt32(dr["Placa"].ToString()); c.Raza = dr["Raza"].ToString(); c.FechaNacido = Convert.ToDateTime(dr["FechaNacido"].ToString()); c.LugarFoto = dr["Imagen"].ToString(); c.PlacaPadre = Convert.ToInt32(dr["PlacaPadre"].ToString()); c.PlacaMadre = Convert.ToInt32(dr["PlacaMadre"].ToString()); c.Observaciones = dr["Observacion"].ToString(); c.Sexo = dr["Sexo"].ToString(); lista.Add(c); } BaseDatos.conn.Close(); } catch (Exception ex) { throw ex; } finally { BaseDatos.conn.Close(); } return lista; }