示例#1
0
 public void xoaNganh(string maNganh)
 {
     if (string.IsNullOrEmpty(maNganh))
     {
         MessageBox.Show("Vui lòng chọn dữ liệu để xoá.");
         return;
     }
     if (MessageBox.Show("Bạn có muốn xoá?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
     {
         NGANH delItem = db.NGANHs.Where(a => a.MaNganh == maNganh).FirstOrDefault();
         if (delItem != null)
         {
             db.NGANHs.DeleteOnSubmit(delItem);
             db.SubmitChanges();
             MessageBox.Show("Xoá thành công.");
             return;
         }
         else
         {
             MessageBox.Show("Dữ liệu không tồn tại.");
             return;
         }
     }
     else
     {
         return;
     }
 }
示例#2
0
        public bool DeleteNganh(int id)
        {
            NGANH obj = new NGANH(id.ToString());

            context.setState(new DeleteState());
            return(context.doAction(obj));
        }
示例#3
0
        public bool EditNganh(string manganh, string tennganh, int chitieu, double diemchuan)
        {
            NGANH obj = new NGANH(manganh, tennganh, chitieu, diemchuan);

            context.setState(new DeleteState());
            return(context.doAction(obj));
        }
示例#4
0
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            NGANH nGANH = db.NGANHs.Find(id);

            db.NGANHs.Remove(nGANH);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#5
0
 public ActionResult Edit([Bind(Include = "IDNGANH,TENNGANH")] NGANH nGANH)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nGANH).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(nGANH));
 }
示例#6
0
        public ActionResult Create([Bind(Include = "IDNGANH,TENNGANH")] NGANH nGANH)
        {
            if (ModelState.IsValid)
            {
                db.NGANHs.Add(nGANH);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(nGANH));
        }
 public ActionResult Edit([Bind(Include = "MaNganh,MaKhoa,TenNganh")] NGANH nGANH)
 {
     if (ModelState.IsValid)
     {
         db.Entry(nGANH).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.MaKhoa = new SelectList(db.KHOAs, "MaKhoa", "TenKhoa", nGANH.MaKhoa);
     return(View(nGANH));
 }
示例#8
0
        // GET: Admin/NGANHs/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NGANH nGANH = db.NGANHs.Find(id);

            if (nGANH == null)
            {
                return(HttpNotFound());
            }
            return(View(nGANH));
        }
        // GET: PDT/NGANHs/Edit/5
        public ActionResult Edit(string id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            NGANH nGANH = db.NGANHs.Find(id);

            if (nGANH == null)
            {
                return(HttpNotFound());
            }
            ViewBag.MaKhoa = new SelectList(db.KHOAs, "MaKhoa", "TenKhoa", nGANH.MaKhoa);
            return(View(nGANH));
        }
        public ActionResult Create([Bind(Include = "MaNganh,MaKhoa,TenNganh")] NGANH nGANH)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.NGANHs.Add(nGANH);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }

                ViewBag.MaKhoa = new SelectList(db.KHOAs, "MaKhoa", "TenKhoa", nGANH.MaKhoa);
                return(View(nGANH));
            }
            catch (Exception e)
            {
                return(RedirectToAction("Create", "NGANHs", new { id = 1 }));
            }
        }
示例#11
0
        public List <NGANH> GetAll()
        {
            List <NGANH> nganhs = new List <NGANH>();
            string       query  = "SELECT * FROM NGANH";
            DataTable    data   = DataProvider.Instance.ExecuteQuery(query);

            foreach (DataRow item in data.Rows)
            {
                string MaN     = item["MaNganh"].ToString();
                string TenN    = item["TenNganh"].ToString();
                int    SoSVHoc = (int)item["SoSinhVienTheoHoc"];
                int    SoCDMax = (int)item["SoChuyenDeToiDa"];

                NGANH NG = new NGANH(MaN, TenN, SoSVHoc, SoCDMax);
                nganhs.Add(NG);
            }

            return(nganhs);
        }
