Esempio n. 1
0
        private void btnDeleteUser_Click(object sender, RoutedEventArgs e)
        {
            if (!IsTrueDbConfig())
            {
                MessageBox.Show("Need right db configuration on the first tab.");
                return;
            }

            if (SelectedUser == null)
            {
                MessageBox.Show("Please select the user to delete.");
                return;
            }

            User           userToDelete = SelectedUser;
            DatabaseConfig config       = DbConfig;

            new Task((Action)(() =>
            {
                MsSqlDataProvider provider = new MsSqlDataProvider();
                DragonflyEntities context = provider.Initizlize(config) as DragonflyEntities;
                try
                {
                    provider.DeleteUser(userToDelete.Login);
                    Dispatcher.Invoke((Action)(() =>
                    {
                        LoadUsersRunner(config);
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            })).Start();
        }
Esempio n. 2
0
        private void btnAddUser_Click(object sender, RoutedEventArgs e)
        {
            if (!IsTrueDbConfig())
            {
                MessageBox.Show("Need right db configuration on the first tab.");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserName))
            {
                MessageBox.Show("User name is empty");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserPassword))
            {
                MessageBox.Show("User password is empty");
                return;
            }
            if (string.IsNullOrWhiteSpace(UserEMail))
            {
                MessageBox.Show("User e-mail is empty");
                return;
            }
            User user = new User()
            {
                E_mail   = UserEMail,
                Login    = UserName,
                Password = UserPassword
            };
            DatabaseConfig config = DbConfig;

            new Task((Action)(() =>
            {
                MsSqlDataProvider provider = new MsSqlDataProvider();
                DragonflyEntities context = provider.Initizlize(config) as DragonflyEntities;
                try
                {
                    provider.AddUser(user.Login, user.Password, user.E_mail);
                    Dispatcher.Invoke((Action)(() =>
                    {
                        UserEMail = string.Empty;
                        UserName = string.Empty;
                        UserPassword = string.Empty;
                        LoadUsersRunner(config);
                    }));
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            })).Start();
        }
Esempio n. 3
0
 /// <summary>Methor run a loading all users from database.</summary>
 private void LoadUsersRunner(DatabaseConfig config)
 {
     Users.Clear();
     new Task(() =>
     {
         MsSqlDataProvider provider = new MsSqlDataProvider();
         DragonflyEntities context  = provider.Initizlize(config) as DragonflyEntities;
         var users = (from u in context.User
                      select u).ToList();
         Dispatcher.Invoke((Action)(() =>
         {
             foreach (User user in users)
             {
                 Users.Add(user);
             }
         }));
     }).Start();
 }