private void Page_Loaded(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { try { Staff staff = _newStaff = new Staff(); _newPhone = new PhoneStaff(); _newEmail = new EmailStaff(); _phoneList = new List <PhoneStaff>(); _emailList = new List <EmailStaff>(); Deal[] dealArr = null; TaskBD[] taskBDArr = null; if (!_isNewRecord) { staff = _databasenEtities.Staff.Single(a => a.ID == _ID_Row); _phoneList.AddRange(_databasenEtities.PhoneStaff.Where(a => a.ID_Staff == _ID_Row).ToArray()); _emailList.AddRange(_databasenEtities.EmailStaff.Where(a => a.ID_Staff == _ID_Row).ToArray()); dealArr = _databasenEtities.Deal.Where(a => a.ID_Staff == staff.ID).ToArray(); taskBDArr = _databasenEtities.TaskBD.Where(a => a.ID_Staff == staff.ID).ToArray(); } PostPeople[] postPeopleArr = _databasenEtities.PostPeople.OrderBy(a => a.Name).ToArray(); Country[] countryArr = _databasenEtities.Country.OrderBy(a => a.Name).ToArray(); TypePhone[] typePhoneArr = _databasenEtities.TypePhone.OrderBy(a => a.Name).ToArray(); TypeEmail[] typeEmailArr = _databasenEtities.TypeEmail.OrderBy(a => a.Name).ToArray(); Dispatcher.Invoke(() => { DataContext = staff; cbPostStaff.ItemsSource = postPeopleArr; cbCountry.ItemsSource = countryArr; cbTypePhone.ItemsSource = dgcbTypePhone.ItemsSource = typePhoneArr; cbTypeEmail.ItemsSource = dgcbTypeEmail.ItemsSource = typeEmailArr; gNewPhone.DataContext = _newPhone; gNewEmail.DataContext = _newEmail; dgPhone.ItemsSource = _phoneList.ToArray(); dgEmail.ItemsSource = _emailList.ToArray(); if (!_isNewRecord) { dgDeal.ItemsSource = dealArr; dgTask.ItemsSource = taskBDArr; } mainGrid.IsEnabled = true; }); } catch (Exception ex) { MessageService.MetroMessageDialogError(ex.Message); } }); }
// Добавление нового Email private void btnAddNewEmail_Click(object sender, RoutedEventArgs e) { if (Regex.IsMatch(_newEmail.Email, @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)) { _emailList.Add(_newEmail); gNewEmail.DataContext = _newEmail = new EmailStaff(); dgEmail.ItemsSource = _emailList.ToArray(); } else { MessageService.MetroMessageDialogError("Вы ввели неверный Email адрес!"); } }
// Удаление email private async void dgEmail_KeyUp(object sender, KeyEventArgs e) { if (e.Key == Key.Delete && dgEmail.SelectedItem != null) { MessageDialogResult dialogResult = await MessageService.MetroMessageDialogQuestion("Подтверждение удаления", "Вы действительно хотите удалить выбранный элемент?"); if (dialogResult == MessageDialogResult.Affirmative) { EmailStaff emailStaff = dgEmail.SelectedItem as EmailStaff; if (emailStaff.ID != 0) { _delEmailList.Add(emailStaff); } _emailList.Remove(emailStaff); dgEmail.ItemsSource = _emailList.ToArray(); } } }