示例#12
0
        public NGANH GetByID(string id)
        {
            string query = "SELECT * FROM NGANH WHERE MaNganh = @maN ";

            object[] para = new object[]
            {
                id
            };
            DataTable data = DataProvider.Instance.ExecuteQuery(query, para);
            DataRow   item = data.Rows[0];

            string MaN     = item["MaNganh"].ToString();
            string TenN    = item["TenNganh"].ToString();
            int    SoSVHoc = (int)item["SoSinhVienTheoHoc"];
            int    SoCDMax = (int)item["SoChuyenDeToiDa"];

            NGANH NG = new NGANH(MaN, TenN, SoSVHoc, SoCDMax);

            return(NG);
        }
示例#13
0
        public JsonResult PostNganh(NGANH nganh)
        {
            ApiResult result = new ApiResult();

            if (nganh is null)
            {
                result.Message = "Vui lòng điền đủ thông tin";
                return(Json(result.Data));
            }
            using (DACSEntities db = new DACSEntities())
            {
                NGANH n = new NGANH();
                if (nganh.IDNGANH > 0)
                {
                    n = db.NGANHs.Where(x => x.IDNGANH == nganh.IDNGANH).FirstOrDefault();
                }
                if (n is null)
                {
                    result.Message = "Vui lòng thử lại";
                    return(Json(result));
                }
                n.NAMENGANH  = nganh.NAMENGANH;
                n.IDNIENKHOA = nganh.IDNIENKHOA;

                if (nganh.IDNGANH == 0)
                {
                    db.NGANHs.Add(n);
                }
                try
                {
                    db.SaveChanges();
                    result.Success = true;
                }
                catch (Exception ex)
                {
                    result.Message = ex.Message;
                }
            }
            return(Json(result));
        }
示例#14
0
        public bool xoaNganhs(string manganh)
        {
            NGANH nganh = db.NGANHs.Where(a => a.MaNganh == manganh).FirstOrDefault();

            if (nganh != null)
            {
                try
                {
                    db.NGANHs.DeleteOnSubmit(nganh);
                    db.SubmitChanges();
                }
                catch (Exception ex)
                {
                    return(false);
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
示例#15
0
        public void suaNganh(string manganh, string tennganh, string makhoa)
        {
            if (string.IsNullOrEmpty(tennganh) || string.IsNullOrEmpty(manganh) || string.IsNullOrEmpty(makhoa))
            {
                MessageBox.Show("Vui lòng chọn dữ liệu để sửa.");
                return;
            }
            NGANH suaNganh = db.NGANHs.Where(a => a.MaNganh == manganh).FirstOrDefault();

            if (suaNganh != null)
            {
                suaNganh.TenNganh = tennganh;
                suaNganh.MaKhoa   = int.Parse(makhoa);
                db.SubmitChanges();
                MessageBox.Show("Sửa thành công.");
                return;
            }
            else
            {
                MessageBox.Show("Dữ liệu không tồn tại.");
                return;
            }
        }
示例#16
0
        public bool suaNganh(string manganh, string tennganh, string makhoa)
        {
            NGANH nganh = db.NGANHs.Where(a => a.MaNganh == manganh).FirstOrDefault();

            if (nganh != null)
            {
                try
                {
                    nganh.TenNganh = tennganh;
                    nganh.MaKhoa   = int.Parse(makhoa);
                    db.SubmitChanges();
                    return(true);
                }
                catch (Exception ex)
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
示例#17
0
        public void themNganh(string manganh, string tennganh, string makhoa)
        {
            if (string.IsNullOrEmpty(tennganh) || string.IsNullOrEmpty(manganh) || string.IsNullOrEmpty(makhoa))
            {
                MessageBox.Show("Vui lòng nhập đầy đủ thông tin để thêm.");
                return;
            }
            NGANH newNganh = new NGANH();

            newNganh.TenNganh = tennganh;
            newNganh.MaNganh  = manganh;
            newNganh.MaKhoa   = int.Parse(makhoa);
            try
            {
                db.NGANHs.InsertOnSubmit(newNganh);
                db.SubmitChanges();
                MessageBox.Show("Thêm thành công.");
                return;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thêm không thành công.");
            }
        }
示例#18
0
        public ActionResult Delete(int id)
        {
            NGANH nganh = db.NGANHs.Find(id);

            return(RedirectToAction("Index"));
        }