private void btnVender_Click(object sender, EventArgs e) { AutoIncremento(); generaColumnas(); // CREA LOS OBJETOS clsVentas objvent = new clsVentas(); clsDatosVentas objDatos = new clsDatosVentas(); clsTitulos objTitulo = new clsTitulos(); //Inicial = Fecha.Value.Year; //Mes = Fecha.Value.Month; //dia = Fecha.Value.Day; //dtpfecha1.Text = Convert.ToDateTime(dtpfecha1.Value);s //DateTime fecha1 = new DateTime(Inicial, Mes, dia);} //Fecha.Value = Convert.ToDateTime(entidades.Fecha); //Fecha.Value.ToString("yyyy//MM/dd"); // LEE LOS DATOS DE LAS CAJAS Y LOS GUARDA EN EL OBJETO objvent.Fecha = Convert.ToDateTime(Fecha.Text.ToString()); objvent.IdVenta = Convert.ToInt32(txtFolio.Text); objvent.IdTitulo = Convert.ToInt32(txtID.Text); objvent.Cantidad = Convert.ToInt32(txtCantidad.Text); objTitulo.Cantidad = Convert.ToInt32(txtCantidad.Text); objTitulo.TituloId = Convert.ToInt32(txtID.Text); // INSERTA AL PRODUCTO MEDIANTE EL MÉTODO objDatos.AgregarVenta(objvent); MessageBox.Show("Venta Realizada con Exito"); objDatos.RestarInventario(objTitulo); txtTotal.Text = ""; comboEmpleado.Text = ""; }
/// <summary> /// Crea una transacción, e inserta todos los datos de las ventas y reporte de ventas /// </summary> /// <param name="venta"></param> /// <param name="productos"></param> /// <returns>True si funcionó, false si nó</returns> public bool insertar(clsVentas venta, List <clsListaProductos> productos) { MySqlConnection cn = new MySqlConnection(); MySqlCommand cm = new MySqlCommand(); try { cn.ConnectionString = "server=localhost; database=puntodeventa; user=root; pwd=root"; cn.Open(); MySqlTransaction trans = cn.BeginTransaction(); try { String str = "Insert into ventas(Fecha,Total,Usuarios_IDusuario) values(@Fecha,@Total,@Usuario)"; cm = new MySqlCommand(str, cn); cm.Parameters.AddWithValue("@Fecha", venta.Fecha); cm.Parameters.AddWithValue("@Total", venta.Total); cm.Parameters.AddWithValue("@Usuario", venta.Usuarios_IDusuario); Console.WriteLine(venta.Usuarios_IDusuario); cm.ExecuteNonQuery(); str = "SELECT LAST_INSERT_ID() as lastid"; cm = new MySqlCommand(str, cn); String id = cm.ExecuteScalar().ToString(); str = "Insert into reporte_de_Ventas values(@IDProducto,@IDVenta,@PrecioUnitario,@Cantidad)"; foreach (clsListaProductos reporte in productos) { cm = new MySqlCommand(str, cn); cm.Parameters.AddWithValue("@IDProducto", reporte.IdProducto); cm.Parameters.AddWithValue("@IDVenta", id); cm.Parameters.AddWithValue("@PrecioUnitario", reporte.Precio); cm.Parameters.AddWithValue("@Cantidad", reporte.Cantidad); cm.ExecuteNonQuery(); } trans.Commit(); return(true); } catch (Exception ex) { trans.Rollback(); return(false); } } catch (Exception ex) { return(false); } finally { cm.Dispose(); cn.Close(); cn.Dispose(); } }
public void AgregarVenta(clsVentas objVentas) { string sql; MySqlCommand cm; Conectar(); cm = new MySqlCommand(); cm.Parameters.AddWithValue("@ventaid", objVentas.IdVenta); cm.Parameters.AddWithValue("@tituloid", objVentas.IdTitulo); cm.Parameters.AddWithValue("@cantidad", objVentas.Cantidad); cm.Parameters.AddWithValue("@fecha", objVentas.Fecha); sql = "INSERT INTO ventas (idVenta, Fecha, idTitulo, Cantidad) VALUES (@ventaid, @tituloid, @cantidad, @fecha)"; cm.CommandText = sql; cm.CommandType = CommandType.Text; cm.Connection = cnConexion; cm.ExecuteNonQuery(); Cerrar(); }
/// <summary> /// Realiza la operación de almacenar la venta /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button4_Click(object sender, EventArgs e) { Console.WriteLine(productos.Count); if (productos != null && productos.Count != 0) { frmVentasCobrar frmVentasCobrar = new frmVentasCobrar(total); if (frmVentasCobrar.abrir()) { clsVentas venta = new clsVentas(); DateTime fecha = DateTime.Now; int idUsuario = usuario.IDusuario; venta.Fecha = fecha; venta.Clientes_ID = idUsuario; venta.Total = total; venta.Usuarios_IDusuario = idUsuario; daoVentas daoVentas = new daoVentas(); if (!daoVentas.insertar(venta, productos)) { MessageBox.Show("Hubo un error al realizar la transacción."); } else { MessageBox.Show("Venta realizada con éxito"); productos = new List <clsListaProductos>(); dgvVenta.DataSource = null; dgvVenta.DataSource = productos; calcularTotal(); } } } else { MessageBox.Show("Debe haberse agregado antes al menos un producto."); } }
private void btnAgregar_Click(object sender, EventArgs e) { clsVentas V = new clsVentas(); PrecioCompraProducto PCP = new PrecioCompraProducto(); decimal precio = 0; decimal itbis = 0; if (txtPorcentaje.Text.Trim() != "" && txtPVenta.Text.Trim() != "") { decimal precioreal = Convert.ToDecimal(txtPVenta.Text); decimal porcentaje = Convert.ToInt32(txtPorcentaje.Text); decimal valortotalporcentaje = 100; decimal divisor = Convert.ToDecimal(txtDivisor.Text); decimal calculoporcentaje = Math.Round(porcentaje / valortotalporcentaje, 2); precio = Math.Round(precioreal / divisor, 2); itbis = Math.Round(precio * calculoporcentaje, 2); } else { precio = Convert.ToDecimal(txtPVenta.Text); itbis = Convert.ToDecimal(txtIgv.Text); } if (txtDescripcion.Text.Trim() != "") { if (txtCantidad.Text.Trim() != "") { if (Convert.ToInt32(txtCantidad.Text) >= 0) { if (Convert.ToInt32(txtCantidad.Text) <= Convert.ToInt32(txtStock.Text)) { V.IdProducto = Convert.ToInt32(txtIdProducto.Text); V.IdVenta = Convert.ToInt32(txtIdVenta.Text); V.Descripcion = (txtDescripcion.Text + "-" + txtMarca.Text).Trim(); V.Cantidad = Convert.ToInt32(txtCantidad.Text); V.PrecioCompra = Program.PrecioCompra; V.Igv = itbis; V.PrecioVenta = precio; V.SubTotal = Math.Round((precio + itbis) * Convert.ToInt32(txtCantidad.Text), 2); btnAgregar.Visible = false; lst.Add(V); PCP.ID = Convert.ToInt32(txtIdProducto.Text); PCP.Precio = Program.PrecioCompra; listProducts.Add(PCP); LlenarGri(); if (cbidentificacion.Checked == false && txtDatos.Text != "" && Program.IdCliente == 0) { txtDocIdentidad.Text = "Sin identificación"; txtDatos.Text = Program.datoscliente; } Limpiar(); } else { DevComponents.DotNetBar.MessageBoxEx.Show("Stock Insuficiente para Realizar la Venta.", "Sistema de Ventas.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1); } } else { DevComponents.DotNetBar.MessageBoxEx.Show("Cantidad Ingresada no Válida.", "Sistema de Ventas.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); txtCantidad.Clear(); txtCantidad.Focus(); } } else { DevComponents.DotNetBar.MessageBoxEx.Show("Por Favor Ingrese Cantidad a Vender.", "Sistema de Ventas.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); txtCantidad.Focus(); } } else { DevComponents.DotNetBar.MessageBoxEx.Show("Por Favor buscar un Producto.", "Sistema de Ventas.", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); } }
public void CargarListados() { #region Listado Ventas if (clsGenericList.listVentas is null) { clsGenericList.listVentas = new List <Venta>(); clsGenericList.idsVentas = new List <int>(); clsVentas V = new clsVentas(); DataTable dtV = new DataTable(); dtV = V.Listado(); try { foreach (DataRow reader in dtV.Rows) { Venta venta = new Venta(); venta.IdVenta = reader["IdVenta"] == DBNull.Value ? 0 : Convert.ToInt32(reader["IdVenta"]); venta.IdEmpleado = reader["IdEmpleado"] == DBNull.Value ? 0 : Convert.ToInt32(reader["IdEmpleado"]); venta.TipoDocumento = reader["TipoDocumento"] == DBNull.Value ? string.Empty : reader["TipoDocumento"].ToString(); venta.NroComprobante = reader["NroDocumento"] == DBNull.Value ? string.Empty : reader["NroDocumento"].ToString(); venta.Total = reader["Total"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["Total"]); venta.Tipofactura = reader["Tipofactura"] == DBNull.Value ? string.Empty : reader["Tipofactura"].ToString(); venta.Restante = reader["Restante"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["Restante"]); venta.FechaVenta = Convert.ToDateTime(reader["FechaVenta"]); venta.NombreCliente = reader["NombreCliente"] == DBNull.Value ? string.Empty : reader["NombreCliente"].ToString(); venta.UltimaFechaPago = Convert.ToDateTime(reader["UltimaFechaPago"]); venta.borrador = reader["borrado"] == DBNull.Value ? 0 : Convert.ToInt32(reader["borrado"]); clsGenericList.listVentas.Add(venta); } clsGenericList.listVentas.ForEach(x => clsGenericList.idsVentas.Add(x.IdVenta)); } catch (Exception ex) { DevComponents.DotNetBar.MessageBoxEx.Show(ex.Message); } } #endregion #region Listado Productos if (clsGenericList.listProducto is null) { clsGenericList.listProducto = new List <Producto>(); clsProducto P = new clsProducto(); DataTable dtP = new DataTable(); dtP = P.Listar(); try { foreach (DataRow reader in dtP.Rows) { Producto product = new Producto(); product.m_IdP = reader["IdProducto"] == DBNull.Value ? 0 : Convert.ToInt32(reader["IdProducto"]); product.m_IdCategoria = reader["IdCategoria"] == DBNull.Value ? 0 : Convert.ToInt32(reader["IdCategoria"]); product.m_Producto = reader["Nombre"] == DBNull.Value ? string.Empty : reader["Nombre"].ToString(); product.m_tipoGoma = reader["tipoGOma"] == DBNull.Value ? string.Empty : reader["tipoGOma"].ToString(); product.m_itbis = reader["itbis"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["itbis"]); product.m_PrecioVenta = reader["PrecioVenta"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["PrecioVenta"]); product.m_PrecioCompra = reader["PrecioCompra"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["PrecioCompra"]); product.m_Preciomax = reader["Pmax"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["Pmax"]); product.m_Preciomin = reader["Pmin"] == DBNull.Value ? 0 : Convert.ToDecimal(reader["Pmin"]); product.m_FechaVencimiento = Convert.ToDateTime(reader["FechaVencimiento"]); product.m_Stock = reader["Stock"] == DBNull.Value ? 0 : Convert.ToInt32(reader["Stock"]); product.m_FechaModificacion = Convert.ToDateTime(reader["FechaModificacion"]); product.m_Marca = reader["Marca"] == DBNull.Value ? string.Empty : reader["Marca"].ToString(); clsGenericList.listProducto.Add(product); } } catch (Exception ex) { DevComponents.DotNetBar.MessageBoxEx.Show(ex.Message); } } #endregion }