private void btnAgregarProducto_Click(object sender, EventArgs e) { frmBuscarProducto frm = new frmBuscarProducto(cod_tienda, alquiler); frm.ShowDialog(); if (frm.ent_producto != null) { if (dgvProductos.Rows.Count > 0) { bool agregar = true; foreach (DataGridViewRow item in dgvProductos.Rows) { if (item.Cells["ID"].Value.ToString().Equals(frm.ent_producto.id.ToString())) { int adicion = int.Parse(item.Cells["CANTIDAD"].Value.ToString()) + 1; if (adicion > BL_Productos.getStockProducto(Convert.ToInt32(item.Cells["ID"].Value), cod_tienda)) { MessageBox.Show("Stock insuficiente, no se pudo agregar el producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { item.Cells["CANTIDAD"].Value = adicion; } item.Selected = true; agregar = false; return; } } if (agregar) { dgvProductos.Rows.Add(frm.ent_producto.cod_producto, frm.ent_producto.nombre, "1", frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.id); } } else { dgvProductos.Rows.Add(frm.ent_producto.cod_producto, frm.ent_producto.nombre, "1", frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.id); } log.Info("Producto agregado: [" + frm.ent_producto.cod_producto + "] " + frm.ent_producto.nombre, System.Reflection.MethodBase.GetCurrentMethod().Name); } sumarTotal(); }
private void btnAgregarProducto_Click(object sender, EventArgs e) { frmBuscarProducto frm = new frmBuscarProducto(cod_tienda, "0"); frm.ShowDialog(); if (frm.ent_producto != null) { if (dgvProductos.Rows.Count > 0) { bool agregar = true; foreach (DataGridViewRow item in dgvProductos.Rows) { if (item.Cells["ID"].Value.ToString().Equals(frm.ent_producto.id.ToString())) { int adicion = int.Parse(item.Cells["CANTIDAD"].Value.ToString()) + 1; if (adicion > BL_Productos.getStockProducto(Convert.ToInt32(item.Cells["ID"].Value), cod_tienda)) { MessageBox.Show("Stock insuficiente, no se pudo agregar el producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { item.Cells["CANTIDAD"].Value = adicion; } item.Selected = true; agregar = false; return; } } if (agregar) { dgvProductos.Rows.Add(BL_Productos.generarCodigoProducto(cod_tienda, frm.ent_producto.id, frm.ent_producto.id_cat), frm.ent_producto.nombre, "1", frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.id); } } else { dgvProductos.Rows.Add(BL_Productos.generarCodigoProducto(cod_tienda, frm.ent_producto.id, frm.ent_producto.id_cat), frm.ent_producto.nombre, "1", frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.precio.ToString("#0.00"), frm.ent_producto.id); } } }
private void multiplicarxCantidad(int row) { try { int id_producto = int.Parse(dgvProductos.Rows[row].Cells["ID"].Value.ToString()); double precio_unitario = (dgvProductos.Rows[row].Cells["PU"].Value == null) ? BL_Productos.getPrecioProducto(id_producto) : Convert.ToDouble(dgvProductos.Rows[row].Cells["PU"].Value); int cantidad = (dgvProductos.Rows[row].Cells["CANTIDAD"].Value == null) ? 1 : int.Parse(dgvProductos.Rows[row].Cells["CANTIDAD"].Value.ToString()); int stock = BL_Productos.getStockProducto(id_producto, cod_tienda); if (dgvProductos.Rows[row].Cells["PU"].Value == null) { dgvProductos.Rows[row].Cells["PU"].Value = BL_Productos.getPrecioProducto(id_producto).ToString("#0.00"); } if (dgvProductos.Rows[row].Cells["CANTIDAD"].Value == null) { dgvProductos.Rows[row].Cells["CANTIDAD"].Value = 1; } if (cantidad > stock) { MessageBox.Show("No contamos con el stock suficiente para el producto.\n\nStock: " + stock, "Atención!", MessageBoxButtons.OK, MessageBoxIcon.Warning); dgvProductos.Rows[row].Cells["CANTIDAD"].Value = stock; return; } double _total = Convert.ToDouble((cantidad * precio_unitario)); dgvProductos.Rows[row].Cells["IMPORTE"].Value = _total.ToString("#0.00"); sumarTotal(); } catch (Exception ex) { MessageBox.Show("Error al calcular precio por cantidad. \n\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); log.Error("Error al calcular precio por cantidad. \n\n" + ex.Message, System.Reflection.MethodBase.GetCurrentMethod().Name); } }