/// <summary> /// Invoco la funcion de listar productos para pasarlos al datagrid /// </summary> private void ListarProductos() { VentasDAO ventasDao = new VentasDAO(); cmbProductos.DisplayMember = "DESCRIPCION"; cmbProductos.ValueMember = "IDPROD"; cmbProductos.DataSource = ventasDao.ListarProductos(); }
public void AgregarALaBaseDeDatosUnaVenta() { VentasDAO dao = new VentasDAO(); Venta venta = new Venta(1, 2, 700); dao.InsertarVentas(venta); }
public LibroVentas() { InitializeComponent(); this.ControlBox = false; this.Text = "Libro Ventas"; this.StartPosition = FormStartPosition.Manual; this.Location = new Point(50, 20); objVentas = new Ventas(); objVentasDao = new VentasDAO(); objProceso = new Proceso(); lbl_anho.Text = DateTime.Now.Year.ToString(); cmbMes(); }
private void checkBox2_MouseDown(object sender, MouseEventArgs e) { Boolean estadoCheckBox2 = checkBox2.Checked; VentasDAO ventasDAO = new VentasDAO(); VentaNota ventaNota = new VentaNota(); if (Convert.ToDouble(textBox7.Text) != 0) { MessageBox.Show("Las Notas con adeudo no se puede Facturar"); textBox2.Focus(); } else { Entidades.Cliente cliente = null; // De lo contrario solo cambia el estado de la nota a Facturada if (cargarNota.IdCliente == 1) { // Se ejecuta solo si el cliente es diferente de contado Popup popup = new Popup(); checkBox2.Enabled = false; if (popup.ShowDialog() == DialogResult.OK) { cliente = popup.ClienteSeleccionado; //Revisar que el Cliente no sea Contado cargarNota.IdCliente = cliente.IdCliente; textBox3.Text = cliente.Nombre + " " + cliente.APaterno + " " + cliente.AMaterno; } else { MessageBox.Show("Selecciona Cliente"); textBox3.Text = "Contado"; cargarNota.IdCliente = 1; checkBox2.Enabled = true; checkBox2.Checked = false; textBox2.Focus(); return; } } //Actualizar estado de la nota */* IdCliente cargarNota.Estado = 3; Boolean actualizar = ventasDAO.updateVenta(cargarNota); checkBox2.Enabled = false; checkBox2.Checked = false; limpiarPantalla(); MessageBox.Show("NOTA FACTURADA"); textBox2.Focus(); } }
// GET: CargarPagos/Create public ActionResult RealizarPagos() { var viewModel = new PagosViewModel(); var listaDeClientes = new List <SelectListItem>(); var listaDeProductos = new List <SelectListItem>(); ClientesDAO _clientesDAO = new ClientesDAO(); VentasDAO ventasDAO = new VentasDAO(); IEnumerable <Cliente> _clientes = _clientesDAO.GetListaCompletaClientes(); foreach (var i in _clientes) { listaDeClientes.Add(new SelectListItem { Text = i.Nombre + i.Apellido, Value = i.Id_Cliente.ToString() }); } viewModel.listaDeClientes = listaDeClientes; viewModel.listaDeProductos = listaDeProductos; return(View(viewModel)); }
public VentasController() { context = new SistemaGestionEntities(); _ventasDAO = new VentasDAO(); }
private void textBox2_KeyDown(object sender, KeyEventArgs e) { VentasDAO ventasDao = new VentasDAO(); if (e.KeyCode == Keys.Enter) { e.Handled = true; if (textBox2.Text.Trim().Equals("")) { //insertar nuevo folio textBox2.Text = ventasDao.nuevoFolio().ToString(); //Moverse al sector siguiente limpiarPantalla(); textBox8.Text = "Nota Pendiente"; textBox3.Text = "Contado"; cargarNota.IdCliente = 1; cargarNota.Adeudo = 0; cargarNota.Subtotal = 0; cargarNota.Total = 0; dataGridView1.Enabled = true; dataGridView1.Focus(); dataGridView1.Rows[0].Cells[0].Selected = true; textBox2.Enabled = false; checkBox1.Enabled = true; checkBox1.Checked = true; checkBox2.Enabled = false; checkBox2.Checked = false; } else { //buscar folio VentaNota ventaBuscar = null; //------------cargarNota = null; //Validar numeros try { ventaBuscar = ventasDao.buscarFolio(Convert.ToInt32(textBox2.Text)); } catch (Exception error) { textBox2.Clear(); MessageBox.Show("SoloNumeros"); return; } if (ventaBuscar == null) { MessageBox.Show("No existe la Nota"); textBox2.Clear(); } else { cargarNota = ventaBuscar; //Mostrar Descripcion Nota limpiarPantalla(); textBox7.Text = cargarNota.Adeudo.ToString(); textBox1.Text = cargarNota.Subtotal.ToString(); textBox5.Text = cargarNota.Iva.ToString(); textBox6.Text = cargarNota.Total.ToString(); checkBox1.Checked = cargarNota.Liquidada; if (cargarNota.IdCliente == 1) { textBox3.Text = "Contado"; } else { textBox3.Text = ventasDao.nombreCliente(cargarNota.IdCliente); } switch (cargarNota.Estado) { case 1: textBox8.Text = "Nota Impresa"; dataGridView1.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = true; break; case 2: textBox8.Text = "Nota Pendiente"; dataGridView1.Enabled = true; dataGridView1.Focus(); dataGridView1.Rows[0].Cells[0].Selected = true; textBox2.Enabled = false; checkBox1.Enabled = true; checkBox1.Checked = true; checkBox2.Enabled = false; checkBox2.Checked = false; break; case 3: textBox8.Text = "Nota Facturada"; checkBox2.Enabled = false; dataGridView1.Enabled = false; break; case 4: textBox8.Text = "Nota Cancelada"; dataGridView1.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = false; break; } int i = 0; OrdenNota[] ordenNota = null; ordenNota = ventasDao.cargarNota(cargarNota.IdNota); while (ordenNota[i] != null) { DataGridViewRow row = (DataGridViewRow)dataGridView1.Rows[0].Clone(); row.Cells[0].Value = ordenNota[i].IdProducto; row.Cells[1].Value = ventasDao.nombreProducto(ordenNota[i].IdProducto); row.Cells[2].Value = ordenNota[i].Cantidad; row.Cells[3].Value = ordenNota[i].PrecioVenta; row.Cells[4].Value = ordenNota[i].Importe; dataGridView1.Rows.Add(row); i++; } } } } if (e.KeyCode == Keys.F9) //CANCELAR NOTA { if (!textBox2.Text.Trim().Equals("")) { if (cargarNota.Estado == 1) { var result = MessageBox.Show("Cancelar", "Desea Cancelar la Nota", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result == DialogResult.OK) { cargarNota.Estado = 4; Boolean actualizar = ventasDao.updateVenta(cargarNota); limpiarPantalla(); } } } } }
private void terminarNota(int opcion) { int filas = dataGridView1.Rows.Count - 1; int nuevoId = 0; OrdenNota[] ordenNota = new OrdenNota[12]; VentasDAO ventasDAO = new VentasDAO(); VentaNota ventaNota = new VentaNota(); VentaNota buscarNota = new VentaNota(); //Busca si la nota existe buscarNota = ventasDAO.buscarFolio(Convert.ToInt32(textBox2.Text)); //Si no existe aun la nota if (buscarNota == null) { ventaNota.FolioNota = Convert.ToInt32(textBox2.Text); ventaNota.Iva = Convert.ToDouble(textBox5.Text); ventaNota.Total = Convert.ToDouble(textBox1.Text); ventaNota.Subtotal = Convert.ToDouble(textBox6.Text); ventaNota.Estado = opcion; ventaNota.Adeudo = Convert.ToDouble(textBox7.Text); ventaNota.IdCliente = cargarNota.IdCliente; ventaNota.Liquidada = checkBox1.Checked; nuevoId = ventasDAO.insertarVenta(ventaNota); for (int i = 0; i < filas; i++) { ordenNota[i] = new OrdenNota(); ordenNota[i].IdNota = nuevoId; ordenNota[i].IdProducto = Convert.ToInt32(dataGridView1[0, i].Value); ordenNota[i].Cantidad = Convert.ToDouble(dataGridView1[2, i].Value); ordenNota[i].PrecioVenta = Convert.ToDouble(dataGridView1[3, i].Value); ordenNota[i].Importe = Convert.ToDouble(dataGridView1[4, i].Value); } } else { //Si existe y hay que actualizarla buscarNota.Iva = Convert.ToDouble(textBox5.Text); buscarNota.Total = Convert.ToDouble(textBox1.Text); buscarNota.Subtotal = Convert.ToDouble(textBox6.Text); buscarNota.Estado = opcion; buscarNota.Adeudo = Convert.ToDouble(textBox7.Text); buscarNota.IdCliente = cargarNota.IdCliente; buscarNota.Liquidada = checkBox1.Checked; Boolean actulizarNota = ventasDAO.updateVenta(buscarNota); for (int i = 0; i < filas; i++) { ordenNota[i] = new OrdenNota(); ordenNota[i].IdNota = buscarNota.IdNota;; ordenNota[i].IdProducto = Convert.ToInt32(dataGridView1[0, i].Value); ordenNota[i].Cantidad = Convert.ToDouble(dataGridView1[2, i].Value); ordenNota[i].PrecioVenta = Convert.ToDouble(dataGridView1[3, i].Value); ordenNota[i].Importe = Convert.ToDouble(dataGridView1[4, i].Value); } Boolean borraOrden = ventasDAO.borrarOrden(buscarNota.IdNota); } Boolean insOrden = ventasDAO.insertarOrden(ordenNota); if (opcion == 1) { MessageBox.Show("DEBERIA DE ESTAR IMRPIMIENDO--->"); /* AHORITA NO JOVEN * //Comprobar impresora en linea * String nombreImpresora = "Citizen GSX-190"; * bool disponible = IsPrinterOnline(nombreImpresora); * while (!disponible) { * MessageBox.Show("No hay impresora"); * disponible = IsPrinterOnline(nombreImpresora); * } * printDocument1.PrinterSettings.PrinterName = nombreImpresora; * printDocument1.Print(); */ } //Se limpia todo y se regresa al inicio dataGridView1.Rows.Clear(); limpiarPantalla(); textBox2.Enabled = true; textBox2.Clear(); textBox2.Focus(); dataGridView1.Enabled = false; checkBox1.Enabled = false; checkBox2.Enabled = false; MessageBox.Show("Nota " + textBox2.Text + " Guardada"); }
private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e) { VentasDAO ventasDao = new VentasDAO(); Double cantidadTemp = 0; Double precioTemp = 0; Double importeTemp = 0; if (dataGridView1.CurrentCell.Value == null) { return; } columna = dataGridView1.CurrentCell.ColumnIndex; fila = dataGridView1.CurrentCell.RowIndex; if (fila > 10) { MessageBox.Show("NO SE PUEDEN MÁS DE 11 PRODUCTOS"); dataGridView1.Rows.RemoveAt(fila); calculaTotal(); columna = 0; flag = true; } else { switch (dataGridView1.SelectedCells[0].ColumnIndex) { case 0: ProductoE productoNuevo = null; int clave; try { clave = Convert.ToInt32(dataGridView1.CurrentCell.Value); } catch (Exception error) { clave = 0; } if (clave != 0) { productoNuevo = ventasDao.cargarProducto(clave); if (productoNuevo == null) { int filaActual = dataGridView1.CurrentCell.RowIndex; MessageBox.Show("No Existe el Producto"); dataGridView1.Rows.RemoveAt(filaActual); calculaTotal(); columna = 0; flag = true; } else { dataGridView1.CurrentRow.Cells[1].Value = productoNuevo.Nombre; dataGridView1.CurrentRow.Cells[2].Value = 0; dataGridView1.CurrentRow.Cells[3].Value = productoNuevo.PrecioVenta; columna = 2; flag = true; } } else { int filaActual = dataGridView1.CurrentCell.RowIndex; dataGridView1.Rows.RemoveAt(filaActual); MessageBox.Show("No Existe el Producto"); calculaTotal(); columna = 0; flag = true; } break; case 2: if (dataGridView1.CurrentRow.Cells[0].Value == null) { MessageBox.Show("Inserta Clave de Producto"); int filaActual = dataGridView1.CurrentCell.RowIndex; columna = 0; flag = true; dataGridView1.Rows.RemoveAt(filaActual); } else { try { cantidadTemp = Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value.ToString()); if (cantidadTemp <= 0) { MessageBox.Show("Solo cifras positivas"); dataGridView1.CurrentRow.Cells[2].Value = 0; dataGridView1.CurrentRow.Cells[4].Value = 0; calculaTotal(); flag = true; return; } } catch (Exception error) { MessageBox.Show("Ingresar Solo numeros"); dataGridView1.CurrentRow.Cells[2].Value = 0; dataGridView1.CurrentRow.Cells[4].Value = 0; calculaTotal(); flag = true; return; } precioTemp = Convert.ToDouble(dataGridView1.CurrentRow.Cells[3].Value.ToString()); importeTemp = precioTemp * cantidadTemp; dataGridView1.CurrentRow.Cells[4].Value = importeTemp; columna = 3; calculaTotal(); flag = true; } break; case 3: if (dataGridView1.CurrentRow.Cells[0].Value == null) { MessageBox.Show("Inserta Clave de Producto"); columna = 0; flag = true; int filaActual = dataGridView1.CurrentCell.RowIndex; dataGridView1.Rows.RemoveAt(filaActual); } else { cantidadTemp = Convert.ToDouble(dataGridView1.CurrentRow.Cells[2].Value.ToString()); try { precioTemp = Convert.ToDouble(dataGridView1.CurrentRow.Cells[3].Value.ToString()); if (precioTemp <= 0) { MessageBox.Show("Solo cifras positivas"); dataGridView1.CurrentRow.Cells[3].Value = 0; dataGridView1.CurrentRow.Cells[4].Value = 0; calculaTotal(); flag = true; return; } } catch (Exception error) { MessageBox.Show("Ingresar Solo numeros"); dataGridView1.CurrentRow.Cells[3].Value = 0; dataGridView1.CurrentRow.Cells[4].Value = 0; calculaTotal(); flag = true; return; } importeTemp = precioTemp * cantidadTemp; dataGridView1.CurrentRow.Cells[4].Value = importeTemp; columna = 0; calculaTotal(); fila++; flag = true; } break; } } }
/// <summary> /// Listo la ventas de la base de datos para visualizarlas en el datagrid /// </summary> private void ListarVentas() { VentasDAO ventasDao = new VentasDAO(); dataGridView1.DataSource = ventasDao.ListarVentas(); }
static void Main(string[] args) { //Instancio clases de las entidades ProductosDAO productosDao = new ProductosDAO(); VentasDAO ventasDao = new VentasDAO(); //Testeo el funcionamiento del abm de Productos #region TestProductos Console.WriteLine("Test de funcionamiento de productos..."); //Instancio un producto Producto producto = new Producto(999, 1, 1, "Producto de test", 10.5); Console.WriteLine("Se instancio el producto"); //Agrego producto a la base de datos try { productosDao.InsertarProductos(producto); Console.WriteLine("Se inserto el producto"); } catch (Exception) { Console.WriteLine("No se pudo insertar el producto"); //throw new ErrorDataBaseException("No se pudo guardar el producto de test, puede que falte la base de datos"); } //Actualizo un dato de ese producto producto.Descripcion = "Este es el producto cambiado"; Console.WriteLine("Actualizando producto"); //Actualizo el producto en la base de datos con el id 999 try { productosDao.EditarProductos(productosDao.ListarUltimoProducto().IdProducto, producto); Console.WriteLine("Se editó el producto"); } catch (Exception) { Console.WriteLine("No se pudo editar el produto"); //throw new ErrorDataBaseException("No se pudo actualizar el producto de test"); //throw; } //Borro ese producto de la base de datos Console.WriteLine("Eliminando producto"); try { productosDao.EliminarProducto(productosDao.ListarUltimoProducto().IdProducto); Console.WriteLine("Se elimino el producto"); } catch (Exception) { Console.WriteLine("No se pudo eliminar el producto"); } #endregion Console.WriteLine("-------------------------------------------------------------------------"); //Testeo el funcionamiento del abm de Ventas #region TestVentas Console.WriteLine("Test de funcionamiento de ventas..."); //Instancio un producto para testearlo con la venta Producto productoParaVenta = new Producto(10000, 1, 1, "Producto para venta", 10.5); Console.WriteLine("Se instancio un producto para la venta"); try { productosDao.InsertarProductos(productoParaVenta); Console.WriteLine("Se inserto el producto para la venta"); } catch (Exception) { Console.WriteLine("No se pudo insertar el producto para la venta"); } //Creo una venta Venta venta = new Venta(999, productosDao.ListarUltimoProducto().IdProducto, 2); Console.WriteLine("Se creo una venta"); //Inserto en la base de datos la venta try { ventasDao.InsertarVentas(venta); Console.WriteLine("Se inserto una venta"); } catch (Exception) { Console.WriteLine("No se pudo guardar la venta"); } //Modifico el objeto de venta venta.Cantidad = 3; //Guardo en la base de datos la modificacion Console.WriteLine("Actualizando venta"); try { ventasDao.EditarVentas(ventasDao.ListarUltimaVenta().IdVenta, venta); Console.WriteLine("Se actualizo la venta en la base de datos"); } catch (Exception) { Console.WriteLine("No se pudo modificar la venta en la base de datos"); } //Borro esa venta de la base de datos Console.WriteLine("Eliminando venta"); try { ventasDao.EliminarVenta(ventasDao.ListarUltimaVenta().IdVenta); productosDao.EliminarProducto(productosDao.ListarUltimoProducto().IdProducto); Console.WriteLine("Se elimino la venta"); } catch (Exception) { Console.WriteLine("No se pudo eliminar la venta"); } #endregion Console.WriteLine("------------------------------------------------------------"); //Pruebo la funcionalidad de archivos con #region Archivos Console.WriteLine("Probando archivo..."); //Creo venta para guardarla en el archivo Venta ventaParaArchivos = new Venta(9999, "Nombre test", 3, 500); Xml <Venta> xml = new Xml <Venta>(); //Seteo la ruta en el escritorio string ruta = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + @"\"; DateTime tiempo = new DateTime(); //Pruebo el metodo de extension para conseguir el timestamp long timestamp = tiempo.GetTimeStamp(); Console.WriteLine("Guardando archivo"); //Guardo archivo if (xml.Guardar(ruta + "Venta" + timestamp + ".xml", venta)) { Console.WriteLine("Se guardo la venta en el escritorio"); } else { Console.WriteLine("No se pudo guardar el archivo correctamente"); } #endregion Console.WriteLine("------------------------------------------------------------"); Console.WriteLine("Se termino el test"); Console.ReadKey(); }
static void Main(string[] args) { UtnStore u = new UtnStore(); Juego j1 = new Juego("God of War", 400, Producto.EPlataforma.Ps4, Juego.EFormato.Digital); Juego j2 = new Juego("God of War", 400, Producto.EPlataforma.Ps4, Juego.EFormato.Digital); Juego j3 = new Juego("Fifa 1990", 100, Producto.EPlataforma.Xbox, Juego.EFormato.Fisico); Juego j4 = new Juego("Pokemon Azul", 100, Producto.EPlataforma.NintendoSwitch, Juego.EFormato.Fisico); Consola c1 = new Consola("Play station 4 500gb", 10000, Producto.EPlataforma.Ps4, ConsoleColor.White); Consola c2 = new Consola("Nintendo Switch", 12000, Producto.EPlataforma.NintendoSwitch, ConsoleColor.Black); //AGREGO PRODUCTOS try { u += j1; } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } try { //se espera Excepcion u += j2; } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } try { u += j3; } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } try { u += c1; } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } try { u += c2; } catch (ProductoRepetidoException e) { Console.WriteLine(e.Message); } Venta <Producto> v1 = new Venta <Producto>(j1, 2); Venta <Producto> v2 = new Venta <Producto>(j3, 2); Venta <Producto> v3 = new Venta <Producto>(j4, 5); Venta <Producto> v4 = new Venta <Producto>(c2, 2); Venta <Producto> v5 = new Venta <Producto>(c2, 11); //AGREGO VENTAS try { u += v1; } catch (CantidadLimiteException e) { Console.WriteLine(e.Message); } try { u += v2; } catch (CantidadLimiteException e) { Console.WriteLine(e.Message); } try { //Se espera excpcion, el producto nunca se agrego a la lista u += v3; } catch (CantidadLimiteException e) { Console.WriteLine(e.Message); } try { u += v4; } catch (CantidadLimiteException e) { Console.WriteLine(e.Message); } try { //Se espera excepcion por exceso de cantidad u += v5; } catch (CantidadLimiteException e) { Console.WriteLine(e.Message); } Console.WriteLine("Precione una tecla para seguir"); Console.ReadKey(); Console.Clear(); //u = UtnStore.Leer(); //Instancio una VentasDao para guardar archivos en la base de datos VentasDAO sql = new VentasDAO(); foreach (Venta <Producto> p in u.Ventas) { try { sql.InsertarVenta(p); } catch (ArchivosException e) { Console.WriteLine(e.Message); } } //intento obtener los datos de una venta por id try { string cadena = sql.ObtenerVentaPorId(23); } catch (ArchivosException e) { Console.WriteLine(e.Message); } Console.WriteLine(u.MostrarProductos()); Console.WriteLine("Precione una tecla para seguir"); Console.ReadKey(); Console.Clear(); Console.WriteLine(u.MostrarVentas()); Console.WriteLine("Precione una tecla para seguir"); Console.ReadKey(); Console.Clear(); UtnStore.GuardarXml(u); Console.WriteLine("Se guardo el archivo xml"); UtnStore.GuardarTxt(u); Console.WriteLine("Se guardo el archivo de texto"); Console.ReadKey(); }