Пример #1
0
        public ActionResult ThongKeBanDo(string keyWord, string type, int?page)
        {
            try
            {
                DT_WebGISEntities MVCContext = new DT_WebGISEntities();
                TempData["TypeOfMapID"] = MVCContext.CMS_TypeOfMap.ToList();
                TempData.Keep("TypeOfMapID");


                int          TypeOfMapID  = type == null ? 0 : Convert.ToInt32(type);
                string       searchString = keyWord != null ? keyWord : "";
                CMS_Maps_DAO objDAO       = new CMS_Maps_DAO();
                var          data         = objDAO.Search(searchString, TypeOfMapID);
                ViewBag.SearchString = searchString;
                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());
            }
        }
Пример #2
0
        public ActionResult export_excel_bando(FormCollection fc)
        {
            try
            {
                DT_WebGISEntities MyContext = new DT_WebGISEntities();
                CMS_Maps_DAO      objDAO    = new CMS_Maps_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);
                MemoryStream stream         = new MemoryStream();

                using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook))
                {
                    CWorkbook workbook  = new CWorkbook(spreadsheetDoc);
                    string    sheetName = "ThongKe";

                    CSheet sheetLH = createSheet_bando(spreadsheetDoc, workbook, sheetName, data);

                    sheetLH._worksheetPart.Worksheet.Save();
                }
                string fileName    = "ThongKeBanDo.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());
            }
        }