public bool Delete(string numeroCedula) { bool flat = false; try { BinaryFormatter formatter = new BinaryFormatter(); Stream lsStream = new FileStream(nombre, FileMode.Open, FileAccess.Read, FileShare.None); mnj = (ManejadorClientes)formatter.Deserialize(lsStream); lsStream.Close(); List <Cliente> clientes = mnj.getClientes(); for (int i = 0; i < clientes.Count; i++) { if (clientes[i].Id.Equals(numeroCedula)) { clientes.RemoveAt(i); flat = true; } } mnj.setClientes(clientes); lsStream = new FileStream(nombre, FileMode.Create, FileAccess.Write, FileShare.None); formatter.Serialize(lsStream, mnj); //serialisamos mnj con la nueva lista lsStream.Close(); } catch (Exception ex) { // Aqui un messagebox } return(flat); }
public List <Cliente> FindAll() { try { BinaryFormatter formatter = new BinaryFormatter(); Stream lsStream = new FileStream(nombre, FileMode.Open, FileAccess.Read, FileShare.None); mnj = (ManejadorClientes)formatter.Deserialize(lsStream); lsStream.Close(); } catch (FileNotFoundException ex) { //Aqui otro messageBox } return(mnj.getClientes()); }
//Buscar por id public List <Cliente> FindById(string id) { BinaryFormatter formatter = new BinaryFormatter(); Stream lsStream = new FileStream(nombre, FileMode.Open, FileAccess.Read, FileShare.None); mnj = (ManejadorClientes)formatter.Deserialize(lsStream); lsStream.Close(); List <Cliente> clientes = mnj.getClientes(); List <Cliente> cliente = new List <Cliente>(); for (int i = 0; i < clientes.Count; i++) { if (clientes[i].Id.Equals(id)) { cliente.Add(clientes[i]); } } return(cliente); }