-
Notifications
You must be signed in to change notification settings - Fork 0
/
SettingsPage.xaml.cs
236 lines (197 loc) · 10.4 KB
/
SettingsPage.xaml.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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using MySqlConnector;
using System.Collections.ObjectModel; //Used to notify listview values when objects are changed
using System.Diagnostics; //Debug
using Windows.UI.Xaml.Media.Imaging; //For using image to URL links
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238
namespace ReviewR
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class SettingsPage : Page
{
//Uses the static Connection String that was set in the Main App Class (private)
private static string ConnectionString = App.ConnectionString;
public SettingsPage()
{
this.InitializeComponent();
//Waits till page is fully loaded before running the event
this.Loaded += Page_Loaded;
}
public partial class MyReviewObject
{
//Test No. 016 improvement
public int ReviewID { get; set; }
public string GameName { get; set; }
public string GameTitle { get; set; }
public string GameDesc { get; set; }
}
private void Page_Loaded(object sender, RoutedEventArgs e)
{
//Sets personalised elements on page load
username_title.Text = App.GlobalUsername;
using (MySqlConnection conn = new MySqlConnection(ConnectionString)) //Uses private connection string
{
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
//Sets variables and SQL command
cmd.CommandText = "SELECT lastlogon, creationdate, useravatar, email FROM user_data WHERE UserID=@UserID";
cmd.Parameters.AddWithValue("@UserID", App.GlobalUserID);
MySqlDataReader details = cmd.ExecuteReader();
if (details.Read())
{
var lastlogon = Convert.ToString(details["lastlogon"]);
var creationdate = Convert.ToString(details["creationdate"]);
var useravatar = Convert.ToString(details["useravatar"]);
PasswordResetDialog.ResetEmail = Convert.ToString(details["email"]);
lastlogon_date.Text = lastlogon;
accountcreated_date.Text = creationdate;
if (useravatar != "" && Uri.IsWellFormedUriString(useravatar, UriKind.Absolute)) //Added check to ensure URL is valid
{
user_avatar.Source = new BitmapImage(new Uri(useravatar));
}
conn.Close();
}
}
using (MySqlConnection conn = new MySqlConnection(App.ConnectionString)) //Uses private connection string
{
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
//Test No. 016 improvement to add clickable elements to listview
cmd.CommandText = "SELECT ReviewID, RevGame, RevTitle, RevDesc FROM review_data WHERE UserID=@UserID ORDER BY ReviewID DESC LIMIT 10"; //Selects the email and password rows from user_data
cmd.Parameters.AddWithValue("@UserID", App.GlobalUserID); //Sets them as variables
cmd.Connection = conn;
MySqlDataReader reviewfetch = cmd.ExecuteReader(); //Executes a read command for the table
if (reviewfetch.Read())
{
ObservableCollection<MyReviewObject> ReviewList = new ObservableCollection<MyReviewObject>();
do
{
//Test No. 016 improvement to add clickable elements to listview
var ReviewID = Convert.ToInt32(reviewfetch["ReviewID"]);
var ReviewGame = Convert.ToString(reviewfetch["RevGame"]);
var ReviewTitle = Convert.ToString(reviewfetch["RevTitle"]);
var ReviewDesc = Convert.ToString(reviewfetch["RevDesc"]);
Debug.WriteLine("Review ID: " + ReviewID);
Debug.WriteLine("Review Reviewed: " + ReviewGame);
Debug.WriteLine("Review Title: " + ReviewTitle);
Debug.WriteLine("Review Description: " + ReviewTitle);
MyReviewObject add = new MyReviewObject() { ReviewID = ReviewID, GameName = ReviewGame, GameTitle = ReviewTitle, GameDesc = ReviewDesc };
ReviewList.Add(add); //Adds item to the temporary list
}
while (reviewfetch.Read());
myreviews_list.ItemsSource = ReviewList; //Inserts all items at once into the listview
conn.Close(); //Close connection
}
else
{
notfound_text.Visibility = Visibility.Visible;
myreviews_list.ItemsSource = null;
}
}
using (MySqlConnection conn = new MySqlConnection(App.ConnectionString)) //Uses private connection string
{
try
{
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "SELECT UserID, IsAdmin FROM user_data WHERE UserID=@userid"; //Selects the email and password rows from user_data
cmd.Parameters.AddWithValue("@userid", App.GlobalUserID); //Sets them as variables
cmd.Connection = conn;
MySqlDataReader adminread = cmd.ExecuteReader();
if (adminread.Read())
{
var AdminCheck = Convert.ToString(adminread["IsAdmin"]);
if (AdminCheck == "Administrator")
{
admin_panel.Visibility = Visibility.Visible;
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
}
//Test No. 016 improvement to add clickable elements to listview
private void myreviews_list_ItemClick(object sender, ItemClickEventArgs e) //When an item in List View is pressed
{
var clickedItem = e.ClickedItem as MyReviewObject;
Debug.WriteLine("Click Item ReviewID: " + clickedItem.ReviewID);
Debug.WriteLine("Click Item Review Name: " + clickedItem.GameName);
Debug.WriteLine("Click Item Review Title: " + clickedItem.GameTitle);
//Set the GameID as a static long variable
ReviewSystem.ReviewSpecificID = clickedItem.ReviewID;
ReviewSystem.ReviewSpecificUserID = App.GlobalUserID;
ReviewSystem.ReviewSpecificGameName = clickedItem.GameName;
ReviewSystem.ReviewSpecificGameTitle = clickedItem.GameTitle;
ReviewSystem.ReviewSpecificDescription = clickedItem.GameDesc;
this.Frame.Navigate(typeof(ReviewSpecificPages), null); //Switch to the profile-specific page
}
private void myreviews_list_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
private void accountcreated_title_SelectionChanged(object sender, RoutedEventArgs e)
{
}
private async void account_edit_Click(object sender, RoutedEventArgs e)
{
ContentDialog usersettingschoice = new SettingsChooseDialog();
await usersettingschoice.ShowAsync();
}
private void profile_preview_Click(object sender, RoutedEventArgs e)
{
try
{
using (MySqlConnection conn = new MySqlConnection(App.ConnectionString)) //Uses private connection string
{
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
notfound_text.Visibility = Visibility.Collapsed;
cmd.CommandText = "SELECT UserID, Username, UserBio, UserAvatar, LastLogon FROM user_data WHERE UserID=@userid"; //Searches for usernames and returns the needed values
cmd.Parameters.AddWithValue("@userid", App.GlobalUserID);
cmd.Connection = conn;
MySqlDataReader reviewfetch = cmd.ExecuteReader(); //Executes a read command for the table
if (reviewfetch.Read())
{
//Set results as variables
ProfilePages.ProfileSpecificUserID = Convert.ToInt32(reviewfetch["UserID"]);
ProfilePages.ProfileSpecificUsername = Convert.ToString(reviewfetch["Username"]);
ProfilePages.ProfileSpecificUserBio = Convert.ToString(reviewfetch["UserBio"]);
ProfilePages.ProfileSpecificUserAvatar = Convert.ToString(reviewfetch["UserAvatar"]);
ProfilePages.ProfileSpecificLastLogon = Convert.ToString(reviewfetch["LastLogon"]);
Debug.WriteLine("User ID: " + ProfilePages.ProfileSpecificUserID);
Debug.WriteLine("Username : " + ProfilePages.ProfileSpecificUsername);
Debug.WriteLine("User Bio: " + ProfilePages.ProfileSpecificUserBio);
Debug.WriteLine("User Avatar : " + ProfilePages.ProfileSpecificUserAvatar);
Debug.WriteLine("Last Logon : " + ProfilePages.ProfileSpecificLastLogon);
this.Frame.Navigate(typeof(ProfileSpecificPages), null); //Switch to the profile-specific page
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex);
}
}
private void admin_panel_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(AdminPanel), null, new Windows.UI.Xaml.Media.Animation.DrillInNavigationTransitionInfo());
}
}
}