public ActionResult ThemMoi(ChucVu ds) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return(RedirectToAction("Index", "Login")); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null && a.Quyen.MoTa == "tcv") { if (ModelState.IsValid) { ds.XoaTam = false; db.ChucVus.InsertOnSubmit(ds); db.SubmitChanges(); } } } return(RedirectToAction("Index", "QuanlyChucvu")); } }
public string Delete(ThongBao position) { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null) { HoatDong hd = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == position.IdHoatDong); hd.SLDaDangKi = hd.SLDaDangKi - 1; DangKiThamGiaHD p = db.DangKiThamGiaHDs.SingleOrDefault(n => n.IdDangKiHD == position.IdDangKiHD); p.XoaTam = true; try { UpdateModel(hd); db.SubmitChanges(); UpdateModel(p); db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } return("ok"); } } return("Bạn không có quyền xóa"); }
public string Delete(HoatDong position) { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null) { HoatDong p = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == position.IdHoatDong); p.TrangThai = "dh"; p.XoaTam = true; try { UpdateModel(p); db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } return("ok"); } } return("Bạn không có quyền xóa"); }
/// <summary> /// Updates a customer record in the database. /// </summary> /// <param name="customer">The customer with updated values.</param> /// <returns>Number of rows affected.</returns> public int UpdateCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.Attach(entity, true); db.SubmitChanges(); // Update business object with new version customer.Version = VersionConverter.ToString(entity.Version); return(1); } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } catch { return(0); } } }
public ActionResult DoiMK(NguoiDung po, FormCollection f) { var pass = f.Get("pass").ToString(); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bHash = md5.ComputeHash(Encoding.UTF8.GetBytes(pass)); StringBuilder sbHash = new StringBuilder(); foreach (byte b in bHash) { sbHash.Append(String.Format("{0:x2}", b)); } pass = sbHash.ToString(); NguoiDung nd = (NguoiDung)Session["Taikhoan"]; NguoiDung a = db.NguoiDungs.SingleOrDefault(n => n.IdInfo == po.IdInfo); a.MatKhau = pass; try { UpdateModel(a); db.SubmitChanges(); } catch (Exception e) { } return(RedirectToAction("Index", "TrangChu")); }
public ActionResult ChinhSua(HoatDong sv, HttpPostedFileBase fileUpload) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return(RedirectToAction("Index", "Login")); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; if (fileUpload == null && nd != null) { HoatDong d = db.HoatDongs.SingleOrDefault(n => (n.IdHoatDong == sv.IdHoatDong) && (n.IdInfo == nd.IdInfo)); d.TenHoatDong = sv.TenHoatDong; d.MoTaChinh = sv.MoTaChinh; d.ThoiGianBD = sv.ThoiGianBD; d.ThoiGianKT = sv.ThoiGianKT; d.GioiHanNguoiThamGia = sv.GioiHanNguoiThamGia; d.Diadiem = sv.Diadiem; UpdateModel(d); db.SubmitChanges(); return(RedirectToAction("Index", "HDChoChinhSuaBCS")); } else if (fileUpload != null && nd != null) { HoatDong d = db.HoatDongs.SingleOrDefault(n => (n.IdHoatDong == sv.IdHoatDong) && (n.IdInfo == nd.IdInfo)); var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); ViewBag.chucvu = nd.ChucVu.MoTa; if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } d.HinhAnh = fileName; UpdateModel(d); db.SubmitChanges(); return(RedirectToAction("Index", "HDChoChinhSuaBCS")); } return(RedirectToAction("Index", "TrangChu")); } }
public string Add(HoatDong hd) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return("Bạn phải đăng nhập"); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null) { //int id = Convert.ToInt32(Request.Form["idlop"]); hd = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == hd.IdHoatDong); hd.SLDaDangKi = hd.SLDaDangKi + 1; DangKiThamGiaHD dk = new DangKiThamGiaHD(); try { UpdateModel(hd); db.SubmitChanges(); dk.IdHoatDong = hd.IdHoatDong; dk.IdInfo = nd.IdInfo; dk.TrangThai = false; dk.XoaTam = false; db.DangKiThamGiaHDs.InsertOnSubmit(dk); db.SubmitChanges(); } catch (Exception ex) { return(ex.Message); } return("ok"); } } } return("Lỗi đăng ký"); }
public ActionResult Index(HoatDong ds, HttpPostedFileBase fileUpload) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return(RedirectToAction("Index", "Login")); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null && a.Quyen.MoTa == "thd") { string message = ""; var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/images/"), fileName); if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } if (ds.ThoiGianBD < DateTime.Now || ds.ThoiGianKT < DateTime.Now || ds.ThoiGianBD > ds.ThoiGianKT) { ViewBag.message = "Ngày tháng không hợp lệ"; return(View()); } ds.HinhAnh = fileName; ds.XoaTam = false; ds.TrangThai = "cd"; ds.IdInfo = nd.IdInfo; ds.SLDaDangKi = 0; ds.ThoiGianT = DateTime.Now; ds.IdDonViToChuc = 3; db.HoatDongs.InsertOnSubmit(ds); db.SubmitChanges(); } } return(RedirectToAction("Index", "HDDaTaoBCS")); } }
/// <summary> /// Inserts a new customer record to the database. /// </summary> /// <param name="customer">The customer to be inserted.</param> public void InsertCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.InsertOnSubmit(entity); db.SubmitChanges(); // update business object with new version and id customer.CustomerId = entity.CustomerId; customer.Version = VersionConverter.ToString(entity.Version); } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } } }
/// <summary> /// Deletes a customer record from the database. /// </summary> /// <param name="customer">The customer to be deleted.</param> /// <returns>Number of rows affected.</returns> public int DeleteCustomer(Customer customer) { using (ActionDataContext db = DataContextFactory.CreateContext()) { try { CustomerEntity entity = Mapper.ToEntity(customer); db.CustomerEntities.Attach(entity, false); db.CustomerEntities.DeleteOnSubmit(entity); db.SubmitChanges(); return(1); } catch (ChangeConflictException) { throw new Exception("A change to customer record was made before your changes."); } catch (Exception) { return(0); } } }
public ActionResult Index(int id, HttpPostedFileBase excelfile) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return(RedirectToAction("Index", "Login")); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null && excelfile != null) { Lop hd = db.Lops.SingleOrDefault(n => n.IdLop == id); List <NguoiDung> lstdk = db.NguoiDungs.OrderBy(n => n.IdInfo).ToList(); ViewBag.tenlop = hd.TenLop; ViewBag.idlop = hd.IdLop; if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx")) { string path = Server.MapPath("~/Excel/" + excelfile.FileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } excelfile.SaveAs(path); // đọc dữ liệu từ file excel Excel.Application application = new Excel.Application(); Excel.Workbook workbook = application.Workbooks.Open(path); Excel.Worksheet worksheet = workbook.ActiveSheet; try { Excel.Range range = worksheet.UsedRange; List <NguoiDung> listds = new List <NguoiDung>(); for (int row = 2; row <= range.Rows.Count; row++) { NguoiDung ds = new NguoiDung(); ds.SoId = string.Concat(((Excel.Range)range.Cells[row, 2]).Text); ds.Ho_Ten = string.Concat(((Excel.Range)range.Cells[row, 3]).Text); ds.SDT = string.Concat(((Excel.Range)range.Cells[row, 4]).Text); ds.IdChucVu = 4; ds.TaiKhoan = ds.SoId; string pass = string.Concat(((Excel.Range)range.Cells[row, 7]).Text); MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider(); byte[] bHash = md5.ComputeHash(Encoding.UTF8.GetBytes(pass)); StringBuilder sbHash = new StringBuilder(); foreach (byte b in bHash) { sbHash.Append(String.Format("{0:x2}", b)); } pass = sbHash.ToString(); ds.MatKhau = pass; ds.IdLop = id; ds.XoaTam = false; listds.Add(ds); } workbook.Close(0); application.Quit(); try { if (ModelState.IsValid) { foreach (var c in lstdk) { foreach (var d in listds) { List <NguoiDung> lstdk2 = db.NguoiDungs.Where(n => n.SoId.Trim() == d.SoId.Trim()).OrderBy(n => n.IdInfo).ToList(); if (lstdk2.Count == 0) { db.NguoiDungs.InsertOnSubmit(d); db.SubmitChanges(); } foreach (var y in lstdk2) { List <NguoiDung> lstdk1 = db.NguoiDungs.Where(n => (n.IdInfo == y.IdInfo) && (n.SoId.Trim() == d.SoId.Trim()) && (n.XoaTam == false)).OrderBy(n => n.IdInfo).ToList(); if (lstdk1.Count == 1) { foreach (var t in lstdk1) { t.SoId = d.SoId; t.Ho_Ten = d.Ho_Ten; t.SDT = d.SDT; UpdateModel(t); db.SubmitChanges(); } } } } } } } catch (Exception e) { Console.WriteLine(e); db.SubmitChanges(); } } catch (Exception ex) { workbook.Close(0); application.Quit(); } return(RedirectToAction("Index", "DsSinhvienTunglop", id)); //return View(lstdk.Where(n => (n.IdLop == hd.IdLop) && (n.XoaTam == false)).ToList()); } else { ViewBag.Error = "Bạn chưa chọn file đúng !"; return(View(lstdk.Where(n => (n.IdLop == hd.IdLop) && (n.XoaTam == false)).ToList())); } } else if (nd != null && a.Quyen.MoTa == "xdssvtl" && excelfile == null) { Lop hd = db.Lops.SingleOrDefault(n => n.IdLop == id); List <NguoiDung> lstdk = db.NguoiDungs.OrderBy(n => n.IdInfo).ToList(); ViewBag.tenlop = hd.TenLop; ViewBag.idlop = hd.IdLop; return(View(lstdk.Where(n => (n.IdLop == hd.IdLop) && (n.XoaTam == false)).ToList())); } } return(RedirectToAction("Loi", "Login")); } }
public ActionResult Index(int id, HttpPostedFileBase fileUpload, HttpPostedFileBase excelfile) { if (Session["Taikhoan"] == null || Session["Taikhoan"].ToString() == "") { return(RedirectToAction("Index", "Login")); } else { NguoiDung nd = (NguoiDung)Session["Taikhoan"]; List <Rel_CV_Q> re = db.Rel_CV_Qs.OrderBy(n => n.IdChucVu).Where(n => n.IdChucVu == nd.IdChucVu).ToList(); foreach (var a in re) { if (nd != null && a.Quyen.MoTa == "xdssvthd" && fileUpload == null && excelfile == null) { HoatDong hd = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == id); List <DangKiThamGiaHD> lstdk = db.DangKiThamGiaHDs.OrderBy(n => n.IdDangKiHD).ToList(); ViewBag.tenhd = hd.TenHoatDong; ViewBag.bg = hd.Background; ViewBag.idhd = id; ViewBag.tgkt = hd.ThoiGianKT; ViewBag.tgbd = hd.ThoiGianBD; return(View(lstdk.Where(n => (n.IdHoatDong == hd.IdHoatDong) && (n.XoaTam == false)).ToList())); } if (nd != null && a.Quyen.MoTa == "tbgcn" && fileUpload != null) { HoatDong hd = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == id); List <DangKiThamGiaHD> lstdk = db.DangKiThamGiaHDs.OrderBy(n => n.IdDangKiHD).ToList(); var fileName = Path.GetFileName(fileUpload.FileName); var path = Path.Combine(Server.MapPath("~/images"), fileName); ViewBag.chucvu = nd.ChucVu.MoTa; if (System.IO.File.Exists(path)) { ViewBag.ThongBao = "Hình ảnh đã tồn tại"; } else { fileUpload.SaveAs(path); } hd.Background = fileName; UpdateModel(hd); db.SubmitChanges(); ViewBag.tenhd = hd.TenHoatDong; ViewBag.bg = hd.Background; ViewBag.idhd = id; ViewBag.tgkt = hd.ThoiGianKT; ViewBag.tgbd = hd.ThoiGianBD; return(View(lstdk.Where(n => (n.IdHoatDong == hd.IdHoatDong) && (n.XoaTam == false)).ToList())); } if (nd != null && excelfile != null) { HoatDong hd = db.HoatDongs.SingleOrDefault(n => n.IdHoatDong == id); List <DangKiThamGiaHD> lstdk = db.DangKiThamGiaHDs.OrderBy(n => n.IdDangKiHD).ToList(); ViewBag.tenhd = hd.TenHoatDong; ViewBag.bg = hd.Background; ViewBag.idhd = id; ViewBag.tgkt = hd.ThoiGianKT; ViewBag.tgbd = hd.ThoiGianBD; if (excelfile.FileName.EndsWith("xls") || excelfile.FileName.EndsWith("xlsx")) { int tong = 0; string path = Server.MapPath("~/Excel/" + excelfile.FileName); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } excelfile.SaveAs(path); // đọc dữ liệu từ file excel Excel.Application application = new Excel.Application(); Excel.Workbook workbook = application.Workbooks.Open(path); Excel.Worksheet worksheet = workbook.ActiveSheet; try { Excel.Range range = worksheet.UsedRange; List <DangKiThamGiaHD> listds = new List <DangKiThamGiaHD>(); for (int row = 2; row <= range.Rows.Count; row++) { DangKiThamGiaHD ds = new DangKiThamGiaHD(); var mssv = string.Concat(((Excel.Range)range.Cells[row, 2]).Text); List <NguoiDung> lstsv = db.NguoiDungs.ToList(); foreach (var fi in lstsv) { if (fi.SoId.Trim() == mssv) { ds.IdInfo = fi.IdInfo; } } ds.IdHoatDong = id; ds.TrangThai = Boolean.Parse(((Excel.Range)range.Cells[row, 4]).Text); ds.XoaTam = false; listds.Add(ds); } workbook.Close(0); application.Quit(); try { if (ModelState.IsValid) { HoatDong hdz = db.HoatDongs.Where(n => n.IdHoatDong == id).SingleOrDefault(); hdz.SLDaDangKi = hdz.SLDaDangKi + listds.Count(); UpdateModel(hdz); db.SubmitChanges(); foreach (var c in lstdk) { foreach (var d in listds) { List <DangKiThamGiaHD> lstdk2 = db.DangKiThamGiaHDs.Where(n => (n.IdInfo == d.IdInfo) && (n.IdHoatDong == id)).OrderBy(n => n.IdDangKiHD).ToList(); if (lstdk2.Count == 0) { d.LayCn = false; db.DangKiThamGiaHDs.InsertOnSubmit(d); UpdateModel(hdz); db.SubmitChanges(); } foreach (var y in lstdk2) { List <DangKiThamGiaHD> lstdk1 = db.DangKiThamGiaHDs.Where(n => (n.IdDangKiHD == y.IdDangKiHD) && (n.IdInfo == d.IdInfo) && (n.IdHoatDong == id)).OrderBy(n => n.IdDangKiHD).ToList(); if (lstdk1.Count == 1) { foreach (var t in lstdk1) { t.TrangThai = d.TrangThai; t.XoaTam = d.XoaTam; t.LayCn = false; UpdateModel(t); db.SubmitChanges(); } } } } } } } catch (Exception e) { Console.WriteLine(e); db.SubmitChanges(); } } catch (Exception ex) { workbook.Close(0); application.Quit(); } //return View(lstdk.Where(n => (n.IdHoatDong == hd.IdHoatDong) && (n.XoaTam == false)).ToList()); return(RedirectToAction("Index", "DsSinhvienTheohd", id)); } else { ViewBag.Error = "Bạn chưa chọn file đúng !"; return(View(lstdk.Where(n => (n.IdHoatDong == hd.IdHoatDong) && (n.XoaTam == false)).ToList())); } } } return(Content("Bạn không có quyền này")); } }