using System; using System.Collections.Generic; using System.Text; using System.Data.SqlClient; namespace SGCV { public class RepositorioConsultaBD { #region RepositorioProcedimentos Members int idAtividade; DateTime data; string hora; string historico; string tratamento; int valor; string exame; int idAnimal; public void Inserir(Consulta consulta, Animal animal) { idAtividade = consulta.Id; data = consulta.Data; hora = consulta.Hora; historico = consulta.Historico; tratamento = consulta.Tratamento; valor = consulta.ValorTotal; exame = consulta.Exame; idAnimal = animal.Id; // tem que ter o animal já inserido!!!! string queryString = String.Format( "insert into Consulta Values ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}')", idAtividade, data.Month+"-"+data.Day+"-"+data.Year, hora, historico, tratamento, valor, exame, idAnimal); Console.WriteLine(queryString); using (SqlConnection connection = new SqlConnection( @"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\icd\Desktop\SGCV v1.1\SGCV\Database1.mdf';Integrated Security=True;User Instance=True")) { SqlCommand command = new SqlCommand( queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}", reader[0], reader[1])); } } finally { // Always call Close when done reading. reader.Close(); } } } public List Buscar() { // tem que ter o animal já inserido!!!! List retorno = new List(); Consulta aux = new Consulta(); int auxIdAnimal; string queryString = String.Format("SELECT * FROM Consulta"); Console.WriteLine(queryString); using (SqlConnection connection = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename='C:\Users\icd\Desktop\SGCV v1.1\SGCV\Database1.mdf';Integrated Security=True;User Instance=True")) { SqlCommand command = new SqlCommand(queryString, connection); connection.Open(); SqlDataReader reader = command.ExecuteReader(); try { while (reader.Read()) { Console.WriteLine(String.Format("{0}, {1}",reader[0], reader[1])); aux.Id = (int)reader["idAtividade"]; aux.Data = (DateTime)reader["data"]; aux.Hora = (string)reader["hora"]; aux.Historico = (string)reader["historico"]; aux.Tratamento = (string)reader["tratamento"]; aux.ValorTotal = (int)reader["valor"]; aux.Exame = (string)reader["exame"]; auxIdAnimal = (int)reader["idAnimal"]; } } finally { // Always call Close when done reading. retorno.Add(aux); reader.Close(); } return retorno; } } public void PagarFatura() { throw new NotImplementedException(); } #endregion } }