public ActionResult Create(LinhVuc model)
 {
     try
     {
         // TODO: Add insert logic here
         if (ModelState.IsValid)
         {
             var result = LinhVucManager.add(model);
             if (result != 0)
             {
                 putSuccessMessage("Thêm thành công");
                 RedirectToAction("Details", new { id = result });
             }
             else
             {
                 putErrorMessage("Thêm thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         setAlertMessage();
         return View(model);
     }
     catch(Exception ex)
     {
         putErrorMessage(ex.Message);
         return RedirectToAction("Create");
     }
 }
 //Khi cập nhật lĩnh vực sửa
 private void btnCapNhat_Click(object sender, EventArgs e)
 {
     DialogResult dialogResult = MessageBox.Show("Bạn có muốn cập nhật", "Thông báo", MessageBoxButtons.YesNo);
     if (dialogResult == DialogResult.Yes)
     {
         if (String.IsNullOrEmpty(txbTenLinhVuc.Text))
         {
             MessageBox.Show("Tên lĩnh vực chưa hợp lệ");
             return;
         }
         //Kiểm tra thông tin sửa có tồn tại không
         if (_DMLinhVuc.Find(l => l.TenLinhVuc.Equals(txbTenLinhVuc.Text)) != null)
         {
             MessageBox.Show("Lĩnh vực đã tồn tại.");
             return;
         }
         LinhVuc lv = new LinhVuc()
         {
             MaSoLinhVuc = Int32.Parse(txbMaLinhVuc.Text),
             TenLinhVuc = txbTenLinhVuc.Text
         };
         if (LinhVucManager.edit(lv))
         {
             MessageBox.Show("Đã cập nhật.");
             reload();
             return;
         }
         MessageBox.Show("Cập nhật thất bại.");
     }
     else if (dialogResult == DialogResult.No)
     {
         return;
     }
 }
 public static int add(LinhVuc linhvuc)
 {
     using (EntitiesDataContext db = new EntitiesDataContext())
     {
         var lv = new LINHVUC();
         lv.ten = linhvuc.TenLinhVuc;
         db.LINHVUCs.InsertOnSubmit(lv);
         db.SubmitChanges();
         return lv.masolinhvuc;
     }
 }
 public static bool edit(LinhVuc linhvuc)
 {
     using (EntitiesDataContext db = new EntitiesDataContext())
     {
         //Kiểm tra lĩnh vực có tồn tại không
         LINHVUC lv;
         lv = (from b in db.LINHVUCs
               where b.masolinhvuc.Equals(linhvuc.MaSoLinhVuc)
               select b).SingleOrDefault();
         if (lv == null) return false;
         lv.ten = linhvuc.TenLinhVuc;
         lv.trangthai = linhvuc.TrangThai;
         db.SubmitChanges();
         return true;
     }
 }
        //Khi chọn Thêm Lĩnh vực
        private void btnThem_Click(object sender, EventArgs e)
        {
            string tensach = Prompt.showDialog("Tên Lĩnh vực :", "Nhập tên lĩnh vực muốn thêm.",this);
            if (!String.IsNullOrEmpty(tensach))
            {
                LinhVuc lv = new LinhVuc() { TenLinhVuc = tensach };

                    var result = LinhVucManager.add(lv);
                    if (result != 0)
                    {
                        MessageBox.Show("Đã thêm.");
                        reload();
                        return;
                    }
                    MessageBox.Show("Không thêm được");

            }
        }
 // GET: LinhVuc/Create
 public ActionResult Create()
 {
     var model = new LinhVuc();
     setAlertMessage();
     return View(model);
 }
 public ActionResult Edit(LinhVuc model, FormCollection collection)
 {
     try
     {
         // TODO: Add update logic here
         if (ModelState.IsValid)
         {
             if (LinhVucManager.edit(model))
             {
                 putSuccessMessage("Cập nhật thành công");
                 return RedirectToAction("Details", new { id = model.MaSoLinhVuc });
             }
             else
             {
                 putErrorMessage("Cập nhật thất bại");
             }
         }
         else
         {
             putModelStateFailErrors(ModelState);
         }
         return RedirectToAction("Edit", new { id = model.MaSoLinhVuc });
     }
     catch(Exception ex)
     {
         putErrorMessage(ex.Message);
         return RedirectToAction("Edit", new { id = model.MaSoLinhVuc });
     }
 }
 private void selectLinhVuc(LinhVuc lv)
 {
     if (lv != null)
     {
         txbMaLinhVuc.Text = lv.MaSoLinhVuc.ToString();
         txbTenLinhVuc.Text = lv.TenLinhVuc;
     }
 }
Example #9
0
 public Sach(SACH sach, NXB nxb, LINHVUC linhvuc)
     : this(sach, nxb)
 {
     LinhVucSach = new LinhVuc(linhvuc);
 }
Example #10
0
 public Sach(SACH sach, LINHVUC linhvuc)
     : this(sach)
 {
     LinhVucSach = new LinhVuc(linhvuc);
 }
Example #11
0
 public Sach(SACH sach, NXB nxb, LINHVUC linhvuc)
     : this(sach, nxb)
 {
     LinhVucSach = new LinhVuc(linhvuc);
 }
Example #12
0
 public Sach(SACH sach, LINHVUC linhvuc)
     : this(sach)
 {
     LinhVucSach = new LinhVuc(linhvuc);
 }