private bool ValidarForm() { bool esFormValido = true; if (producto == null) { esFormValido = false; MessageBox.Show($"Debe seleccionar un producto.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false) { esFormValido = false; MessageBox.Show("Cantidad de unidades inválida.", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (Ayudantes.EsDecimalNoNegativo(inversion_total_tb.Text) == false) { esFormValido = false; MessageBox.Show("Inversión total inválida.", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } if (Ayudantes.EsDecimalNoNegativo(precio_venta_defecto_tb.Text) == false) { esFormValido = false; MessageBox.Show("Precio de venta inválido.", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(esFormValido); }
private void cargar_lote_button_Click(object sender, EventArgs e) { if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false) { MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } try { var loteId = int.Parse(lote_id_tb.Text); lote = ConfigGlobal.conexion.CargarLote_PorId(loteId); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (lote == null) { MessageBox.Show("El lote no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } producto_tb.Text = lote.Producto.Nombre; unidades_adquiridas_tb.Text = lote.UnidadesCompradas.ToString(); unidades_disponibles_tb.Text = lote.UnidadesDisponibles.ToString(); inversion_unidad_tb.Text = lote.InversionUnidad.ToString(); precio_venta_unidad_tb.Text = lote.PrecioVentaUnidad.ToString(); inversion_total_tb.Text = (lote.InversionUnidad * lote.UnidadesCompradas).ToString(); }
/// <summary> /// Valida el id del lote a cargar y las unidades a cargar. /// </summary> /// <returns> /// false si el id del lote o las unidades a cargar no son validas. /// true si lo son. /// </returns> private bool ValidarCampos() { if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false) { MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false) { MessageBox.Show("Cantidad de unidades inválida", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } return(true); }
private void ventas_dtgv_CellValidating(object sender, DataGridViewCellValidatingEventArgs e) { // Columna precio de venta. if (e.ColumnIndex == 3) { var precioVenta = e.FormattedValue.ToString(); if (Ayudantes.EsDecimalNoNegativo(precioVenta) == false) { e.Cancel = true; MessageBox.Show("Precio de venta inválido", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var venta = ((VentaModelo)ventas_dtgv.Rows[e.RowIndex].DataBoundItem); venta.PrecioVentaUnidad = decimal.Parse(e.FormattedValue.ToString()); CalcularTotal(); } // Columna unidades. else if (e.ColumnIndex == 4) { var stringUnidadesAVender = e.FormattedValue.ToString(); if (Ayudantes.EsEnteroPositivo(stringUnidadesAVender) == false) { e.Cancel = true; MessageBox.Show($"Cantidad solicitada de unidades inválida.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } var venta = ((VentaModelo)ventas_dtgv.Rows[e.RowIndex].DataBoundItem); var intUnidadesAVender = uint.Parse(stringUnidadesAVender); if (intUnidadesAVender > venta.Lote.UnidadesDisponibles) { e.Cancel = true; MessageBox.Show($"Cantidad solicitada de unidades inválida. Solo { venta.Lote.UnidadesDisponibles } unidades disponibles.", "Cantidad insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } venta.Unidades = intUnidadesAVender; CalcularTotal(); } }
private void cargar_venta_button_Click(object sender, EventArgs e) { if (venta != null) { return; } if (Ayudantes.EsEnteroPositivo(venta_id_tb.Text) == false) { MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } try { var ventaId = Convert.ToInt32(venta_id_tb.Text); venta = ConfigGlobal.conexion.CargarVenta_PorId(ventaId); } catch (ArgumentException ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (venta == null) { MessageBox.Show("La venta no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } lote_id_tb.Text = venta.Lote.Id.ToString(); producto_tb.Text = venta.Lote.Producto.Nombre; unidades_vendidas_tb.Text = venta.Unidades.ToString(); total_tb.Text = venta.Total.ToString(); fecha_venta_tb.Text = venta.Fecha; cliente_tb.Text = venta.Cliente?.NombreCompleto; }
private void CalcularInversionPorUnidad() { inversion_unidad_tb.Text = "N/A"; if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false) { return; } if (Ayudantes.EsDecimalNoNegativo(inversion_total_tb.Text) == false) { return; } int unidades = int.Parse(unidades_tb.Text); if (unidades == 0) { return; } decimal inversion = decimal.Parse(inversion_total_tb.Text); inversion_unidad_tb.Text = (inversion / unidades).ToString(); }
private void agregar_lote_button_Click(object sender, EventArgs e) { // validar campos if (Ayudantes.EsEnteroPositivo(lote_id_tb.Text) == false) { MessageBox.Show("ID del lote inválido", "ID inválido", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } if (Ayudantes.EsEnteroPositivo(unidades_tb.Text) == false) { MessageBox.Show("Cantidad de unidades inválida", "Cantidad inválida", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // cargar lote y verificar que el lote se haya encontrado var loteId = int.Parse(lote_id_tb.Text.Trim()); LoteModelo lote = null; try { lote = ConfigGlobal.conexion.CargarLote_PorId(loteId); } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (lote == null) { MessageBox.Show("El lote no existe.", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // verificar que el lote no exista en la lista var loteExistente = ventas.List.OfType <VentaModelo>().ToList().Find(x => x.LoteId == lote.Id); if (loteExistente != null) { MessageBox.Show("El lote ya existe en la lista.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // verificar que existan suficientes unidades en el lote var unidadesAVender = int.Parse(unidades_tb.Text); if (unidadesAVender > lote.UnidadesDisponibles) { if (lote.UnidadesDisponibles == 0) { MessageBox.Show($"El lote no contiene unidades.", "Lote vacío", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } MessageBox.Show($"Cantidad solicitada de unidades inválida. Solo { lote.UnidadesDisponibles } unidades disponibles.", "Cantidad disponible insuficiente", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } // crear venta var venta = new VentaModelo(); venta.Unidades = unidadesAVender; venta.Lote = lote; venta.PrecioVentaUnidad = lote.PrecioVentaUnidad; ventas.Add(venta); CalcularTotal(); }