-
Notifications
You must be signed in to change notification settings - Fork 0
/
Settings.cs
259 lines (223 loc) · 8.62 KB
/
Settings.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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.Forms;
using MaterialSkin;
using MaterialSkin.Controls;
using System.Data.SQLite;
namespace WWM
{
public partial class Settings : MaterialForm
{
//Переменные текста (пиши класс ленивый)
public string user_name;
public string user_midname;
public string user_id1;
//Переменные формы
public MaterialForm form;
public Authorization_Form af;
//Переменная темы
public MaterialSkinManager ThemeManager = MaterialSkinManager.Instance;
//Строка запроса
public SQLiteCommand m_sqlCmd = new SQLiteCommand();
//Конструктор формы
public Settings(string name, string midname, string user_id, MaterialForm mf)
{
//Обозначение глобальных переменных
user_name = name;
user_midname = midname;
user_id1 = user_id;
//Установка значений темы
#region Установка_темы
InitializeComponent();
var materialSkinManager = MaterialSkinManager.Instance;
materialSkinManager.AddFormToManage(this);
materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT;
materialSkinManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);
if (themeToggle.Checked)
{
ThemeManager.Theme = MaterialSkinManager.Themes.DARK;
}
else
{
ThemeManager.Theme = MaterialSkinManager.Themes.LIGHT;
}
if (materialRadioButton1.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Green700, Primary.Green900, Primary.Green500, Accent.Green400, TextShade.WHITE);
}
else if (materialRadioButton2.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Blue700, Primary.Blue900, Primary.Blue500, Accent.Blue400, TextShade.WHITE);
}
else if (materialRadioButton3.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Amber700, Primary.Amber900, Primary.Amber500, Accent.Amber400, TextShade.WHITE);
}
#endregion
//Установка глобального значения формы
form = mf;
}
//Подгрузка формы
private void Settings_Load(object sender, EventArgs e)
{
this.Text = "WWM/" + user_name + " " + user_midname + "/Настройки";
}
//Изменение темы в приложении
private void themeToggle_CheckedChanged(object sender, EventArgs e)
{
//Проверка на нажатие
if (themeToggle.Checked)
{
ThemeManager.Theme = MaterialSkinManager.Themes.DARK;
}
else
{
ThemeManager.Theme = MaterialSkinManager.Themes.LIGHT;
}
}
//Изменение цвета
#region Изменение_цвета
private void materialRadioButton1_CheckedChanged(object sender, EventArgs e)
{
//Проверка на нажатие
if (materialRadioButton1.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Green700, Primary.Green900, Primary.Green500, Accent.Green400, TextShade.WHITE);
}
else
{
ThemeManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);
}
}
private void materialRadioButton2_CheckedChanged(object sender, EventArgs e)
{
//Проверка на нажатие
if (materialRadioButton2.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Blue700, Primary.Blue900, Primary.Blue500, Accent.Blue400, TextShade.WHITE);
}
else
{
ThemeManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);
}
}
private void materialRadioButton3_CheckedChanged(object sender, EventArgs e)
{
//Проверка на нажатие
if (materialRadioButton3.Checked == true)
{
ThemeManager.ColorScheme = new ColorScheme(Primary.Amber700, Primary.Amber900, Primary.Amber500, Accent.Amber400, TextShade.WHITE);
}
else
{
ThemeManager.ColorScheme = new ColorScheme(Primary.BlueGrey800, Primary.BlueGrey900, Primary.BlueGrey500, Accent.LightBlue200, TextShade.WHITE);
}
}
#endregion
//Событие закрытия формы
private void Settings_FormClosing(object sender, FormClosingEventArgs e)
{
//Определение с какой формы была открыта форма настроек и открытие нужной формы
if(form.Name == "AdminPanel")
{
form.Refresh();
form.Show();
}
else if(form.Name == "UserPanel")
{
form.Show();
}
Properties.Settings.Default.Save();
}
//Изменение логина
private void materialButton3_Click(object sender, EventArgs e)
{
af = new Authorization_Form();
try
{
if (materialTextBox1.Text.Length >= 4)
{
//Запрос в БД
using (var m_dbConn = new SQLiteConnection("Data Source=" + af.dbFileName + ";Version=3;"))
{
m_dbConn.Open();
m_sqlCmd.Connection = m_dbConn;
SQLiteCommand command = new SQLiteCommand(@"UPDATE Users SET user_login = '" + materialTextBox1.Text + "' WHERE user_id = '" + user_id1 + "'", m_dbConn);
command.ExecuteNonQuery();
}
MaterialMessageBox.Show("Логин успешно изменён.", "Изменение логина", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MaterialMessageBox.Show("Логин должен быть больше 4-х символов.", "Изменение логина", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
MaterialMessageBox.Show("Возникла некоторая ошибка.\nЛогин не был изменён.", "Ошибка изменения логина", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//Изменение пароля
private void materialButton5_Click(object sender, EventArgs e)
{
af = new Authorization_Form();
try
{
if (materialTextBox2.Text.Length >= 4)
{
//Запрос в БД
using (var m_dbConn = new SQLiteConnection("Data Source=" + af.dbFileName + ";Version=3;"))
{
m_dbConn.Open();
m_sqlCmd.Connection = m_dbConn;
SQLiteCommand command = new SQLiteCommand(@"UPDATE Users SET user_password = '" + materialTextBox2.Text + "' WHERE user_id = '" + user_id1 + "'", m_dbConn);
command.ExecuteNonQuery();
}
MaterialMessageBox.Show("Пароль успешно изменён.", "Изменение пароля", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MaterialMessageBox.Show("Пароль должен быть больше 4-х символов.", "Изменение пароля", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
MaterialMessageBox.Show("Возникла некоторая ошибка.\nПароль не был изменён.", "Ошибка изменения пароля", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
//Изменение почты
private void materialButton11_Click(object sender, EventArgs e)
{
af = new Authorization_Form();
try
{
if (materialTextBox3.Text.Length >= 4)
{
//Запрос в БД
using (var m_dbConn = new SQLiteConnection("Data Source=" + af.dbFileName + ";Version=3;"))
{
m_dbConn.Open();
m_sqlCmd.Connection = m_dbConn;
SQLiteCommand command = new SQLiteCommand(@"UPDATE Users SET user_email = '" + materialTextBox3.Text + "' WHERE user_id = '" + user_id1 + "'", m_dbConn);
command.ExecuteNonQuery();
}
MaterialMessageBox.Show("Почта успешно изменена.", "Изменение почты", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MaterialMessageBox.Show("Почта должна быть больше 4-х символов.", "Изменение почты", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch
{
MaterialMessageBox.Show("Возникла некоторая ошибка.\nПочта не была изменёна.", "Ошибка изменения почты", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}