public DataSet GetAll_paginacion(string empresaid, tb_60grupo BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTb60Grupo_SEARCH_paginacion", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@grupoid", SqlDbType.Char, 4).Value = BE.grupoid;
                 cmd.Parameters.Add("@posicion", SqlDbType.VarChar, 10).Value = BE.posicion;
                 //cmd.Parameters.Add("@status", SqlDbType.Char, 1).Value = BE.status;
             }
             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_60grupo BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTb60Grupo_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@grupoid", SqlDbType.Char, 4).Value = BE.grupoid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        private void Update()
        {
            try
            {
                if (grupoid.Text.Trim().Length != 4)
                {
                    MessageBox.Show("Falta Codigo grupo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (gruponame.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese nombre de Grupo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_60grupoBL();
                        var BE = new tb_60grupo();
                        BE.moduloid = moduloiddes.SelectedValue.ToString();
                        BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');
                        BE.gruponame = gruponame.Text.ToUpper();
                        BE.ctacte = ctacte.Text.Trim().ToUpper();
                        BE.usuar = VariablesPublicas.Usuar.Trim();

                        if (BL.Update(EmpresaID, BE))
                        {
                            SEGURIDAD_LOG("M");
                            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 form_cargar_datos(String posicion)
        {
            try
            {
                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();
                var dt = new DataTable();

                BE.moduloid = moduloiddes.SelectedValue.ToString();
                if (moduloiddes.SelectedValue.ToString() == "0000")
                {
                    MessageBox.Show("Seleccione Almacen", "Information");
                    return;
                }

                if (grupoid.Text.Trim().Length > 0)
                {
                    BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');
                }
                BE.posicion = posicion.Trim();

                dt = BL.GetAll_paginacion(EmpresaID, BE).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    limpiar_documento();
                    ssModo = "EDIT";

                    grupoid.Text = dt.Rows[0]["grupoid"].ToString().Trim();
                    gruponame.Text = dt.Rows[0]["gruponame"].ToString().Trim();
                    ctacte.Text = dt.Rows[0]["ctacte"].ToString().Trim();
                    ctactename.Text = dt.Rows[0]["ctactename"].ToString().Trim();

                    btn_editar.Enabled = true;
                    btn_eliminar.Enabled = true;
                    btn_imprimir.Enabled = true;

                    btn_primero.Enabled = true;
                    btn_anterior.Enabled = true;
                    btn_siguiente.Enabled = true;
                    btn_ultimo.Enabled = true;

                    btn_log.Enabled = true;
                    btn_salir.Enabled = true;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Delete()
        {
            try
            {
                if (grupoid.Text.Trim().Length != 4)
                {
                    MessageBox.Show("Falta Codigo grupo !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new tb_60grupoBL();
                    var BE = new tb_60grupo();
                    BE.moduloid = moduloiddes.SelectedValue.ToString();
                    BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');
                    BE.gruponame = gruponame.Text.ToUpper();
                    BE.ctacte = ctacte.Text.Trim().ToUpper();
                    BE.usuar = VariablesPublicas.Usuar.Trim();

                    if (BL.Delete(EmpresaID, BE))
                    {
                        SEGURIDAD_LOG("E");
                        MessageBox.Show("Datos eliminado correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        NIVEL_FORMS();
                        form_bloqueado(false);
                        data_Tablagrupo();
                        btn_nuevo.Enabled = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Tablagrupo()
        {
            try
            {
                if (Tablagrupo.Rows.Count > 0)
                {
                    Tablagrupo.Rows.Clear();
                }
                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();

                BE.moduloid = moduloiddes.SelectedValue.ToString();
                if (moduloiddes.SelectedValue.ToString() == "0000")
                {
                    MessageBox.Show("Seleccione Almacen", "Information");
                    return;
                }
                BE.gruponame = txt_criterio.Text.Trim().ToUpper();

                Tablagrupo = BL.GetAll(EmpresaID, BE).Tables[0];
                if (Tablagrupo.Rows.Count > 0)
                {
                    btn_imprimir.Enabled = true;
                    gridgrupo.DataSource = Tablagrupo;
                    gridgrupo.Rows[0].Selected = false;
                    gridgrupo.Focus();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void ValidaGrupo()
        {
            if (grupoid.Text.Trim().Length > 0)
            {
                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();
                var dt = new DataTable();

                BE.moduloid = cbomodulo.SelectedValue.ToString();
                BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    grupoid.Text = dt.Rows[0]["grupoid"].ToString().Trim();
                    gruponame.Text = dt.Rows[0]["gruponame"].ToString().Trim();
                }
                else
                {
                    grupoid.Text = string.Empty;
                    gruponame.Text = string.Empty;
                }
            }
            else
            {
                grupoid.Text = string.Empty;
                gruponame.Text = string.Empty;
            }
        }
        private DataTable Movimiento_grupo()
        {
            try
            {
                DtReporte = new DataTable("Grupo");

                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();

                BE.moduloid = moduloid.Trim();

                DtReporte = BL.GetReport(VariablesPublicas.EmpresaID.ToString(), BE).Tables[0];
                if (DtReporte != null)
                {
                    return DtReporte;
                }
                else
                {
                    return DtReporte;
                }
            }
            catch (Exception ex)
            {
                return null;
            }
        }
 public bool Insert(string empresaid, tb_60grupo BE)
 {
     return tablaDA.Insert(empresaid, BE);
 }
 public DataSet GetReport(string empresaid, tb_60grupo BE)
 {
     return tablaDA.GetReport(empresaid, BE);
 }
 public DataSet GetAll_paginacion(string empresaid, tb_60grupo BE)
 {
     return tablaDA.GetAll_paginacion(empresaid, BE);
 }
 public bool Delete(string empresaid, tb_60grupo BE)
 {
     return tablaDA.Delete(empresaid, BE);
 }
        public bool Update(string empresaid, tb_60grupo BE)
        {
            using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
            {
                using (SqlCommand cmd = new SqlCommand("gspTb60Grupo_UPDATE", cnx))
                {

                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                        cmd.Parameters.Add("@grupoid", SqlDbType.Char, 4).Value = BE.grupoid;
                        cmd.Parameters.Add("@gruponame", SqlDbType.VarChar, 30).Value = BE.gruponame;
                        cmd.Parameters.Add("@ctacte", SqlDbType.Char, 7).Value = BE.ctacte;
                        //cmd.Parameters.Add("@status", SqlDbType.Char, 1).Value = BE.status;
                        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);
                    }
                }
            }
        }
        private void ValidaGrupo()
        {
            if (grupoid.Text.Trim().Length > 0 && ssModo == "NEW")
            {
                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();
                var dt = new DataTable();

                BE.moduloid = modulo;
                BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    grupoid.Text = dt.Rows[0]["grupoid"].ToString().Trim();
                    gruponame.Text = dt.Rows[0]["gruponame"].ToString().Trim();
                    generar_denominacion();
                }
                else
                {
                    grupoid.Text = string.Empty;
                    gruponame.Text = string.Empty;
                    generar_denominacion();
                }
            }
            if (grupoid.Text.Trim().Length == 0 && ssModo == "NEW")
            {
                grupoid.Text = string.Empty;
                gruponame.Text = string.Empty;
                generar_denominacion();
            }
        }
 public bool Update(string empresaid, tb_60grupo BE)
 {
     return tablaDA.Update(empresaid, BE);
 }
        private void ValidaGrupo()
        {
            if (grupoid.Text.Trim().Length > 0 && ssModo == "NEW")
            {
                var BL = new tb_60grupoBL();
                var BE = new tb_60grupo();
                var dt = new DataTable();

                BE.moduloid = moduloiddes.SelectedValue.ToString();
                if (moduloiddes.SelectedValue.ToString() == "0000")
                {
                    MessageBox.Show("Seleccione Almacen", "Information");
                    return;
                }
                BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');

                dt = BL.GetAll(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    grupoid.Text = dt.Rows[0]["grupoid"].ToString().Trim();
                    gruponame.Text = dt.Rows[0]["gruponame"].ToString().Trim();
                    generar_denominacion();
                }
                else
                {
                    grupoid.Text = string.Empty;
                    gruponame.Text = string.Empty;
                    generar_denominacion();
                }
            }
            if (grupoid.Text.Trim().Length == 0 && ssModo == "NEW")
            {
                grupoid.Text = string.Empty;
                gruponame.Text = string.Empty;
                generar_denominacion();
            }
        }
        private void Insert()
        {
            try
            {
                if (grupoid.Text.Trim().Length != 3)
                {
                    MessageBox.Show("Falta Codigo grupoid !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (gruponame.Text.Trim().Length == 0)
                    {
                        MessageBox.Show("Ingrese nombre de grupo", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        var BL = new tb_60grupoBL();
                        var BE = new tb_60grupo();

                        BE.moduloid = modulo;
                        BE.grupoid = grupoid.Text.Trim().PadLeft(4, '0');
                        BE.gruponame = gruponame.Text.ToUpper();
                        BE.ctacte = ctacte.Text.Trim().ToUpper();
                        BE.usuar = VariablesPublicas.Usuar.Trim();

                        if (BL.Insert(EmpresaID, BE))
                        {
                            MessageBox.Show("Datos grabados correctamente !!!", "Confirmación", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            procesado = true;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }