using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using Bowin.Common.Linq;
using Bowin.Common.JSON;
using Bowin.Web.Controls.Mvc;
using EMIS.Utility;
using EMIS.Web.Controls;
using EMIS.ViewModel;
using EMIS.ViewModel.EnrollManage.NewStudentManage;
using EMIS.CommonLogic.EnrollManage.NewStudentManage;
namespace EMIS.Web.Controllers.EnrollManage.NewStudentManage
{
[Authorization]
public class NewStudentCollegeController : Controller
{
public INewStudentCollegeServices newStudentCollegeServices { get; set; }
///
/// 新生分配页面
///
///
public ActionResult List()
{
return View();
}
///
/// 新生分配页面列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var gradeID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
var isPhotoUrl = pararms.getExtraInt("IsPhotoUrlDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsPhotoUrlDropdown");
return base.Json(newStudentCollegeServices.GetNewStudentCollegeViewGrid(configuretView, campusID, collegeID, gradeID, standardID, educationID, learningformID, learnSystem, isPhotoUrl, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑
///
///
///
[HttpGet]
public ActionResult Edit(Guid? newStudentID)
{
NewStudentView newStudentView = new NewStudentView();
if (newStudentID.HasValue && newStudentID != Guid.Empty)
{
newStudentView = newStudentCollegeServices.GetNewStudentCollegeView(newStudentID);
}
return View(newStudentView);
}
///
/// 导入分配
///
///
///
///
[HttpGet]
public ActionResult AssignCollegeImport(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "点击查看失败原因...";
}
ViewBag.operationTips = operationTips;
return View();
}
///
/// 导入分配
///
///
///
[HttpPost]
public ActionResult AssignCollegeImport(HttpPostedFileBase file)
{
try
{
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
}
//注:只获取Excel模板中的有效列
Dictionary cellheader = new Dictionary
{
{ "OrderNoStr", "序号" }, //序号
{ "IDNumber", "身份证号" }, //身份证号
{ "Name", "姓名" }, //姓名
{ "GradeStr", "年级" }, //年级
{ "CollegeNo", RSL.Get("CollegeCode") }, //院系所代码
{ "ErrorMessage", "未导入原因" }
};
StringBuilder errorMsg = new StringBuilder(); // 错误信息
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
List errList = new List();
List dataList = new List();
int? inCount = 0; //导入个数
int? upCount = 0; //更新个数
int? errCount = 0; //失败个数
newStudentCollegeServices.NewStudentAssignCollegeImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
System.IO.File.Delete(sourcePhysicalPath);//删除本地缓存文件
if (errList.Count() > 0)
{
//获取错误数据文件路径
string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "名单归站导入失败文件", sourcePhysicalPath));
ViewBag.ErrorFile = errorWebPath;
string Errinfo = string.Format("提示:{0}个新生分配成功,{1}个新生分配更新成功,{2}个新生分配失败,点击查看。", inCount, upCount, errCount);
ViewBag.operationTips = Errinfo;
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = Errinfo,
url = Url.Action("AssignCollegeImport").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
});
}
else
{
string successInfo = string.Format("提示:{0}个新生分配成功,{1}个新生分配更新成功。", inCount, upCount);
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = successInfo,
url = Url.Action("List").AddMenuParameter()
});
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = "导入失败,原因:" + ex.Message,
url = Url.Action("AssignCollegeImport").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
});
}
}
///
/// 名单分配批量新增
///
///
[HttpGet]
public ActionResult AssignCollegeBatchAdd()
{
NewStudentView newStudentView = new NewStudentView();
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
newStudentView.CollegeID = user.CollegeID;
return View(newStudentView);
}
///
/// 名单分配批量新增
///
///
///
[HttpPost]
public ActionResult AssignCollegeBatchAdd(NewStudentView newStudentView)
{
try
{
var newStudentIDList = Request["newStudentIDs"].JsonToObject>();
string result = newStudentCollegeServices.NewStudentAssignCollegeConfirm(newStudentView.CollegeID, newStudentIDList);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "分配成功" + result + "。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "分配失败,原因:" + ex.Message
});
}
}
///
/// 未分配名单页面列表查询
///
///
///
[HttpPost]
public ActionResult UnAssignCollegeList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var gradeID = pararms.getExtraInt("DictionaryGrade") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryGrade");
var standardID = pararms.getExtraInt("DictionaryStandard") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryStandard");
var educationID = pararms.getExtraInt("DictionaryEducation") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryEducation");
var learningformID = pararms.getExtraInt("DictionaryLearningform") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryLearningform");
var learnSystem = pararms.getExtraString("DictionaryLearnSystem");
return base.Json(newStudentCollegeServices.GetUnAssignNewStudentViewGrid(configuretView, gradeID, standardID, educationID, learningformID, learnSystem, (int)pararms.page, (int)pararms.rows));
}
///
/// 删除照片(批量删除)
///
///
///
[HttpPost]
public ActionResult PicDelete(string newStudentIDs)
{
try
{
List list = newStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
newStudentCollegeServices.PicDelete(list);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "删除照片成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "删除照片失败:" + ex.Message
});
}
}
///
/// 取消分配
///
///
///
[HttpPost]
public ActionResult CancleAssign(string newStudentIDs)
{
try
{
List list = newStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
string result = newStudentCollegeServices.NewStudentCollegeCancleAssign(list);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "取消分配成功" + result + "。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "取消分配失败,原因:" + ex.Message
});
}
}
///
/// 提交(需对招生专业进行验证,再提交,同时生成录取通知书编号(默认:年级+院系所代码+5位流水号))
/// 注:个性化生成录取通知书编号(暂不考虑)
///
///
///
[HttpPost]
public ActionResult SubmitAssign(string newStudentIDs)
{
try
{
List list = newStudentIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => (Guid?)new Guid(x)).ToList();
string result = newStudentCollegeServices.NewStudentCollegeSubmitAssign(list);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "提交成功" + result + "。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "提交失败,原因:" + ex.Message
});
}
}
///
/// 导入照片
///
///
///
///
[HttpGet]
public ActionResult PicImport(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "点击查看失败原因...";
}
ViewBag.operationTips = operationTips;
return View();
}
///
/// 导入照片
///
///
///
///
[HttpPost]
public ActionResult PicImport(HttpPostedFileBase file, string importPicType)
{
try
{
if (file.ContentLength <= 0)
{
throw new Exception("请选择你要上传的照片(注:格式为zip或rar的压缩包文件)。");
}
var acceptFileExtensions = new[] { ".zip", ".rar" };
var fileExtensionName = Path.GetExtension(file.FileName);
if (!acceptFileExtensions.Contains(fileExtensionName))
{
throw new Exception("格式错误,只允许上传zip或rar格式的压缩包文件。");
}
string fileSourceWebPath = null;
string errorSourceWebPath = null;
var photoPathList = FileUploadHelper.UploadFileAndExtractFile(file, out fileSourceWebPath, out errorSourceWebPath);
System.IO.File.Delete(Server.MapPath(fileSourceWebPath));
if (photoPathList == null || photoPathList.Count <= 0)
{
throw new Exception("压缩包中文件为空。");
}
var acceptPicExtensions = new[] { ".jpg", ".jpeg", ".png", ".bmp" };
List newPhotoPathList = new List();
foreach (var photoPath in photoPathList)
{
string photoExtensionName = Path.GetExtension(photoPath).ToLower();
if (acceptPicExtensions.Contains(photoExtensionName))
{
newPhotoPathList.Add(photoPath);
}
else
{
throw new Exception("压缩包中含有不支持的照片格式。");
}
}
int? inCount = 0;
int? errCount = 0;
var errDataTable = new DataTable();
newStudentCollegeServices.NewStudentCollegePicImport(newPhotoPathList, importPicType, out inCount, out errCount, out errDataTable);
if (errDataTable != null && errDataTable.Rows.Count > 0)
{
NpoiExcelHelper npoiExcelHelper = new NpoiExcelHelper();
npoiExcelHelper.SaveInServer(errDataTable, Server.MapPath(errorSourceWebPath));
string errorWebPath = string.Format("{0}", errorSourceWebPath);
ViewBag.ErrorFile = errorWebPath;
string Errinfo = string.Format("提示:{0}个照片导入成功,{1}个照片导入失败,点击查看。", inCount, errCount);
ViewBag.operationTips = Errinfo;
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = Errinfo,
url = Url.Action("PicImport").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips=" + Errinfo + "&WindowID=" + Request["WindowID"]
});
}
else
{
string successInfo = string.Format("提示:{0}个照片导入成功。", inCount);
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = successInfo,
url = Url.Action("List").AddMenuParameter()
});
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = "导入照片失败,原因:" + ex.Message,
url = Url.Action("PicImport").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
});
}
}
///
/// Excel导入名单(匹配相应的配置表,个性化配置)
///
///
///
///
[HttpGet]
public ActionResult Import(string errorFile, string operationTips)
{
ViewBag.ErrorFile = errorFile;
if (string.IsNullOrEmpty(operationTips))
{
operationTips = "点击查看失败原因...";
}
ViewBag.operationTips = operationTips;
return View();
}
///
/// Excel导入名单(匹配相应的配置表,个性化配置)
///
///
///
[HttpPost]
public ActionResult Import(HttpPostedFileBase file)
{
try
{
if (!NpoiExcelHelper.GetIsCompatible(file.FileName))
{
throw new Exception("格式错误,只允许导入xls或xlsx格式的Excel文件。");
}
//注:与Excel模板一一对应(只读取Excel模板中的有效列)
Dictionary cellheader = new Dictionary
{
{ "ExamineeNum", "ksh" }, //考生号
{ "AdmissionTicketNo", "zkzh" }, //准考证号
{ "Name", "xm" }, //姓名
{ "SexStr", "xbdm" }, //性别代码
{ "NationStr", "mzdm" }, //民族代码
{ "PoliticsStr", "zzmmdm" }, //政治面貌代码
{ "BirthDateStr", "csrq" }, //出生日期
{ "gzrq", "gzrq" }, //gz日期
{ "byrq", "byrq" }, //毕业日期(以前读的学校的毕业日期)
{ "byxx", "byxx" }, //毕业学校
{ "wyyzdm", "wyyzdm" }, //外语语种代码
{ "zslbdm", "zslbdm" }, //招生类别代码
{ "zylbdm", "zylbdm" }, //职业类别代码
{ "whcddm", "whcddm" }, //文化程度代码
{ "FeaturesStr", "kstzbz" }, //考生特征标记
{ "IDNumber", "sfzh" }, //身份证号
{ "ZIPCode", "yzbm" }, //邮政编码
{ "Telephone", "lxdh" }, //联系电话
{ "Address", "txdz" }, //通讯地址
{ "TerritorialStr", "xzqhdm" }, //行政区划代码
{ "bh", "bh" }, //bh
{ "kslsczbz", "kslsczbz" },
{ "tdzyh", "tdzyh" },
{ "zydh1", "zydh1" },
{ "zydh2", "zydh2" },
{ "zydh3", "zydh3" },
{ "zydh4", "zydh4" },
{ "zydh5", "zydh5" },
{ "zydh6", "zydh6" },
{ "fczytj", "fczytj" },
{ "ffdy", "ffdy" },
{ "sfzltd", "sfzltd" },
{ "cjx01", "cjx01" },
{ "cjx02", "cjx02" },
{ "cjx03", "cjx03" },
{ "cjx04", "cjx04" },
{ "cjx05", "cjx05" },
{ "cjx06", "cjx06" },
{ "cjx07", "cjx07" },
{ "cjx08", "cjx08" },
{ "cjx10", "cjx10" },
{ "cjx11", "cjx11" },
{ "cjx13", "cjx13" },
{ "cjx14", "cjx14" },
{ "cjx15", "cjx15" },
{ "cjx16", "cjx16" },
{ "cjx17", "cjx17" },
{ "cjx18", "cjx18" },
{ "cjx19", "cjx19" },
{ "cjx31", "cjx31" },
{ "cjx32", "cjx32" },
{ "cjx34", "cjx34" },
{ "cjx35", "cjx35" },
{ "cjx36", "cjx36" },
{ "cjx37", "cjx37" },
{ "cjx38", "cjx38" },
{ "cjx91", "cjx91" },
{ "cjx92", "cjx92" },
{ "cjx93", "cjx93" },
{ "ScoreStr", "zf" }, //总分
{ "pxzf", "pxzf" }, //px总分
{ "ccdm", "ccdm" }, //层次代码
{ "tdzysxdm", "tdzysxdm" }, //td专业sx代码
{ "bkzysxdm", "bkzysxdm" }, //bk专业sx代码
{ "tdfs", "tdfs" }, //投档分数
{ "tdzydm", "tdzydm" }, //投档专业代码
{ "lqyxdm", "lqyxdm" }, //录取院校代码
{ "lqccdm", "lqccdm" }, //录取层次代码
{ "lqzysxdm", "lqzysxdm" }, //录取专业sx代码
{ "CustomStandardCode", "lqzy" }, //录取专业(省招代码),取后4位
{ "tdyydm", "tdyydm" },
{ "kstzbz", "kstzbz" },
{ "tdcs", "tdcs" },
{ "Remark", "bz" }, //备注
{ "ErrorMessage", "未导入原因" }
};
int? inCount = 0;
int? upCount = 0;
int? errCount = 0;
List errList = new List();
string sourceWebPath = FileUploadHelper.UploadFile(file);
var sourcePhysicalPath = Server.MapPath(sourceWebPath);
newStudentCollegeServices.NewStudentCollegeImport(cellheader, out inCount, out upCount, out errList, out errCount, sourcePhysicalPath);
System.IO.File.Delete(sourcePhysicalPath);
if (errList.Count() > 0)
{
string errorWebPath = string.Format("{0}", NpoiExcelHelper.EntityListToExcel2003(cellheader, errList, "招生信息导入失败文件", sourcePhysicalPath));
ViewBag.ErrorFile = errorWebPath;
string Errinfo = string.Format("提示:{0}条招生信息导入成功,{1}条招生信息更新成功,{2}条招生信息导入失败,点击查看。", inCount, upCount, errCount);
ViewBag.operationTips = Errinfo;
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = Errinfo,
url = Url.Action("Import").AddMenuParameter() + "&errorFile=" + errorWebPath + "&operationTips="
+ Errinfo + "&WindowID=" + Request["WindowID"]
});
}
else
{
string successInfo = string.Format("提示:{0}条招生信息导入成功,{1}条招生信息更新成功。", inCount, upCount);
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = successInfo,
url = Url.Action("List").AddMenuParameter()
});
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = "none",
msg = "导入失败,原因:" + ex.Message,
url = Url.Action("Import").AddMenuParameter() + "&WindowID=" + Request["WindowID"]
});
}
}
///
/// Excel导出
///
///
///
[HttpPost]
public ActionResult Excel(QueryParamsModel pararms)
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var campusID = Request.Form["CampusDropdown"].ParseStrTo();
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var gradeID = Request.Form["DictionaryGrade"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryGrade"].ParseStrTo();
var standardID = Request.Form["DictionaryStandard"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryStandard"].ParseStrTo();
var educationID = Request.Form["DictionaryEducation"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryEducation"].ParseStrTo();
var learningformID = Request.Form["DictionaryLearningform"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryLearningform"].ParseStrTo();
var learnSystem = Request.Form["DictionaryLearnSystem"].ToString();
var isPhotoUrl = Request.Form["IsPhotoUrlDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsPhotoUrlDropdown"].ParseStrTo();
var dt = newStudentCollegeServices.GetNewStudentCollegeViewList(configuretView, campusID, collegeID, gradeID, standardID, educationID, learningformID, learnSystem, isPhotoUrl)
.Select(x => new
{
x.ExamineeNum,
x.AdmissionTicketNo,
x.Name,
x.SexName,
x.NationName,
x.PoliticsName,
BirthDate = x.BirthDate.HasValue ? x.BirthDate.Value.ToString("yyyy-MM-dd") : "",
x.CertificatesTypeName,
x.IDNumber,
x.GradeID,
x.SemesterName,
x.StandardCode,
x.StandardID,
x.StandardName,
x.EducationName,
x.LearningformName,
LearnSystem = x.LearnSystem.HasValue ? x.LearnSystem.Value.ToString("#.#") : null,
EntranceDate = x.EntranceDate.HasValue ? x.EntranceDate.Value.ToString("yyyy-MM-dd") : "",
x.Score,
x.Telephone,
x.Address,
x.Dormitory,
x.RecruitPictureUrl,
x.CollegeNo,
x.CollegeName,
x.AssignStatusName,
x.Remark
}).ToTable();
string[] liststring = {
"考生号", "准考证号","姓名", "性别", "民族", "政治面貌", "出生日期", "证件类型", "身份证号",
"年级", "学期", "专业代码", "专业ID(Value)", "专业名称", RSL.Get("EducationID"), "学习形式", "学制",
"入学日期", "总分", "联系电话", "通讯地址", "宿舍地址", "照片Url", RSL.Get("CollegeCode"),
RSL.Get("CollegeName"), "分配状态", "备注"
};
neh.Export(dt, liststring, "新生分配信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
}
}