static void Main(string[] args) { try { Console.WriteLine(Division.Operar(4, 0)); } catch (DivideByZeroException e) { ArchivoTexto.Guardar(e.Message, "log.txt"); } catch (UnaException e) { ArchivoTexto.Guardar(e.Message, "log.txt"); } catch (MiException e) { ArchivoTexto.Guardar(e.Message, "log.txt"); ArchivoTexto.Guardar(e.InnerException.ToString(), "log.txt"); } finally { Console.ReadKey(); Console.Clear(); } Console.WriteLine(ArchivoTexto.Leer("log.txt")); Console.ReadKey(); }
static void Main(string[] args) { MiClase miClase = new MiClase(); string aux = ""; DateTime fecha = DateTime.Now; string nombreArchivo = ""; try { miClase.Metodo(); } catch (Exception e) { if (!object.ReferenceEquals(e.InnerException, null)) { Exception ex = e; do { aux = aux + ex.Message + " "; ex = ex.InnerException; } while (!object.ReferenceEquals(ex, null)); nombreArchivo += fecha.Year.ToString() + fecha.Month.ToString() + fecha.Day.ToString() + "-" + fecha.Hour.ToString() + fecha.Minute.ToString() + ".txt"; ArchivoTexto.Guardar(nombreArchivo, aux); } } Console.WriteLine(ArchivoTexto.Leer(nombreArchivo)); Console.ReadKey(); }
/// <summary> /// Manejador del evento OnClick del btnEliminar. /// Elimina el producto seleccionado de la base de datos. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEliminar_Click(object sender, EventArgs e) { try { DialogResult result = MessageBox.Show("¿Seguro desea eliminar el producto?", "Eliminar Producto", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.Yes) { // 4B - Realizar una baja física del producto seleccionado en la tabla de productos. try { ComiqueriaLogic.Entidades.ComiqueriaDAO.Quitar(productoSeleccionado); } catch (ComiqueriaException ex) { ArchivoTexto.Escribir(ex.Ruta, ex.Texto, true); MessageBox.Show(ex.Message); } } } catch (Exception ex) { this.ManejarExcepciones(ex); } }
static void Main(string[] args) { string rutaDelArchivo = DateTime.Now.ToString("yyyyMMdd-HHmm") + ".txt"; try { OtraClase oc = new OtraClase(); oc.MetodoDeInstancia(); } catch (MiExcepcion ex) { ArchivoTexto.Guardar(rutaDelArchivo, ex.Message); if (ex.InnerException != null) { Exception e = ex.InnerException; do { ArchivoTexto.Guardar(rutaDelArchivo, e.Message); //Muestra los msj de las InnerException e = e.InnerException; }while (e != null); } } try { Console.WriteLine(ArchivoTexto.Leer(rutaDelArchivo)); } catch (FileNotFoundException ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
static void Main(string[] args) { string fileLocation = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string fileName = string.Format("\\{0}{1}{2}-{3}{4}.txt", DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, DateTime.Now.Hour, DateTime.Now.Minute); StringBuilder path = new StringBuilder(fileLocation + fileName); StringBuilder data = new StringBuilder(); try { // 1. Instancio una clase y llamao a un metodo 'X' Persona p = new Persona(); p.MetodoQueGeneraError(); } catch (MyThirdException e) { Exception ex = e; while (ex != null) { data.AppendLine(ex.Message); ex = ex.InnerException; } ArchivoTexto.Guardar(path.ToString(), data.ToString()); } Console.WriteLine(ArchivoTexto.Leer(path.ToString())); }
static void Main(string[] args) { string ruta = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("yyyyMMdd-hhmm") + ".txt"; ClaseC test = new ClaseC(); try { test.MetodoInstancia(); } catch (MiException e) { Exception exception = new Exception(); exception = e; do { ArchivoTexto.Guardar(ruta, exception.Message); exception = exception.InnerException; } while (exception != null); } Console.Write(ArchivoTexto.Leer(ruta)); Console.ReadKey(); }
private void abrirToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.ShowDialog(); rutaArchivoActual = ofd.FileName; rtb_texto.Text = ArchivoTexto.Leer(rutaArchivoActual); }
public void GuardarComo() { SaveFileDialog dialog = new SaveFileDialog(); dialog.InitialDirectory = (this.path == null) ? AppDomain.CurrentDomain.BaseDirectory : this.path; if (DialogResult.OK == dialog.ShowDialog()) { this.path = dialog.FileName; ArchivoTexto.Guardar(this.path, richTextBox1.Text); } }
private void toolStripTextBox2_Click(object sender, EventArgs e) //guardar { toolStripMenuItem1.HideDropDown(); if (this.path == null) //si ya se abrió o guardó un archivo path no va a ser null { GuardarComo(); } else { ArchivoTexto.Guardar(this.path, richTextBox1.Text); } }
private void guardarCtrlSToolStripMenuItem_Click(object sender, EventArgs e) { if (rutaArchivoActual == null) { SaveFileDialog sfd = new SaveFileDialog(); sfd.ShowDialog(); rutaArchivoActual = sfd.FileName; ArchivoTexto.Guardar(rutaArchivoActual, rtb_texto.Text, false); } else { ArchivoTexto.Guardar(rutaArchivoActual, rtb_texto.Text, true); } }
static void Main(string[] args) { Console.Title = "Ejercicio Nro 54"; string auxStackTrace = String.Empty; string path = AppDomain.CurrentDomain.BaseDirectory + DateTime.Now.ToString("yyyyMMdd-HHmm"); try { OtraClase auxClase = new OtraClase(); auxClase.MetodoInstancia(); } catch (Exception e) { try { while (e != null) { //Console.WriteLine(e.Message); auxStackTrace += e.StackTrace.ToString() + "\n"; e = e.InnerException; } if (ArchivoTexto.Guardar(path, auxStackTrace)) { Console.WriteLine("Archivo guardado correctamente"); } } catch (Exception error) { Console.WriteLine(error.Message); } } finally { Console.WriteLine("Presione una tecla para continuar..."); Console.ReadKey(); Console.Clear(); Console.WriteLine("Lista de stacktrace traida desde archivo: "); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ArchivoTexto.Leer(path)); Console.ResetColor(); Console.ReadKey(); } }
private void toolStripTextBox1_Click(object sender, EventArgs e) { toolStripMenuItem1.HideDropDown(); OpenFileDialog dialog = new OpenFileDialog(); dialog.DefaultExt = ".txt"; dialog.InitialDirectory = (this.path == null) ? AppDomain.CurrentDomain.BaseDirectory : this.path; if (DialogResult.OK == dialog.ShowDialog()) //si click cancel no entra { this.path = dialog.FileName; richTextBox1.Text = ArchivoTexto.Leer(path); } richTextBox1.Focus(); }
/// <summary> /// Genera el archivo de texto de la lista de vehiculos terminados /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnGenerarArchivoTexto_Click(object sender, EventArgs e) { try { this.Width = 1194; this.rtbVehiculosTerminados.ReadOnly = true; ArchivoTexto texto = new ArchivoTexto(); texto.GuardarArchivo("InformeVehiculosTerminados.txt", InformeVehiculosTerminados()); this.rtbVehiculosTerminados.Text = texto.LeerArchivo("InformeVehiculosTerminados.txt"); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
static void Main(string[] args) { Console.WriteLine("Ingrese un numero:"); Console.WriteLine("1) guardarlo en el escritorio"); Console.WriteLine("Otro para guardarlo por default"); string path = null; if (Console.ReadLine() == "1") { path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\" + DateTime.Now.ToString("yyyyMMdd-HHmm") + ".txt"; } else { path = DateTime.Now.ToString("yyyyMMdd-HHmm") + ".txt"; } try { OtraClase a = new OtraClase(); a.OtraClaseInstancia(); } catch (MiExcepcion ex) { Exception excep = ex; //Puede contener todas las excepciones while (excep != null) { ArchivoTexto.Guardar(path, excep.Message); excep = excep.InnerException; } } try { ArchivoTexto.Leer(path); } catch (FileNotFoundException ex) { ArchivoTexto.Guardar(path, ex.ToString()); } Console.WriteLine(ArchivoTexto.Leer(path)); Console.ReadKey(); }
private bool GuardarTicketDelivery(PedidoDelivery delivery) { bool response = true; ArchivoTexto archivo = new ArchivoTexto(); try { archivo.Guardar(delivery.ToString()); } catch (ArchivosException e) { Console.WriteLine(e.Message); response = false; } return(response); }
private void btnGenerarFactura_Click(object sender, EventArgs e) { ArchivoTexto texto = new ArchivoTexto(); ArchivosXml <Games> xmlGames = new ArchivosXml <Games>(); ArchivosXml <PS> xmlConsola = new ArchivosXml <PS>(); foreach (Games g in games.ListaJuegos) { texto.GuardarArchivoTexto("FacturaJuegos.txt", Games.MostrarDatos(games.ListaJuegos), false); xmlGames.Guardar("Juegos.xml", g); } foreach (PS p in ps.ListaJuegosPSVenta) { texto.GuardarArchivoTexto("FacturaConsolas.txt", PS.MostrarDatosPS(ps.ListaJuegosPSVenta), false); xmlConsola.Guardar("Consola.xml", p); } MessageBox.Show("Factura creada con exito"); }
/// <summary> /// Guarda en un archivo txt las ventas actuales /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ventasTxtButton_Click(object sender, EventArgs e) { ArchivoTexto archivo = new ArchivoTexto(); try { archivo.Guardar(ListaVentas); MostrarMensaje( "Archivo de texto descargado con exito en la ruta del proyecto!", "Descarga finalizada" ); } catch (ArchivosException exc) { Console.WriteLine(exc.Message); MostrarMensajeError( "Ocurrió un error al querer guardar las ventas en archivo de texto", "Error archivo de texto" ); } }
static void Main(string[] args) { DateTime fecha = DateTime.Now; string nombreArchivo = fecha.ToString("yyyyMMdd-hhmm") + ".txt"; try { OtraClase obj = new OtraClase(); obj.MetodoInstancia(); } catch (Exception ex) { ArchivoTexto.Guardar(nombreArchivo, ex.Message); while (ex.InnerException != null) { ex = ex.InnerException; ArchivoTexto.Guardar(nombreArchivo, ex.Message); } } Console.WriteLine(ArchivoTexto.Leer(nombreArchivo)); Console.ReadKey(); }
static void Main(string[] args) { ClaseMetodo test; string nombreArchivo = DateTime.Now.ToString("yyyyMMdd-Hmm") + ".txt"; try { test = new ClaseMetodo(); test.MetodoInstancia(1); } catch (MiExcepcion excepcion) { ArchivoTexto.Guardar(nombreArchivo, excepcion.Message); if (!object.ReferenceEquals(excepcion.InnerException, null)) { Exception auxiliar = excepcion.InnerException; do { ArchivoTexto.Guardar(nombreArchivo, auxiliar.Message); auxiliar = auxiliar.InnerException; } while (!object.ReferenceEquals(auxiliar, null)); } } try { Console.Write(ArchivoTexto.Leer(nombreArchivo)); } catch (FileNotFoundException exception) { Console.Write(exception.Message); } Console.ReadKey(); }
public static void Main(string[] args) { string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "-" + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + ".txt"; string filePath = desktopPath + "\\" + fileName; try { new Divider(5, "asd"); } catch (MiException e) { ArchivoTexto.Guardar(filePath, Divider.GetStack(e)); } Console.WriteLine(ArchivoTexto.Leer(filePath)); Console.ReadKey(); }
//PROGRAMA DE CONSOLA PARA PROBAR FUNCIONALIDADES static void Main(string[] args) { GamesDAO gamesDAO = new GamesDAO(); //CREO INSTANCIA DE CLASE ENCARGADA DE CONECTAR CON LA BD ConsolasDAO consolasDAO = new ConsolasDAO(); Games juegos = new Games(); PS ps = new PS(); List <Games> listGames = gamesDAO.List(); //OBTENGO UNA LISTA DE JUEGOS DE LA BD List <PS> listPs = consolasDAO.List(); //OBETENGO UNA LISTA DE CONSOLA DE LA BD juegos.CargarStock(); // CARGA DATOS DE LA TABLA DE JUEGOS ps.CargarStockPS(); //CARGA DATOS DE LA TABLA DE CONSOLAS //EJEMPLO DE CARGA DE DATOS POR MODELO List <PS> PS1 = new List <PS>(); PS1 = ps.StockConsolaPS1(ps); Console.WriteLine(PS.MostrarDatosPS(PS1)); Console.WriteLine("Juegos agregados correctamente"); //VENTA DE JUEGO try { Games venta = new Games(2100, 2008, "Uncharted 3", 83, Games.EFormato.Fisico, "PS5"); //DATOS INVALIDOS PARA PROBAR EXCEPCIONES } catch (PlataformaInvalidaException ex) { Console.WriteLine("Exception Games " + ex.Message); } //VENTA DE CONSOLA PS ventaps = new PS(10000, 500, "PS1", 1, 2013); //CARGA DE CLIENTES try { Cliente cli = new Cliente("45Elpepe", "42568956", EMedioDePago.efectivo, 12000); } catch (NombreInvalidoException e) { Console.WriteLine(e.Message); } try { Cliente cliente = new Cliente("Elpepe", "425615sadf", EMedioDePago.efectivo, 12000); } catch (DniInvalidoException ex) { Console.WriteLine(ex.Message); } Console.WriteLine("DESERIALIZACION\n"); ///PRUEBA DE SERIALIZACION ArchivosXml <List <Games> > xml = new ArchivosXml <List <Games> >(); xml.Guardar("ArchivoXmlGamesPrueba.txt", listGames); List <Games> datos; xml.Leer("ArchivoXmlGamesPrueba.txt", out datos); Console.WriteLine(Games.MostrarDatos(datos)); //PRUEBA DE ARCHIVO DE TEXTO ArchivoTexto t = new ArchivoTexto(); t.GuardarArchivoTexto("ArchivoTexTest.txt", Games.MostrarDatos(datos), false); // Console.ReadKey(); }
public SerialiceException(string message, Exception innerException) : base(message, innerException) { ArchivoTexto.Escribir(this, true); }
static void Main(string[] args) { //-----------FEATURES DISPONIBLES--------------- //Base de datos: //INSERT a productos disponibles (puede arrojar una excepcion si se trata de un producto repetido por nombre): Producto p1 = new Producto("ProductoLimpieza", ProductoItem.TipoProducto.Limpieza, 70.5f, 5); Producto p2 = new Producto("ProductoLimpieza", ProductoItem.TipoProducto.Limpieza, 100, 2); Producto p3 = new Producto("Papas lays", ProductoItem.TipoProducto.Comida, 120, 7); Producto p4 = new Producto("Redbull", ProductoItem.TipoProducto.Bebida, 80, 0); DataBaseHelper.InsertarItem(p1); //Agrego ProductoLimpieza DataBaseHelper.InsertarItem(p3); //Agrego Papas lays DataBaseHelper.InsertarItem(p4); //Agrego Redbull //Los siguientes productos serán insertados a la tabla Productos para que puedan probarse en el form de ante mano (no son ventas) DataBaseHelper.InsertarItem(new Producto("Choripan", ProductoItem.TipoProducto.Comida, 150.5f, 25)); DataBaseHelper.InsertarItem(new Producto("Jabón en polvo", ProductoItem.TipoProducto.Limpieza, 42.8f, 13)); DataBaseHelper.InsertarItem(new Producto("Cerveza Quilmes", ProductoItem.TipoProducto.Bebida, 80.6f, 25)); try { DataBaseHelper.InsertarItem(p2); //Captura excepcion por repetido } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } //INSERT a productos vendidos ProductoItem item = new ProductoItem("Fanta", ProductoItem.TipoProducto.Bebida, 95.5f); ProductoItem item2 = new ProductoItem("7up", ProductoItem.TipoProducto.Bebida, 95.5f); ProductoItem item3 = new ProductoItem("Fanta zero", ProductoItem.TipoProducto.Bebida, 95.5f); DataBaseHelper.InsertarItem(item); //Este metodo acepta tanto Producto como ProductoItem (los agrega a su tabla correspondiente) DataBaseHelper.InsertarItem(item2); DataBaseHelper.InsertarItem(item3); //UPDATE de stock a algún producto DataBaseHelper.ActualizarStockProducto(p1.StockDisponible - 1, "ProductoLimpieza"); Console.WriteLine($"Nuevo stock: ${p1.StockDisponible}"); //Nuevo stock: 4 //SELECT de productos List <Producto> productosDisponibles = DataBaseHelper.GetListaItems <Producto>(); List <Producto> productosConStock = DataBaseHelper.GetListaItems <Producto>(true); //Devuelve solo los productos con stock foreach (Producto p in productosDisponibles) { Console.WriteLine(p.ToString()); } foreach (Producto p in productosConStock) { Console.WriteLine(p.ToString()); } //SELECT de productos vendidos List <ProductoItem> productosVendidos = DataBaseHelper.GetListaItems <ProductoItem>(); foreach (Producto p in productosConStock) { Console.WriteLine(p.ToString()); } //ARCHIVOS ArchivoTexto texto = new ArchivoTexto(); if (texto.Guardar(GetListaVentas(productosVendidos))) { Console.WriteLine("Archivo de texto guardado con exito! (ruta del proyecto)"); } ArchivoXml <List <Producto> > xml = new ArchivoXml <List <Producto> >(); if (xml.Guardar(productosConStock)) { Console.WriteLine("Archivo XML guardado con exito (ruta del proyecto)!"); } //THREADS, DELEGADOS Y EVENTOS //Estos están funcionando en los FORM (animaciones y mensajes) //METODOS DE EXTENSIÓN string fechaActual = DateTime.Now.FechaActualFormateada(); //devuelve la fecha actual -> dd-MM-yyyy Console.WriteLine($"Fecha de hoy: {fechaActual}"); EliminarProductos(); EliminarProductosVendidos(); }
public ComiqueriaException(string mensaje, Exception innerException) : base(mensaje, innerException) { ArchivoTexto.Escribir(this, true); }
static void Main(string[] args) { //CREO FABRICAS, AUTOS Y MOTOS Auto auto0 = new Auto(); Auto auto1 = new Auto(Puertas.CuatroPuertas, TipoMotor.Mediano, "SVB 319", Color.Blanco); Moto moto = new Moto(ModeloMoto.Enduro, TipoMotor.Grande, "SLG 923", Color.Negro); Moto aux = new Moto(); Fabrica miFabrica = new Fabrica("Fabrica"); Fabrica auxFab = new Fabrica(); //AGREGO DOS AUTOS IGUALES PARA PROBAR LA EXCEPCION try { miFabrica.ListaVehiculos += auto0; miFabrica.ListaVehiculos += auto0; } catch (VehiculoRepetidoException e) { Console.WriteLine(e.Message); } miFabrica.ListaVehiculos.Clear(); Console.ReadKey(); Console.Clear(); //AGREGO LOS AUTOS Y LAS MOTOS A LA FABRICA miFabrica.ListaVehiculos += auto0; miFabrica.ListaVehiculos += auto1; miFabrica.ListaVehiculos += moto; //SE GUARDA UNA MOTO EN UN ARCHIVO DE TEXTO, SE LEE ESE MISMO ARCHIVO Y SE MUESTRA EN PANTALLA ArchivoTexto texto = new ArchivoTexto(); Console.WriteLine("Guardo la moto en un archivo de texto y lo leo desde el mismo archivo."); texto.GuardarArchivo("Prueba.txt", moto.MostrarDatos()); // Creo archivo de texto Console.WriteLine(texto.LeerArchivo("Prueba.txt")); // Leo archivo de texto y lo muestro Console.ReadKey(); Console.Clear(); //SERIALIZA LA FABRICA Console.WriteLine("Guardo la fabrica en un archivo xml, lo leo desde el mismo archivo y lo asigno en otro objeto. Despues muestro los autos que tiene cargados"); ArchivoXml <Fabrica> xml = new ArchivoXml <Fabrica>(); xml.GuardarArchivo("PruebaXML.xml", miFabrica); // Serializo la fabrica completa auxFab = xml.LeerArchivo("PruebaXML.xml"); // Cargo la serializacion en la fabrica auxiliar Console.WriteLine(auxFab.ListaVehiculos[0].MostrarDatos()); Console.WriteLine(auxFab.ListaVehiculos[1].MostrarDatos()); Console.WriteLine(auxFab.ListaVehiculos[2].MostrarDatos()); Console.WriteLine("\n\nMuestro el detalle del ensamble de un vehiculo."); Console.WriteLine(auxFab.ListaVehiculos[2].DetalleDeEnsamblado()); Console.ReadKey(); Console.Clear(); }