tijian_tieying/web/dccdc/Controllers/PersonalCheckController.cs
2025-02-20 12:14:39 +08:00

173 lines
6.0 KiB
C#

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 static dccdc.Controllers.ResultController;
/**
* 个人信息审核
*
*/
namespace dccdc.Controllers
{
public class PersonalCheckController : Controller
{
// GET: Inspection
public ActionResult Index()
{
return View();
}
public JsonResult getData(string filtrate)
{
var bll = new PersonalCheckBll();
List<PersonalCheckModel> result = bll.getList(filtrate);
//DateTimeFormatInfo dtFormat = new DateTimeFormatInfo();
//dtFormat.ShortDatePattern = "yyyy/MM/dd";
//foreach (var m in result)
//{
// DateTime date = Convert.ToDateTime("2011/05/26", dtFormat);
// m.passTime = date.ToString();
//}
return Json(new { Rows = result });
}
//详情
[HttpGet]
public ActionResult getDetails(string id)
{
if (string.IsNullOrEmpty(id))
return Json(null);
var bll = new PersonalCheckBll();
if (id != "")
{
var model = bll.getOne(id);
var viewModel = new PersonalCheckModel
{
id = model.id,
name = model.name,
ident = model.ident,
phone = model.phone,
type = model.type,
nickname = model.nickname,
passTime = model.passTime,
unit = model.unit,
};
return View(viewModel);
}
else
{
return View();
}
}
//修改、添加
public ActionResult amend(string id)
{
var al = new List<Droplist>() { new Droplist { Value = "0", Title = "未审核" }, new Droplist { Value = "1", Title = "通过" }, new Droplist { Value = "2", Title = "未通过" } };
ViewData["type"] = new SelectList(al, "Value", "Title");
//ViewData["yszyb"] = new SelectList(new PhysicalQueryBll().GetAllList2(), "id", "state");
PersonalCheckModel model;
if (string.IsNullOrEmpty(id))
{
model = new PersonalCheckModel() { };
}
else
{
model = new PersonalCheckBll().getOne(id);
}
return View(model);
}
//保存
[HttpPost]
public ActionResult amend(PersonalCheckModel model)
{
ModelState.Remove("id");
if (!ModelState.IsValid)
{
var errors = ModelState.Values.SelectMany(v => v.Errors);
var al = new List<Droplist>() { new Droplist { Value = "0", Title = "未审核" }, new Droplist { Value = "1", Title = "通过" }, new Droplist { Value = "2", Title = "未通过" } };
ViewData["ischeck"] = new SelectList(al, "Value", "Title");
return View(model);
}
if (model.id ==null) {
var erpUser = Session["loginUser"] as Models.ERPUser;
if (erpUser != null)
{
model.user_id = erpUser.ID;
}
}
PersonalCheckBll bll = new PersonalCheckBll();
return Json(bll.save(model));
}
//审核
public JsonResult audit(string id,string type) {
var bll = new PersonalCheckBll();
DateTime createTime = System.DateTime.Now;
return Json(bll.updateType(id, type));
}
//导出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);
return Json(new { State = "1", Message = file });
}
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;
}
}
}