private async void Button_Click(object sender, RoutedEventArgs e) { var clickedButton = sender as Button; if (clickedButton.Content.ToString() == "Close") { this.Close(); } if (clickedButton.Content.ToString() == "Add") { if (string.IsNullOrEmpty(TbxNewListValue.Text) || string.IsNullOrWhiteSpace(TbxNewListValue.Text)) { MessageBox.Show ( "Input error", "New list value should not be emplty string", MessageBoxButton.OK, MessageBoxImage.Error ); return; } var selectedList = this.MainViewModel.SelectedList; var newListValue = new ListValueModel() { ListValue = TbxNewListValue.Text, OldListValue = TbxNewListValue.Text }; var connectionString = ConfigurationManager.ConnectionStrings["cs_login"].ConnectionString; var connection = new MySqlConnection(connectionString); var commandString = $"INSERT INTO `{selectedList.ListName}s_{MainViewModel.LaboratoryBookName}` (`{selectedList.ListName}`) " + $"VALUES ('{newListValue.ListValue}');"; var sqlCommand = new MySqlCommand(commandString, connection); try { await connection.OpenAsync(); var result = await sqlCommand.ExecuteNonQueryAsync(); if (result > 0) { newListValue.PropertyChanged += MainViewModel.ListModel_PropertyChanged; selectedList.Values.Add(newListValue); } this.Close(); } catch (Exception exception) { MessageBox.Show ( exception.Message, "SQL error", MessageBoxButton.OK, MessageBoxImage.Error ); } finally { await connection.CloseAsync(); sqlCommand?.Dispose(); } } }
public Task UpdateListValue(ListValueModel listValue) { throw new NotImplementedException(); }