public ActionResult Create(FormCollection f) { if (ModelState.IsValid) { GIAO_VIEN gv = new GIAO_VIEN(); var ma_gv = db.GIAO_VIEN.Find("1000000001"); if (ma_gv == null) { gv.MA_GV = "1000000001"; } else { int ma = int.Parse(db.GIAO_VIEN.Select(m => m.MA_GV).ToList().Last()) + 1; gv.MA_GV = ma.ToString(); } gv.HO_TEN = f["name"]; gv.SDT = f["SDT"]; gv.NG_SINH = Convert.ToDateTime(f["ngaysinh"]); gv.GIOI_TINH = f["Gioitinh"]; gv.EMAIL = f["email"]; db.GIAO_VIEN.Add(gv); bASE.create_TAI_KHOAN(gv.MA_GV); db.SaveChanges(); return(RedirectToAction("Index", "GIAO_VIEN", new { area = "Admin" })); } return(View()); }
public ActionResult Edit([Bind(Include = "MA_GV,HO_TEN,SDT,GIOI_TINH,EMAIL,NG_SINH")] GIAO_VIEN gIAO_VIEN) { if (ModelState.IsValid) { db.Entry(gIAO_VIEN).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.MA_GV = new SelectList(db.TAI_KHOAN, "TAI_KHOAN1", "MAT_KHAU", gIAO_VIEN.MA_GV); return(View(gIAO_VIEN)); }
public ActionResult DeleteConfirmed(string id) { GIAO_VIEN gIAO_VIEN = db.GIAO_VIEN.Find(id); db.GIAO_VIEN.Remove(gIAO_VIEN); TAI_KHOAN tAI_KHOAN = db.TAI_KHOAN.Find(id); db.TAI_KHOAN.Remove(tAI_KHOAN); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Admin/GIAO_VIEN/Delete/5 public ActionResult Delete(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GIAO_VIEN gIAO_VIEN = db.GIAO_VIEN.Find(id); if (gIAO_VIEN == null) { return(HttpNotFound()); } return(View(gIAO_VIEN)); }
//====================================================== // GET: Admin/GIAO_VIEN/Edit/5 public ActionResult Edit(string id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } GIAO_VIEN gIAO_VIEN = db.GIAO_VIEN.Find(id); if (gIAO_VIEN == null) { return(HttpNotFound()); } ViewBag.MA_GV = new SelectList(db.TAI_KHOAN, "TAI_KHOAN1", "MAT_KHAU", gIAO_VIEN.MA_GV); return(View(gIAO_VIEN)); }
private void Remove() { try { if (System.Windows.Forms.MessageBox.Show("Xác nhận xoá? ", "Thông Báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { GIAO_VIEN gv = data.GIAO_VIENs.Single(item => item.MaGiaoVien == txt_id.Text); data.GIAO_VIENs.DeleteOnSubmit(gv); data.SubmitChanges(); } } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning); } finally { GetData(); } }
private void Add() { var id = data.GIAO_VIENs.Where(u => u.MaGiaoVien == txt_id.Text.Trim()).SingleOrDefault <GIAO_VIEN>(); if (id != null) { tb_thongbao.Text = "Mã Giáo viên đã tồn tại."; return; } else { GIAO_VIEN gv = new GIAO_VIEN(); gv.MaGiaoVien = txt_id.Text; gv.HoTenGiaoVien = txt_ten.Text; gv.NgaySinh = date_ngaysinh.DateTime; gv.DiaChi = txt_diachi.Text; gv.Email = txt_email.Text; data.GIAO_VIENs.InsertOnSubmit(gv); data.SubmitChanges(); } }
private void Datagrid_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { int rowindex = datagrid.SelectedIndex; if (rowindex == -1) { Clear(); } else { GIAO_VIEN gv = (GIAO_VIEN)datagrid.SelectedItem; txt_id.Text = gv.MaGiaoVien; txt_ten.Text = gv.HoTenGiaoVien; date_ngaysinh.DateTime = gv.NgaySinh; } } catch (Exception ex) { throw; } }
private void Update() { GIAO_VIEN gv = (data.GIAO_VIENs.Where(t => t.MaGiaoVien == txt_id.Text).SingleOrDefault <GIAO_VIEN>()); try { gv.HoTenGiaoVien = txt_ten.Text; gv.NgaySinh = date_ngaysinh.DateTime; gv.Email = txt_email.Text; gv.Email = txt_email.Text; data.SubmitChanges(); tb_thongbao.Text = "Chỉnh sửa thành công!"; } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message, "Lỗi"); } finally { GetData(); } }