public DataSet GetAll(string empresaid, tb_pp_constantes BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPpConstantes_SEARCH", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                 cmd.Parameters.Add("@percgadm", SqlDbType.Decimal).Value = BE.percgadm;
                 cmd.Parameters.Add("@percgvta", SqlDbType.Decimal).Value = BE.percgvta;
                 cmd.Parameters.Add("@percgfin", SqlDbType.Decimal).Value = BE.percgfin;
                 cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Delete(string empresaid, tb_pp_constantes BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPpConstantes_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 private void CargarConstantes()
 {
     var BE = new tb_pp_constantes();
     var BL = new tb_pp_constantesBL();
     var dt = new DataTable();
     BE.perianio = DateTime.Today.Year.ToString();
     dt = BL.GetAll(EmpresaID, BE).Tables[0];
     if (dt.Rows.Count > 0)
     {
         gastoadm.Text = Math.Round(Convert.ToDecimal(dt.Rows[0]["percgadm"]), 2).ToString();
         gastovta.Text = Math.Round(Convert.ToDecimal(dt.Rows[0]["percgvta"]), 2).ToString();
         gastofin.Text = Math.Round(Convert.ToDecimal(dt.Rows[0]["percgfin"]), 2).ToString();
     }
     else
     {
         gastoadm.Text = "0.00";
         gastovta.Text = "0.00";
         gastofin.Text = "0.00";
     }
 }
 public bool Update(string empresaid, tb_pp_constantes BE)
 {
     return tablaDA.Update(empresaid, BE);
 }
 public bool Insert(string empresaid, tb_pp_constantes BE)
 {
     return tablaDA.Insert(empresaid, BE);
 }
 public DataSet GetAll(string empresaid, tb_pp_constantes BE)
 {
     return tablaDA.GetAll(empresaid, BE);
 }
        private void Update()
        {
            try
            {
                if (cbo_perianio.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccion el Año...!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    tb_pp_constantesBL BL = new tb_pp_constantesBL();
                    tb_pp_constantes BE = new tb_pp_constantes();

                    BE.perianio = cbo_perianio.SelectedValue.ToString();
                    BE.percgadm = Convert.ToDecimal(percgadm.Text);
                    BE.percgvta = Convert.ToDecimal(percgvta.Text);
                    BE.percgfin = Convert.ToDecimal(percgfin.Text);
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (BL.Update(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos Modificado Correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        procesado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (cbo_perianio.SelectedIndex == -1)
                {
                    MessageBox.Show("Seleccione el Año...!!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    tb_pp_constantesBL BL = new tb_pp_constantesBL();
                    tb_pp_constantes BE = new tb_pp_constantes();

                    BE.perianio = cbo_perianio.SelectedValue.ToString();

                    if (BL.Delete(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos eliminado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        limpiar_documento();
                        form_bloqueado(false);
                        Data_TablaConstantes();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Data_TablaConstantes()
        {
            try
            {
                if (cbo_perianio.SelectedIndex != -1)
                {
                    if (TablaConstantes.Rows.Count > 0)
                        TablaConstantes.Rows.Clear();

                    tb_pp_constantesBL BL = new tb_pp_constantesBL();
                    tb_pp_constantes BE = new tb_pp_constantes();

                    BE.perianio = cbo_perianio.SelectedValue.ToString();

                    TablaConstantes = BL.GetAll(EmpresaID, BE).Tables[0];
                    if (TablaConstantes.Rows.Count > 0)
                    {
                        btn_imprimir.Enabled = true;
                        MDI_dgb_constantes.DataSource = TablaConstantes;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public bool Insert(string empresaid, tb_pp_constantes BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTbPpConstantes_INSERT", cnx))
                {

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@perianio", SqlDbType.Char, 4).Value = BE.perianio;
                    cmd.Parameters.Add("@percgadm", SqlDbType.Decimal).Value = BE.percgadm;
                    cmd.Parameters.Add("@percgvta", SqlDbType.Decimal).Value = BE.percgvta;
                    cmd.Parameters.Add("@percgfin", SqlDbType.Decimal).Value = BE.percgfin;
                    cmd.Parameters.Add("@usuar", SqlDbType.Char, 15).Value = BE.usuar;

                    try
                    {
                        cnx.Open();
                        if (cmd.ExecuteNonQuery() > 0)
                        {
                            return true;
                        }
                        else
                        {
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception(ex.Message);
                    }
                }
            }
        }