Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                cbPresentacion.DisplayMember = "Text";
                cbPresentacion.ValueMember   = "Value";
                // cbPresentacion.Items.Add(new { Text = "Liquidos", Value = "Liquidos" });

                if (txtNombreDelProducto.Text == "" || txtCantidad.Text == "" || txtCostoUnitario.Text == "" || txtGrupoPerteneciente.Text == "" || txtPrecioCredito.Text == "" || txtPrecioDeContado.Text == "" || cbPresentacion.Text == "")
                {
                    MessageBox.Show("Parece que olvidaste llenar todos los campos", "¡Cuidado!", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    _en.Cantidad            = decimal.Parse(txtCantidad.Text);
                    _en.CostoUnitario       = decimal.Parse(txtCostoUnitario.Text);//Tipo de variable de int a decimal
                    _en.GrupoPertenenciente = txtGrupoPerteneciente.Text;
                    _en.NombreProducto      = txtNombreDelProducto.Text;
                    // _en.PorcentajeGananciaContado = decimal.Parse(txtPorcentajeDeContado.Text);
                    //_en.PorcentajeGananciaCredito = decimal.Parse(txtPorcentajePrecioCredito.Text);sadas
                    _en.PrecioACredito = decimal.Parse(txtPrecioCredito.Text);
                    _en.PrecioContado  = decimal.Parse(txtPrecioDeContado.Text);
                    _en.Presentacion   = cbPresentacion.Text;

                    int Resultado = _inventarioBl.AgregarProductos(_en);
                    dgInventario.Refresh();
                    dgInventario.DataSource = _inventarioBl.MostrarInventario();

                    if (Resultado == 1)
                    {
                        MessageBox.Show("Se agrego el nuevo producto correctamente", "¡Éxito!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        Limpiar();
                    }
                }
            }

            catch (Exception)
            {
                MessageBox.Show("Hubo un error al agregar el producto", "¡Advertencia!", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
        }