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); } }
public void cargarDatos() { this.limpiar_inputs(); dgvOfertas.DataSource = OfertaDAO.listarDatos(); txtCreditosDisponibles.Text = cliente.credito.ToString(); numCantidad.Value = 1; }
private void btnPublicar_Click(object sender, EventArgs e) { try { if (this.dgvOferta.SelectedRows.Count == 0) { MessageBox.Show("Error: Debe seleccionar una oferta a publicar.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { OfertaDAO ofertaDao = new OfertaDAO(); WindowsFormsApp1.Model.Negocio.Entities.Oferta oferta = ofertaDao.getOfertaByCodigo(long.Parse(this.dgvOferta.SelectedRows[0].Cells[0].Value.ToString())); if (oferta.isPublicada.Equals(1)) { MessageBox.Show("La oferta ya se encuentra publicada."); return; } else { DialogResult result = MessageBox.Show("¿Está seguro que desea publicar la oferta seleccionada?", "Publicar " + oferta, MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { ofertaDao.publicarOferta(oferta.idOferta); MessageBox.Show("Oferta publicada exitosamente."); cargaGrilla(); } } } } catch (Exception ex) { MessageBox.Show("Error grave publicando oferta.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void cargaGrilla() { OfertaDAO ofertaDAO = new OfertaDAO(); listaOfertas = new BindingList <OfertaGridVO>(ofertaDAO.getListaOfertasGrid()); this.dgvOferta.DataSource = listaOfertas; }
private void btnModificar_Click(object sender, EventArgs e) { try { if (this.dgvOferta.SelectedRows.Count == 0) { MessageBox.Show("Error: Debe seleccionar una oferta para editar.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { OfertaDAO ofertaDAO = new OfertaDAO(); WindowsFormsApp1.Model.Negocio.Entities.Oferta oferta = ofertaDAO.getOfertaByCodigo(long.Parse(this.dgvOferta.SelectedRows[0].Cells[0].Value.ToString())); EditarOferta modif = new EditarOferta(); modif.ofertaSeleccionada = oferta; modif.ShowDialog(); listaOfertas = new BindingList <OfertaGridVO>(ofertaDAO.getListaOfertasGrid()); this.dgvOferta.DataSource = listaOfertas; } } catch (Exception ex) { MessageBox.Show("Error grave editando Oferta.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnNuevo_Click(object sender, EventArgs e) { CrearOferta crearOferta = new CrearOferta(); crearOferta.ShowDialog(); OfertaDAO ofertaDAO = new OfertaDAO(); listaOfertas = new BindingList <OfertaGridVO>(ofertaDAO.getListaOfertasGrid()); this.dgvOferta.DataSource = listaOfertas; }
private string obtenerCodigoOfertaAleatorio() { string codigoAleatorio = this.obtenerCodigoAleatorio(10); while (OfertaDAO.existeCodigoOferta(codigoAleatorio)) //mientras exista, genera otro { codigoAleatorio = this.obtenerCodigoAleatorio(10); } return(codigoAleatorio); }
private void CargaOfertas() { try { OfertaDAO Oferta = new OfertaDAO(); listaOferta = Oferta.getListaOfertasGrid(); } catch (Exception ex) { MessageBox.Show("Ha ocurrido un error al listar las ofertas. Favor comunique a soporte."); return; } }
private void btnActualizar_Click(object sender, EventArgs e) { try { OfertaDAO ofertaDAO = new OfertaDAO(); listaOfertas = new BindingList <OfertaGridVO>(ofertaDAO.getListaOfertasGrid()); this.dgvOferta.DataSource = listaOfertas; } catch (Exception ex) { MessageBox.Show("Error grave listando Ofertas.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void EditarOferta_Load(object sender, EventArgs e) { try { ProductoDAO prodDAO = new ProductoDAO(); DataTable dt = prodDAO.getProductosCbx(); this.cbxProducto.DataSource = dt; this.cbxProducto.DisplayMember = "NOMBRE"; this.cbxProducto.ValueMember = "IDPRODUCTO"; TiendaDAO tiendaDAO = new TiendaDAO(); DataTable dtTienda = tiendaDAO.getTiendasCbx(); ((ListBox)this.chkListBoxTiendas).DataSource = dtTienda; ((ListBox)this.chkListBoxTiendas).DisplayMember = "NOMBRE"; ((ListBox)this.chkListBoxTiendas).ValueMember = "IDTIENDA"; OfertaDAO ofertaDAO = new OfertaDAO(); //Carga de datos de oferta List <RlOFertaTienda> listaOfertas = ofertaDAO.getOfertasTiendas(this.ofertaSeleccionada.idOferta); this.dtpFechaFin.Value = this.ofertaSeleccionada.fechaFin; this.dtpFechaInicio.Value = this.ofertaSeleccionada.fechaInicio; this.cbxProducto.SelectedValue = this.ofertaSeleccionada.idProducto; //this.txtUrlImagen.Text = this.ofertaSeleccionada.rutaFoto; this.nudCantMinProd.Value = this.ofertaSeleccionada.minimoProductos; this.nudCantMaxProd.Value = this.ofertaSeleccionada.maximoProductos; this.pictureBox1.Image = Image.FromStream(new MemoryStream(this.ofertaSeleccionada.fotografia)); foreach (RlOFertaTienda rlofer in listaOfertas) { for (var i = 0; i < this.chkListBoxTiendas.Items.Count; i++) { DataRowView item = (DataRowView)chkListBoxTiendas.Items[i]; chkListBoxTiendas.SetItemChecked(i, rlofer.nombreTienda.Trim().Equals(((DataRowView)item).Row["NOMBRE"].ToString())); } } } catch (Exception ex) { MessageBox.Show("Error grave Cargando datos para creación.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { } }
private void btnCrear_Click(object sender, EventArgs e) { if (this.datosValidos()) { MessageBox.Show("Complete los campos"); } else if (!this.fechasValidas()) { MessageBox.Show("La fecha de publicación debe ser mayor igual a la actual y la fecha de vencimiento debe ser mayor a la de publicación"); } else if (!this.preciosValidos()) { MessageBox.Show("El precio de oferta debe ser menor o igual al precio de lista"); } else { Oferta oferta = new Oferta(); oferta.proveedor = proveedor; oferta.cantidad_disponible = int.Parse(numCantidadDisponible.Value.ToString()); oferta.cantidad_max_cliente = int.Parse(numCantidadMaxima.Value.ToString()); oferta.codigo = this.obtenerCodigoOfertaAleatorio(); oferta.descripcion = txtDescripcion.Text; oferta.precio_lista = double.Parse(numPrecioLista.Value.ToString()); oferta.precio_oferta = double.Parse(numPrecioOferta.Value.ToString()); oferta.descuento = (double.Parse(numPrecioLista.Value.ToString()) - double.Parse(numPrecioOferta.Value.ToString())) / double.Parse(numPrecioLista.Value.ToString()); oferta.fecha_vencimiento = DateTime.Parse(dtmFechaVencimiento.Value.ToString("yyyy-MM-dd")); oferta.fecha_publicacion = DateTime.Parse(dtmFechaPublicacion.Value.ToString("yyyy-MM-dd")); if (OfertaDAO.agregarOferta(oferta)) { MessageBox.Show("Oferta creada correctamente", "Oferta", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Close(); } else { MessageBox.Show("Error al crear Oferta"); } } }
private void ListadoOfertas_Load(object sender, EventArgs e) { dgvOfertas.DataSource = OfertaDAO.listarOfertasDeProveedor(proveedor.id, inicio, fin); }
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 { } }
private void btnBuscar_Click(object sender, EventArgs e) { dgvOfertas.DataSource = OfertaDAO.buscar_ofertas(txtDescripcion.Text, txtPrecioMinimo.Text, txtPrecioMaximo.Text); }