/// <summary> /// Al abrir el programa se deberá leer el archivo y mostrarlo en el RichTextBox /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Form1_Load(object sender, EventArgs e) { #region Leer desde txt y muestro Richtextbox try { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "GuardoTXT.txt"; IArchivos <string, string> archivoTXT = new ArchivoTexto(); rtbMensaje.Text = archivoTXT.Leer(path); } catch (FileNotFoundException excep) { MessageBox.Show(excep.Message); } #endregion }
/// <summary> /// Primer Parcial: Agregar el elemento a la mueblería. /// Segundo Parcial y Final: Al presionar el botón agregar se deberá guardar la información a un archivo, anexando el nuevo Asiento al final. Agregar el elemento a la lista. /// Luego, leer el archivo y mostrarlo en el RichTextBox. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAgregar_Click(object sender, EventArgs e) { #region Crear un sofa Sofa unSofa = new Sofa(); unSofa.alto = (short)nudAlto.Value; unSofa.ancho = (short)nudAncho.Value; Random ram = new Random(); int devuelveRam; devuelveRam = ram.Next(0, 4); switch (devuelveRam) { case 0: unSofa.color = Sofa.Color.Blanco; break; case 1: unSofa.color = Sofa.Color.Natural; break; case 2: unSofa.color = Sofa.Color.Negro; break; case 3: unSofa.color = Sofa.Color.Rojo; break; default: break; } #endregion #region Guardar en TXT y agregar a la lista try { //TextWriter WriteFileStream = new StreamWriter(Environment.GetFolderPath(Environment.SpecialFolder.CommonDocuments)); string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "GuardoTXT.txt"; IArchivos <string, string> archivoTXT = new ArchivoTexto(); archivoTXT.Guardar(ruta, unSofa.ToString()); this.listaAsientos.Add(unSofa); } catch (PathTooLongException excep) { MessageBox.Show(excep.Message); } #endregion #region Leer desde txt y actualizo richtextbox try { string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\" + "GuardoTXT.txt"; IArchivos <string, string> archivoTXT = new ArchivoTexto(); rtbMensaje.Text = archivoTXT.Leer(path); } catch (FileNotFoundException excep) { MessageBox.Show(excep.Message); } #endregion }