Esempio n. 1
0
 private void btnThem_Click(object sender, EventArgs e)
 {
     using (var uow = new UnitOfWork())
     {
         Religion insert = new Religion(uow);
         insert.ReligionID   = txtMaTonGiao.Text;
         insert.ReligionName = txtTenTonGiao.Text;
         try
         {
             if (LaHopLe() == true)
             {
                 insert.Save();
                 uow.CommitChanges();
                 frmReligionList f = this.Tag as frmReligionList;
                 f.RefreshData();
                 XtraMessageBox.Show("Thêm thành công", "THÔNG BÁO");
                 CleanForm();
             }
         }
         catch (Exception ex)
         {
             Religion c = uow.FindObject <Religion>(CriteriaOperator.Parse("ReligionID = ?", txtMaTonGiao.Text));
             if (c != null)
             {
                 er.SetError(this, "Mã tôn giáo đã tồn tại!");
                 XtraMessageBox.Show("Mã tôn giáo đã tồn tại!!!", "THÔNG BÁO");
             }
             else
             {
                 XtraMessageBox.Show(ex.Message, "THÔNG BÁO");
             }
         }
     }
 }
Esempio n. 2
0
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            using (var uow = new UnitOfWork())
            {
                Religion update = uow.FindObject <Religion>(CriteriaOperator.Parse("ReligionID = ?", txtMaTonGiao.Text));
                if (update != null)
                {
                    update.ReligionName = txtTenTonGiao.Text;
                    try
                    {
                        if (LaHopLe() == true)
                        {
                            update.Save();
                            uow.CommitChanges();
                            frmReligionList f = this.Tag as frmReligionList;
                            f.RefreshData();
                            XtraMessageBox.Show("Cập nhật thành công", "THÔNG BÁO");
                        }
                    }

                    catch (Exception ex)
                    {
                        XtraMessageBox.Show(ex.Message, "THÔNG BÁO");
                    }
                }
            }
        }