using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Bowin.Common.Exceptions;
using Bowin.Common.Linq;
using Bowin.Common.Utility;
using Bowin.Web.Controls.Mvc;
using EMIS.CommonLogic.Students;
using EMIS.ViewModel;
using EMIS.ViewModel.DifferentDynamic;
using EMIS.Web.Controls;
using EMIS.CommonLogic.CalendarManage;
namespace EMIS.Web.Controllers.StudentWeb.MyProfileManager
{
[Authorization]
public class ChangeRecordController : Controller
{
public ISchoolYearServices SchoolYearServices { get; set; }
public IDifferentDynamicServices DifferentDynamicServices { get; set; }
public IStudentRecordServices StudentRecordService { get; set; }
//[StaticFileWriteFilter]
public ActionResult List()
{
var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
ViewBag.UserID = user.UserID;
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var campusID = pararms.getExtraGuid("CampusDropdown"); //校区
var collegeID = pararms.getExtraGuid("CollegeDropdown"); //院系所
var year = CheckIsSelectAll(pararms.getExtraInt("DictionarySchoolyear")); //年级
var standard = CheckIsSelectAll(pararms.getExtraInt("DictionaryStandard")); //专业名称
var education = CheckIsSelectAll(pararms.getExtraInt("DictionaryEducation")); //培养层次
var learningform = CheckIsSelectAll(pararms.getExtraInt("DictionaryLearningform")); //学习形式
var classmajorID = pararms.getExtraGuid("ClassmajorDropdown"); //班级名称
var schoolYearID = pararms.getExtraGuid("SchoolYearDropdown"); //异动学期
var differentDynamicType = CheckIsSelectAll(pararms.getExtraInt("DictionaryDifferentDynamicType")); //异动类型
var differentDynamicStatus = CheckIsSelectAll(pararms.getExtraInt("DictionaryDifferentDynamicStatus")); //审批状态
var result = DifferentDynamicServices.GetDifferentDynamicViewGrid(configuretView, campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, differentDynamicStatus,null, (int)pararms.page, (int)pararms.rows, 0);
return Json(result);
}
public ActionResult Edit(Guid? id)
{
var vm = new DifferentDynamicView();
var schoolYear = SchoolYearServices.GetSchoolYearIsCurrent(true);
if (id != null && id != Guid.Empty)
{
vm = DifferentDynamicServices.GetDifferentDynamicView(id);
}
else
{
var user = EMIS.Utility.FormValidate.CustomPrincipal.Current;
var Student = StudentRecordService.GetStudentByStudentNo(user.UserID);
vm.ClassmajorID = Student.ClassID;
vm.ClassmajorName = Student.ClassName;
vm.InSchoolStatusID = Student.InSchoolStatusID;
vm.StudentStatus = Student.StudentStatus;
vm.StandardID = Student.StandardID;
vm.UserID = user.UserID;
vm.SchoolyearID = schoolYear.SchoolyearID;
vm.ApplyTypeID = (int)CF_ChangeApplyType.Normal;
}
var isView = (vm.EntityApprovalStatus.HasValue && vm.EntityApprovalStatus != DifferentDynamicServices.GetStartStatus()) ? true : false;
ViewBag.IsView = isView;
ViewBag.StartStatusID = DifferentDynamicServices.GetStartStatus();
return View(vm);
}
///
/// 新增或更新
///
///
///
[HttpPost]
public ActionResult Edit(DifferentDynamicView vm)
{
try
{
DifferentDynamicServices.AddOrUpdateDifferentDynamic(vm);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功!"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string ids)
{
try
{
var list = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => Guid.Parse(s)).ToList();
DifferentDynamicServices.DeleteDifferentDynamic(list);
return base.Json("删除成功");
}
catch (Exception ex)
{
string mge = ex.Message;
System.Data.SqlClient.SqlException num = ExceptionHelper.GetSqlException(ex);
if (num != null)
{
if (num.Number == 547)
//mge = "请先删除所有关联的数据,如:专业计划、选修计划等!";
mge = "请先删除所有关联的数据!";
}
return base.Json("删除失败,原因:" + mge);
}
}
///
/// 提交
///
///
///
[HttpPost]
public ActionResult Submit(string ids)
{
try
{
var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
var list = ids.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => Guid.Parse(s)).ToList();
DifferentDynamicServices.Submit(list, user.UserID);
return Json("提交成功");
}
catch (Exception ex)
{
string mge = ex.Message;
return Json("提交失败,原因:" + mge);
}
}
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
//避开全选值
//var roleID = Request.Form["Role"].ParseStrTo();
var campusID = Request.Form["CampusDropdown"].ParseStrTo(); //校区
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo(); //院系所
var year = CheckIsSelectAll(Request.Form["DictionarySchoolyear"].ParseStrTo()); //年级
var standard = CheckIsSelectAll(Request.Form["DictionaryStandard"].ParseStrTo()); //专业名称
var education = CheckIsSelectAll(Request.Form["DictionaryEducation"].ParseStrTo()); //培养层次
var learningform = CheckIsSelectAll(Request.Form["DictionaryLearningform"].ParseStrTo()); //学习形式
var classmajorID = Request.Form["ClassmajorDropdown"].ParseStrTo(); //班级名称
var schoolYearID = Request.Form["SchoolYearDropdown"].ParseStrTo(); //异动学期
var differentDynamicType = CheckIsSelectAll(Request.Form["DictionaryDifferentDynamicType"].ParseStrTo()); //异动类型
var differentDynamicStatus = CheckIsSelectAll(Request.Form["DictionaryDifferentDynamicStatus"].ParseStrTo()); //审批状态
var result = DifferentDynamicServices.GetDifferentDynamicViewList(configuretView, campusID, collegeID, year, standard, education, learningform, classmajorID, schoolYearID, differentDynamicType, differentDynamicStatus,null,0);
var dt = result.Select(s => new
{
s.SchoolyearCode,
s.LoginID,
s.Name,
s.DifferentDynamicTypeName,
s.Reason,
s.InSchoolStatusName,
s.StudentStatusName,
s.StandardName,
s.ClassmajorName,
s.AfterStandardName,
s.AfterClassmajorName,
s.AfterInSchoolStatusName,
s.AfterStudentStatusName,
s.ReturnSchoolyearCode,
s.ApprovalStatusName,
s.ReportStatusName,
}).ToTable();
string[] liststring = { "异动学期", "学号", "姓名", "异动类型", "异动原因", "在校状态", "学籍状态",
"异动前专业", "异动前班级", "异动后专业", "异动后班级", "异动后在校状态", "异动后学籍状态",
"返校学期", "审批状态", "注册状态" };
neh.Export(dt, liststring, "异动申请");
return RedirectToAction("MsgShow", "Common", new
{
msg = "导出成功!",
url = Url.Action("List").AddMenuParameter()
});
}
protected static int? CheckIsSelectAll(int? argment)
{
return argment == DropdownList.SELECT_ALL ? null : argment;
}
}
}