| 9 |
Kevin |
1 |
using System;
|
|
|
2 |
using System.Collections.Generic;
|
|
|
3 |
using System.ComponentModel;
|
|
|
4 |
using System.Data;
|
|
|
5 |
using System.Drawing;
|
|
|
6 |
using System.Linq;
|
|
|
7 |
using System.Text;
|
|
|
8 |
using System.Windows.Forms;
|
| 53 |
Kevin |
9 |
using System.DirectoryServices.AccountManagement;
|
| 9 |
Kevin |
10 |
|
|
|
11 |
namespace SWAT_Office_App
|
|
|
12 |
{
|
| 63 |
Kevin |
13 |
public partial class Manage_User_Accounts_Form : Form
|
| 9 |
Kevin |
14 |
{
|
| 63 |
Kevin |
15 |
public Manage_User_Accounts_Form()
|
| 9 |
Kevin |
16 |
{
|
|
|
17 |
InitializeComponent();
|
|
|
18 |
// Designate columns to include in listview for the Manage User Accounts Form
|
|
|
19 |
ColumnHeader Column_1 = new ColumnHeader();
|
|
|
20 |
Column_1.Text = "Username";
|
| 53 |
Kevin |
21 |
Column_1.Width = 121;
|
| 9 |
Kevin |
22 |
this.lst_UserAccounts.Columns.Add(Column_1);
|
|
|
23 |
ColumnHeader Column_2 = new ColumnHeader();
|
| 53 |
Kevin |
24 |
Column_2.Text = "Share";
|
| 9 |
Kevin |
25 |
Column_2.Width = 46;
|
|
|
26 |
Column_2.TextAlign = HorizontalAlignment.Center;
|
|
|
27 |
this.lst_UserAccounts.Columns.Add(Column_2);
|
|
|
28 |
ColumnHeader Column_3 = new ColumnHeader();
|
| 53 |
Kevin |
29 |
Column_3.Text = "Size";
|
|
|
30 |
Column_3.Width = 75;
|
| 9 |
Kevin |
31 |
Column_3.TextAlign = HorizontalAlignment.Center;
|
|
|
32 |
this.lst_UserAccounts.Columns.Add(Column_3);
|
|
|
33 |
ColumnHeader Column_4 = new ColumnHeader();
|
| 53 |
Kevin |
34 |
Column_4.Text = "Date Created";
|
|
|
35 |
Column_4.Width = 80;
|
| 9 |
Kevin |
36 |
Column_4.TextAlign = HorizontalAlignment.Center;
|
|
|
37 |
this.lst_UserAccounts.Columns.Add(Column_4);
|
|
|
38 |
|
|
|
39 |
PaintUserListbox();
|
|
|
40 |
this.btn_Delete.Enabled = false;
|
|
|
41 |
this.btn_Pass.Enabled = false;
|
|
|
42 |
this.btn_Share.Enabled = false;
|
|
|
43 |
this.btn_OpenShare.Enabled = false;
|
|
|
44 |
|
|
|
45 |
this.lst_UserAccounts.ItemSelectionChanged += new ListViewItemSelectionChangedEventHandler(this.lst_ItemSelectionChanged);
|
|
|
46 |
this.Activated += new EventHandler(this.form_Activated);
|
|
|
47 |
}
|
|
|
48 |
private void PaintUserListbox()
|
|
|
49 |
{
|
| 53 |
Kevin |
50 |
try
|
|
|
51 |
{
|
|
|
52 |
// Function for refreshing/painting the listbox
|
|
|
53 |
this.lst_UserAccounts.BeginUpdate();
|
| 63 |
Kevin |
54 |
Manage_User_Accounts.QueryUserAccounts();
|
| 9 |
Kevin |
55 |
|
| 53 |
Kevin |
56 |
// Temporary entries in listview
|
|
|
57 |
//ListViewItem entry;
|
|
|
58 |
//ListViewItem.ListViewSubItem s_entry;
|
|
|
59 |
//entry = new ListViewItem();
|
|
|
60 |
//entry.Text = "TestUser";
|
|
|
61 |
//s_entry = new ListViewItem.ListViewSubItem();
|
|
|
62 |
//s_entry.Text = "Yes";
|
|
|
63 |
//entry.SubItems.Add(s_entry);
|
|
|
64 |
//s_entry = new ListViewItem.ListViewSubItem();
|
|
|
65 |
//s_entry.Text = "Yes";
|
|
|
66 |
//entry.SubItems.Add(s_entry);
|
|
|
67 |
//s_entry = new ListViewItem.ListViewSubItem();
|
|
|
68 |
//s_entry.Text = "01/05/2010";
|
|
|
69 |
//entry.SubItems.Add(s_entry);
|
|
|
70 |
//this.lst_User_Accounts.Items.Add(entry);
|
| 9 |
Kevin |
71 |
|
| 53 |
Kevin |
72 |
this.lst_UserAccounts.Items.Clear();
|
|
|
73 |
// Prevents system accounts from showing, depending on settings
|
| 63 |
Kevin |
74 |
foreach (UserPrincipal user in Manage_User_Accounts.UserAccountsList)
|
| 9 |
Kevin |
75 |
{
|
| 53 |
Kevin |
76 |
ListViewItem entry = new ListViewItem();
|
|
|
77 |
bool remove = false;
|
|
|
78 |
foreach (string hiddenUser in Settings_Form.hiddenAccounts)
|
| 9 |
Kevin |
79 |
{
|
| 53 |
Kevin |
80 |
if (user.Name.ToLower() == hiddenUser.ToLower())
|
|
|
81 |
{
|
|
|
82 |
remove = true;
|
|
|
83 |
break;
|
|
|
84 |
}
|
| 9 |
Kevin |
85 |
}
|
| 53 |
Kevin |
86 |
// Populates the subitem columns for each entry
|
|
|
87 |
if (remove == false)
|
| 50 |
Kevin |
88 |
{
|
| 53 |
Kevin |
89 |
ListViewItem.ListViewSubItem s_share = new ListViewItem.ListViewSubItem();
|
| 63 |
Kevin |
90 |
if (Manage_User_Accounts.QueryUserSharedFolderExist(user.Name))
|
| 53 |
Kevin |
91 |
s_share.Text = "Yes";
|
|
|
92 |
else
|
|
|
93 |
s_share.Text = "No";
|
|
|
94 |
entry.SubItems.Add(s_share);
|
|
|
95 |
ListViewItem.ListViewSubItem s_size = new ListViewItem.ListViewSubItem();
|
| 63 |
Kevin |
96 |
long size = Manage_User_Accounts.GetShareSize(user.Name);
|
| 50 |
Kevin |
97 |
if ((size / 1073741824) > 0)
|
|
|
98 |
s_size.Text = (size / 1073741824).ToString() + " GB";
|
|
|
99 |
else
|
|
|
100 |
s_size.Text = (size / 1048576).ToString() + " MB";
|
| 53 |
Kevin |
101 |
entry.SubItems.Add(s_size);
|
|
|
102 |
ListViewItem.ListViewSubItem s_datecreated = new ListViewItem.ListViewSubItem();
|
|
|
103 |
s_datecreated.Text = user.Description;
|
|
|
104 |
entry.SubItems.Add(s_datecreated);
|
| 50 |
Kevin |
105 |
}
|
| 53 |
Kevin |
106 |
if (remove == false)
|
| 50 |
Kevin |
107 |
{
|
| 53 |
Kevin |
108 |
entry.Text = user.Name;
|
|
|
109 |
this.lst_UserAccounts.Items.Add(entry);
|
| 50 |
Kevin |
110 |
}
|
| 9 |
Kevin |
111 |
}
|
| 53 |
Kevin |
112 |
this.lst_UserAccounts.EndUpdate();
|
| 9 |
Kevin |
113 |
}
|
| 53 |
Kevin |
114 |
catch (Exception e)
|
|
|
115 |
{
|
|
|
116 |
//MessageBox.Show(e.ToString(), "Error");
|
| 63 |
Kevin |
117 |
Debug.appendText(e.ToString());
|
| 53 |
Kevin |
118 |
MessageBox.Show("An error has occured. Please notify a supervisor to debug.", "Error");
|
|
|
119 |
}
|
| 9 |
Kevin |
120 |
}
|
|
|
121 |
private void lst_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
|
122 |
{
|
|
|
123 |
lst_ValidateAll();
|
|
|
124 |
}
|
|
|
125 |
private void lst_ValidateAll()
|
|
|
126 |
{
|
| 53 |
Kevin |
127 |
// Enables/disables certain buttons depending on number of items selected
|
| 9 |
Kevin |
128 |
ListView.SelectedListViewItemCollection collection = this.lst_UserAccounts.SelectedItems;
|
|
|
129 |
|
|
|
130 |
if (collection.Count == 0)
|
|
|
131 |
{
|
|
|
132 |
this.btn_Delete.Enabled = false;
|
|
|
133 |
this.btn_Pass.Enabled = false;
|
|
|
134 |
this.btn_Share.Enabled = false;
|
|
|
135 |
this.btn_OpenShare.Enabled = false;
|
|
|
136 |
}
|
|
|
137 |
else if (collection.Count == 1)
|
|
|
138 |
{
|
|
|
139 |
// Checks if any of the selected items are system accounts
|
|
|
140 |
bool check = false;
|
|
|
141 |
foreach (string systemUser in Settings_Form.systemAccounts)
|
|
|
142 |
{
|
|
|
143 |
if (collection[0].Text.ToLower() == systemUser.ToLower())
|
|
|
144 |
check = true;
|
|
|
145 |
}
|
|
|
146 |
if (check == false)
|
|
|
147 |
{
|
|
|
148 |
this.btn_Delete.Enabled = true;
|
|
|
149 |
this.btn_Pass.Enabled = true;
|
|
|
150 |
this.btn_Share.Enabled = true;
|
| 53 |
Kevin |
151 |
ListViewItem.ListViewSubItem subItem = collection[0].SubItems[1];
|
| 9 |
Kevin |
152 |
if (subItem.Text == "Yes")
|
|
|
153 |
this.btn_OpenShare.Enabled = true;
|
|
|
154 |
else
|
|
|
155 |
this.btn_OpenShare.Enabled = false;
|
|
|
156 |
}
|
|
|
157 |
else
|
|
|
158 |
{
|
|
|
159 |
this.btn_Delete.Enabled = false;
|
|
|
160 |
this.btn_Pass.Enabled = false;
|
|
|
161 |
this.btn_Share.Enabled = false;
|
|
|
162 |
this.btn_OpenShare.Enabled = false;
|
|
|
163 |
}
|
|
|
164 |
}
|
|
|
165 |
else
|
|
|
166 |
{
|
|
|
167 |
this.btn_Delete.Enabled = true;
|
|
|
168 |
this.btn_Pass.Enabled = false;
|
|
|
169 |
this.btn_Share.Enabled = false;
|
|
|
170 |
this.btn_OpenShare.Enabled = false;
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
private void form_Activated(object sender, EventArgs e)
|
|
|
174 |
{
|
|
|
175 |
// Refreshes form on form activation
|
| 63 |
Kevin |
176 |
Manage_User_Accounts.QueryUserAccounts();
|
| 9 |
Kevin |
177 |
PaintUserListbox();
|
|
|
178 |
}
|
|
|
179 |
private void btn_Exit_Click(object sender, EventArgs e)
|
|
|
180 |
{
|
|
|
181 |
this.Close();
|
|
|
182 |
}
|
|
|
183 |
private void btn_Refresh_Click(object sender, EventArgs e)
|
|
|
184 |
{
|
|
|
185 |
PaintUserListbox();
|
|
|
186 |
}
|
|
|
187 |
private void btn_Add_Click(object sender, EventArgs e)
|
|
|
188 |
{
|
| 63 |
Kevin |
189 |
Add_User_Account_Form.Add_User_Account_Instance.ShowDialog();
|
| 9 |
Kevin |
190 |
lst_ValidateAll();
|
|
|
191 |
}
|
|
|
192 |
private void btn_Delete_Click(object sender, EventArgs e)
|
|
|
193 |
{
|
| 63 |
Kevin |
194 |
if (!Manage_User_Accounts.SessionsOpen())
|
| 9 |
Kevin |
195 |
{
|
|
|
196 |
ListView.SelectedListViewItemCollection selectedItems = this.lst_UserAccounts.SelectedItems;
|
|
|
197 |
List<string> userList = new List<string>();
|
|
|
198 |
foreach (ListViewItem user in selectedItems)
|
|
|
199 |
userList.Add(user.Text);
|
| 63 |
Kevin |
200 |
Delete_User_Verify_Form newForm = new Delete_User_Verify_Form(userList);
|
| 9 |
Kevin |
201 |
newForm.ShowDialog();
|
|
|
202 |
}
|
|
|
203 |
else
|
|
|
204 |
MessageBox.Show("Sessions are still open. Please close them before deleting accounts", "Error");
|
|
|
205 |
PaintUserListbox();
|
|
|
206 |
lst_ValidateAll();
|
|
|
207 |
}
|
|
|
208 |
private void btn_Pass_Click(object sender, EventArgs e)
|
|
|
209 |
{
|
|
|
210 |
ListView.SelectedListViewItemCollection selectedItems = this.lst_UserAccounts.SelectedItems;
|
| 63 |
Kevin |
211 |
Reset_User_Password_Form newForm = new Reset_User_Password_Form(selectedItems[0].Text);
|
| 9 |
Kevin |
212 |
newForm.ShowDialog();
|
|
|
213 |
|
|
|
214 |
PaintUserListbox();
|
|
|
215 |
lst_ValidateAll();
|
|
|
216 |
}
|
|
|
217 |
private void btn_Share_Click(object sender, EventArgs e)
|
|
|
218 |
{
|
|
|
219 |
ListView.SelectedListViewItemCollection selectedItems = this.lst_UserAccounts.SelectedItems;
|
| 63 |
Kevin |
220 |
Toggle_User_Verify_Form newForm = new Toggle_User_Verify_Form(selectedItems[0].Text);
|
| 9 |
Kevin |
221 |
newForm.ShowDialog();
|
|
|
222 |
|
|
|
223 |
PaintUserListbox();
|
|
|
224 |
lst_ValidateAll();
|
|
|
225 |
}
|
|
|
226 |
private void btn_OpenShare_Click(object sender, EventArgs e)
|
|
|
227 |
{
|
|
|
228 |
ListView.SelectedListViewItemCollection selectedItems = this.lst_UserAccounts.SelectedItems;
|
|
|
229 |
string openFolderString = Settings_Form.sharedFolderLocation + "\\" + selectedItems[0].Text;
|
|
|
230 |
System.Diagnostics.Process proc = new System.Diagnostics.Process();
|
|
|
231 |
proc.StartInfo.FileName = openFolderString;
|
|
|
232 |
proc.Start();
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
}
|