Ejemplo n.º 1
0
 public PiezaItemList(RefaccionDTO refaccion)
 {
     InitializeComponent();
     this.Refaccion   = refaccion;
     lblPieza.Text    = Refaccion.Descripcion;
     lblCantidad.Text = Refaccion.Cantidad.ToString();
     lblTotal.Text    = "$" + Refaccion.Total;
 }
        private void btnAgregar_Click(object sender, EventArgs e)
        {
            bool isValid = Helper.Llenos(txtCant, txtCodigo, txtPrecio) && CurrentRefaccion != null;

            if (!isValid)
            {
                return;
            }

            int     cantidad = int.Parse(txtCant.Text);
            decimal precio   = decimal.Parse(txtPrecio.Text);

            if (precio < CurrentRefaccion.PrecioMinimo)
            {
                MessageBox.Show("El precio es menor que el costo minimo", "Advertencia", MessageBoxButtons.OK, MessageBoxIcon.Warning); return;
            }

            var newRef = new RefaccionDTO()
            {
                Id            = CurrentRefaccion.Id,
                Codigo        = CurrentRefaccion.Codigo,
                Descripcion   = CurrentRefaccion.Descripcion,
                Cantidad      = cantidad,
                PrecioUnitrio = precio,
            };

            var resp = RefaccionValidator.Validate(newRef);

            if (ShowErrorValidation.Valid(resp))
            {
                Refacciones.Add(newRef);
            }

            MessageDialog.ShowMessageDialog("", $"Se ha agregado la refaccion {CurrentRefaccion.Codigo} a la orden ", true);
            Helper.VaciarTexto(txtCant, txtCodigo, txtPrecio);
            CurrentRefaccion = null;
        }