using dccdc.BLL; using dccdc.Models; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Data; using System.Globalization; using System.IO; using System.Linq; using System.Web; using System.Web.Mvc; using xiaoy.Excel; using static dccdc.Controllers.DictionariesController; /** * 个人信息审核 * */ namespace dccdc.Controllers { public class PhysicalQueryController : Controller { // GET: Inspection public ActionResult Index() { return View(); } public JsonResult getData(string start, string end) { var bll = new PhysicalQueryBll(); List result = bll.GetAllList(start,end); return Json(new { Rows = result }); } //修改 public ActionResult physicalQueryMessage(string id) { var al = new List() { new Droplist { Value = "0", Title = "已预约" }, new Droplist { Value = "1", Title = "已体检" } }; ViewData["state"] = new SelectList(al, "Value", "Title"); PhysicalQueryModel model; if (string.IsNullOrEmpty(id)) { model = new PhysicalQueryModel() { }; } else { model = new PhysicalQueryBll().getOne(id); } return View(model); } [HttpPost] public ActionResult physicalQueryMessage(PhysicalQueryModel model) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(v => v.Errors); var al = new List() { new Droplist { Value = "0", Title = "已预约" }, new Droplist { Value = "1", Title = "已体检" } }; ViewData["ischeck"] = new SelectList(al, "Value", "Title"); return View(model); } PhysicalQueryBll bll = new PhysicalQueryBll(); return Json(bll.save(model)); } //取消预约 public ActionResult abolishOrder(string id) { PhysicalQueryModel model; if (string.IsNullOrEmpty(id)) { model = new PhysicalQueryModel() { }; } else { model = new PhysicalQueryBll().getOne(id); } return View(model); } [HttpPost] public ActionResult abolishOrder(PhysicalQueryModel model) { ModelState.Remove("id"); if (!ModelState.IsValid) { return View(model); } PhysicalQueryBll bll = new PhysicalQueryBll(); return Json(bll.abolishOrder(model)); } //导出excel public JsonResult downFile(string start, string end) { start = start + " 00:00:00"; end = end + " 23:59:59"; var result = new BLL.PhysicalQueryBll().downFile(start, end); DataTable dt = new DataTable(); dt.Columns.Add("姓名"); dt.Columns.Add("出生日期"); dt.Columns.Add("电话"); dt.Columns.Add("所属单位"); dt.Columns.Add("身份证号码"); dt.Columns.Add("预约时间"); dt.Columns.Add("体检状态"); foreach (var v in result) { DataRow mdr = dt.NewRow(); mdr["姓名"] = v.name; mdr["出生日期"] = v.test_date; mdr["电话"] = v.phone; mdr["所属单位"] = v.test_org; mdr["身份证号码"] = v.ident; mdr["预约时间"] = v.order_date; mdr["体检状态"] = v.state; dt.Rows.Add(mdr); } string file = Guid.NewGuid().ToString("N") + ".xlsx"; string path = Server.MapPath("~/exp/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } try { xiaoy.Excel.ExcelFile.SetData(dt, path + file, xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes); return Json(new { State = "1", Message = file }); } catch (Exception ex) { return Json(new { State = "0", Message = ex.Message }); } } //{ // PhysicalQueryBll bll = new PhysicalQueryBll(); // DataTable expdt; // if (start !=null && start !=""&& end !=null && end != "") // { // expdt = bll.downFile(start,end); // } // else // { // return Json(new { State = 0, Message = "没有导出的数据" }); // } // string path = Server.MapPath("~/export"); // if (!System.IO.Directory.Exists(path)) // { // System.IO.Directory.CreateDirectory(path); // } // string fn = Guid.NewGuid().ToString("N") + ".xlsx"; // path += "\\" + fn; // if (expdt == null) // { // return Json(new { State = 0, Message = "没有要导出的数据!" }); // } // try // { // ExcelFile.SetData(expdt, path, xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes); // //xiaoy.Excel.ExcelFile.SetData(expdt, path, xiaoy.Excel.ExcelVersion.Excel12, xiaoy.Excel.HDRType.Yes); // return Json(new { State = 1, Message = Url.Content("~/export/" + fn) }); // } // catch (Exception ex) // { // return Json(new { State = 0, Message = ex.Message }); // } //} public FileResult down(string file) { string path = Server.MapPath("~/exp/"); if (file.EndsWith("drimp")) return File(path + file, "application/drimp", DateTime.Now.ToString("yyyyMMdd") + ".drimp"); if (file.EndsWith("xlsx")) return File(path + file, "application/Excel", DateTime.Now.ToString("yyyyMMdd") + ".xlsx"); if (file.EndsWith("syzip")) return File(path + file, "application/Zip", DateTime.Now.ToString("yyyyMMdd") + ".syzip"); return null; } } }