//Distribuye la linea completa del archivo de la base de datos public Swine Distribute(string line) { Swine newSwine = new Swine(); string Main = ""; Main = DistribuirMain(line); //Obtiene la primera parte (sin dividir) que no depende de partos var items = Main.Split('|'); //Se distribuye cada parametro del archivo en una variable newSwine.setArete(items.ElementAt(0)); newSwine.setActiva(Convert.ToInt32(items.ElementAt(1))); newSwine.setAreteMadre(items.ElementAt(2)); newSwine.setIdPadre(items.ElementAt(3)); newSwine.setTotalPartos(Convert.ToInt32(items.ElementAt(4))); newSwine.setTotalLechonesVivos(Convert.ToInt32(items.ElementAt(5))); newSwine.setTotalLechonesMuertos(Convert.ToInt32(items.ElementAt(6))); newSwine.setTotalLechonesMomia(Convert.ToInt32(items.ElementAt(7))); newSwine.setFechaPrimerCelo(items.ElementAt(8)); newSwine.setFechaSegundoCelo(items.ElementAt(9)); newSwine.setFechaTercerCelo(items.ElementAt(10)); newSwine.setFechaIngreso(items.ElementAt(11)); newSwine.setfechaNacimiento(items.ElementAt(12)); newSwine.setComentario(items.ElementAt(13)); newSwine.partos = DistribuirParto(line); //Distribuye por parto return(newSwine); }
//Verifica que el arete exista con EQUALS public Swine ExisteArete(string item) { StreamReader sr = new StreamReader(MainfileDirectory + fileName); Swine result = new Swine(); try { while (!sr.EndOfStream) { string line = sr.ReadLine(); oldSwine = swineFabric.Distribute(line); if (oldSwine.getArete().Equals(item)) { result = oldSwine; break; } else { result = null; } } sr.Close(); } catch (Exception) { result = null; } return(result); }
public void Delete(string deleteData) { StreamReader sr = new StreamReader(MainfileDirectory + fileName); string tempName = MainfileDirectory + "\\temp.txt"; StreamWriter sw = new StreamWriter(tempName); newSwine = swineFabric.Distribute(deleteData); while (!sr.EndOfStream) { string old = sr.ReadLine(); if (old != deleteData) { sw.WriteLine(old); } else if (old == deleteData) { continue; } } sr.Close(); sw.Close(); File.Delete(fileName); File.Move(tempName, fileName); }
public void Update(Swine updatedData) { string oldName = MainfileDirectory + fileName; StreamReader sr = new StreamReader(oldName); string tempName = MainfileDirectory + "\\temp.txt"; StreamWriter sw = new StreamWriter(tempName); newSwine = updatedData; while (!sr.EndOfStream) { string old = sr.ReadLine(); oldSwine = swineFabric.Distribute(old); if (newSwine.getArete() != oldSwine.getArete()) { sw.WriteLine(old); } else if (newSwine.getArete() == oldSwine.getArete()) { sw.WriteLine(newSwine.ConvertString()); } } sr.Close(); sw.Close(); File.Delete(oldName); File.Move(tempName, oldName); }
/*----------------------------------BUSCADORES POR CADA PARAMETRO NECESARIO----------------------------------*/ //Diferente a "ExisteArete" porque este busca con 'parecidos' public List <Swine> BuscarPorArete(string item) { StreamReader sr = new StreamReader(MainfileDirectory + fileName); List <Swine> results = new List <Swine>(); while (!sr.EndOfStream) { string old = sr.ReadLine(); oldSwine = swineFabric.Distribute(old); if (oldSwine.getArete().Contains(item)) { results.Add(oldSwine); } } sr.Close(); return(results); }
public double PesoPromedio(Swine hembra) { return(0); }