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 btnCrearOferta_Click(object sender, EventArgs e) { try { if (DateTime.Compare(this.dtpFechaInicio.Value.Date, this.dtpFechaFin.Value.Date) > 0 || DateTime.Compare(this.dtpFechaInicio.Value.Date, this.dtpFechaFin.Value.Date) == 0) { MessageBox.Show("Error: La fecha de inicio debe ser anterior a la fecha de fin de la Oferta.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (this.txtUrlImagen.Text == null || this.txtUrlImagen.Text.Trim().Equals(string.Empty)) { MessageBox.Show("Error: Se debe adjuntar una imagen a la Oferta.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (this.nudCantMaxProd.Value < this.nudCantMinProd.Value) { MessageBox.Show("Error: La cantidad máxima de productos debe ser mayor a la cantidad mínima.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (this.nudCantMaxProd.Value == 0 || this.nudCantMinProd.Value == 0) { MessageBox.Show("Error: La cantidad de productos mínimos y máximos debe ser mayor a 0.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else if (this.chkListBoxTiendas.CheckedItems.Count == 0) { MessageBox.Show("Error: Se debe seleccionar al menos una Tienda.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { OfertaDAO ofertaDAO = new OfertaDAO(); Negocio.Entities.Oferta ofer = ofertaDAO.getOfertaVigenteByCodigoProducto(int.Parse(cbxProducto.SelectedValue.ToString())); if (ofer != null) { MessageBox.Show("Error: Ya existe una oferta creada para el producto seleccionado.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //Creamos los objetos. Negocio.Entities.Oferta nuevaOferta = new Negocio.Entities.Oferta(); nuevaOferta.fechaInicio = this.dtpFechaInicio.Value; nuevaOferta.fechaFin = this.dtpFechaFin.Value; nuevaOferta.idProducto = long.Parse(this.cbxProducto.SelectedValue.ToString()); nuevaOferta.isPublicada = 0; nuevaOferta.minimoProductos = (int)this.nudCantMinProd.Value; nuevaOferta.maximoProductos = (int)this.nudCantMaxProd.Value; FileStream fs = new FileStream(this.txtUrlImagen.Text, FileMode.Open, FileAccess.Read); byte[] blobValue = new byte[fs.Length]; fs.Read(blobValue, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); nuevaOferta.fotografia = blobValue; List <long> listaTiendas = new List <long>(); for (int i = 0; i < this.chkListBoxTiendas.CheckedItems.Count; i++) { listaTiendas.Add(long.Parse(((DataRowView)this.chkListBoxTiendas.CheckedItems[i])["IDTIENDA"].ToString())); } ofertaDAO.crearOferta(nuevaOferta); foreach (long l in listaTiendas) { ofertaDAO.creaRelacionOfertaProducto(nuevaOferta.idOferta, l); } //Envío de email ConsumidorDAO.enviarEMailNuevaOferta(this.cbxProducto.GetItemText(this.cbxProducto.SelectedItem)); this.Dispose(); MessageBox.Show("Oferta creada exitosamente.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } }catch (Exception ex) { MessageBox.Show("Error grave Creando Oferta.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }finally { } }