public void InsertMedia(IOrganize media) { try { command = new OleDbCommand(); command.Connection = connection; String statement = $"INSERT INTO media (type_id, title, description, genre, length, artists, cost, date_released," + $" publisher, location, format, [size]) VALUES" + $" ('{media.TypeId}', '{media.Title}', '{media.Description}', '{media.Genre}', '{media.Length}', '{media.Artists}', " + $"'{media.Cost}', '{media.DateReleased}', '{media.Publisher}', '{media.Location}', '{media.Format}', " + $"'{media.Size}')"; command.CommandText = statement; connection.Open(); int result = command.ExecuteNonQuery(); } catch (Exception ex) { Console.WriteLine($"ERROR inserting record {media.Title} into table: {ex}"); throw new Exception("Could not store record. Please try again."); } finally { connection.Close(); } }
private void UpdateMedia() { if (mediaId.Length == 0) { return; } Model model = new Model(databasePath); IOrganize media = model.GetMedia(mediaId); DataRowView dataRowView = type.SelectedItem as DataRowView; try { media.TypeId = dataRowView.Row["id"].ToString(); media.Title = title.Text; media.Description = description.Text; media.Genre = genre.Text; media.Length = length.Text; media.Artists = artist.Text; media.Cost = cost.Text; media.DateReleased = dateReleased.Text; media.Publisher = publisher.Text; media.Location = location.Text; media.Format = format.Text; media.Size = size.Text; model.UdpateMedia(media, mediaId); } catch (Exception e) { MessageBox.Show(e.Message); } }
private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e) { if (e.RowIndex < 0) { return; } String id = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); Model model = new Model(databasePath); IOrganize media = model.GetMedia(id); mediaId = id; type.SelectedIndex = type.FindStringExact(media.TypeId); title.Text = media.Title; description.Text = media.Description; genre.Text = media.Genre; length.Text = media.Length; artist.Text = media.Artists; cost.Text = media.Cost; dateReleased.Text = media.DateReleased; publisher.Text = media.Publisher; location.Text = media.Location; format.Text = media.Format; size.Text = media.Size; }
private void CreateNewMedia() { DataRowView dataRowView = type.SelectedItem as DataRowView; String mediaType = string.Empty; if (dataRowView != null) { mediaType = dataRowView.Row["type"].ToString(); } IOrganize media = null; switch (mediaType) { case "Game": media = new Game(); break; case "Movie": media = new Movie(); break; case "Music": media = new Music(); break; default: MessageBox.Show("Invalid media type selected."); break; } Model model = new Model(databasePath); if (media != null) { try { media.TypeId = dataRowView.Row["id"].ToString(); media.Title = title.Text; media.Description = description.Text; media.Genre = genre.Text; media.Length = length.Text; media.Artists = artist.Text; media.Cost = cost.Text; media.DateReleased = dateReleased.Text; media.Publisher = publisher.Text; media.Location = location.Text; media.Format = format.Text; media.Size = size.Text; model.InsertMedia(media); } catch (Exception e) { MessageBox.Show(e.Message); } } }
public IOrganize UdpateMedia(IOrganize media, String id) { try { String statement = $"UPDATE media SET " + $"type_id = {media.TypeId}, " + $"title = '{media.Title}', " + $"description = '{media.Description}', " + $"genre = '{media.Genre}', " + $"length = '{media.Length}', " + $"artists = '{media.Artists}', " + $"cost = '{media.Cost}', " + $"date_released = '{media.DateReleased}', " + $"publisher = '{media.Publisher}', " + $"location = '{media.Location}', " + $"format = '{media.Format}', " + $"[size] = '{media.Size}' WHERE id = {id}"; command.CommandText = statement; connection.Open(); int result = command.ExecuteNonQuery(); connection.Close(); return(GetMedia(id)); } catch (Exception e) { Console.WriteLine(e); return(null); } finally { connection.Close(); } }
private void FileMenuDeleteClick(object sender, EventArgs e) { if (mediaId.Length == 0) { return; } Model model = new Model(databasePath); IOrganize media = model.GetMedia(mediaId); if (media == null) { MessageBox.Show("Media not found."); return; } String message = $"Are you sure you want to delete {media.Title}?"; String caption = "Media Delete"; var result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Question); // If the yes button was pressed ... if (result == DialogResult.Yes) { model.DeleteMedia(mediaId); ClearForm(); ReloadData(); return; } // No was pressed }
public Organize() { dataOrganize = Factory.GetOrganize(); }
public Organize() { this.dataOrganize = RoadFlow.Data.Factory.Factory.GetOrganize(); }
public IOrganize GetMedia(String id) { try { command = new OleDbCommand(); command.Connection = connection; String statement = $"SELECT * FROM existing_media WHERE id = {id}"; command.CommandText = statement; connection.Open(); reader = command.ExecuteReader(); IOrganize media = null; while (reader.Read()) { switch (reader.GetValue(1).ToString()) { case "Game": media = new Game(); break; case "Movie": media = new Movie(); break; case "Music": media = new Music(); break; default: throw new Exception("Invalid media type"); } media.TypeId = reader.GetValue(1).ToString(); media.Title = reader.GetValue(2).ToString(); media.Description = reader.GetValue(3).ToString(); media.Genre = reader.GetValue(4).ToString(); media.Length = reader.GetValue(5).ToString(); media.Artists = reader.GetValue(6).ToString(); media.Cost = reader.GetValue(7).ToString(); media.DateReleased = reader.GetValue(8).ToString(); media.Publisher = reader.GetValue(9).ToString(); media.Location = reader.GetValue(10).ToString(); media.Format = reader.GetValue(11).ToString(); media.Size = reader.GetValue(12).ToString(); return(media); } return(media); } catch (Exception e) { Console.WriteLine(e); return(null); } finally { connection.Close(); } }