Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new MySqlContext())
            {

                LoginModel user = db.LoginModels.Where(r => r.User == txt_usuario.Text).FirstOrDefault();
                if (user!=null)
                {
                    if (user.Pass==txt_pass.Text)
                    {
                        this.Hide();
                        MainWindow mwWindow = new MainWindow();
                        mwWindow.Show();
                    }
                    else
                    {
                        MessageBox.Show("Nombre de Usuario o Password Invalido");
                    }
                }
                else
                {
                    MessageBox.Show("Nombre de Usuario o Password Invalido");
                }
            }
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            using (var db = new MySqlContext())
            {
                var permissions = from a in db.Permissions
                                  select a.Name;
                this.checkedListBox_permissions.Items.AddRange(permissions.ToArray());
                this.checkedListBox_modificar_permissions.Items.AddRange(permissions.ToArray());

                var users = from b in db.LoginModels
                            select b.User;
                this.checkedListBox_users.Items.AddRange(users.ToArray());
                this.checkedListBox_modificar_users.Items.AddRange(users.ToArray());

                var roles = from r in db.Roles
                            select r.Name;
                AutoCompleteStringCollection accl = new AutoCompleteStringCollection();
                accl.AddRange(roles.ToArray());

                txt_rol_nombre.AutoCompleteMode = AutoCompleteMode.Suggest;
                txt_rol_nombre.AutoCompleteCustomSource = accl;
                txt_rol_nombre.AutoCompleteSource = AutoCompleteSource.CustomSource;

                txt_modificar_nombre.AutoCompleteMode = AutoCompleteMode.Suggest;
                txt_modificar_nombre.AutoCompleteCustomSource = accl;
                txt_modificar_nombre.AutoCompleteSource = AutoCompleteSource.CustomSource;

            }
        }
Beispiel #3
0
        static void Main()
        {
            Database.SetInitializer<MySqlContext>(new DropCreateDatabaseIfModelChanges<MySqlContext>());

            var connString = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ToString();

            using (var db = new MySqlContext())
            {

                #region Load CheckedList1

                const string f = "/Users/Rafa/Documents/Proyecto NS/SavedList.txt";
                List<string> lines = new List<string>();
                using (StreamReader r = new StreamReader(f))
                {
                    string line;
                    while ((line = r.ReadLine()) != null)
                    {
                        lines.Add(line);
                    }
                }

                foreach (string s in lines)
                {

                    var permissions_in_db = db.Permissions
                        .Where(a => a.Name == s)
                        .Count();
                    if (permissions_in_db < 1)
                    {
                        if (s!="")
                        {
                            db.Permissions.AddOrUpdate(new Permission
                            {
                                Name = s
                            });
                            db.SaveChanges();
                        }

                    }
                }
                #endregion

                db.SaveChanges();
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Login());
        }
Beispiel #4
0
        private void btn_modificar_buscar_Click(object sender, EventArgs e)
        {
            using (var db = new MySqlContext())
            {
                #region ClearCheckedList
                for (int i = 0; i < checkedListBox_modificar_permissions.Items.Count; i++)
                {
                    checkedListBox_modificar_permissions.SetItemChecked(i, false);
                }
                for (int i = 0; i < checkedListBox_modificar_users.Items.Count; i++)
                {
                    checkedListBox_modificar_users.SetItemChecked(i, false);
                }
                #endregion

                var permissions = db.Roles.Where(r => r.Name == txt_modificar_nombre.Text)
                                  .SelectMany(r => r.Permissions);

                var users_per_role = db.Roles.Where(r => r.Name == txt_modificar_nombre.Text)
                                     .SelectMany(r => r.Users);

                foreach (var permission in permissions)
                {

                    for (int i = 0; i < checkedListBox_modificar_permissions.Items.Count; i++)
                    {
                        if ((string)checkedListBox_modificar_permissions.Items[i] == permission.Name)
                        {
                            checkedListBox_modificar_permissions.SetItemChecked(i, true);
                        }
                    }
                }

                foreach (var user in users_per_role)
                {

                    for (int i = 0; i < checkedListBox_modificar_users.Items.Count; i++)
                    {
                        if ((string)checkedListBox_modificar_users.Items[i] == user.User)
                        {
                            checkedListBox_modificar_users.SetItemChecked(i, true);
                        }
                    }
                }

            }
        }
