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); } } }