-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSettingPage.xaml.cs
More file actions
164 lines (151 loc) · 6.71 KB
/
SettingPage.xaml.cs
File metadata and controls
164 lines (151 loc) · 6.71 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
using Microsoft.Data.Sqlite;
using SchoolManagement;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
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 Windows.UI.Xaml.Shapes;
// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板
namespace StudentManagmentSystem
{
/// <summary>
/// 可用于自身或导航至 Frame 内部的空白页。
/// </summary>
public sealed partial class SettingPage : Page
{
string username = DatabaseHelper.userName;
public SettingPage()
{
this.InitializeComponent();
useraccountbox.Text = DatabaseHelper.Useraccount.ToString();
if (DatabaseHelper.usertype != 3)
useraccountbox.IsEnabled = true;
}
private bool AreAllTextBoxesEmpty()
{
return string.IsNullOrEmpty(useraccountbox.Text) &&
string.IsNullOrEmpty(usernamebox.Text) &&
string.IsNullOrEmpty(usedpasswordbox.Text) &&
string.IsNullOrEmpty(passwordbox.Text)&&
string.IsNullOrEmpty(passwordcheckbox.Text) ;
}
public string getusedpassword()
{
string dbPath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
string usedpassword="";
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
var selectCommand = new SqliteCommand("SELECT password FROM Users WHERE username = @Username ", db);
selectCommand.Parameters.AddWithValue("@Username", username);
using (var reader = selectCommand.ExecuteReader())
{
while (reader.Read())
{
usedpassword = reader.GetString(0);
}
}
}
return usedpassword;
}
private async void applyBtn_Click(object sender, RoutedEventArgs e)
{
if (!AreAllTextBoxesEmpty())
{
if (passwordbox.Text == passwordcheckbox.Text)
{
if (usedpasswordbox.Text == getusedpassword())
{
if (DatabaseHelper.usertype != 3)
{
string Username = usernamebox.Text;
string useraccount = useraccountbox.Text;
string password = passwordbox.Text;
string dbPath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
string updateCommand = "UPDATE Users SET usraccount=@Newusraccount,username=@Newusername,password=@Newpassword WHERE username = @username;";
using (var updateCmd = new SqliteCommand(updateCommand, db))
{
updateCmd.Parameters.AddWithValue("@Newusraccount", useraccount);
updateCmd.Parameters.AddWithValue("@Newusername", Username);
updateCmd.Parameters.AddWithValue("@Newpassword", password);
updateCmd.Parameters.AddWithValue("@username", username);
updateCmd.ExecuteNonQuery();
}
}
}
else
{
string Username = usernamebox.Text;
string password = passwordbox.Text;
string dbPath = System.IO.Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "SchoolManagement.db");
using (var db = new SqliteConnection($"Filename={dbPath}"))
{
db.Open();
string updateCommand = "UPDATE Users SET username=@Newusername,password=@Newpassword WHERE username = @username;";
using (var updateCmd = new SqliteCommand(updateCommand, db))
{
updateCmd.Parameters.AddWithValue("@Newusername", Username);
updateCmd.Parameters.AddWithValue("@Newpassword", password);
updateCmd.Parameters.AddWithValue("@username", username);
updateCmd.ExecuteNonQuery();
}
}
}
}
else
{
ContentDialog loginFailedDialog = new ContentDialog
{
Title = "错误",
Content = "之前密码不正确",
CloseButtonText = "Ok"
};
await loginFailedDialog.ShowAsync();
}
ContentDialog loginSucceedDialog = new ContentDialog
{
Title = "成功",
Content = "应用成功",
CloseButtonText = "Ok"
};
await loginSucceedDialog.ShowAsync();
}
else
{
ContentDialog loginFailedDialog = new ContentDialog
{
Title = "错误",
Content = "两次密码不相符",
CloseButtonText = "Ok"
};
await loginFailedDialog.ShowAsync();
}
}
else
{
ContentDialog loginFailedDialog = new ContentDialog
{
Title = "错误",
Content = "请填写完整",
CloseButtonText = "Ok"
};
await loginFailedDialog.ShowAsync();
}
}
}
}