using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using EMIS.CommonLogic.TeachingMaterial;
using Bowin.Web.Controls.Mvc;
using EMIS.ViewModel.WorkflowManage;
using Bowin.Common.Utility;
using Bowin.Common.JSON;
using Bowin.Common.Data;
using EMIS.ViewModel.TeachingMaterial;
using EMIS.Utility;
using EMIS.CommonLogic.CalendarManage;
using EMIS.Utility.FormValidate;
namespace EMIS.Web.Controllers.TeachingMaterial
{
[Authorization]
public class TeachersOrderExamineController : Controller
{
public ITeachersOrderExamineServices TeachersOrderExamineServices { get; set; }
public ISchoolYearServices schoolYearServices { get; set; }
///
/// 页面列表查询
///
///
[HttpGet]
public ActionResult List()
{
//默认加载当前校历下学年学期的下一个学期
var schoolYearView = schoolYearServices.GetSchoolYearIsCurrent(true);
var schoolyear = schoolYearServices.GetSchoolYearViewListAfterCurrent().OrderBy(x => x.Code).Where(x => x.Value > schoolYearView.Value).FirstOrDefault();
ViewBag.SchoolYearID = schoolyear.SchoolYearID;
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
publishID = pararms.getExtraGuid("PublishDropdown");
coursematerialID = pararms.getExtraGuid("CourseDropdown");
var schoolYearID = pararms.getExtraGuid("SchoolYearDropdown");
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var approvalStatus = pararms.getExtraInt("StatusDropdown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StatusDropdown");
return base.Json(TeachersOrderExamineServices.GetTeachersOrderViewGrid(configuretView, schoolYearID, collegeID, coursematerialID, publishID, approvalStatus, (int)pararms.page, (int)pararms.rows));
}
#region 3.0 获取下一步环节
///
/// 获取下一步动作
///
///
///
[HttpGet]
public ActionResult ApprovalHandle(string teachersOrderIDs)
{
try
{
if (string.IsNullOrEmpty(teachersOrderIDs))
{
teachersOrderIDs = Session["teachersOrderIDs"].ToString();
}
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
if (!string.IsNullOrEmpty(teachersOrderIDs))
{
Guid teachersOrderID = new Guid(teachersOrderIDs.Split(',')[0]);
List listAction = TeachersOrderExamineServices.GetAuditingActionView(teachersOrderID, user.UserID).OrderBy(x => x.ActionID).ToList();
List list = new List();
foreach (var item in listAction)
{
DropdownListItem dli = new DropdownListItem { Text = item.ActionName, Value = item.ToJson() };
list.Add(dli);
}
ViewData["teachersOrderIDs"] = teachersOrderIDs;
ViewData["listAction"] = list;
}
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
WindowID = Request["WindowID"],
msg = "操作失败原因:" + ex.Message,
url = Url.Action("List").AddMenuParameter()
});
}
return View();
}
[HttpPost]
public ActionResult ApprovalHandle()
{
string teachersOrderIDs = Request.Form["teachersOrderIDs"].ToString();
Session["teachersOrderIDs"] = teachersOrderIDs;
return Json("成功", JsonRequestBehavior.AllowGet);
}
#endregion
#region 4.0 提交审核
[HttpPost]
public ActionResult Approve(string teachersOrderIDs, Guid actionID, string comment)
{
var teachersOrderIDList = teachersOrderIDs.Split(',').Where(x => !string.IsNullOrEmpty(x)).Select(x => new Guid(x)).ToList();
var curUserID = CustomPrincipal.Current.UserID;
if (teachersOrderIDList.Count == 0)
{
return Json(new ReturnMessage { IsSuccess = false, Message = "请选择至少一条记录进行审核。" });
}
try
{
this.TeachersOrderExamineServices.Approve(teachersOrderIDList, curUserID, actionID, string.IsNullOrEmpty(comment) ? "同意" : comment);
return Json(new ReturnMessage { IsSuccess = true, Message = "审核成功。" });
}
catch (Exception ex)
{
return Json(new ReturnMessage { IsSuccess = false, Message = "审核失败:" + ex.Message });
}
}
#endregion
#region 5.0 获取流程流转步骤
///
/// 获取流程步骤详细信息
///
///
///
[HttpPost]
public ActionResult ApproveWorkflowList(Guid? teachersOrderID)
{
return base.Json(TeachersOrderExamineServices.GetWorkflowApproveHistoryView(teachersOrderID));
}
#endregion
#region 6.0 导出Excel
///
/// 导出Excel
///
///
[HttpPost]
public ActionResult Excel()
{
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
bool? isLate = null;
publishID = Request.Form["PublishDropdown"].ParseStrTo();
coursematerialID = Request.Form["CourseDropdown"].ParseStrTo();
var schoolYearID = Request.Form["SchoolYearDropdown"].ParseStrTo();
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var approvalStatus = Request.Form["StatusDropdown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["StatusDropdown"].ParseStrTo();
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var dt = TeachersOrderExamineServices.GetTeachersOrderExamineViewExcel(configuretView, schoolYearID, collegeID, coursematerialID, publishID, approvalStatus).Select(x => new
{
x.SchoolyearName,
x.TeachingMaterialCode,
x.CoursematerialCode,
x.CoursematerialName,
x.CoursematerialLevelName,
x.CoursematerialTypeName,
x.ISBN,
x.TeachingMaterialName,
x.PublishTime,
x.PublishName,
x.Author,
x.OrderQty,
x.OrderUserName,
x.CollegeName,
x.OrderDate,
x.OrderDesc,
x.ApproveStatusName
}).ToTable();
string[] liststring = { "学年学期","教材编号","课程代码","课程名称","课程级别","课程科类","ISBN","教材名称"
,"版本时间","出版单位","作者","征订数量","征订人",RSL.Get("College"),"征订日期","征订说明","审核状态 "};
neh.Export(dt, liststring, "征订审核信息");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/TeachersOrder/List").AddMenuParameter()
});
}
#endregion
///
/// 编辑
///
///
///
[HttpGet]
public ActionResult Edit(Guid? teachersOrderID)
{
List list = new List();
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
TeachersOrderView teachersOrderView = new TeachersOrderView();
if (teachersOrderID.HasValue)
teachersOrderView = TeachersOrderExamineServices.GetTeachersOrderExamineView(teachersOrderID);
List listAction = TeachersOrderExamineServices.GetAuditingActionView((Guid)teachersOrderID, user.UserID);
foreach (var item in listAction)
{
DropdownListItem dli = new DropdownListItem { Text = item.ActionName, Value = item.ToJson() };
list.Add(dli);
}
ViewData["listAction"] = list;
ViewData["endStatus"] = TeachersOrderExamineServices.GetCorrectEndStatus();
return View(teachersOrderView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(TeachersOrderView teachersOrderView)
{
try
{
List list = new List();
string action = Request.Form["ddlAction"];
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
ActionView actionView = action.JsonToObject();
string comment = Request.Form["txtOpinioncomment"];
list.Add(teachersOrderView.TeachersOrderID);
TeachersOrderExamineServices.ApproveTeachersOrderExamine(list, user.UserID, actionView, comment);
return RedirectToAction("MsgShow", "Common", new
{
msg = "审核成功!",
url = Url.Content("~/TeachersOrderExamine/List").AddMenuParameter()
});
}
catch (Exception ex)
{
return RedirectToAction("MsgShow", "Common", new
{
msg = "审核失败,原因:" + ex.Message,
url = Url.Content("~/TeachersOrderExamine/List").AddMenuParameter()
});
}
}
}
}