public static bool IsKhongRangBuoc(GoiTap g)
 {
     using (var db = DBContext.GetContext()) {
         var phieuThus = db.PhieuThu.Include(p=>p.GoiTap).FirstOrDefault(p=>p.GoiTap.MaGoiTap ==  g.MaGoiTap);
         if (phieuThus != null)
             return false;
         return true;
     }
 }
Example #2
0
 public FrmGoiTapEdit(GoiTap h = null)
 {
     InitializeComponent();
     current = h;
     if (current != null)
     {
         Text = "Chỉnh sửa gói tập";
         loadField();
         isThem = false;
         cbbPhong.Enabled = false;
     }
     else
     {
         isThem = true;
     }
     cbbPhong.Properties.NullText = "Chọn một phòng tập";
     DataFiller.fillPhongCombo(cbbPhong);
 }
 internal static CODE_RESULT_RETURN Update(GoiTap hv)
 {
     using (var db = DBContext.GetContext())
     {
         var goiCU = db.GoiTap.FirstOrDefault(h => h.MaGoiTap  == hv.MaGoiTap);
         if (goiCU != null)
         {
             goiCU.SoThang = hv.SoThang;
             goiCU.TenGoiTap = hv.TenGoiTap;
             goiCU.Gia = hv.Gia;
             goiCU.Type = hv.Type;
             goiCU.PhongTap = db.PhongTap.Find(hv.PhongTap.MaPhongTap);
             db.SaveChanges();
             return CODE_RESULT_RETURN.ThanhCong;
         }
         return CODE_RESULT_RETURN.ThatBai;
     }
 }
 internal static CODE_RESULT_RETURN Add(GoiTap sp)
 {
     using (var db = DBContext.GetContext())
     {
         try
         {
             var n1 = db.GoiTap.FirstOrDefault(n => n.MaGoiTap == sp.MaGoiTap);
             if (n1 == null)
             {
                 sp.PhongTap = db.PhongTap.Find(sp.PhongTap.MaPhongTap);
                 db.GoiTap.Add(sp);
                 db.SaveChanges();
                 return CODE_RESULT_RETURN.ThanhCong;
             }
             return CODE_RESULT_RETURN.MaTrung;
         }
         catch
         {
             return CODE_RESULT_RETURN.ThatBai;
         }
     }
 }
Example #5
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            String sTen = txtTen.Text;
            String sSoThang = txtSoThang.Text;
            String sGia = txtGia.Text;
            int soThang, gia;
            if (sTen == "")
            {
                dxErrorProvider1.SetError(txtTen, "Tên không được trống");
                txtTen.Focus();
                return;
            }
            if (sSoThang == "")
            {
                dxErrorProvider1.SetError(txtSoThang, "Chưa nhập số tháng");
                txtTen.Focus();
                return;
            }

            if (!int.TryParse(sSoThang, out soThang))
            {
                dxErrorProvider1.SetError(txtSoThang, "Số tháng không hợp lệ");
                txtSoThang.Focus();
                return;
            }

            if (sGia == "")
            {
                dxErrorProvider1.SetError(txtSoThang, "Chưa nhập giá");
                txtGia.Focus();
                return;
            }

            if (!int.TryParse(sGia, out gia))
            {
                dxErrorProvider1.SetError(txtSoThang, "Giá không hợp lệ");
                txtGia.Focus();
                return;
            }

            PhongTap p = (PhongTap)cbbPhong.GetSelectedDataRow();

            if (p == null)
            {
                dxErrorProvider1.SetError(cbbPhong, "Chưa chọn phòng tập");
                cbbPhong.Focus();
                return;
            }
            if (current == null)
            {
                current = new GoiTap()
                {
                    MaGoiTap = -1
                };
            }
            current.TenGoiTap = sTen;
            current.SoThang = soThang;
            current.Gia = gia;
            current.Type = radGYM.Checked ? 1 : 2;
            current.PhongTap = p;
            if (isThem)
            {
                if (GoiTapController.Add(current) == CODE_RESULT_RETURN.ThanhCong)
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageBox.Show("Có lỗi khi thêm");
                }
            }
            else
            {
                if (GoiTapController.Update(current) == CODE_RESULT_RETURN.ThanhCong)
                {
                    DialogResult = DialogResult.OK;
                    Close();
                }
                else
                {
                    MessageBox.Show("Có lỗi khi cập nhật");
                }
            }
        }