private void ShowList() { var db = new HistorySoftwareEntities2(); var list = db.SuKiens.ToList(); this.lstEvent.DataSource = list; }
private void btnDelete_Click(object sender, EventArgs e) { var db = new HistorySoftwareEntities2(); if (MessageBox.Show("Do you want to delete", "Confirm", MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.Yes) { for (int i = 0; i < this.dtlShow.SelectedRows.Count; i++) { var row = this.dtlShow.SelectedRows[i]; var item = (SuKien)row.DataBoundItem; try { SuKien @class = db.SuKiens.Find(item.Id); db.SuKiens.Remove(@class); db.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot delete class: " + item.Id); } this.ShowList(); } } }
private void btnAdd_Click(object sender, EventArgs e) { SuKien sukien = new SuKien(); sukien.Id = this.txtId.Text; sukien.TenSuKien = this.txtTitle.Text; sukien.NgaySuKien = this.txtDay.Text; sukien.ThangSuKien = this.txtMonth.Text; sukien.NamSuKien = this.txtYear.Text; sukien.NoiDungSuKien = this.rtxtContent.Text; try { var db = new HistorySoftwareEntities2(); db.SuKiens.Add(sukien); db.SaveChanges(); this.Close(); }catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnEdit_Click(object sender, EventArgs e) { try { var db = new HistorySoftwareEntities2(); var newClass = db.SuKiens.Find(this.sukien.Id); newClass.Id = this.txtId.Text; newClass.TenSuKien = this.txtTitle.Text; newClass.NgaySuKien = this.txtDay.Text; newClass.ThangSuKien = this.txtMonth.Text; newClass.NamSuKien = this.txtYear.Text; newClass.NoiDungSuKien = this.rtxtContent.Text; db.Entry(newClass).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); this.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }