private void btn_Fritos_Click(object sender, EventArgs e) { List <DatosProducto> ResultadoDatosProducto = new List <DatosProducto>(); int rowEscribir = dgvInformacionCompra.Rows.Count - 1; try { VentasBC Ventas = new VentasBC(); DataSet dataset = new DataSet(); string CodigoProducto = "1478529642"; ResultadoDatosProducto = Ventas.ObtenerProducto(CodigoProducto); if (ResultadoDatosProducto == null) { MessageBox.Show("Este codigo no se encuentra registrado", "No se encontro algún producto", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { foreach (DatosProducto Datos in ResultadoDatosProducto) { Producto = Datos.CodigoProducto; descripcion = Datos.Descripcion; precio = Datos.Precio; } IVA = decimal.Parse(lblPorcentaje.Text) / 100; if (lblSubTotalDinero.Text != "0") { UltimoprecioLabel = Convert.ToDecimal(lblSubTotalDinero.Text); PrecioTotal = UltimoprecioLabel + precio; lblSubTotalDinero.Text = Convert.ToString(PrecioTotal); lblTotalDinero.Text = Convert.ToString(PrecioTotal + IVA); dgvInformacionCompra.Rows.Add(1); } else { lblSubTotalDinero.Text = Convert.ToString(precio); lblTotalDinero.Text = Convert.ToString(precio + IVA); dgvInformacionCompra.Rows.Add(1); } dgvInformacionCompra.Rows[rowEscribir].Cells[0].Value = Producto; dgvInformacionCompra.Rows[rowEscribir].Cells[1].Value = descripcion; dgvInformacionCompra.Rows[rowEscribir].Cells[2].Value = precio; dgvInformacionCompra.Rows[rowEscribir].Cells[3].Value = cantidad; txtCodigoProducto.Text = ""; } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), "Error, Favor de comunicarse al departamento de sistemas", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void button8_Click(object sender, EventArgs e) { var conexion = ConfigurationManager.ConnectionStrings["CSSQL"].ConnectionString; VentasBE Entidadventas = new VentasBE(); VentasBC VentasController = new VentasBC(); List <VentasBE> ListaVentas = new List <VentasBE>(); DataGridView Gridview = new DataGridView(); try { if (Convert.ToDecimal(lblTotalDinero.Text) == 0) { MessageBox.Show("Favor de escanear algun producto", "No se puede cobrar, debido a que no hay registros de productos.", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { MessageBox.Show("El total de la venta es: " + lblTotalDinero.Text, "Total de la venta", MessageBoxButtons.OK, MessageBoxIcon.Information); int rowEscribir = dgvInformacionCompra.Rows.Count - 1; SqlConnection sql = new SqlConnection(conexion); sql.Open(); SqlCommand cmd = new SqlCommand("SpInsVentas", sql); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@Cajero", lblUsuarioAutenticadoVentas.Text + " " + lblApellidoVentas.Text); cmd.Parameters.AddWithValue("@Iva", Convert.ToInt16(lblPorcentaje.Text)); cmd.Parameters.AddWithValue("@Subtotal", Convert.ToDouble(lblSubTotalDinero.Text)); cmd.Parameters.AddWithValue("@Total", Convert.ToDouble(lblTotalDinero.Text)); cmd.ExecuteNonQuery(); foreach (DataGridViewRow row in dgvInformacionCompra.Rows) { if (row.Cells[0].Value == null || string.IsNullOrEmpty(row.Cells[0].Value.ToString())) { /*SI UNA FILA NO TIENE DATOS ENTONCES: */ } else { SqlCommand cmd2 = new SqlCommand("SpInsDetalleVenta", sql); cmd2.CommandType = CommandType.StoredProcedure; //ResultadoMax= VentasController.ObtenerMaximoId(conexion); cmd2.Parameters.AddWithValue("@CodigoProducto", row.Cells[0].Value.ToString()); cmd2.Parameters.AddWithValue("@DescripcionProducto", row.Cells[1].Value.ToString()); cmd2.Parameters.AddWithValue("@Precio", Convert.ToDouble(row.Cells[2].Value)); cmd2.Parameters.AddWithValue("@Cantidad", Convert.ToInt16(row.Cells[3].Value)); cmd2.ExecuteNonQuery(); } } sql.Close(); //VentasController.RegistrarVentas(ListaVentas, conexion); dgvInformacionCompra.Rows.Clear(); lblSubTotalDinero.Text = "0"; lblTotalDinero.Text = "0"; } } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message, "Error en la operación", MessageBoxButtons.OK, MessageBoxIcon.Error); } }