-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserAccount.xaml.cs
More file actions
191 lines (167 loc) · 6.37 KB
/
UserAccount.xaml.cs
File metadata and controls
191 lines (167 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using dbCon2.Properties;
namespace dbCon2
{
/// <summary>
/// Interaction logic for Login.xaml
/// </summary>
public partial class UserAccount : Page
{
//add changeing defaulff user's password
List<User> UsersList = new List<User>();
public UserAccount()
{
InitializeComponent();
//Visability admins elements
if (LoginWindow.LoggedIn.GetRankNumr() == "1")
{
NameLabel.Content = "Hello " + LoginWindow.LoggedIn.GetUserName + "!";
UsersGrind.Visibility = Visibility.Visible;
AddNewGrind.Visibility = Visibility.Visible;
RefreshUserList();
}
else
{
UsersGrind.Visibility = Visibility.Collapsed;
AddNewGrind.Visibility = Visibility.Collapsed;
}
}
private void NameLabel_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
}
//Change Password Button
private void ChangePasswordButton_Click(object sender, RoutedEventArgs e)
{
if (ActualPassword.Password != "" && NewPassword.Password != "" && ConfirmPassword.Password != "")
{
if (NewPassword.Password == ConfirmPassword.Password)
{
if (LoginWindow.LoggedIn.DefaultUser)
{
if(Settings.Default.DefaultPassword == ActualPassword.Password.ToString())
{
Settings.Default.DefaultPassword = NewPassword.Password.ToString();
MessageBox.Show("Default User password changed");
}
else
{
MessageBox.Show("Default User password changed faild!");
}
}
else
{
AccessUserDB checkUser = new AccessUserDB();
if (checkUser.TryToFindUser(LoginWindow.LoggedIn.GetUserName, ActualPassword.Password.ToString()) != null)
{
AccessChangePassword accessChangePassword = new AccessChangePassword(LoginWindow.LoggedIn.GetID, NewPassword.Password.ToString());
checkUser = null;
accessChangePassword = null;
GC.Collect();
}
else
{
ChangeingPasswordInfo.Content = "Wrong password!";
}
}
}
else
{
ChangeingPasswordInfo.Content = "Confrim password faild!";
}
}
else
{
ChangeingPasswordInfo.Content = "Fill in all the boxes!";
}
}
// Add new user
private void AddUserButton_Click(object sender, RoutedEventArgs e)
{
try
{
bool userExist = false;
foreach(User user in UsersList)
{
if(user.UserNameDB == AddUserName.Text)
{
userExist = true;
MessageBox.Show("User Already Exists!");
}
}
if (AddUserName.Text != "" && AddUserPassword.Password.ToString() != "" && !userExist)
{
string userRank;
if (AddUserType.IsChecked == true)
{
userRank = "1";
}
else
{
userRank = "2";
}
AddNewUser user = new AddNewUser(AddUserName.Text, AddUserPassword.Password.ToString(), userRank);
}
}
catch
{
}
RefreshUserList();
}
// Refresh users list
private void RefreshUserList()
{
UserList Users = new UserList();
UsersList = Users.GetAllUsers();
User DefaultUser = new User();
DefaultUser.Userset(Settings.Default.DefaultUser, "1", "", true);
UsersList.Add(DefaultUser);
AllUserGrind.ItemsSource = UsersList;
AllUserGrind.DisplayMemberPath = "FullInfo";
}
//enable delete button when item selected
private void AllUserGrind_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if(AllUserGrind.SelectedIndex != -1 && AllUserGrind.SelectedIndex != UsersList.Count()-1)
{
RemoveUserButton.Visibility = Visibility.Visible;
}
else
{
RemoveUserButton.Visibility = Visibility.Collapsed;
}
}
//Remove selected User
private void RemoveUserButton_Click(object sender, RoutedEventArgs e)
{
if (UsersList[AllUserGrind.SelectedIndex].GetID != LoginWindow.LoggedIn.GetID)
{
if (MessageBox.Show("Do you really want to delete selected user and all its data?", "Remove User", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
{
DeleteUser deleteUser = new DeleteUser(UsersList[AllUserGrind.SelectedIndex].GetID);
RefreshUserList();
}
else
{
//Nothing
}
}
else
{
MessageBox.Show("You cant't remove default user and your admin acount!");
}
}
}
}