private async void edit_Click(object sender, RoutedEventArgs e) { StackPanel panel = new StackPanel(); PasswordBox password = new PasswordBox(); password.PlaceholderText = "Пароль"; password.HorizontalAlignment = HorizontalAlignment.Stretch; PasswordBox password1 = new PasswordBox(); password1.PlaceholderText = "Подтверждения пароля"; password1.HorizontalAlignment = HorizontalAlignment.Stretch; TextBox Email = new TextBox(); Email.PlaceholderText = "Почта"; Email.HorizontalAlignment = HorizontalAlignment.Stretch; TextBox Name = new TextBox(); Name.IsEnabled = false; Database name = new Database(); var tablename = name.Select("SELECT user_login FROM `users` WHERE id_user = "******"SELECT CONCAT(last_name,' ',first_name,' ',mid_name) FROM `users` WHERE id_user = "******"Группа"; namegroup.SelectedIndex = 0; Database goups = new Database(); var tablegroups = goups.Select("SELECT CONCAT(groups.group_name) FROM `groups` WHERE 1"); var collection = new ObservableCollection <object>(); foreach (DataRow row in tablegroups.Rows) { collection.Add(row.ItemArray[0]); } namegroup.ItemsSource = collection; panel.Children.Add(password); panel.Children.Add(password1); panel.Children.Add(Email); panel.Children.Add(Name); panel.Children.Add(date_name); panel.Children.Add(namegroup); var dialog = new ContentDialog(); dialog.Content = panel; dialog.PrimaryButtonText = "Изменить"; dialog.PrimaryButtonClick += async(a, b) => { if (password.Password != password1.Password) { MessageDialog message = new MessageDialog("Пароли не совпадают"); await message.ShowAsync(); return; } if (Email.Text == "") { MessageDialog message = new MessageDialog("Поле с почтой пустое"); await message.ShowAsync(); return; } Database database = new Database(); config config = new config(); string sql = "UPDATE `users` SET id_group = '" + (namegroup.SelectedIndex + 1) + "',`user_email`= '" + Email.Text + "',`user_password`= '" + config.Hash(password.Password) + "' WHERE id_user = "******"Отменить"; await dialog.ShowAsync(); }
//Добавление пользователя private async void Add_Click(object sender, RoutedEventArgs e) { config config = new config(); StackPanel panel = new StackPanel(); Database data_base = new Database(); var collection = new ObservableCollection <object>(); PasswordBox password = new PasswordBox(); TextBox Name = new TextBox(); PasswordBox password1 = new PasswordBox(); TextBox Email = new TextBox(); ContentDialog contentDialog = new ContentDialog(); Name.PlaceholderText = "Имя пользователя"; Name.HorizontalAlignment = HorizontalAlignment.Stretch; Name.SelectionChanged += (send, args) => { contentDialog.IsPrimaryButtonEnabled = Prov(password, Name, Email, password1); }; password.PlaceholderText = "Пароль"; password.HorizontalAlignment = HorizontalAlignment.Stretch; password.PasswordChanged += (send, args) => { contentDialog.IsPrimaryButtonEnabled = Prov(password, Name, Email, password1); }; password1.PlaceholderText = "подтверждения пароля"; password1.HorizontalAlignment = HorizontalAlignment.Stretch; password1.PasswordChanged += (send, args) => { contentDialog.IsPrimaryButtonEnabled = Prov(password, Name, Email, password1); }; Email.PlaceholderText = "Почта"; Email.HorizontalAlignment = HorizontalAlignment.Stretch; Email.SelectionChanged += (send, args) => { contentDialog.IsPrimaryButtonEnabled = Prov(password, Name, Email, password1); }; ComboBox sotrudnik = new ComboBox(); DataTable data_table = data_base.Select("SELECT CONCAT(Imya_sotrydnika,' ',Familiya_sotrydnika,' ',Otchestvo_sotrydnika) FROM `sotrydnik` WHERE 1"); collection = new ObservableCollection <object>(); foreach (DataRow row in data_table.Rows) { collection.Add(row.ItemArray[0]); } sotrudnik.ItemsSource = collection; ComboBox group = new ComboBox(); data_table = data_base.Select("SELECT group_name FROM `groups` WHERE 1"); collection = new ObservableCollection <object>(); foreach (DataRow row in data_table.Rows) { collection.Add(row.ItemArray[0]); } group.ItemsSource = collection; panel.Children.Add(Name); panel.Children.Add(Email); panel.Children.Add(password); panel.Children.Add(password1); panel.Children.Add(sotrudnik); panel.Children.Add(group); contentDialog.Content = panel; contentDialog.CloseButtonText = "Отмена"; contentDialog.PrimaryButtonText = "Сохранить"; contentDialog.IsPrimaryButtonEnabled = false; contentDialog.PrimaryButtonClick += async(send, arg) => { if (password1.Password != password.Password) { await config.Alert("Пароль не совподает", "Ошибка"); } if (data_base.Select("SELECT * FROM `users` WHERE users.user_login = '******'").Rows.Count == 0) { await config.Alert("Логин существует", "ошибка"); } string[] FIO_DataBase = sotrudnik.SelectedItem.ToString().Split(' '); data_base.Insert("INSERT INTO `users` (`id_user`, `id_group`, `id_employee`, `last_name`, `first_name`, `mid_name`, `user_login`, `user_email`, `user_password`) VALUES(NULL, '" + (group.SelectedIndex + 1) + "', '" + (sotrudnik.SelectedIndex + 1) + "', '" + FIO_DataBase[1] + "', '" + FIO_DataBase[2] + "', '" + FIO_DataBase[2] + "', '" + Name.Text.Trim() + "', '" + Email.Text.Trim() + "', '" + config.Hash(password.Password) + "')"); }; await contentDialog.ShowAsync(); }