Example #1
0
 public bool Them(LoaiThucPham x)
 {
     try
     {
         db.LoaiThucPhams.InsertOnSubmit(x);
         db.SubmitChanges();
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Example #2
0
        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);
        }
Example #3
0
 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);
     }
 }
Example #4
0
 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);
 }
Example #5
0
        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();
        }
Example #6
0
 public bool Sua(LoaiThucPham x)
 {
     return(typeFood.Sua(x));
 }
Example #7
0
 public bool Them(LoaiThucPham x)
 {
     return(typeFood.Them(x));
 }