using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.JSON;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using EMIS.CommonLogic.TeachingMaterial;
using Bowin.Web.Controls.Mvc;
using EMIS.ViewModel.TeachingMaterial;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using EMIS.ViewModel.WorkflowManage;
using EMIS.CommonLogic.CalendarManage;
using Newtonsoft.Json;
using EMIS.Utility;
namespace EMIS.Web.Controllers.TeachingMaterial
{
[Authorization]
public class TeachersOrderController : Controller
{
public ITeachersOrderServices TeachersOrderServices { get; set; }
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(TeachersOrderServices.GetTeachersOrderViewGrid(configuretView, schoolYearID, collegeID, coursematerialID, publishID, approvalStatus, (int)pararms.page, (int)pararms.rows));
}
///
/// 编辑页面
///
///
[HttpGet]
public ActionResult Edit(Guid? teachersOrderID)
{
TeachersOrderView TeachersOrderView;
if (teachersOrderID != null && teachersOrderID != Guid.Empty)
{
TeachersOrderView = null;
TeachersOrderView = TeachersOrderServices.GetSingleTeachersOrder(teachersOrderID.Value);
}
else
{
TeachersOrderView = new TeachersOrderView()
{
TeachersOrderID = Guid.Empty
};
}
return View(TeachersOrderView);
}
///
/// 编辑
///
///
///
[HttpPost]
public ActionResult Edit(TeachersOrderView teachersOrderView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
TeachersOrderView teachersOrder = new TeachersOrderView();
if (teachersOrderView.TeachersOrderID != null)
{
TeachersOrderServices.EditTeachersOrder(teachersOrderView, user.UserID);
}
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
[HttpPost]
public ActionResult TeachersSave(string orderJson, TeachersOrderView teachersOrderView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
orderJson = Request.Form["hid_orderJsonStr"];
var collegeID = user.CollegeID;//获取当前登录用户对应的院系所
if (collegeID == null)
{
throw new Exception("该用户没有对应的" + RSL.Get("College") + ",请联系相关人员!");
}
var orderList = orderJson.JsonToObject>();
List teachersOrderList = new List();
orderList.ForEach(x =>
{
TeachersOrderView order = new TeachersOrderView
{
TeachingMaterialPoolID = x.TeachingMaterialPoolID,
SchoolyearID = teachersOrderView.SchoolyearID,
CollegeID = collegeID == null ? Guid.Empty : collegeID,
OrderQty = x.OrderQty,
OrderUserID = user.UserID,
OrderDate = DateTime.Now,
OrderDesc = teachersOrderView.OrderDesc
};
teachersOrderList.Add(order);
});
TeachersOrderServices.AddTeachersOrder(teachersOrderList, user.UserID);
//return base.Json("征订成功");
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
///
/// 提交申请
///
/// 申请征订ID
///
[HttpPost]
public ActionResult SubmitTeachersOrder(string TeachersOrderIDs)
{
try
{
List list = new List();
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
for (int i = 0; i < TeachersOrderIDs.Split(',').Length; i++)
{
string id = TeachersOrderIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid TeachersOrderID = new Guid(id);
list.Add(TeachersOrderID);
}
}
TeachersOrderServices.SubmitTeachersOrder(list, user.UserID, "");
return base.Json("成功");
}
catch (Exception ex)
{
return base.Json("失败,原因:" + ex.Message);
}
}
///
/// 删除
///
/// 征订ID
///
[HttpPost]
public ActionResult Delete(string teachersOrderIDs)
{
try
{
List list = new List();
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
for (int i = 0; i < teachersOrderIDs.Split(',').Length; i++)
{
string id = teachersOrderIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid specialtyApplyID = new Guid(id);
list.Add(specialtyApplyID);
}
}
TeachersOrderServices.DeleteTeachersOrder(list);
return base.Json("删除成功");
}
catch (Exception ex)
{
return base.Json("删除失败,原因:" + ex.Message);
}
}
///
/// Excel导出
///
///
[HttpPost]
public ActionResult Excel()
{
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
publishID = Request.Form["PublishDropdown"].ParseStrTo();
coursematerialID = Request.Form["CourseDropdown"].ParseStrTo();
Guid? schoolYearID = Request.Form["SchoolYearDropdown"].ParseStrTo();
Guid? collegeID = Request.Form["CollegeDropdownListBanids"].ParseStrTo();
int? approvalStatus = Request.Form["StatusDropdown"].ParseStrTo();
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
if (Request.Form["ExcelType"] == "1")
{
var dt = TeachersOrderServices.GetTeachersOrderViewList(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, "征订申请信息");
}
else
{
var dt = TeachersOrderServices.GetTeachersOrderViewList(configuretView, schoolYearID, collegeID, coursematerialID, publishID, approvalStatus).Select(x => new
{
x.SchoolyearName,
x.CollegeName,
x.CoursematerialName,
x.TeachingMaterialCode,
x.TeachingMaterialName,
x.Price,
x.ISBN,
x.PublishTime,
x.PublishName,
x.Author,
x.OrderQty,
x.OrderUserName
}).ToTable();
string[] liststring = { "学年学期",RSL.Get("College"),"课程名称","教材编号","教材名称","单价","ISBN","版本时间","出版单位"
,"作者","征订数量","征订人"};
neh.Export(dt, liststring, "征订申请预订汇总导出");
}
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Content("~/TeachersOrder/List").AddMenuParameter()
});
}
///
/// 页面数据增加
///
///
[HttpGet]
public ActionResult Add(Guid? teachersOrderID)
{
TeachersOrderView TeachersOrderView;
if (teachersOrderID != null && teachersOrderID != Guid.Empty)
{
TeachersOrderView = null;
TeachersOrderView = TeachersOrderServices.GetSingleTeachersOrder(teachersOrderID.Value);
}
else
{
TeachersOrderView = new TeachersOrderView()
{
SchoolyearID = schoolYearServices.GetSchoolYearIsCurrent(true).SchoolyearID,//默认当前学年
TeachersOrderID = Guid.Empty
};
}
EMIS.Entities.CF_Schoolyear schoolyear = schoolYearServices.GetSchoolYearIsCurrent(true);
if (schoolyear != null)
ViewData["SchoolyearID"] = schoolyear.SchoolyearID;
return View(TeachersOrderView);
}
///
/// 页面数据增加
///
///
///
[HttpPost]
public ActionResult Add(TeachersOrderView teachersOrderView)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
TeachersOrderServices.EditTeachersOrder(teachersOrderView, user.UserID);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message + "!"
});
}
}
[HttpGet]
public ActionResult AuditStatusView(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"] = TeachersOrderServices.GetCorrectEndStatus();
return View(teachersOrderView);
}
[HttpPost]
public ActionResult AuditStatusView(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()
});
}
}
[HttpGet]
public ActionResult GetTeachingMaterialPoolList()
{
ViewData["SchoolyearID"] = Guid.Empty;
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult GetTeachingMaterialPoolList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
//避开全选值
Guid? publishID = null;
Guid? coursematerialID = null;
Guid? teachingMaterialID = null;
bool? isLate = false;
teachingMaterialID = pararms.getExtraGuid("TeachingMaterialDropdown");
publishID = pararms.getExtraGuid("PublishDropdown");
coursematerialID = pararms.getExtraGuid("CourseDropdown");
var schoolyearID = pararms.getExtraGuid("SchoolyearID");
if (configuretView.Attribute == DropdownList.SELECT_ALL.ToString()) configuretView.Attribute = "";
return base.Json(TeachersOrderServices.GetTeachersOrderOrTeachingMaterialPoolViewGrid(configuretView, teachingMaterialID, coursematerialID, isLate, user.CollegeID, schoolyearID, (int)pararms.page, (int)pararms.rows));
}
[HttpGet]
public ActionResult DetailList()
{
ViewData["TeachersOrderID"] = Request.Params["TeachersOrderID"];
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult DetailList(QueryParamsModel pararms)
{
Guid? teachersOrderID = new Guid(Request.Params["teachersOrderID"]);
return base.Json(TeachersOrderServices.GetTeachersOrderDetailViewList(teachersOrderID, (int)pararms.page, (int)pararms.rows));
}
}
}