public bool Them(LoaiThucPham x) { try { db.LoaiThucPhams.InsertOnSubmit(x); db.SubmitChanges(); return(true); } catch { return(false); } }
public List <LoaiThucPham> getDuLieu() { string sql = "SELECT * FROM LOAITHUCPHAM"; DataTable dt = ldc.getDuLieu(sql); List <LoaiThucPham> lst = new List <LoaiThucPham>(); foreach (DataRow row in dt.Rows) { LoaiThucPham table = new LoaiThucPham(row); lst.Add(table); } return(lst); }
public bool Sua(LoaiThucPham x) { try { LoaiThucPham l = db.LoaiThucPhams.Single(s => s.maLoaiTP == x.maLoaiTP); l.tenLoaiTP = x.tenLoaiTP; db.SubmitChanges(); return(true); } catch { return(false); } }
public bool Xoa(int id) { try { LoaiThucPham l = db.LoaiThucPhams.Single(x => x.maLoaiTP == id); db.LoaiThucPhams.DeleteOnSubmit(l); db.SubmitChanges(); } catch { return(false); } return(true); }
private void btnLuu_Click(object sender, EventArgs e) { LoaiThucPham x = new LoaiThucPham(); if (isADD) { //x.maLoaiTP = Convert.ToInt32(txtMaLoai.Text); x.tenLoaiTP = txtTenLoai.Text; bool success = loaiTP.Them(x); if (success) { MessageBox.Show("Thêm thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else // thêm thất bại { MessageBox.Show("Thêm thất bại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else // sửa { x.maLoaiTP = Convert.ToInt32(txtMaLoai.Text); x.tenLoaiTP = txtTenLoai.Text; bool success = loaiTP.Sua(x); if (success) { MessageBox.Show("Cập nhật thành công!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } else // thêm thất bại { MessageBox.Show("Cập nhật thất bại!", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); } } HienThiDanhSachLoaiThucPham(); EnableProject(false); FocusRowChanged(); }
public bool Sua(LoaiThucPham x) { return(typeFood.Sua(x)); }
public bool Them(LoaiThucPham x) { return(typeFood.Them(x)); }