using dccdc.BLL; using dccdc.DAL; using System; using System.Collections.Generic; using System.Data; using System.Data.OleDb; using System.IO; using System.Text; using System.Web.Mvc; using System.Web.WebPages; namespace dccdc.Controllers { public class InspectionController : Controller { // GET: Inspection public ActionResult Index() { return View(); } /// /// 从业主检 查询数据 /// /// /// /// /// /// public string getData(string start,string end,string where,string sort) { var u= Session["loginUser"] as Models.ERPUser; if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end) || string.IsNullOrEmpty(sort)) return Newtonsoft.Json.JsonConvert.SerializeObject(null); var bll = new ProfessionalExamRegisterBll(); var result = bll.getCyzj(start, end, where, sort,Common.Global.jgid); return Newtonsoft.Json.JsonConvert.SerializeObject(new { Rows = result }); } public JsonResult getData2(string id) { if (string.IsNullOrEmpty(id)) return Json(null); var bll = new professionalExam_project_resultBll(); var result = bll.getPersonResult(id, ""); return Json(new { Rows = result }); } [AllowAnonymous] public JsonResult getData3(string id) { if (string.IsNullOrEmpty(id)) return Json(null); var bll = new professionalExam_project_resultBll(); var result = bll.getPersonResult(id, ""); return Json( result , JsonRequestBehavior.AllowGet); } //2:保存 6:暂不发证 4:合格 5:不合格 8:撤回 public bool op(string id, string sort, string zjjl, string zjjg) { if (string.IsNullOrEmpty(id) || string.IsNullOrEmpty(sort)) return false; var bll = new ProfessionalExamRegisterBll(); var result = bll.op(id, sort, zjjl, zjjg, Session["loginUser"] as Models.ERPUser); return result; } public bool opAll(string ids) { if (string.IsNullOrEmpty(ids)) return false; var bll = new ProfessionalExamRegisterBll(); var result = bll.opAll(ids.TrimEnd(','), Session["loginUser"] as Models.ERPUser); return result; } public bool opFj(string id, string zjjl, string zjjg, string items) { if (string.IsNullOrEmpty(id)) return false; var bll = new ProfessionalExamRegisterBll(); var result = bll.opFj(id, zjjl, zjjg, Session["loginUser"] as Models.ERPUser, items); return result; } public JsonResult getOne(string id) { if (string.IsNullOrEmpty(id)) return Json(null); var bll = new ProfessionalExamRegisterBll(); var result = bll.getOne(id); return Json(result, JsonRequestBehavior.AllowGet); } [AllowAnonymous] public JsonResult getOne1(string id) { if (string.IsNullOrEmpty(id)) return Json(null); var bll = new ProfessionalExamRegisterBll(); var result = bll.getOne(id); List rs = new List(); rs.Add(result); return Json(rs, JsonRequestBehavior.AllowGet); } public ActionResult getCl() { return View(); } public JsonResult getClData(string start, string end, string type, string status, bool flag =false) { if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end)) return Json(null, JsonRequestBehavior.AllowGet); var bll = new ProfessionalExamRegisterBll(); var result = bll.getCl(start, end, type, status,flag); return Json(new { Rows = result }, JsonRequestBehavior.AllowGet); } public ActionResult getZjjl() { return View(); } public JsonResult getZjjlData() { var bll = new MainDoctorConclusionMaintainBll(); var result = bll.GetAllList("", "是"); return Json(new { Rows = result }); } public ActionResult getZjjg(string id) { return View(Convert.ToInt32(id)); } public ActionResult getZjjgData(string id) { if (string.IsNullOrEmpty(id)) return Json(null); var bll = new professionalExam_project_resultBll(); var result = bll.getPersonResult(id, "不合格"); return Json(new { Rows = result }); } /// /// 根据personid获取体检小组列表 /// /// /// public ActionResult getTjxm(string id) { //ViewData["team"] = new SelectList(new ExamGroupMaintainBll().GetAllListTrue(""), "id", "team_name"); ViewData["team"] = new SelectList(new ExamGroupMaintainDal().GetGroupListByPersonId(id), "id", "team_name"); return View(Convert.ToInt32(id)); } /// /// 获取所有体检项目 /// /// /// /// public ActionResult getTjxmData(string teamid,string id) { var bll = new ExamProjectMaintainBll(); var result = bll.GetAllList2("", teamid, id); return Json(new { Rows = result }); } /// /// 根据personid获取体检结果异常项目 /// /// /// public ActionResult getTjxmData2(string id) { var bll = new ExamProjectMaintainBll(); var result = bll.GetAllList3("", id); return Json(new { Rows = result }); } /// /// 根据personid获取其体检项目 /// /// /// public ActionResult getTjxmData3(string teamid, string id) { var bll = new ExamProjectMaintainBll(); var result = bll.GetAllList4("", teamid, id); return Json(new { Rows = result }); } //导出excel public JsonResult downFile(string start, string end, string type, string status, bool flag = false) { if (string.IsNullOrEmpty(start) || string.IsNullOrEmpty(end)) return Json(null, JsonRequestBehavior.AllowGet); var bll = new ProfessionalExamRegisterBll(); var result = bll.getCl(start, end, type, status, flag); DataTable dt = new DataTable(); dt.Columns.Add("体检编号"); dt.Columns.Add("姓名"); dt.Columns.Add("企业"); dt.Columns.Add("登记日期"); dt.Columns.Add("联系电话"); foreach (var m in result) { DataRow mdr = dt.NewRow(); mdr["体检编号"] = m.physical_num; mdr["姓名"] = m.person_name; mdr["企业"] = m.util_name; mdr["登记日期"] = m.register_date; mdr["联系电话"] = m.phone; 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); ExportExcel(dt, path + file); return Json(new { State = "1", Message = file }); } catch (Exception ex) { return Json(new { State = "0", Message = ex.Message }); } } //导出excel方法 public void ExportExcel(DataTable dt,string savePath) { //设置导出文件路径 //string path = HttpContext.Current.Server.MapPath("Export/"); ////设置新建文件路径及名称 //string savePath = path + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".xls"; //创建文件 FileStream file = new FileStream(savePath, FileMode.CreateNew, FileAccess.Write); //以指定的字符编码向指定的流写入字符 StreamWriter sw = new StreamWriter(file, Encoding.GetEncoding("GB2312")); StringBuilder strbu = new StringBuilder(); //写入标题 for (int i = 0; i < dt.Columns.Count; i++) { strbu.Append(dt.Columns[i].ColumnName.ToString() + "\t"); } //加入换行字符串 strbu.Append(Environment.NewLine); //写入内容 for (int i = 0; i < dt.Rows.Count; i++) { for (int j = 0; j < dt.Columns.Count; j++) { strbu.Append(dt.Rows[i][j].ToString() + "\t"); } strbu.Append(Environment.NewLine); } sw.Write(strbu.ToString()); sw.Flush(); file.Flush(); sw.Close(); sw.Dispose(); file.Close(); file.Dispose(); } 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; } } }