private void cg_Click(object sender, RoutedEventArgs e) { try { CTest test = (CTest)data.SelectedItem; adt = new kak(test.nb_field.ToString(), test.fio_field.ToString(), test.ph_field.ToString(), test.mt_field.ToString()); if (adt.ShowDialog() == true) { data.Items.RemoveAt(data.SelectedIndex); string sql = "UPDATE test_table SET nb_field = " + adt.nb.Text + ", fio_field = '" + adt.fio.Text + "', ph_field = " + adt.ph.Text + ", mt_field = " + adt.mt.Text + " WHERE nb_field = " + test.nb_field; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); var d = new CTest { nb_field = int.Parse(adt.nb.Text), fio_field = adt.fio.Text, ph_field = int.Parse(adt.ph.Text), mt_field = int.Parse(adt.mt.Text) }; data.Items.Add(d); } } catch (InvalidOperationException) { MessageBox.Show("Ошибка!"); } catch (FormatException) { MessageBox.Show("Неверный формат записи!"); } catch (ArgumentNullException) { MessageBox.Show("Пусто!"); } catch (OverflowException) { MessageBox.Show("Переполнение!"); } catch (NullReferenceException) { MessageBox.Show("Выберите элемент!"); } catch (SQLiteException) { MessageBox.Show("Пусто!"); } }
private void add_Click(object sender, RoutedEventArgs e) { adt = new kak(); try { if (adt.ShowDialog() == true) { string sql = "INSERT INTO test_table (nb_field, fio_field,ph_field,mt_field) VALUES (" + adt.nb.Text + ",'" + adt.fio.Text + "'," + adt.ph.Text + "," + adt.mt.Text + ")"; SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection); command.ExecuteNonQuery(); var d = new CTest { nb_field = int.Parse(adt.nb.Text), fio_field = adt.fio.Text, ph_field = int.Parse(adt.ph.Text), mt_field = int.Parse(adt.mt.Text) }; data.Items.Add(d); } } catch (InvalidOperationException) { MessageBox.Show("Ошибка!"); } catch (FormatException) { MessageBox.Show("Неверный формат записи!"); } catch (ArgumentNullException) { MessageBox.Show("Пусто!"); } catch (OverflowException) { MessageBox.Show("Переполнение!"); } catch (SQLiteException) { MessageBox.Show("Пусто!"); } }