public bool Add(DaiDoi item) { try { db.DaiDois.Add(item); db.SaveChanges(); return(true); } catch { return(false); } }
public bool Edit(DaiDoi item) { try { DaiDoi temp = db.DaiDois.Find(item.ID); temp.Ten = item.Ten; temp.GhiChu = item.GhiChu; temp.TieuDoanID = item.TieuDoanID; db.SaveChanges(); return(true); } catch { return(false); } }
private void btn_Them_Click(object sender, EventArgs e) { if (Common.Acc_type == "Root" || Common.Acc_type == "Admin") { if (btn_Them.Text == "Thêm") { btn_Sua.Enabled = false; btn_Them.Text = "Lưu"; btn_Xoa.Text = "Hủy"; UnLockControl(); Empty(); } else { DaiDoi item = new DaiDoi(); item.Ten = txbTen.Text; item.GhiChu = txbGhiChu.Text; item.TieuDoanID = Convert.ToInt32(cboTieuDoan.SelectedValue); if (new DaiDoiDAO().Add(item)) { LoadDaiDoi(); MessageBox.Show("Thêm thành công"); } else { MessageBox.Show("Không thành công"); } LockControl(); } } else { MessageBox.Show("Bạn không có quyền thực hiện tác vụ này"); } }