示例#1
0
 private void GuardarButton_Click(object sender, EventArgs e)
 {
     if (validar()) return;
     RolDTO rol = new RolDTO();
     //RolxFuncDTO rolxfun = new RolxFuncDTO();
     rol.NombreRol = NombreText.Text;
     rol.Estado = ActivoCheck.Checked;
     //rol.ListaFunc.Add(this.FuncionalidadesCombo.SelectedItem as FuncionalidadDTO);
     //rolxfun.funcionalidad = (this.FuncionalidadesCombo.SelectedItem as FuncionalidadDTO).IdFuncionalidad;
     //rolxfun.rol = rol.IdRol;
     if (RolDAO.GetByNombre(rol) == null)
     {
         if (RolDAO.insertarRol(rol))
         {
             rol=RolDAO.GetByNombre(rol);
             FuncionalidadDAO.InsertarFuncionalidades(this.Agregar, rol.IdRol);
             MessageBox.Show("Los datos se guardaron con exito");
             this.Close();
         }
         else
         {
             MessageBox.Show("Error al guardar los datos. El Cliente ya existe");
         }
     }
     else
     {
         MessageBox.Show(string.Format("Ya existe un rol con el nombre : {0}",rol.NombreRol));
     }
 }
示例#2
0
 public ModificarRol(RolDTO unRol)
 {
     InitializeComponent();
     this.rol = unRol;
     this.Agregar = new List<FuncionalidadDTO>();
     this.Eliminar = new List<FuncionalidadDTO>();
 }
示例#3
0
 //Crear rol
 public static bool insertarRol(RolDTO rol)
 {
     int retorno = 0;
     using (SqlConnection Conn = Conexion.Conexion.obtenerConexion())
     {
         SqlCommand Comando = new SqlCommand(string.Format("INSERT INTO [NORMALIZADOS].Rol(Nombre, Activo)VALUES('{0}', '{1}')", rol.NombreRol, rol.Estado), Conn);
         retorno = Comando.ExecuteNonQuery();
         return retorno > 0;
     }
 }
示例#4
0
 public static BindingSource getDataGrid(RolDTO rol)
 {
     using (SqlConnection conn = Conexion.Conexion.obtenerConexion())
     {
         using (SqlCommand com = new SqlCommand(string.Format("SELECT R.Id, R.Nombre, R.Activo, RxF.Funcionalidad, F.Descripcion FROM [NORMALIZADOS].Rol R, [NORMALIZADOS].RolxFuncionalidad RxF, [NORMALIZADOS].Funcionalidad F WHERE R.Id = RxF.Rol AND RxF.Funcionalidad = F.Id AND R.Nombre = '{0}'", rol.NombreRol), conn))
         {
             SqlDataReader dataReader = com.ExecuteReader();
             return getRoles(dataReader);
         }
     }
 }
示例#5
0
 public static bool delete(RolDTO rol)
 {
     int retorno = 0;
     using (SqlConnection Conn = Conexion.Conexion.obtenerConexion())
     {
         SqlCommand com = new SqlCommand("[NORMALIZADOS].[SP_Baja_Rol]", Conn);
         com.CommandType = CommandType.StoredProcedure;
         com.Parameters.AddWithValue("@Rol", rol.IdRol);
         retorno = com.ExecuteNonQuery();
         return retorno > 0;
     }
 }
 public static List<FuncionalidadDTO> selectByRol(RolDTO rol)
 {
     using (SqlConnection conn = Conexion.Conexion.obtenerConexion())
     {
         using (SqlCommand com = new SqlCommand("SELECT F.Id,F.Descripcion FROM [NORMALIZADOS].Funcionalidad F JOIN [NORMALIZADOS].RolxFuncionalidad RxF ON RxF.Funcionalidad=F.Id AND RxF.Rol=" + rol.IdRol, conn))
         {
             SqlDataReader reader = com.ExecuteReader();
             List<FuncionalidadDTO> funcionalidades = readerToListFunc(reader);
             return funcionalidades;
         }
     }
 }
示例#7
0
        private void Buscar_Click(object sender, EventArgs e)
        {
            //Ignora el buscar si no hay un rol que buscar.
            if (this.comboBox2.SelectedIndex == -1) return;

            RolDTO rol = new RolDTO();
            rol.NombreRol = comboBox2.SelectedItem as String;

            BindingSource bsA = RolDAO.getDataGrid(rol);
            BindingSource bsB = new BindingSource();
            this.dataGridView1.DataSource = bsA;
            this.dataGridView1.AutoGenerateColumns = true;

            // Set up data binding for the child
            bsB.DataSource = bsA; // chaining bsP to bsA
            bsB.DataMember = "ListaFunc";                 //**
            listBox1.DataSource = bsB;
            listBox1.DisplayMember = "Descripcion";
        }
