public ActionResult ThongKeCauHoi(string keyWord, string type, int?page) { try { DT_WebGISEntities MVCContext = new DT_WebGISEntities(); TempData["TypeOfQuestionID"] = MVCContext.CMS_TypeOfQuestion.ToList(); TempData.Keep("TypeOfQuestionID"); int typeID = type != null?Convert.ToInt32(type) : 0; keyWord = keyWord != null ? keyWord : ""; CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); var data = objDAO.Search(keyWord, typeID, true); ViewBag.SearchString = keyWord; ViewBag.TYPE = type; 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 PartialViewResult DSHoiDap(string title, string category, string key, string type, int?page) { try { ViewBag.TITLE = title; ViewBag.CATE = category; int typeID = type != null?Convert.ToInt32(type) : 0; key = key != null ? key : ""; CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); var data = objDAO.Search(key, typeID, true); int pageSize = 10; int pageNumber = (page ?? 1); using (DT_WebGISEntities MyContext = new DT_WebGISEntities()) { TempData["LoaiCauHoi"] = MyContext.CMS_TypeOfQuestion.ToList(); TempData.Keep("LoaiCauHoi"); } ViewBag.KEY = key; ViewBag.TYPE = typeID; return(PartialView(data.ToPagedList(pageNumber, pageSize))); } catch (Exception ex) { Logs.WriteLog(ex); return(PartialView()); } }
public ActionResult Create(FormCollection fc, CMS_Questions obj) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); TempData.Keep("TypeOfQuestionID"); if (ModelState.IsValid) { CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); CSF_Users_DAO objUserDao = new CSF_Users_DAO(); int userID = objUserDao.GetUserIDByUserName(HttpContext.User.Identity.Name); obj.UserCreate = userID; int ReturnID = objDAO.Insert(obj); if (ReturnID > 0) { SetAlert("Thêm câu hỏi thành công", AlertType.Success); return(RedirectToAction("Index", "CMS_Questions")); } else { ModelState.AddModelError("", "Thêm 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()); } }
public ActionResult Create() { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); DT_WebGISEntities MVCContext = new DT_WebGISEntities(); TempData["TypeOfQuestionID"] = MVCContext.CMS_TypeOfQuestion.ToList(); TempData.Keep("TypeOfQuestionID"); return(View()); } catch (Exception ex) { SetAlert("Lỗi" + ex.Message.ToString(), AlertType.Error); Logs.WriteLog(ex); return(View()); } }
public ActionResult export_excel_cauhoi(FormCollection fc) { try { DT_WebGISEntities MyContext = new DT_WebGISEntities(); CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); int typeID = fc["type_excel"].ToString() != "" ? Convert.ToInt32(fc["type_excel"].ToString()) : 0; string keyWord = fc["key_excel"].ToString(); var data = objDAO.Search(keyWord, typeID, true); MemoryStream stream = new MemoryStream(); using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook)) { CWorkbook workbook = new CWorkbook(spreadsheetDoc); string sheetName = "ThongKe"; CSheet sheetLH = createSheet_cauhoi(spreadsheetDoc, workbook, sheetName, data); sheetLH._worksheetPart.Worksheet.Save(); } string fileName = "ThongKeCauHoi.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 Index(string keyWord, string type, int?page) { try { int typeID = type != null?Convert.ToInt32(type) : 0; keyWord = keyWord != null ? keyWord : ""; CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); var data = objDAO.Search(keyWord, typeID, null); 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 JsonResult Delete(int id) { try { //if (!this.HasPermission) return RedirectToAction("Unauthorized", "Home"); CMS_Questions_DAO objDAO = new CMS_Questions_DAO(); if (objDAO.Delete(id)) { SetAlert("Xóa câu hỏi 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 câu hỏi" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { Logs.WriteLog(ex); return(Json(new { status = false, message = "Lỗi: " + ex }, JsonRequestBehavior.AllowGet)); } }