private void SetDataToTheList() { try { listWorkers.Items.Clear(); WorkersCatalog.Model.Archive.Instance.data = WorkersCatalog.Database.DatabaseProvider.Instance.GetWorkers(); string fullName; foreach (var item in WorkersCatalog.Model.Archive.Instance.data) { fullName = item.Name.ToString() + " " + item.Surname.ToString(); fullName = fullName.ToLower(); if (fullName.Contains(searchingString.ToLower())) { listWorkers.Items.Add(item.Name + " " + item.Surname); } } } catch (Exception err) { if (MessageBox.Show(ShowText.ConnectionError(), ShowText.ConnectionErrorTitle(), MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.Yes) == MessageBoxResult.Yes) { View.DatabaseConnectionWindow databaseSettings = new View.DatabaseConnectionWindow(); databaseSettings.ShowDialog(); SetDataToTheList(); } } }
private void OnAddNewClick(object sender, RoutedEventArgs e) { try { DatabaseController.AddNewWorkerToDatabase(txtName.Text, txtSurname.Text, calendar.SelectedDate.ToString() == "" ? new DateTime(1900, 1, 1) : DateTime.Parse(calendar.SelectedDate.ToString()), txtPosition.Text, txtImpl.Text, DateTime.Parse(calendarImpl.SelectedDate.ToString()), txtfire.Text, DateTime.Parse(calendarFire.SelectedDate.ToString()), txtPhoto.Text); MessageBox.Show(ShowText.AddNewWorker(), ShowText.AddNewWorkerTitle(), MessageBoxButton.OK, MessageBoxImage.Information); OnClearClick(sender, e); } catch (Exception err) { MessageBox.Show(err.Message); } }
private void OnChangeButtonClick(object sender, RoutedEventArgs e) { if (lstChoose.SelectedIndex == -1) { MessageBox.Show(ShowText.ErrorSelect(), ShowText.ErrorSelectTitle(), MessageBoxButton.OK, MessageBoxImage.Error); selectedIndex = -1; } else { selectedIndex = lstChoose.SelectedIndex; this.Close(); } }
public void ListFiller() { try { lstChoose.Items.Clear(); WorkersCatalog.Model.Archive.Instance.data = WorkersCatalog.Database.DatabaseProvider.Instance.GetWorkers(); foreach (var item in WorkersCatalog.Model.Archive.Instance.data) { lstChoose.Items.Add(item.Name + " " + item.Surname); } } catch (Exception err) { if (MessageBox.Show(ShowText.ConnectionError(), ShowText.ConnectionErrorTitle(), MessageBoxButton.YesNo, MessageBoxImage.Error, MessageBoxResult.Yes) == MessageBoxResult.Yes) { View.DatabaseConnectionWindow databaseSettings = new View.DatabaseConnectionWindow(); databaseSettings.ShowDialog(); ListFiller(); } MessageBox.Show(err.Message); } }
private void OnDeleteClick(object sender, RoutedEventArgs e) { if (listWorkers.SelectedIndex == -1) { MessageBox.Show(ShowText.Deletechoose(), ShowText.DeletechooseTitle(), MessageBoxButton.OK, MessageBoxImage.Warning); return; } if (MessageBox.Show(ShowText.DeleteMessage(), ShowText.DeleteSimple(), MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes) { try { DatabaseController.DeleteValueFromDatabase(listWorkers.SelectedIndex); listWorkers.SelectedIndex = -1; SetDataToTheList(); } catch (Exception err) { listWorkers.SelectedIndex = -1; SetDataToTheList(); } } }