示例#8
0
        public static BindingSource getRoles(SqlDataReader dataReader)
        {
            List<RolDTO> ListaRoles = new List<RolDTO>();
            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    RolDTO rol = new RolDTO();

                    rol.IdRol = Convert.ToInt32(dataReader["Id"]);
                    rol.Estado = Convert.ToBoolean(dataReader["Activo"]);
                    rol.NombreRol = Convert.ToString(dataReader["Nombre"]);

                    if (ListaRoles.Contains(rol))
                    {
                        RolDTO rol1 = ListaRoles.Find(delegate(RolDTO rolcito)
                        {
                            return rolcito.Equals(rol);
                        });

                        rol1.ListaFunc.Add(new FuncionalidadDTO(Convert.ToInt32(dataReader["Funcionalidad"]), Convert.ToString(dataReader["Descripcion"])));
                    }
                    else
                    {
                        rol.ListaFunc.Add(new FuncionalidadDTO(Convert.ToInt32(dataReader["Funcionalidad"]), Convert.ToString(dataReader["Descripcion"])));

                        ListaRoles.Add(rol);
                    }
                }
            }
            BindingSource bs = new BindingSource();

            foreach (RolDTO rol in ListaRoles)
            {
                bs.Add(rol);
            }
            dataReader.Close();
            dataReader.Dispose();
            return bs;
        }
示例#9
0
        private void GuardarButton_Click(object sender, EventArgs e)
        {
            if (validar()) return;

            RolDTO rol = new RolDTO();
            RolxFuncDTO rolxfun = new RolxFuncDTO();
            rol.NombreRol = NombreText.Text;
            rol.Estado = ActivoCheck.Checked;
            rol.ListaFunc.Add(this.FuncionalidadesCombo.SelectedItem as FuncionalidadDTO);
            rolxfun.funcionalidad = (this.FuncionalidadesCombo.SelectedItem as FuncionalidadDTO).IdFuncionalidad;
            rolxfun.rol = rol.IdRol;

            if ((RolDAO.insertarRol(rol)) && (RolxFuncDAO.insertarRolxFuncionalidad(rolxfun)))
            {
                MessageBox.Show("Los datos se guardaron con exito");
                this.Close();
            }
            else
            {
                MessageBox.Show("Error al guardar los datos. El Cliente ya existe");
            }
        }
示例#10
0
 public static void StartAsUser(RolDTO rol)
 {
     RolActual = rol;
 }
示例#11
0
 public static void StartAsClient()
 {
     UsuarioActual = DefaultUser();
     RolActual = Roles[0];
 }
示例#12
0
 /*
 public static bool FuncionalidadHabilitada(ClaseFuncionalidad funcionalidad)
 {
     return RolActual.tienePermiso(funcionalidad);
 }
 */
 public static void Start(RolDTO rol)
 {
     if (rol == null)
         StartAsClient();
     else
         StartAsUser(rol);
 }
示例#13
0
        public static List<RolDTO> ReaderToListClaseRol(SqlDataReader dataReader)
        {
            List<RolDTO> listaRoles = new List<RolDTO>();
            if (dataReader.HasRows)
            {
                while (dataReader.Read())
                {
                    RolDTO rol = new RolDTO();
                    rol.IdRol = Convert.ToInt32(dataReader["Id"]);
                    rol.NombreRol = Convert.ToString(dataReader["Nombre"]);
                    rol.Estado = Convert.ToBoolean(dataReader["Activo"]);
                    rol.ListaFunc = FuncionalidadDAO.selectByRol(rol);

                    listaRoles.Add(rol);
                }
            }
            dataReader.Close();
            dataReader.Dispose();
            return listaRoles;
        }
示例#14
0
 public static bool update(RolDTO rol)
 {
     int retorno = 0;
     using (SqlConnection Conn = Conexion.Conexion.obtenerConexion())
     {
         SqlCommand Comando = new SqlCommand(string.Format("UPDATE [NORMALIZADOS].Rol SET Nombre = '{0}', Activo = '{1}' WHERE Id = {2}", rol.NombreRol, rol.Estado, rol.IdRol), Conn);
         retorno = Comando.ExecuteNonQuery();
         return retorno > 0;
     }
 }