Delivery Notes Object:
public class Albaranes implements Serializable {
private int id_albaran;
private int id_cliente;
private Date fecha_venta;
private String comentario;
private Articulos articulo;
Object Articles:
public class Articulos implements Serializable{
private int id_articulo;
private int unidades;
private int precio;
I have to store in the same file, 1 or more delivery notes with all the items of the delivery note.
With the setters of each class I can save it, but it only saves one article per delivery note.
Here the delivery note object is stored:
albaran.setId_albaran(Integer.parseInt(jTextFieldid_albaran.getText())); albaran.setId_cliente(Integer.parseInt(jTextFieldid_cliente.getText()));
SimpleDateFormat formatoFecha = new SimpleDateFormat("dd/MM/yyyy");
dateFieldfecha_venta.setDateFormat(formatoFecha);
java.util.Date fecha = (Date) dateFieldfecha_venta.getValue();
albaran.setFecha_venta(fecha);
albaran.setComentario(jTextFieldcomentario.getText());
CrearFichero.guardarNuevo(albaran);
Here are the articles:
articulo.setId_articulo(Integer.parseInt(jTextFieldid_articulo.getText()));
articulo.setUnidades(Integer.parseInt(jTextFieldunidades.getText()));
articulo.setPrecio(Integer.parseInt(jTextFieldprecio.getText()));
albaran.setArticulo(articulo);
Method of creating the file:
public static void guardarNuevo(Albaranes albaran) {
try {
Properties propiedades = new Properties();
propiedades.load(new FileInputStream("E:\GradoSuperior2\ExamenRecuperar\ExamenAliciaDatos\Examen\ExamenAlicia\src\archivos\GestionPropiedades.properties"));
String nombre = propiedades.getProperty("nombreArchivo");
//Coger la propiedad ponerle la ruta y la extension
String archivo = "..\Archivos\"+nombre+".dat";
//Nuevo
String ruta = "..\Archivos";
File carpeta = new File(ruta);
File[] listaArchivos = carpeta.listFiles();
for (int i = 0; i < listaArchivos.length; i++) {
File f = new File(archivo);
if (f.exists()) {
archivo = "..\Archivos\"+nombre+i+".dat";
}
}
FileOutputStream fos = new FileOutputStream(archivo);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(albaran);
if (oos != null) {
oos.close();
fos.close();
}
} catch (FileNotFoundException ex) {
Logger.getLogger(CrearFichero.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(CrearFichero.class.getName()).log(Level.SEVERE, null, ex);
}
}
The problem is that he only saves me an article by way of delivery note, and he should keep all the ones I want, I do not know how to do this. Any ideas? Thanks.