private void btnModificar_Click(object sender, EventArgs e) { try { if (dgvDescuento.SelectedRows.Count == 0) { MessageBox.Show("Error: Debe seleccionar un descuento para editar.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { OfertaDAO ofertaDAO = new OfertaDAO(); DescuentoDAO descuentoDAO = new DescuentoDAO(); WindowsFormsApp1.Model.Negocio.Entities.Descuento descuentoSeleccionado = descuentoDAO.obtenerDescuentoPorID(long.Parse(dgvDescuento.SelectedRows[0].Cells[0].Value.ToString())); WindowsFormsApp1.Model.Negocio.Entities.Oferta oferta = ofertaDAO.getOfertaVigenteByCodigoProducto(descuentoSeleccionado.idProducto); if (oferta != null) { MessageBox.Show("Error: Existe una oferta activa para este descuento, no puede ser editado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } ModificarDescuento modif = new ModificarDescuento(); modif.descuentoSeleccionado = descuentoSeleccionado; modif.ShowDialog(); listaDescuentos = new BindingList <DescuentoGridVO>(descuentoDAO.getAllDescuentosGrid()); this.dgvDescuento.DataSource = listaDescuentos; } } catch (Exception ex) { MessageBox.Show("Error grave editando Descuento.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnCrearProducto_Click(object sender, EventArgs e) { try { //Validaciones varias if (txtNombre.Text == null || txtNombre.Text.Trim().Equals(string.Empty) || (txtNombre.Text.Trim().Equals("Nombre") && txtNombre.ForeColor == Color.Gray)) { MessageBox.Show("Error: El Nombre del descuento es obligatorio.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtNombre.Focus(); } else if (txtDescripcion.Text == null || txtDescripcion.Text.Trim().Equals(string.Empty) || (txtDescripcion.Text.Trim().Equals("Descripción") && txtDescripcion.ForeColor == Color.Gray)) { MessageBox.Show("Error: La Descripción del descuento es obligatoria.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtDescripcion.Focus(); } else if (cbxProducto.SelectedIndex == -1) { MessageBox.Show("Error: Debe seleccionar un producto", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (!chkDescuentoPorcentaje.Checked && !chkDescuentoPrecio.Checked) { MessageBox.Show("Error: Debe seleccionar un tipo de descuento.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (chkDescuentoPorcentaje.Checked && (txtPorcentajeDescuento.Text == null || txtPorcentajeDescuento.Text.Trim().Equals(string.Empty) || (txtPorcentajeDescuento.Text.Trim().Equals("0%")))) { MessageBox.Show("Error: Debe ingresar un porcentaje de descuento.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (chkDescuentoPrecio.Checked && (txtPrecioDescuento.Text == null || txtPrecioDescuento.Text.Trim().Equals(string.Empty) || (txtPrecioDescuento.Text.Trim().Equals("$0")))) { MessageBox.Show("Error: Debe ingresar un precio de descuento.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { ProductoDAO productoDAO = new ProductoDAO(); DescuentoDAO descuentoDAO = new DescuentoDAO(); Productos prod = productoDAO.getProductoPorID(long.Parse(cbxProducto.SelectedValue.ToString())); if (chkDescuentoPrecio.Checked && (prod.precio < int.Parse(txtPrecioDescuento.Text))) { MessageBox.Show("Error: El descuento por precio ingresado no puede superar el precio del producto: " + prod.precio + ".", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } else if (chkDescuentoPorcentaje.Checked && (double.Parse(txtPorcentajeDescuento.Text) == 0 || double.Parse(txtPorcentajeDescuento.Text) > 100)) { MessageBox.Show("Error: El Porcentaje de Descuento debe estar entre 1 y 100.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } WindowsFormsApp1.Model.Negocio.Entities.Descuento descOriginal = descuentoDAO.obtenerDescuentoPorProducto(prod.idProducto); if (descOriginal == null) { WindowsFormsApp1.Model.Negocio.Entities.Descuento desc = new WindowsFormsApp1.Model.Negocio.Entities.Descuento(); desc.nombre = txtNombre.Text.Trim(); desc.descripcion = txtDescripcion.Text.Trim(); desc.isPorcentaje = chkDescuentoPorcentaje.Checked ? (short)1 : (short)0; desc.porcentajeDescuento = desc.isPorcentaje == 1 ? double.Parse(txtPorcentajeDescuento.Text) : 0; desc.isPrecioDirecto = chkDescuentoPrecio.Checked ? (short)1 : (short)0; desc.precioDescuento = desc.isPrecioDirecto == 1 ? int.Parse(txtPrecioDescuento.Text) : 0; desc.idProducto = prod.idProducto; descuentoDAO.crearDescuento(desc); this.Dispose(); MessageBox.Show("Descuento creado exitosamente.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Error: Ya existe un descuento creado para este Producto.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }catch (Exception ex) { MessageBox.Show("Error grave creando Descuento.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }