/// <summary> /// allows you to register that a package was delivered /// </summary> /// <param name="u">Object type Encomienda</param> public void entregarEncomienda(Encomienda u) { StreamReader lectura; StreamWriter escribir; string cadena, empleado; bool encontrado; encontrado = false; string[] campos = new string[5]; char[] separador = { ',' }; try { string path = Path.GetFullPath("Encomiendas.txt"); //para agregar carpetas afuera agrego ..\\ string patho = Path.GetFullPath("temp.txt"); //para agregar carpetas afuera agrego ..\\ lectura = File.OpenText(path); //escribir = File.CreateText(@"C:\Users\Usuario\Desktop\temp.txt"); escribir = File.CreateText(patho); cadena = lectura.ReadLine(); while (cadena != null) { campos = cadena.Split(separador); if (campos[0].Trim().Equals(u.GSNumEncomienda)) { encontrado = true; } else { escribir.WriteLine(cadena); } cadena = lectura.ReadLine(); } if (encontrado == true) { } else { } lectura.Close(); escribir.Close(); File.AppendAllText(patho, u.ToString() + "\n"); File.Delete(path); File.Move(patho, path); } catch (FileNotFoundException fe) { } catch (Exception be) { } }
/// <summary> /// Allows registering a new Encomienda /// </summary> /// <param name="u">Object type Encomienda</param> public void registrarEncomienda(Encomienda u) { //string path = @"C:\Users\Usuario\Desktop\lol.txt"; string path = Path.GetFullPath("Encomiendas.txt");//para agregar carpetas afuera agrego ..\\ if (!File.Exists(path)) { // Create a file to write to. using (StreamWriter sw = File.CreateText(path)) { sw.WriteLine(u.ToString()); sw.Close(); } } else { using (StreamWriter file = new StreamWriter(path, true)) { file.WriteLine(u.ToString()); //se agrega información al documento file.Close(); } } }