Ejemplo n.º 1
0
        private void btnRegistrar_Click(object sender, EventArgs e)
        {
            string mensaje = "";

            try
            {
                errorProvider1.Clear();
                if (Utilidades.ValidarForm(this, errorProvider1) == false)
                {
                    return;
                }
                if (Program.Evento == 0)
                {
                    Pr.Descripcion = txtDescripcion.Text;
                    Pr.Referencia  = txtReferencia.Text;
                    Pr.Idcategoria = Convert.ToInt32(cbCategoria.SelectedValue);
                    Pr.Idunidad    = Convert.ToInt32(cbUnidad.SelectedValue);
                    Pr.Idmarca     = Convert.ToInt32(cbMarca.SelectedValue);
                    Pr.Iditbis     = Convert.ToInt32(cbItbis.SelectedValue);
                    Pr.Codigob     = txtCodigoB.Text;
                    Pr.Costoc      = Convert.ToDouble(txtCostoC.Text);
                    Pr.Costop      = Convert.ToDouble(txtCostoP.Text);
                    Pr.Puntor      = Convert.ToDouble(txtPuntoR.Text);
                    Pr.Puntom      = Convert.ToDouble(txtPuntoMax.Text);
                    mensaje        = Pr.Registrar();
                    if (mensaje == "1")
                    {
                        for (int x = 0; x < dtgProveedor.Rows.Count; x++)
                        {
                            Pr.Idproveedor = Convert.ToInt32(dtgProveedor.Rows[x].Cells[0].Value);
                            Pr.Idproducto  = 0;
                            mensaje        = Pr.RegistrarP();
                        }
                        MessageBoxEx.Show("Registrado con éxito", "FactSYS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Limpiar();
                    }
                }
                else if (Program.Evento == 1)
                {
                    Pr.Idproducto  = Program.Idproducto;
                    Pr.Descripcion = txtDescripcion.Text;
                    Pr.Referencia  = txtReferencia.Text;
                    Pr.Idcategoria = Convert.ToInt32(cbCategoria.SelectedValue);
                    Pr.Idunidad    = Convert.ToInt32(cbUnidad.SelectedValue);
                    Pr.Idmarca     = Convert.ToInt32(cbMarca.SelectedValue);
                    Pr.Iditbis     = Convert.ToInt32(cbItbis.SelectedValue);
                    Pr.Codigob     = txtCodigoB.Text;
                    Pr.Costoc      = Convert.ToDouble(txtCostoC.Text);
                    Pr.Costop      = Convert.ToDouble(txtCostoP.Text);
                    Pr.Puntor      = Convert.ToDouble(txtPuntoR.Text);
                    Pr.Puntom      = Convert.ToDouble(txtPuntoMax.Text);
                    mensaje        = Pr.Actualizar();
                    if (mensaje == "1")
                    {
                        for (int x = 0; x < dtgProveedor.Rows.Count; x++)
                        {
                            Pr.Idproveedor = Convert.ToInt32(dtgProveedor.Rows[x].Cells[0].Value);
                            Pr.Idproducto  = Program.Idproducto;
                            mensaje        = Pr.RegistrarP();
                        }
                        MessageBoxEx.Show("Actualizado con éxito", "FactSYS", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        Limpiar();
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBoxEx.Show(ex.Message);
            }
        }