void ButtonEditClick(object sender, EventArgs e) { if (listBoxEditCombo.SelectedIndex < 0) { return; } FormEditOneTheme formOne = new FormEditOneTheme(listBoxEditCombo.SelectedItem.ToString()); if (formOne.ShowDialog() != DialogResult.OK) { return; } try{ SQLiteConnection db = new SQLiteConnection("Data source = db/Library.db; Version=3"); db.Open(); SQLiteCommand command = db.CreateCommand(); command.CommandText = @"UPDATE Theme SET nameTheme = @nametheme WHERE idTheme = @idtheme;"; command.Parameters.Add("@idtheme", System.Data.DbType.Int32).Value = themesId [listBoxEditCombo.SelectedIndex]; command.Parameters.Add("@nametheme", System.Data.DbType.String).Value = formOne.textBoxEdit.Text; command.ExecuteNonQuery(); db.Close(); LoadAllCatalog(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void ButtonAddClick(object sender, EventArgs e) { FormEditOneTheme form = new FormEditOneTheme(); if (form.ShowDialog() != DialogResult.OK) { return; } if (form.textBoxEdit.Text == string.Empty) { return; } using (SQLiteConnection db = new SQLiteConnection("Data Source=db/" + DATABASENAME + "; Version=3")){ try{ db.Open(); SQLiteCommand command = db.CreateCommand(); command.CommandText = @"INSERT INTO Theme (nameTheme) VALUES (@name);"; command.Parameters.Add("@name", System.Data.DbType.String).Value = form.textBoxEdit.Text; command.ExecuteNonQuery(); themesId.Add(listBoxEditCombo.Items.Count, currentId += 1); listBoxEditCombo.Items.Add(form.textBoxEdit.Text); db.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); db.Close(); } } }