public ActionResult Index(string keyWord, string type, string area, string org, int?page) { try { int typeID = type != null?Convert.ToInt32(type) : 0; int areaID = area != null?Convert.ToInt32(area) : 0; int orgID = org != null?Convert.ToInt32(org) : 0; keyWord = keyWord != null ? keyWord : ""; CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); var data = objDAO.Search(keyWord, typeID, areaID, orgID); ViewBag.SearchString = keyWord; int pageSize = 10; int pageNumber = (page ?? 1); return(View(data.ToPagedList(pageNumber, pageSize))); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), "error"); Logs.WriteLog(ex); return(View()); } }
public ActionResult Edit(FormCollection fc, CMS_Documents obj) { try { if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } if (objDAO.Update(obj)) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Cập nhật văn bản thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Documents")); } else { SetAlert("Cập nhật không thành công", AlertType.Error); } } return(View(obj)); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult ThongKeVanBan(string keyWord, string type, string area, string org, int?page) { try { DT_WebGISEntities MVCContext = new DT_WebGISEntities(); TempData["TypeOfDocumentID"] = MVCContext.CMS_TypeOfDocument.ToList(); TempData.Keep("TypeOfDocumentID"); TempData["AreaOfDocument"] = MVCContext.CMS_AreaOfDocument.ToList(); TempData.Keep("AreaOfDocument"); TempData["OrganizationID"] = MVCContext.CMS_Organization.ToList(); TempData.Keep("OrganizationID"); int typeID = Convert.ToInt32(type); int areaID = Convert.ToInt32(area); int orgID = Convert.ToInt32(org); keyWord = keyWord != null ? keyWord : ""; CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); var data = objDAO.Search(keyWord, typeID, areaID, orgID).Where(x => x.Publish == true); ViewBag.SearchString = keyWord; ViewBag.TYPE = type; ViewBag.AREA = area; ViewBag.ORG = org; int pageSize = 10; int pageNumber = (page ?? 1); return(View(data.ToPagedList(pageNumber, pageSize))); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), "error"); Logs.WriteLog(ex); return(View()); } }
public void Cache_VanBan() { try { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); MemoryCache objCache = MemoryCache.Default; List <CMS_Documents_LayTatCa_Result> lstNews = objDAO.Search("", 0, 0, 0).Where(s => s.Publish == true).ToList(); objCache.Remove("VanBan"); objCache.Add("VanBan", lstNews, DateTime.Now.AddDays(SoNgayCache)); } catch (Exception ex) { Logs.WriteLog(ex); } }
public ActionResult export_excel(FormCollection fc) { try { DT_WebGISEntities MyContext = new DT_WebGISEntities(); CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); int typeID = fc["type_excel"].ToString() != "" ? Convert.ToInt32(fc["type_excel"].ToString()) : 0; int areaID = fc["area_excel"].ToString() != "" ? Convert.ToInt32(fc["area_excel"].ToString()) : 0; int orgID = fc["org_excel"].ToString() != "" ? Convert.ToInt32(fc["org_excel"].ToString()) : 0; string keyWord = fc["key_excel"].ToString(); var data = objDAO.Search(keyWord, typeID, areaID, orgID).Where(x => x.Publish == true).ToList(); MemoryStream stream = new MemoryStream(); using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) { CWorkbook workbook = new CWorkbook(spreadsheetDoc); string sheetName = "ThongKe"; CSheet sheetLH = createSheet(spreadsheetDoc, workbook, sheetName, data); sheetLH._worksheetPart.Worksheet.Save(); } string fileName = "ThongKeVanBan.xlsx"; var contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; Response.Clear(); Response.ContentType = contentType; string contentDisposition = "attachment; filename*=UTF-8''" + Uri.EscapeDataString(fileName); Response.AddHeader("content-disposition", contentDisposition); Response.AddHeader("Content-Length", stream.Length.ToString()); Response.Cache.SetCacheability(HttpCacheability.NoCache); Response.BinaryWrite(stream.ToArray()); Response.Flush(); Response.SuppressContent = true; System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest(); return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), "error"); Logs.WriteLog(ex); return(View()); } }
public ActionResult Create(FormCollection fc, CMS_Documents obj) { try { TempData.Keep("TypeOfDocumentID"); TempData.Keep("AreaOfDocument"); TempData.Keep("OrganizationID"); if (ModelState.IsValid) { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); if (objDAO.CheckExist_DocumentNumber(obj)) { SetAlert("Số hiệu đã tồn tại!", AlertType.Error); return(View()); } CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int intUserID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = intUserID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Thêm văn bản thành công", AlertType.Success); return(RedirectToAction("index", "cms_documents")); } else { ModelState.AddModelError("", "Thêm văn bản không thành công"); } return(View("Index")); } return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
// // GET: /VanBan/ public PartialViewResult Index(string title, string category, string key, string type, string area, string org, int?page) { try { ViewBag.TITLE = title; int typeID = type != null?Convert.ToInt32(type) : 0; int areaID = area != null?Convert.ToInt32(area) : 0; int orgID = org != null?Convert.ToInt32(org) : 0; key = key != null ? key : ""; #region DATA-SEARCH DT_WebGISEntities MyContext = new DT_WebGISEntities(); TempData["LoaiVanBan"] = MyContext.CMS_TypeOfDocument.ToList(); TempData["LinhVuc"] = MyContext.CMS_AreaOfDocument.ToList(); TempData["CoQuanBanHanh"] = MyContext.CMS_Organization.ToList(); TempData.Keep("LoaiVanBan"); TempData.Keep("LinhVuc"); TempData.Keep("CoQuanBanHanh"); ViewBag.KEY = key; ViewBag.TYPE = typeID; ViewBag.AREA = areaID; ViewBag.ORG = orgID; #endregion CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); HomeController homeController = new HomeController(); var listData = homeController.GetCacheVanBan().Where(x => (typeID == 0 || x.TypeOfDocumentID == typeID) && (areaID == 0 || x.AreaOfDocument == areaID) && (orgID == 0 || x.OrganizationID == orgID) && x.Abstract.ToLower().Contains(key.ToLower()) ).ToList(); int pageSize = 10; int pageNumber = (page ?? 1); return(PartialView(listData.ToPagedList(pageNumber, pageSize))); } catch (Exception ex) { Logs.WriteLog(ex); return(PartialView()); } }
public ActionResult Create() { try { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); DT_WebGISEntities MVCContext = new DT_WebGISEntities(); TempData["TypeOfDocumentID"] = MVCContext.CMS_TypeOfDocument.ToList(); TempData.Keep("TypeOfDocumentID"); TempData["AreaOfDocument"] = MVCContext.CMS_AreaOfDocument.ToList(); TempData.Keep("AreaOfDocument"); TempData["OrganizationID"] = MVCContext.CMS_Organization.ToList(); TempData.Keep("OrganizationID"); return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public JsonResult Delete(int id) { try { CMS_Documents_DAO objDAO = new CMS_Documents_DAO(); if (objDAO.Delete(id)) { //cache lai van ban WebApp.Controllers.HomeController hController = new WebApp.Controllers.HomeController(); hController.Cache_VanBan(); SetAlert("Xóa văn bản thành công", AlertType.Success); return(Json(new { status = true, message = "" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { status = false, message = "Lỗi xóa văn bản" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logs.WriteLog(ex); return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet)); } }