public void Edit(TIEU_CHI entity)
 {
     unitOfWorkNV.SaveChanges();
 }
 public void Add(TIEU_CHI entity)
 {
     unitOfWorkNV.Repository <TIEU_CHI>().Add(entity);
     unitOfWorkNV.SaveChanges();
 }
 public void Delete(TIEU_CHI entity)
 {
     unitOfWorkNV.Repository <TIEU_CHI>().Delete(entity);
     unitOfWorkNV.SaveChanges();
 }
Example #4
0
        private void btnLuuTC_Click(object sender, EventArgs e)
        {
            if (txtMaTieuChi.Text == "" || txtTenTC.Text == "")
            {
                if (string.IsNullOrEmpty(txtMaTieuChi.Text.Trim()))
                {
                    txtMaTieuChi.BorderColor          = Color.Red;
                    txtMaTieuChi.PlaceholderText      = "bạn chưa nhập mã tiêu chí";
                    txtMaTieuChi.PlaceholderForeColor = Color.Red;
                }
                if (string.IsNullOrEmpty(txtTenTC.Text.Trim()))
                {
                    txtTenTC.BorderColor          = Color.Red;
                    txtTenTC.PlaceholderText      = "bạn chưa nhập tên tiêu chí";
                    txtTenTC.PlaceholderForeColor = Color.Red;
                }
                if (string.IsNullOrEmpty(txtTienDoTong.Text.Trim()))
                {
                    txtTienDoTong.BorderColor          = Color.Red;
                    txtTienDoTong.PlaceholderText      = "bạn chưa nhập tên tiêu chí";
                    txtTienDoTong.PlaceholderForeColor = Color.Red;
                }
            }
            else
            {
                if (flagLuu == 0)
                {
                    TIEU_CHI tc = editTieuChiBLL.Get(x => x.MaTieuChi.ToString() == txtMaTieuChi.Text.Trim());
                    if (tc == null)
                    {
                        tc                = new TIEU_CHI();
                        tc.MaTieuChi      = txtMaTieuChi.Text;
                        tc.TenTieuChi     = txtTenTC.Text;
                        tc.TienDoTong     = Convert.ToInt32(txtTienDoTong.Text);
                        btnThemTC.Enabled = true;
                        editTieuChiBLL.Add(tc);
                        MessageBox.Show("Thêm thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loadTC(editTieuChiBLL.dstieuchi().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList());
                        loadbtnluu();
                    }
                    else
                    {
                        MessageBox.Show("Dữ liệu đã bị trùng!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        btnThemTC.Enabled = true;
                        btnThemTC_Click(sender, e);
                    }
                }
                else
                {
                    try
                    {
                        TIEU_CHI tc = editTieuChiBLL.Get(x => x.MaTieuChi.ToString() == txtMaTieuChi.Text.Trim());

                        tc.TenTieuChi     = txtTenTC.Text;
                        tc.TienDoTong     = Convert.ToInt32(txtTienDoTong.Text);
                        btnThemTC.Enabled = true;
                        editTieuChiBLL.Edit(tc); MessageBox.Show("Sửa thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        loadTC(editTieuChiBLL.dstieuchi().Skip((pagenumber - 1) * numberRecord).Take(numberRecord).ToList());
                        loadbtnluu();
                    }
                    catch (NullReferenceException)
                    {
                        MessageBox.Show("Sửa thất bại!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        btnThemTC.Enabled = true;
                    }
                }
            }
        }