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); }
//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); }
/*----------------------------------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); }