private void Btn_Next_Click(object sender, RoutedEventArgs e) { int currentIndex = recordIds.IndexOf(currentId); if (currentIndex < (recordIds.Count - 1)) { MessageBoxResult result = MessageBoxResult.No; if (Tools.hasDataChanged) { result = MessageBox.Show(Tools.unsavedMessage, Tools.unsavedTitle, MessageBoxButton.YesNo); } if (!Tools.hasDataChanged || result == MessageBoxResult.Yes) { VeteranRecord vetWin; vetWin = new VeteranRecord(mainWin); vetWin.SetMultiRecord(recordIds); vetWin.BuildAndShowDialog(recordIds[currentIndex + 1]); mainWin.DataContext = null; mainWin.MainWindowContent = vetWin; mainWin.DataContext = mainWin; // User has changed the page, discarding the changed data Tools.hasDataChanged = false; } } }
private void Btn_Add_Click(object sender, RoutedEventArgs e) { vetWin = new VeteranRecord(parentWin); vetWin.SetSingleRecord(); vetWin.BuildAndShowDialog(); parentWin.DataContext = null; parentWin.MainWindowContent = vetWin; parentWin.DataContext = parentWin; }
private void Btn_ViewResults_Click(object sender, RoutedEventArgs e) { int selectedId; selectedId = Convert.ToInt32(ListBox_SearchResults.SelectedValue); vetWin = new VeteranRecord(parentWin); vetWin.SetMultiRecord(searchResultIds); vetWin.BuildAndShowDialog(selectedId); parentWin.DataContext = null; parentWin.MainWindowContent = vetWin; parentWin.DataContext = parentWin; }
private void LoadSingleSearchResult(string searchTerm) { int veteranNumber = 0; try { using (MySqlConnection conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString)) { conn.OpenAsync(); using (MySqlCommand command = conn.CreateCommand()) { command.CommandText = @"SELECT ID FROM Veterans WHERE LName=@searchTerm"; command.Parameters.Add("@searchTerm", MySqlDbType.VarChar).Value = searchTerm; using (MySqlDataReader reader = command.ExecuteReader()) { if (reader.Read()) { veteranNumber = reader.GetInt32(0); } } } } } catch (InvalidOperationException) { MessageBox.Show(Tools.DBErrorMessage, Tools.DBErrorTitle); } catch (MySqlException e) { Tools.HandleSQLExceptions(e); } vetWin = new VeteranRecord(parentWin); vetWin.SetSingleRecord(); vetWin.BuildAndShowDialog(veteranNumber); parentWin.DataContext = null; parentWin.MainWindowContent = vetWin; parentWin.DataContext = parentWin; }