-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountWindow.xaml.cs
325 lines (285 loc) · 20.5 KB
/
AccountWindow.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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;
using System.Data.SqlClient;
namespace CursedProjectAN
{
/// <summary>
/// Логика взаимодействия для AccountWindow.xaml
/// </summary>
public partial class AccountWindow : Window
{
Account account = Account.getInstance();
private bool isAlreadyHaveAccInfo = false;
public AccountWindow()
{
InitializeComponent();
AccountLoginBox.Text = account.login;
AccountNameBox.Text = account.name;
AccountSurnameBox.Text = account.surname;
AccountMiddleNameBox.Text = account.middlename;
AccountPassportNumberBox.Text = account.passportnum;
AccountPassportSeriesBox.Text = account.passportser;
AccountEmailBox.Text = account.mail;
AccountPhoneNumberBox.Text = account.phonenum;
AccountSexBox.Text = account.sex;
DateOfBirthPicker.Text = account.dateofbirth;
CheckForAcc();
}
private void CheckForAcc()
{
SqlConnection toAccountData = new SqlConnection(@"Data Source=LAPTOP-BFCVFHEM\SQLEXPRESS;Initial Catalog=TOUR_AGENCY;Integrated Security=True");
toAccountData.Open();
int i = 0;
SqlCommand AccountData = new SqlCommand("SELECT login, clientName, clientSurname, clientMiddlename, passportNumber," +
" passportSeries, [e-mail], phoneNumber, date_of_birth, sex FROM clients WHERE login = '" + AccountLoginBox.Text + "'", toAccountData);
AccountData.ExecuteNonQuery();
DataTable containsi = new DataTable();
SqlDataAdapter convertsqltovs = new SqlDataAdapter(AccountData);
convertsqltovs.Fill(containsi);
i = Convert.ToInt32(containsi.Rows.Count.ToString());
if (i != 0)
{
isAlreadyHaveAccInfo = true;
}
}
private void BackToMain_Click(object sender, RoutedEventArgs e)
{
LogInMainWindow logInMainWindow = new LogInMainWindow();
logInMainWindow.Show();
this.Close();
}
private void ExitFromAccount_Click(object sender, RoutedEventArgs e)
{
LoginWindow loginWindow = new LoginWindow();
loginWindow.Show();
this.Close();
}
private void EditAcount_Click(object sender, RoutedEventArgs e)
{
AccountNameBox.IsEnabled = true;
AccountSurnameBox.IsEnabled = true;
AccountMiddleNameBox.IsEnabled = true;
AccountPassportNumberBox.IsEnabled = true;
AccountPassportSeriesBox.IsEnabled = true;
AccountEmailBox.IsEnabled = true;
AccountPhoneNumberBox.IsEnabled = true;
AccountSexBox.IsEnabled = true;
DateOfBirthPicker.IsEnabled = true;
}
private void SaveAccountButton_Click(object sender, RoutedEventArgs e)
{
{
if (!string.IsNullOrWhiteSpace(AccountNameBox.Text))
{
if (!string.IsNullOrWhiteSpace(AccountSurnameBox.Text))
{
if (!string.IsNullOrWhiteSpace(AccountPassportNumberBox.Text))
{
if (!string.IsNullOrWhiteSpace(AccountEmailBox.Text))
{
if (!string.IsNullOrWhiteSpace(AccountPhoneNumberBox.Text))
{
if (!string.IsNullOrWhiteSpace(AccountSexBox.Text))
{
if (!string.IsNullOrWhiteSpace(DateOfBirthPicker.Text))
{
string[] dataLogin = AccountEmailBox.Text.Split('@');
if (dataLogin.Length == 2)
{
string[] data2Login = dataLogin[1].Split('.');
if (data2Login.Length == 2)
{
CheckForAcc();
SqlConnection toAccountData = new SqlConnection(@"Data Source=LAPTOP-BFCVFHEM\SQLEXPRESS;Initial Catalog=TOUR_AGENCY;Integrated Security=True");
toAccountData.Open();
/*int i = 0;
SqlCommand AccountData = new SqlCommand("SELECT login, clientName, clientSurname, clientMiddlename, passportNumber," +
" passportSeries, [e-mail], phoneNumber, date_of_birth, sex FROM clients WHERE login = '" + AccountLoginBox.Text + "' AND clientName ='" + AccountNameBox.Text + "' AND clientSurname ='" + AccountSurnameBox.Text + "' AND " +
"clientMiddlename ='" + AccountMiddleNameBox.Text + "' AND passportNumber ='" + AccountPassportNumberBox.Text + "' AND passportSeries ='" + AccountPassportSeriesBox.Text +
"' AND [e-mail] ='" + AccountEmailBox.Text + "' AND phoneNumber ='" + AccountPhoneNumberBox.Text + "' AND date_of_birth ='" + DateOfBirthPicker.Text + "' AND sex ='" + AccountSexBox.Text + "'", toAccountData);
AccountData.ExecuteNonQuery();
DataTable containsi = new DataTable();
SqlDataAdapter convertsqltovs = new SqlDataAdapter(AccountData);
convertsqltovs.Fill(containsi);
i = Convert.ToInt32(containsi.Rows.Count.ToString());*/
if (!isAlreadyHaveAccInfo)
{
SqlCommand command = new SqlCommand(null, toAccountData); //вставка в таблицу
command.CommandText =
"INSERT INTO clients (login, clientName, clientSurname, clientMiddlename, passportNumber, passportSeries, " +
"[e-mail], phoneNumber, date_of_birth, sex)" +
"VALUES ( @Login, @Name, @Surname, @MiddleName, @PassNumber, @PassSeries, @EMail, @Phone, @DateOfBirth, @Sex)";
SqlParameter LoginParam = new SqlParameter("@Login", SqlDbType.NVarChar, 120);
SqlParameter NameParam = new SqlParameter("@Name", SqlDbType.NVarChar, 120);
SqlParameter SurnameParam = new SqlParameter("@Surname", SqlDbType.NVarChar, 120);
SqlParameter MiddleNameParam = new SqlParameter("@MiddleName", SqlDbType.NVarChar, 120);
MiddleNameParam.IsNullable = true;
SqlParameter PassNumberParam = new SqlParameter("@PassNumber", SqlDbType.NVarChar, 50);
SqlParameter PassSeriesParam = new SqlParameter("@PassSeries", SqlDbType.Int);
PassSeriesParam.IsNullable = true;
SqlParameter EMailParam = new SqlParameter("@EMail", SqlDbType.NVarChar, 120);
SqlParameter PhoneParam = new SqlParameter("@Phone", SqlDbType.NVarChar, 120);
SqlParameter DateOfBirthParam = new SqlParameter("@DateOfBirth", SqlDbType.Date);
SqlParameter SexParam = new SqlParameter("@Sex", SqlDbType.Char, 1);
LoginParam.Value = AccountLoginBox.Text;
NameParam.Value = AccountNameBox.Text;
SurnameParam.Value = AccountSurnameBox.Text;
MiddleNameParam.Value = AccountMiddleNameBox.Text;
PassNumberParam.Value = AccountPassportNumberBox.Text;
if (string.IsNullOrWhiteSpace(AccountPassportSeriesBox.Text))
{
PassSeriesParam.Value = DBNull.Value;
}
else
{
PassSeriesParam.Value = Convert.ToInt32(AccountPassportSeriesBox.Text);
}
EMailParam.Value = AccountEmailBox.Text;
PhoneParam.Value = AccountPhoneNumberBox.Text;
DateOfBirthParam.Value = DateOfBirthPicker.Text;
SexParam.Value = AccountSexBox.Text;
command.Parameters.Add(LoginParam);
command.Parameters.Add(NameParam);
command.Parameters.Add(SurnameParam);
command.Parameters.Add(MiddleNameParam);
command.Parameters.Add(PassNumberParam);
command.Parameters.Add(PassSeriesParam);
command.Parameters.Add(EMailParam);
command.Parameters.Add(PhoneParam);
command.Parameters.Add(DateOfBirthParam);
command.Parameters.Add(SexParam);
command.Prepare();
command.ExecuteNonQuery();
//добавить к полям аккаунта значения
//подобного плана:
account.name = AccountNameBox.Text;
account.surname = AccountSurnameBox.Text;
account.middlename = AccountMiddleNameBox.Text;
account.passportnum = AccountPassportNumberBox.Text;
account.passportser = AccountPassportSeriesBox.Text;
account.mail = AccountEmailBox.Text;
account.phonenum = AccountPhoneNumberBox.Text;
account.sex = AccountSexBox.Text;
account.dateofbirth = DateOfBirthPicker.Text;
}
else if (isAlreadyHaveAccInfo)
{
SqlCommand command1 = new SqlCommand(null, toAccountData);
command1.CommandText = "UPDATE clients SET login = @Login, clientName = @Name, clientSurname = @Surname, clientMiddlename = @MiddleName, passportNumber = @PassNumber, passportSeries = @PassSeries, " +
"[e-mail] = @EMail, phoneNumber = @Phone, date_of_birth = @DateOfBirth, sex = @Sex WHERE login = '" + AccountLoginBox.Text + "'";
SqlParameter NameParam = new SqlParameter("@Name", SqlDbType.NVarChar, 120);
SqlParameter LoginParam = new SqlParameter("@Login", SqlDbType.NVarChar, 120);
SqlParameter SurnameParam = new SqlParameter("@Surname", SqlDbType.NVarChar, 120);
SqlParameter MiddleNameParam = new SqlParameter("@MiddleName", SqlDbType.NVarChar, 120);
MiddleNameParam.IsNullable = true;
SqlParameter PassNumberParam = new SqlParameter("@PassNumber", SqlDbType.NVarChar, 50);
SqlParameter PassSeriesParam = new SqlParameter("@PassSeries", SqlDbType.Int);
PassSeriesParam.IsNullable = true;
SqlParameter EMailParam = new SqlParameter("@EMail", SqlDbType.NVarChar, 120);
SqlParameter PhoneParam = new SqlParameter("@Phone", SqlDbType.NVarChar, 120);
SqlParameter DateOfBirthParam = new SqlParameter("@DateOfBirth", SqlDbType.Date);
SqlParameter SexParam = new SqlParameter("@Sex", SqlDbType.Char, 1);
LoginParam.Value = AccountLoginBox.Text;
NameParam.Value = AccountNameBox.Text;
SurnameParam.Value = AccountSurnameBox.Text;
MiddleNameParam.Value = AccountMiddleNameBox.Text;
PassNumberParam.Value = AccountPassportNumberBox.Text;
if (string.IsNullOrWhiteSpace(AccountPassportSeriesBox.Text))
{
PassSeriesParam.Value = DBNull.Value;
}
else
{
PassSeriesParam.Value = Convert.ToInt32(AccountPassportSeriesBox.Text);
}
EMailParam.Value = AccountEmailBox.Text;
PhoneParam.Value = AccountPhoneNumberBox.Text;
DateOfBirthParam.Value = DateOfBirthPicker.Text;
SexParam.Value = AccountSexBox.Text;
command1.Parameters.Add(LoginParam);
command1.Parameters.Add(NameParam);
command1.Parameters.Add(SurnameParam);
command1.Parameters.Add(MiddleNameParam);
command1.Parameters.Add(PassNumberParam);
command1.Parameters.Add(PassSeriesParam);
command1.Parameters.Add(EMailParam);
command1.Parameters.Add(PhoneParam);
command1.Parameters.Add(DateOfBirthParam);
command1.Parameters.Add(SexParam);
command1.Prepare();
command1.ExecuteNonQuery();
//обновить все поля аккаунта
account.name = AccountNameBox.Text;
account.surname = AccountSurnameBox.Text;
account.middlename = AccountMiddleNameBox.Text;
account.passportnum = AccountPassportNumberBox.Text;
account.passportser = AccountPassportSeriesBox.Text;
account.mail = AccountEmailBox.Text;
account.phonenum = AccountPhoneNumberBox.Text;
account.sex = AccountSexBox.Text;
account.dateofbirth = DateOfBirthPicker.Text;
}
LogInMainWindow logInMainWindow = new LogInMainWindow();
logInMainWindow.Show();
this.Close();
}
else
{
CustomMessageBox.Show("Укажите верный формат почты");
}
}
else
{
CustomMessageBox.Show("Укажите верный формат почты");
}
}
else
{
CustomMessageBox.Show("Выберите дату рождения");
}
}
else
{
CustomMessageBox.Show("Выберите пол");
}
}
else
{
CustomMessageBox.Show("Введите номер телефона");
}
}
else
{
CustomMessageBox.Show("Введите почту");
}
}
else
{
CustomMessageBox.Show("Введите номер паспорта");
}
}
else
{
CustomMessageBox.Show("Введите фамилию");
}
}
else
{
CustomMessageBox.Show("Введите имя");
}
}
}
}
}