You are on page 1of 9

using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PrestamoLibros
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void btnLectores_Click(object sender, EventArgs e)


{
Form3 Lectores= new Form3();
Lectores.Show();
this.Hide();
}

private void btnPrestamos_Click(object sender, EventArgs e)


{
Form4 Prestamos = new Form4();
Prestamos.Show();
this.Hide();
}

private void btnLibros_Click(object sender, EventArgs e)


{
Form2 Libros = new Form2();
Libros.Show();
this.Hide();
}

private void btnDevoluciones_Click(object sender, EventArgs e)


{
Form5 Devoluciones = new Form5();
Devoluciones.Show();
this.Hide();
}

private void btnSalir_Click(object sender, EventArgs e)


{
this.Close();
}

private void Form1_Load(object sender, EventArgs e)


{

}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace PrestamoLibros
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void CargarDatos()
{
StreamReader Leer = File.OpenText("D:\\Libros.txt");
txtLista.Text = Leer.ReadToEnd();
Leer.Close();
}
public void LimpiarCajas()
{
txtCodigo.Clear();
txtTitulo.Clear();
txtEditorial.Clear();
cmbEstado.Text = "";
txtCodigo.Focus();
}
private void btnAdicionar_Click(object sender, EventArgs e)
{
string Codigo, Titulo, Editorial, Estado;
try
{
Codigo = txtCodigo.Text;
Titulo = txtTitulo.Text;
Editorial = txtEditorial.Text;
Estado = cmbEstado.Text;
StreamWriter Escribir = File.AppendText("D:\\Libros.txt");
Escribir.Write(Codigo + "\t" + Titulo + "\t" + Editorial + "\t" +
Estado + Environment.NewLine);
Escribir.Close();
MessageBox.Show("Archivo Guardado ");
//Lista los datos
CargarDatos();
LimpiarCajas();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void btnSalir_Click(object sender, EventArgs e)


{
Form1 Inicio= new Form1();
Inicio.Show();
this.Hide();
}

private void Form2_Load(object sender, EventArgs e)


{
if (File.Exists("D:\\Libros.txt") == false)
{
StreamWriter Escribir = File.AppendText("D:\\Libros.txt");
Escribir.Write("Codigo\tCantidad\tPrecio\tNombre" +
Environment.NewLine);
Escribir.Write("======\t=======\t=======\t=====" +
Environment.NewLine);
Escribir.Close();
}
else
{
CargarDatos();
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace PrestamoLibros
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void CargarDatos()
{
StreamReader Leer = File.OpenText("D:\\Lectores.txt");
txtLista.Text = Leer.ReadToEnd();
Leer.Close();
}
public void LimpiarCajas()
{
txtCi.Clear();
txtNombre.Clear();
txtPaterno.Clear();
txtTelefono.Text = "";
txtCi.Focus();
}
private void btnSalir_Click(object sender, EventArgs e)
{
Form1 Inicio = new Form1();
Inicio.Show();
this.Hide();
}

private void Form3_Load(object sender, EventArgs e)


{
if (File.Exists("D:\\Lectores.txt") == false)
{
StreamWriter Escribir = File.AppendText("D:\\Lectores.txt");
Escribir.Write("CI\tNombre\tPaterno\tTelefono" +
Environment.NewLine);
Escribir.Write("======\t=======\t=======\t=====" +
Environment.NewLine);
Escribir.Close();
}
else
{
CargarDatos();
}
}

private void btnAdicionar_Click(object sender, EventArgs e)


{
string CI, Nombre, Paterno, Telefono;
try
{
CI = txtCi.Text;
Nombre = txtNombre.Text;
Paterno = txtPaterno.Text;
Telefono= txtTelefono.Text;
StreamWriter Escribir = File.AppendText("D:\\Lectores.txt");
Escribir.Write(CI + "\t" + Nombre + "\t" + Paterno + "\t" +
Telefono + Environment.NewLine);
Escribir.Close();
MessageBox.Show("Archivo Guardado ");
//Lista los datos
CargarDatos();
LimpiarCajas();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace PrestamoLibros
{
public partial class Form4 : Form
{
string estado;
public Form4()
{
InitializeComponent();
}

private void label6_Click(object sender, EventArgs e)


{

private void btnSalir_Click(object sender, EventArgs e)


{
Form1 Inicio = new Form1();
Inicio.Show();
this.Hide();
}

private void Form4_Load(object sender, EventArgs e)


{
CargarLibro();
if (File.Exists("D:\\Prestamos.txt") == false)
{
StreamWriter Escribir = File.AppendText("D:\\Prestamos.txt");
Escribir.Write("Codigo\tCantidad\tPrecio\tNombre" +
Environment.NewLine);
Escribir.Write("======\t=======\t=======\t=====" +
Environment.NewLine);
Escribir.Close();
}
else
{
CargarDatosPrestamos();
}
}
private void CargarLibro()
{
cmbLibro.Items.Clear();
string Datos;
char[] Caracteres = { '\t' };
try
{
StreamReader Leer = File.OpenText("D:\\Libros.txt");
Datos = Leer.ReadLine();
Datos = Leer.ReadLine();
while (Leer.EndOfStream == false)
{
Datos = Leer.ReadLine();
string[] MisDatos = Datos.Split(Caracteres);
cmbLibro.Items.Add(MisDatos[1]);

}
Leer.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
}
private void txtCodigo_Leave(object sender, EventArgs e)
{
string Datos, CILector;
int sw = 0;
char[] Caracteres = { '\t' };
try
{
StreamReader Leer = File.OpenText("D:\\Lectores.txt");
Datos = Leer.ReadLine(); Datos = Leer.ReadLine();
while (Leer.EndOfStream == false)
{
Datos = Leer.ReadLine();
string[] MisDatos = Datos.Split(Caracteres);
CILector = MisDatos[0];
if (CILector == txtCI.Text)
{
txtNombreCompleto.Text = MisDatos[1] + " " +
MisDatos[2];
sw = 1;
}
}
Leer.Close();
}
catch (Exception ex)
{ MessageBox.Show(ex.Message); }
if (sw == 0)
{
MessageBox.Show("DEbe registrar al Lector", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
txtCI.Clear(); txtCI.Focus();
}
}

private void txtCI_TextChanged(object sender, EventArgs e)


{

private void btnAdicionar_Click(object sender, EventArgs e)


{// prestar
if (estado == "Ocupado")
{
MessageBox.Show("El libro se encuentra prestado a otro
lector"); ;
}
else
{
string Datos, CodLibro;
char[] Caracteres = { '\t' };
try
{
StreamReader Leer = File.OpenText("D:\\Libros.txt");
StreamWriter Escribir =
File.AppendText("D:\\LibrosCopia.txt");
Datos = Leer.ReadLine();
Escribir.Write(Datos + Environment.NewLine);
Datos = Leer.ReadLine();
Escribir.Write(Datos + Environment.NewLine);
while (Leer.EndOfStream == false)
{
Datos = Leer.ReadLine();
string[] MisDatos = Datos.Split(Caracteres);
CodLibro = MisDatos[0];
if (CodLibro != txtCodLibro.Text)
{
Escribir.Write(MisDatos[0] + "\t" + MisDatos[1] +
"\t" + MisDatos[2] + "\t" + MisDatos[3] + Environment.NewLine);
}
else
{
Escribir.Write(MisDatos[0] + "\t" + MisDatos[1] +
"\t" + MisDatos[2] + "\t" +"Ocupado" + Environment.NewLine);
}
}
Leer.Close();
Escribir.Close();
File.Replace("D:\\LibrosCopia.txt", "D:\\Libros.txt",
"D:\\Libros2.txt");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
MessageBox.Show("Prestamo exitoso!!");
string CodLector, Lector, CodLib, Libro;
try
{
CodLector = txtCI.Text;
Lector = txtNombreCompleto.Text;
CodLib = txtCodLibro.Text;
Libro = cmbLibro.Text;
StreamWriter Escribir = File.AppendText("D:\\Prestamos.txt");
Escribir.Write(CodLector + "\t" + Lector+ "\t" + CodLib +
"\t" + Libro + Environment.NewLine);
Escribir.Close();

//Lista los datos


CargarDatosPrestamos();
LimpiarCajas();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void CargarDatosPrestamos()
{
StreamReader Leer = File.OpenText("D:\\Prestamos.txt");
txtLista.Text = Leer.ReadToEnd();
Leer.Close();
}
private void LimpiarCajas()
{
txtCI.Clear();
txtCodLibro.Clear();
txtNombreCompleto.Clear();
cmbLibro.Text = "";
}
private void cmbLibro_SelectedIndexChanged(object sender, EventArgs e)
{
string Datos, Libro="";
char[] Caracteres = { '\t' };
try
{
StreamReader Leer = File.OpenText("D:\\Libros.txt");
Datos = Leer.ReadLine();
Datos = Leer.ReadLine();
while (Leer.EndOfStream == false)
{
Datos = Leer.ReadLine();
string[] MisDatos = Datos.Split(Caracteres);
Libro = MisDatos[1];
if (Libro == cmbLibro.Text)
{
txtCodLibro.Text = MisDatos[0];
estado = MisDatos[3];
}
} Leer.Close(); }
catch (Exception ex)
{ MessageBox.Show(ex.Message);}
}

private void cmbLibro_Click(object sender, EventArgs e)


{

}
}
}

Realizar el diseño de los formularios y debe funcionar libros lectores y la caratula

You might also like