Esempio n. 1
0
 public bool AddOrUpdate(TieuChiDanhGia item, int mode)
 {
     if (mode == 0)
     {
         _db.TieuChiDanhGias.Add(item);
     }
     else
     {
         var up = GetByMaTC(item.MaTC);
         up.NoiDung   = item.NoiDung;
         up.DiemTCMax = item.DiemTCMax;
     }
     return(SaveToDatabase());
 }
Esempio n. 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var dao  = new TieuChiDanhGiaDAO();
            var item = dao.GetByMaTC(MaTC);

            string sErr  = "";
            bool   bVali = true;
            var    maso  = txtMS.Text;
            var    nd    = txtNoiDung.Text;
            var    max   = numDiem.Text;

            if (string.IsNullOrEmpty(maso))
            {
                bVali = false;
                sErr  = sErr + "Vui lòng nhập mã";
            }
            if (string.IsNullOrEmpty(nd))
            {
                bVali = false;
                sErr  = sErr + "Vui lòng nhập nội dung tiêu chí đánh giá";
            }
            if (string.IsNullOrEmpty(max))
            {
                bVali = false;
                sErr  = sErr + "Vui lòng nhập số điểm tối đa";
            }
            if (bVali)
            {
                var mode = 1;
                if (item == null)
                {
                    item      = new TieuChiDanhGia();
                    mode      = 0;
                    item.MaTC = int.Parse(maso);
                }
                item.NoiDung   = nd;
                item.DiemTCMax = int.Parse(max);
                var res = dao.AddOrUpdate(item, mode);
                if (res)
                {
                    if (mode == 1)
                    {
                        sErr = "Cập nhật thành công";
                    }
                    else
                    {
                        sErr = "Thêm thành công";
                    }
                    if (XtraMessageBox.Show(sErr, "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information) == DialogResult.OK)
                    {
                        this.Close();
                    }
                }
                else
                {
                    XtraMessageBox.Show("Tạo lỗi", "Thông Báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                XtraMessageBox.Show(sErr, "Thông Báo!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }