private void LeerArquilados() { FileStream stream = new FileStream("arquiler.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(stream); while (reader.Peek() > -1) { alquiler prestamoTemp = new alquiler(); prestamoTemp.Carnet_del_Alumno = Int32.Parse(reader.ReadLine()); prestamoTemp.Codigo_Libro = Int32.Parse(reader.ReadLine()); prestamoTemp.Fecha_Prestamo = Convert.ToDateTime(reader.ReadLine()); prestamoTemp.Fecha_Devolucion = Convert.ToDateTime(reader.ReadLine()); lista1.Add(prestamoTemp); } reader.Close(); }
private void button1_Click(object sender, EventArgs e) { alquiler presTemp = new alquiler(); presTemp.Carnet_del_Alumno = Int32.Parse(textBox1.Text); presTemp.Codigo_Libro = Int32.Parse(textBox2.Text); presTemp.Fecha_Prestamo = monthCalendar1.SelectionStart; presTemp.Fecha_Devolucion = monthCalendar2.SelectionStart; lista1.Add(presTemp); FileStream stream = new FileStream("prestamos.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter writer = new StreamWriter(stream); foreach (var p in lista1) { writer.WriteLine(p.Carnet_del_Alumno); writer.WriteLine(p.Codigo_Libro); writer.WriteLine(p.Fecha_Prestamo); writer.WriteLine(p.Fecha_Devolucion); } writer.Close(); }