-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathManager.cs
193 lines (164 loc) · 5.99 KB
/
Manager.cs
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
192
193
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
namespace prelab1
{
public partial class Manager : Form
{
// provides sending data to the profile screen
public static Manager instance;
// shows if list with scores or not
bool withscores = false;
public Manager()
{
InitializeComponent();
instance = this;
}
// data to be sent
public string user;
// Add users to listview
public void ShowUsers()
{
withscores = false;
listviewusers.Clear();
listviewusers.Columns.Add("Users", 600);
XmlDocument doc = new XmlDocument();
doc.Load(@"../../Information.xml");
foreach (XmlNode node in doc.SelectNodes("//User"))
{
string Username = node.SelectSingleNode("Username").InnerText;
ListViewItem item = new ListViewItem(Username);
listviewusers.Items.Add(item);
}
listviewusers.Visible = true;
}
// list all users
private void btnallusers_Click(object sender, EventArgs e)
{
ShowUsers();
}
// adds a user
private void btnadduser_Click(object sender, EventArgs e)
{
withscores = false;
Signup form4 = new Signup();
form4.ShowDialog();
listviewusers.Clear();
ShowUsers();
}
// updates a user
private void btnupdateuser_Click(object sender, EventArgs e)
{
ShowUsers();
}
// deletes a user
private void btndeleteuser_Click(object sender, EventArgs e)
{
ShowUsers();
for (int i = 0; i < listviewusers.Items.Count; i++)
{
if (listviewusers.Items[i].Selected)
{
listviewusers.Items[i].Remove();
}
}
}
// Show users by ascending scores
private void ascendingScoresToolStripMenuItem_Click(object sender, EventArgs e)
{
withscores = true;
listviewusers.Clear();
listviewusers.Visible = true;
listviewusers.Columns.Add("BestScore", 140);
listviewusers.Columns.Add("User", 600);
XmlDocument doc = new XmlDocument();
doc.Load(@"../../Information.xml");
int Points;
String Username = null;
List<String> point = new List<String>();
foreach (XmlNode node in doc.SelectNodes("//User"))
{
Points = Convert.ToInt32(node.SelectSingleNode("BestScore").InnerText);
point.Add(Points.ToString());
}
point.Sort();
for (int i = point.Count() - 1; i > -1; i--)
{
foreach (XmlNode node in doc.SelectNodes("//User"))
{
if (point[i].ToString() == node.SelectSingleNode("BestScore").InnerText)
{
Username = node.SelectSingleNode("Username").InnerText;
}
}
ListViewItem item = new ListViewItem(point[i].ToString());
item.SubItems.Add(Username);
listviewusers.Items.Add(item);
}
}
// Show users by descending scores
private void descendingScoresToolStripMenuItem_Click(object sender, EventArgs e)
{
withscores = true;
listviewusers.Clear();
listviewusers.Visible = true;
listviewusers.Columns.Add("BestScore", 140);
listviewusers.Columns.Add("User", 600);
XmlDocument doc = new XmlDocument();
doc.Load(@"../../Information.xml");
int Points;
String Username = null;
List<String> point = new List<String>();
foreach (XmlNode node in doc.SelectNodes("//User"))
{
Points = Convert.ToInt32(node.SelectSingleNode("BestScore").InnerText);
point.Add(Points.ToString());
}
point.Sort();
for (int i = 0; i < point.Count(); i++)
{
foreach (XmlNode node in doc.SelectNodes("//User"))
{
if(point[i].ToString() == node.SelectSingleNode("BestScore").InnerText)
{
Username = node.SelectSingleNode("Username").InnerText;
}
}
ListViewItem item = new ListViewItem(point[i].ToString());
item.SubItems.Add(Username);
listviewusers.Items.Add(item);
}
}
// Select user in listbox
// redirects to profile screen
private void listviewusers_SelectedIndexChanged(object sender, EventArgs e)
{
for (int i = 0; i < listviewusers.Items.Count; i++)
{
if (listviewusers.Items[i].Selected)
{
if(withscores) user = listviewusers.Items[i].SubItems[1].Text;
else user = listviewusers.Items[i].Text;
ProfileScreen form6 = new ProfileScreen();
form6.ShowDialog();
}
}
}
// Close the manager screen shows the game screen
private void goBackToMainGameToolStripMenuItem_Click(object sender, EventArgs e)
{
Hide();
MainGame form10 = new MainGame();
form10.ShowDialog();
}
}
}