public bool Delete(string empresaid, tb_perfilitems BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPerfilitems_DELETE", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@idper", SqlDbType.Char, 9).Value = BE.idper;
                 cmd.Parameters.Add("@plataforma", SqlDbType.Char, 1).Value = BE.plataforma;
                 cmd.Parameters.Add("@menid", SqlDbType.Int).Value = BE.menid;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll(string empresaid, tb_perfilitems BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPerfilitems_SEARCH", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@idper", SqlDbType.Char, 9).Value = BE.idper;
                 cmd.Parameters.Add("@plataforma", SqlDbType.Char, 1).Value = BE.plataforma;
                 cmd.Parameters.Add("@menid", SqlDbType.Int).Value = BE.menid;
                 //cmd.Parameters.Add("@padid", SqlDbType.Int).Value = BE.padid;
                 //cmd.Parameters.Add("@posic", SqlDbType.Int).Value = BE.posic;
                 cmd.Parameters.Add("@descr", SqlDbType.VarChar, 100).Value = BE.descr;
                 cmd.Parameters.Add("@icono", SqlDbType.VarChar, 100).Value = BE.icono;
                 //cmd.Parameters.Add("@habil", SqlDbType.Bit).Value = BE.habil;
                 cmd.Parameters.Add("@pgurl", SqlDbType.VarChar, 100).Value = BE.pgurl;
                 cmd.Parameters.Add("@nivelacc", SqlDbType.Char, 5).Value = BE.nivelacc;
                 cmd.Parameters.Add("@dominioid", SqlDbType.Char, 2).Value = BE.dominioid;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@local", SqlDbType.Char, 3).Value = BE.local;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public DataSet GetAll_actives(string empresaid, tb_perfilitems BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPerfilitems_SEARCH_actives", cnx))
         {
             DataSet ds = new DataSet();
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@idper", SqlDbType.Char, 9).Value = BE.idper;
                 cmd.Parameters.Add("@plataforma", SqlDbType.Char, 1).Value = BE.plataforma;
                 cmd.Parameters.Add("@menid", SqlDbType.Int).Value = BE.menid;
                 cmd.Parameters.Add("@descr", SqlDbType.VarChar, 100).Value = BE.descr;
             }
             try
             {
                 cnx.Open();
                 using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                 {
                     da.Fill(ds);
                 }
                 return ds;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
 public bool Update_propied(string empresaid, tb_perfilitems BE)
 {
     using (SqlConnection cnx = new SqlConnection(conex.empConexion(empresaid)))
     {
         using (SqlCommand cmd = new SqlCommand("gspTbPerfilitems_UPDATE_propied", cnx))
         {
             {
                 cmd.CommandType = CommandType.StoredProcedure;
                 cmd.Parameters.Add("@idper", SqlDbType.Char, 9).Value = BE.idper;
                 cmd.Parameters.Add("@plataforma", SqlDbType.Char, 1).Value = BE.plataforma;
                 cmd.Parameters.Add("@menid", SqlDbType.Int).Value = BE.menid;
                 cmd.Parameters.Add("@padid", SqlDbType.Int).Value = BE.padid;
                 cmd.Parameters.Add("@posic", SqlDbType.Int).Value = BE.posic;
                 cmd.Parameters.Add("@descr", SqlDbType.VarChar, 100).Value = BE.descr;
                 cmd.Parameters.Add("@icono", SqlDbType.VarChar, 100).Value = BE.icono;
                 cmd.Parameters.Add("@habil", SqlDbType.Bit).Value = BE.habil;
                 cmd.Parameters.Add("@pgurl", SqlDbType.VarChar, 100).Value = BE.pgurl;
                 cmd.Parameters.Add("@nivelacc", SqlDbType.Char, 5).Value = BE.nivelacc;
                 cmd.Parameters.Add("@dominioid", SqlDbType.Char, 2).Value = BE.dominioid;
                 cmd.Parameters.Add("@moduloid", SqlDbType.Char, 4).Value = BE.moduloid;
                 cmd.Parameters.Add("@local", SqlDbType.Char, 3).Value = BE.local;
             }
             try
             {
                 cnx.Open();
                 if (cmd.ExecuteNonQuery() > 0)
                 {
                     return true;
                 }
                 else
                 {
                     return false;
                 }
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }
     }
 }
        private void Update_propied()
        {
            try
            {
                if (idper.Text.Trim().Length != 9)
                {
                    MessageBox.Show("Ingrese Perfil !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    if (menid.Text.Trim().Length != 3)
                    {
                        MessageBox.Show("No existe Id Menu !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    else
                    {
                        data_nuevoperfil();
                        var BL = new perfilitemsBL();
                        var BE = new tb_perfilitems();

                        BE.idper = idper.Text.Trim();
                        BE.plataforma = "1";
                        BE.menid = Convert.ToInt16(menid.Text.Trim());
                        BE.descr = descr.Text.Trim();
                        if (nivelacc.SelectedIndex != -1 && nivelacc.SelectedValue.ToString().Trim().Trim().Length > 0)
                        {
                            BE.nivelacc = nivelacc.SelectedValue.ToString().PadRight(5, '0');
                        }
                        BE.habil = habil.Checked;

                        if (BL.Update_propied(EmpresaID, BE))
                        {
                            MessageBox.Show("Datos Modificados", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            data_Perfil_user(idper.Text.Trim());
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void data_Perfil_user(String perfil)
        {
            try
            {
                TreeNode Tperfil;
                var BL = new perfilitemsBL();
                var BE = new tb_perfilitems();
                var dt = new DataTable();

                treeperfil.Nodes.Clear();

                if (perfil.Trim().Length != 9)
                {
                    MessageBox.Show("Seleccione un perfil !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                BE.idper = perfil.Trim();
                BE.plataforma = "1";
                dt = BL.GetAll_actives(EmpresaID, BE).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    Tablaperfil = dt;

                    treeperfil.CheckBoxes = true;
                    foreach (DataRow DRmenu in dt.Rows)
                    {
                        Tperfil = new TreeNode();
                        Tperfil.Name = DRmenu["menid"].ToString();
                        Tperfil.Text = DRmenu["descr"].ToString();
                        Tperfil.ToolTipText = DRmenu["padid"].ToString();
                        if (DRmenu["activo"].ToString().Trim().Length > 0)
                        {
                            Tperfil.Checked = Convert.ToBoolean(DRmenu["activo"]);
                        }
                        if (DRmenu["menid"].Equals(DRmenu["padid"]))
                        {
                            treeperfil.Nodes.Add(Tperfil);
                        }
                        Perfil_item_user(ref Tperfil, dt);
                    }
                }
                else
                {
                    MessageBox.Show("No hay Datos !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void Update()
        {
            try
            {
                if (idper.Text.Trim().Length != 9)
                {
                    MessageBox.Show("Ingrese Perfil !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    data_nuevoperfil();
                    var BL = new perfilitemsBL();
                    var BE = new tb_perfilitems();
                    var Detalle = new tb_perfilitems.Item();
                    var ListaItems = new List<tb_perfilitems.Item>();

                    foreach (DataRow fila in Tablanuevoperfil.Rows)
                    {
                        Detalle = new tb_perfilitems.Item();

                        Detalle.idper = fila["idper"].ToString();
                        Detalle.plataforma = fila["plataforma"].ToString();
                        Detalle.menid = Convert.ToInt16(fila["menid"]);
                        Detalle.padid = Convert.ToInt16(fila["padid"]);
                        Detalle.posic = Convert.ToInt16(fila["posic"]);
                        Detalle.descr = fila["descr"].ToString();
                        Detalle.grupo = fila["grupo"].ToString();
                        Detalle.icono = fila["icono"].ToString();
                        Detalle.habil = Convert.ToBoolean(fila["habil"]);
                        Detalle.pgurl = fila["pgurl"].ToString();
                        Detalle.nivelacc = fila["nivelacc"].ToString();
                        Detalle.dominioid = fila["dominioid"].ToString();
                        Detalle.moduloid = fila["moduloid"].ToString();
                        Detalle.local = fila["local"].ToString();

                        ListaItems.Add(Detalle);
                    }
                    BE.idper = idper.Text.Trim();
                    BE.plataforma = "1";
                    BE.ListaItems = ListaItems;
                    if (BL.Update_xml(EmpresaID, BE))
                    {
                        MessageBox.Show("Datos grabados correctamente !!!", "Información", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        procesado = true;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public bool Update_xml(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.Update_xml(empresaid, BE);
 }
        private void Delete2()
        {
            try
            {
                if (idper2.Text.Trim().Length != 9)
                {
                    MessageBox.Show("Seleccione Perfil !!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                {
                    var BL = new perfilitemsBL();
                    var BE = new tb_perfilitems();

                    BE.idper = idper2.Text.Trim();
                    BL.Delete(EmpresaID, BE);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
 public bool Insert_xml(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.Insert_xml(empresaid, BE);
 }
 public DataSet GetOne(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.GetOne(empresaid, BE);
 }
 public DataSet GetAll_nivel_acceso(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.GetAll_nivel_acceso(empresaid, BE);
 }
 public DataSet GetAll_actives(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.GetAll_actives(empresaid, BE);
 }
 public bool Delete(string empresaid, tb_perfilitems BE)
 {
     return tablaDA.Delete(empresaid, BE);
 }