Beispiel #5
0
 public static LoginModel GetUsers(string user_name, MySqlContext db)
 {
     var query = db.LoginModels.SingleOrDefault(p => p.User == user_name);
     return query;
 }
Beispiel #6
0
 public static Permission GetPermission(string permission_name, MySqlContext db)
 {
     var query = db.Permissions.SingleOrDefault(p => p.Name == permission_name);
     return query;
 }
Beispiel #7
0
        private void btn_rol_modificar_Click(object sender, EventArgs e)
        {
            using (var db = new MySqlContext())
            {

                Role role = (from s in db.Roles
                             where s.Name == txt_modificar_nombre.Text
                             select s).FirstOrDefault<Role>();

                foreach (var item in checkedListBox_modificar_permissions.CheckedItems)
                {

                    Permission newPermission = (from r in db.Permissions
                                                 .Where(n => n.Name == item)
                                                select r).FirstOrDefault<Permission>();

                    role.Permissions.Clear();
                    db.SaveChanges();

                }

                foreach (var item in checkedListBox_modificar_permissions.CheckedItems)
                {

                    Permission newPermission = (from r in db.Permissions
                                                 .Where(n => n.Name == item)
                                                select r).FirstOrDefault<Permission>();

                    role.Permissions.Add(newPermission);
                    db.SaveChanges();
                }
                MessageBox.Show("Cambios realizados satisfactoriamente.", "Role Creator - Modificar ", MessageBoxButtons.OK,
                                         MessageBoxIcon.Information);
                this.usuarios_por_rolTableAdapter.Fill(this.authDataSet.usuarios_por_rol);

            }
        }
Beispiel #8
0
        private void btn_rol_create_Click(object sender, EventArgs e)
        {
            bool checked_per =  HandyClass.CheckedListValidator(checkedListBox_permissions);
            bool checked_users =  HandyClass.CheckedListValidator(checkedListBox_users);

                using (var db = new MySqlContext())
                {
                    if (txt_rol_nombre.Text != "")
                    {
                        if ((checked_per != false) && (checked_users != false))
                        {
                            var role = db.Roles.Where(a => a.Name == txt_rol_nombre.Text).FirstOrDefault();
                            if (role != null)
                            {
                                MessageBox.Show("Ya existe un rol con este nombre", "Error", MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                                txt_rol_nombre.Focus();
                            }
                            else
                            {
                                var permissions = new List<Permission>();
                                foreach (var item in checkedListBox_permissions.CheckedItems)
                                {
                                    Permission permission = HandyClass.GetPermission(item.ToString(), db);
                                    permissions.Add(permission);
                                }

                                var users = new List<LoginModel>();
                                foreach (var item in checkedListBox_users.CheckedItems)
                                {
                                    LoginModel user = HandyClass.GetUsers(item.ToString(), db);
                                    users.Add(user);

                                }

                                db.Roles.Add(new Role
                                {
                                    Name = txt_rol_nombre.Text,
                                    Permissions = permissions,
                                    Users = users
                                });
                                db.SaveChanges();
                                this.usuarios_por_rolTableAdapter.Fill(this.authDataSet.usuarios_por_rol);
                                MessageBox.Show("Rol creado satisfactoriamente!");
                                HandyClass.ClearCheckedListBox(checkedListBox_permissions);
                                HandyClass.ClearCheckedListBox(checkedListBox_users);
                                txt_rol_nombre.Text = "";
                                txt_rol_nombre.Focus();
                            }
                        }
                        else
                        {
                                 MessageBox.Show(
                                "Debe seleccionar al menos un Usuario y al menos un Permisso, para asignar al Rol.",
                                "Rol Creator", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }
                    else
                    {
                         MessageBox.Show("Debe Introducir un nombre para el Rol a crear.", "", MessageBoxButtons.OK,
                                         MessageBoxIcon.Exclamation);
                         txt_rol_nombre.Text = "";
                         txt_rol_nombre.Focus();
                    }

                }
        }