void ДобавитьКгигуToolStripMenuItemClick(object sender, EventArgs e) { if (comboBoxTheme.SelectedIndex < 0) { MessageBox.Show("Выберите соответствующий каталог для добавлении книги."); return; } FormAllBooks form = new FormAllBooks(listBoxBooks.Items); if (form.ShowDialog() != DialogResult.OK) { return; } try{ SQLiteConnection db = new SQLiteConnection(@"Data source=db/Library.db; Version=3"); db.Open(); SQLiteCommand command = db.CreateCommand(); foreach (int idbookselect in form.ExtractSelectedId()) { command.CommandText = @"INSERT INTO Books_Theme (idBook, idTheme) VALUES (@idB, @idT);"; command.Parameters.Add("@idT", System.Data.DbType.Int32).Value = themeKeys[comboBoxTheme.SelectedIndex]; command.Parameters.Add("@idB", System.Data.DbType.Int32).Value = idbookselect; command.ExecuteNonQuery(); } db.Close(); LoadTable_BooksTheme(themeKeys[comboBoxTheme.SelectedIndex]); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
void ВсеКнигиToolStripMenuItemClick(object sender, EventArgs e) { FormAllBooks form = new FormAllBooks(); form.buttonCansel.Visible = false; form.buttonOk.Visible = false; form.buttonDelete.Visible = true; form.buttonRead.Visible = true; form.ShowDialog(); LoadInCombo(); }
void ДобавитьКнигиToolStripMenuItemClick(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() != DialogResult.OK) { return; } SQLiteConnection db = new SQLiteConnection("Data Source=db/" + DATABASENAME + "; Version=3"); db.Open(); SQLiteCommand command = db.CreateCommand(); try{ Directory.CreateDirectory(FOLDERBOOKS); foreach (string filename in openFileDialog1.FileNames) { try{ File.Copy(filename, FOLDERBOOKS + "\\" + Path.GetFileName(filename)); } catch { break; } try{ command.CommandText = @"INSERT INTO Books (nameBook) VALUES (@name);"; command.Parameters.Add("@name", System.Data.DbType.String).Value = System.IO.Path.GetFileName(filename); command.ExecuteNonQuery(); } catch { File.Delete(FOLDERBOOKS + "\\" + Path.GetFileName(filename)); } } db.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); db.Close(); } FormAllBooks formall = new FormAllBooks(); formall.buttonCansel.Visible = false; formall.buttonOk.Visible = false; formall.buttonDelete.Visible = true; formall.buttonRead.Visible = true; formall.ShowDialog(); LoadInCombo(); }