private void Popularity_Form_Load(object sender, EventArgs e) { this.dgw_popularity.Size = new Size(568, 220); this.dgw_popularity.DataSource = Popularity.Show_All_Popularities(); this.pnl_operation.Hide(); this.lbl_msg1.Text = ""; this.lbl_msg2.Text = ""; }
private void btn_ok_Click(object sender, EventArgs e) { this.lbl_msg1.Text = ""; this.lbl_msg2.Text = ""; if (tb_name.Text.Trim() == "") { lbl_msg1.Text = "*Invalid"; lbl_msg1.ForeColor = Color.Red; return; } if (tb_score.Text.Trim() == "") { lbl_msg2.Text = "*Invalid"; lbl_msg2.ForeColor = Color.Red; return; } this.name = tb_name.Text.Trim(); this.score = int.Parse(tb_score.Text.Trim()); if (Popularity.Contains_Name(name) != this.id && Popularity.Contains_Name(name) != -1) { lbl_msg1.Text = "*Exist"; lbl_msg1.ForeColor = Color.Red; return; } if (Popularity.Contains_Score(score) != this.id && Popularity.Contains_Score(score) != -1) { lbl_msg2.Text = "*Exist"; lbl_msg2.ForeColor = Color.Red; return; } if (opr == OPERATION.ADD) { Popularity new_pop = new Popularity(0, name, score); new_pop.Add(); dgw_popularity.DataSource = Popularity.Show_All_Popularities(); new_pop = null; } else if (opr == OPERATION.EDIT) { Popularity curr_pop = new Popularity(id, name, score); curr_pop.Edit(); dgw_popularity.DataSource = Popularity.Show_All_Popularities(); curr_pop = null; } }
private void btn_remove_Click(object sender, EventArgs e) { Microwave main_page = (Microwave)Application.OpenForms["Microwave"]; string msg = "Are you sure to delete a popularity type?"; main_page.Create_Warning_Form(msg, Color.DarkRed); if (main_page.Warning_form.Result) { main_page.Warning_form.Refresh_Form(); this.id = int.Parse(dgw_popularity.SelectedRows[0].Cells[0].Value.ToString()); if (this.id == -1) { return; } if (this.id == 0) { MessageBox.Show("Default cannot be deleted.", "", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } Popularity pop_delete = new Popularity(id, name, score); pop_delete.Delete(); this.dgw_popularity.DataSource = Popularity.Show_All_Popularities(); } main_page.Warning_form.Refresh_Form(); return; }