private void btnAdd_Click(object sender, EventArgs e) { if (!(validateUI(btnAdd))) { return; } try { Genre myGenre = new Genre(); myGenre.id = txtID.Text.Trim(); myGenre.name = txtName.Text.Trim(); bool status = GenreDB.AddGenre(myGenre); if (status) //returns true { MessageBox.Show("Genre added to the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information); //Automatically refresh the data grid this.btnBrowse_Click(null, null); } else //returns false { MessageBox.Show("Genre was not added to the database.", "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Information); //Automatically refresh the data grid this.btnBrowse_Click(null, null); } } catch (Exception ex) { MessageBox.Show(ex.Message, "MeramecNetFlix", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnAdd_Click(object sender, EventArgs e) { //Validate the UI if (string.IsNullOrEmpty(txtGenreID.Text.Trim())) { try { List <Genre> genreList = new List <Genre>(); genreList = GenreDB.GetGenres(); int num = 1; foreach (Genre genre in genreList) { if (num <= genre.ID) { num = genre.ID + 1; } } txtGenreID.Text = num.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message); } } if (string.IsNullOrEmpty(txtGenreName.Text.Trim())) { MessageBox.Show("Please enter a genre name."); txtGenreID.Focus(); return; } Genre objGenre = new Genre(); objGenre.ID = Convert.ToInt32(txtGenreID.Text.Trim()); objGenre.Name = txtGenreName.Text.Trim(); try { bool status = GenreDB.AddGenre(objGenre); if (status) //You can use this syntax as well..if (status ==true) { Reload_Data(); MessageBox.Show("Genre added to the database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Genre was not added to database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_Add_Click(object sender, EventArgs e) { if (GenreDB.AddGenre(GetGenreObjFromUI())) { MessageBox.Show("Add Successful."); } else { MessageBox.Show("Add Failed."); } }
private void btnAdd_Click(object sender, EventArgs e) { //Validate the UI if (string.IsNullOrEmpty(txtGenreID.Text.Trim())) { MessageBox.Show("Please enter a genre id."); txtGenreID.Focus(); return; } if (string.IsNullOrEmpty(txtGenreName.Text.Trim())) { MessageBox.Show("Please enter a genre name."); txtGenreID.Focus(); return; } Genre objGenre = new Genre(); objGenre.ID = txtGenreID.Text.Trim(); objGenre.Name = txtGenreName.Text.Trim(); try { bool status = GenreDB.AddGenre(objGenre); if (status) //You can use this syntax as well..if (status ==true) { MessageBox.Show("Genre added to the database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Genre was not added to database.", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error); } }