public async Task <IActionResult> Edit(string id, [Bind("MhMa,MhTen,ChitietdanhgiaCtdgMa")] Monhoc monhoc) { if (id != monhoc.MhMa) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(monhoc); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MonhocExists(monhoc.MhMa)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["ChitietdanhgiaCtdgMa"] = new SelectList(_context.Chitietdanhgia, "CtdgMa", "CtdgMa", monhoc.ChitietdanhgiaCtdgMa); return(View(monhoc)); }
public IActionResult Edit(Monhoc monhoc) { try { mongoDatabase = GetMongoDatabase(); //Build the where condition var filter = Builders <Monhoc> .Filter.Eq("MonhocId", monhoc.MonhocId); //Build the update statement var updatestatement = Builders <Monhoc> .Update.Set("MonhocId", monhoc.MonhocId); updatestatement = updatestatement.Set("MaMH", monhoc.MaMH); updatestatement = updatestatement.Set("TenMH", monhoc.TenMH); updatestatement = updatestatement.Set("KhoaQL", monhoc.KhoaQL); //fetch the details from CustomerDB based on id and pass into view UpdateResult result = mongoDatabase.GetCollection <Monhoc>("Monhoc").UpdateOne(filter, updatestatement); if (result.IsAcknowledged == false) { return(BadRequest("Unable to update Fullname " + monhoc.TenMH)); } } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }
/// <summary> /// cập nhật môn học /// </summary> /// <param name="mamh"></param> /// <param name="tenmh"></param> /// <param name="sochi"></param> public void update(string mamh, string tenmh, int sochi) { try { dbConnect.Open(); Monhoc obj = (from Monhoc o in dbConnect.db where o.Mamh == mamh select o).FirstOrDefault(); if (obj != null) { obj.Tenmh = tenmh; obj.Sochi = sochi; dbConnect.db.Store(obj); } dbConnect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dbConnect.Close(); } }
public async Task <IActionResult> Edit(string id, [Bind("MaMh,TenMh,Tinchi,MaKhoa")] Monhoc monhoc) { if (id != monhoc.MaMh) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(monhoc); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MonhocExists(monhoc.MaMh)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["MaKhoa"] = new SelectList(_context.Khoa, "MaKhoa", "MaKhoa", monhoc.MaKhoa); return(View(monhoc)); }
public async Task <IActionResult> PutMonhoc(Monhoc monhoc) { //if (id != monhoc.Mamonhoc) //{ // return BadRequest(); //} _context.Entry(monhoc).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { //if (!MonhocExists(id)) //{ // return NotFound(); //} //else //{ // throw; //} } return(NoContent()); }
public async Task <IActionResult> Edit(string id, [Bind("MaMon,TenMon,SoTinChi")] Monhoc monhoc) { if (id != monhoc.MaMon) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(monhoc); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MonhocExists(monhoc.MaMon)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(monhoc)); }
public string getNewID() { Monhoc obj = null; string newID = "MH000001"; try { dbConnect.Open(); obj = (from Monhoc o in dbConnect.db orderby o.Mamh descending select o).FirstOrDefault(); dbConnect.Close(); int i = 0; if (obj != null && int.TryParse(obj.Mamh.Substring(2), out i)) { newID = "MH" + (i + 1).ToString("D6"); } return(newID); } catch (Exception ex) { MessageBox.Show(ex.Message); return(newID); } finally { dbConnect.Close(); } }
/// <summary> /// Kiểm tra mã môn học có trong csdl chưa /// </summary> /// <param name="mamh"></param> /// <returns></returns> public bool isExist(string ma) { Monhoc obj = this.getById(ma); if (obj == null) { return(false); } return(true); }
public async Task <IActionResult> Create([Bind("MaMon,TenMon,SoTinChi")] Monhoc monhoc) { if (ModelState.IsValid) { _context.Add(monhoc); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(monhoc)); }
public async Task <IActionResult> Create([Bind("MaMh,TenMh,Tinchi,MaKhoa")] Monhoc monhoc) { if (ModelState.IsValid) { _context.Add(monhoc); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["MaKhoa"] = new SelectList(_context.Khoa, "MaKhoa", "TenKhoa", monhoc.MaKhoa); return(View(monhoc)); }
public async Task <IActionResult> Create([Bind("MhMa,MhTen,ChitietdanhgiaCtdgMa")] Monhoc monhoc) { if (ModelState.IsValid) { _context.Add(monhoc); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["ChitietdanhgiaCtdgMa"] = new SelectList(_context.Chitietdanhgia, "CtdgMa", "CtdgMa", monhoc.ChitietdanhgiaCtdgMa); return(View(monhoc)); }
public IActionResult Create(Monhoc monhoc) { try { mongoDatabase = GetMongoDatabase(); mongoDatabase.GetCollection <Monhoc>("Monhoc").InsertOne(monhoc); } catch (Exception ex) { throw ex; } return(RedirectToAction("Index")); }
public List <Monhoc> GetAccountList() { List <Monhoc> list = new List <Monhoc>(); string qr = "SELECT * FROM dbo.Monhoc"; DataTable data = DataProvider.Instance.ExecuteQuery(qr); foreach (DataRow item in data.Rows) { Monhoc monhoc = new Monhoc(item); list.Add(monhoc); } return(list); }
public List <Monhoc> SearchAccountByUserName(string name) { List <Monhoc> list = new List <Monhoc>(); string qr = string.Format("SELECT * FROM dbo.Monhoc WHERE dbo.fuConvertToUnsign1(UserName) LIKE N'%' + dbo.fuConvertToUnsign1(N'{0}') + '%'", name); DataTable data = DataProvider.Instance.ExecuteQuery(qr); foreach (DataRow item in data.Rows) { Monhoc account = new Monhoc(item); list.Add(account); } return(list); }
public IActionResult Details(int?id) { if (id == null) { return(NotFound()); } mongoDatabase = GetMongoDatabase(); Monhoc monhoc = mongoDatabase.GetCollection <Monhoc>("Monhoc").Find <Monhoc>(k => k.MonhocId == id).FirstOrDefault(); if (monhoc == null) { return(NotFound()); } return(View(monhoc)); }
public async Task <ActionResult <Monhoc> > PostMonhoc([FromBody] Monhoc monhoc) { _context.Monhoc.Add(monhoc); try { await _context.SaveChangesAsync(); } catch (DbUpdateException) { if (MonhocExists(monhoc.Mamonhoc)) { return(Conflict()); } else { throw; } } return(CreatedAtAction("GetMonhoc", new { id = monhoc.Mamonhoc }, monhoc)); }
/// <summary> /// thêm môn học /// </summary> /// <param name="mamh"></param> /// <param name="tenmh"></param> /// <param name="sochi"></param> public void add(string mamh, string tenmh, int sochi) { Monhoc obj = new Monhoc(); obj.Mamh = mamh; obj.Tenmh = tenmh; obj.Sochi = sochi; try { dbConnect.Open(); dbConnect.db.Store(obj); dbConnect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dbConnect.Close(); } }
public int kiemtradb_mamh(string mamh) { try { dbConnect.Open(); Monhoc mhchk = (from Monhoc p in dbConnect.db where p.Mamh == mamh select p).SingleOrDefault(); if (mhchk == null) { return(0); } else { return(1); } } finally { dbConnect.Close(); } }
/// <summary> /// lấy môn học theo mã /// </summary> /// <param name="ma"></param> /// <returns></returns> public Monhoc getById(string ma) { Monhoc obj = null; try { dbConnect.Open(); obj = (from Monhoc o in dbConnect.db where o.Mamh == ma select o).FirstOrDefault(); dbConnect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dbConnect.Close(); } return(obj); }
/// <summary> /// xóa môn học /// </summary> /// <param name="ma"></param> public void delete(string ma) { try { dbConnect.Open(); Monhoc obj = (from Monhoc o in dbConnect.db where o.Mamh == ma select o).FirstOrDefault(); if (obj != null) { dbConnect.db.Delete(obj); } dbConnect.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { dbConnect.Close(); } }
public static string taomatudong(string tendoituong) { try { Opendb(ketnoicsdl._db_path); string t = ""; switch (tendoituong) { case "giaovien": Khoa khoa = (from Khoa p in ketnoicsdl.db orderby p.Makhoa descending select p).FirstOrDefault(); if (khoa == null) //xem lai giao dien khoa { t = " " + "00000001"; } else { t = khoa.Makhoa.Substring(1, 4) + Int32.Parse(khoa.Makhoa.Substring(4, 8)) + 1; } break; case "sinhvien": Sinhvien sv = (from Sinhvien p in ketnoicsdl.db orderby p.Ma descending select p).FirstOrDefault(); if (sv == null) { t = DateTime.Now.Year.ToString() + "00000001"; } else { string thu = sv.Ma.Substring(4, 8); t = sv.Ma.Substring(0, 4) + themsokhong(Int32.Parse(sv.Ma.Substring(4, 8)) + 1); } break; case "lophoc": Lop lop = (from Lop p in ketnoicsdl.db orderby p.Malop descending select p).FirstOrDefault(); if (lop == null) { t = "LH" + DateTime.Now.Year.ToString() + "000001"; } else { t = lop.Malop.Substring(1, 6) + Int32.Parse(lop.Malop.Substring(4, 6)) + 1; } break; case "monhoc": //xem lai giao dien mon hoc roi lam Monhoc mh = (from Monhoc p in ketnoicsdl.db orderby p.Mamh descending select p).FirstOrDefault(); if (mh == null) { t = "MH" + " " + "000001"; } else { t = mh.Mamh.Substring(1, 6) + Int32.Parse(mh.Mamh.Substring(4, 6)) + 1; } break; /* case "khoa": * Khoa khoa = (from Khoa p in ketnoicsdl.db * orderby p.Makhoa descending * select p).FirstOrDefault(); * if (khoa==null) * { * t = DateTime.Now.Year.ToString() + "00000001"; * } * else * { * t =khoa.Makhoa.Substring(1,4)+ Int32.Parse(sv.Ma.Substring(4, 8))+1; * } * * break;*/ } return(t); } finally { ketnoicsdl.db.Close(); } }