using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.Mvc;
using EMIS.ViewModel;
using EMIS.Web.Controls;
using Bowin.Web.Controls.Mvc;
using Bowin.Common.Exceptions;
using Bowin.Common.Utility;
using Bowin.Common.Data;
using EMIS.Utility;
using EMIS.ViewModel.ChargeManage.ChargeSituation;
using EMIS.CommonLogic.ChargeManage.ChargeSituation;
using EMIS.CommonLogic.CalendarManage;
using System.Data;
namespace EMIS.Web.Controllers.ChargeManage.ChargeSituation
{
[Authorization]
public class StudentChargePaymenController : Controller
{
public IStudentChargePaymenServices StudentChargePaymenServices { get; set; }
public ISchoolYearServices SchoolYearServices { get; set; }
///
/// 学生缴费页面
///
///
public ActionResult List()
{
return View();
}
///
/// 列表查询
///
///
///
[HttpPost]
public ActionResult List(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var yearID = pararms.getExtraInt("SchoolyearDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolyearDictionaryDropDown");
var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
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 chargeYearID = pararms.getExtraInt("ChargeYearDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ChargeYearDropDown");
var chargeProjectID = pararms.getExtraGuid("ChargeProjectComboGrid");
var chargeTagID = pararms.getExtraInt("DictionaryChargeTag") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryChargeTag");
//在校状态
var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus");
//是否圆梦计划
var isDream = pararms.getExtraInt("IsDreamDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDreamDropDown");
//备注
var Remark = pararms.getExtraString("DictionaryRemark");
return base.Json(StudentChargePaymenServices.GetStudentChargePamenViewGrid(configuretView, collegeID, yearID, standardID,
educationID, learningformID, learnSystem,chargeYearID, chargeProjectID,
inSchoolStatus, isDream, chargeTagID, Remark, (int)pararms.page, (int)pararms.rows));
}
///
/// 学生缴费页面缴费金额统计
///
///
///
public ActionResult AmountCountList(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var collegeID = pararms.getExtraGuid("CollegeDropdown");
var yearID = pararms.getExtraInt("SchoolyearDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("SchoolyearDictionaryDropDown");
var standardID = pararms.getExtraInt("StandardDictionaryDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("StandardDictionaryDropDown");
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 chargeYearID = pararms.getExtraInt("ChargeYearDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("ChargeYearDropDown");
var chargeProjectID = pararms.getExtraGuid("ChargeProjectComboGrid");
var chargeTagID = pararms.getExtraInt("DictionaryChargeTag") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryChargeTag");
//在校状态
var inSchoolStatus = pararms.getExtraInt("DictionaryInschoolStatus") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("DictionaryInschoolStatus");
//是否圆梦计划
var isDream = pararms.getExtraInt("IsDreamDropDown") == DropdownList.SELECT_ALL ? null : pararms.getExtraInt("IsDreamDropDown");
//备注
var Remark = pararms.getExtraString("DictionaryRemark");
var amountCount = StudentChargePaymenServices.GetAmountCount(configuretView, collegeID, yearID, standardID,
educationID, learningformID, learnSystem,chargeYearID, chargeProjectID,
inSchoolStatus, isDream, chargeTagID, Remark, 1, 1);
return Json(new StudentChargePaymenView { AmountSum = amountCount });
}
///
/// 编辑
///
///
///
[HttpGet]
public ActionResult Edit(Guid? studentChargePaymentID)
{
StudentChargePaymenView studentChargePaymenView = new StudentChargePaymenView();
if (studentChargePaymentID.HasValue && studentChargePaymentID != Guid.Empty)
{
studentChargePaymenView = StudentChargePaymenServices.GetStudentChargePaymenView(studentChargePaymentID);
}
else
{
studentChargePaymenView.ChargeYear = BaseExtensions.GetCurrentYearID();
}
return View(studentChargePaymenView);
}
///
/// 编辑(新增、修改)
/// 存在对应的应收名单时,才可新增
/// 业务主键不可修改(业务主键:用户ID、缴费学年、收费项目ID)
///
///
///
[HttpPost]
public ActionResult Edit(StudentChargePaymenView StudentChargePaymenView)
{
try
{
StudentChargePaymenServices.StudentChargePaymenEdit(StudentChargePaymenView);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "保存成功。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "保存失败,原因:" + ex.Message + "。"
});
}
}
///
/// 查询对应的应收名单及缴费信息(根据应收名单业务主键)
///
///
///
///
///
[HttpPost]
public ActionResult StudentChargeStandard(Guid? userID, int? chargeYearID, Guid? chargeProjectID)
{
try
{
var result = StudentChargePaymenServices.QueryStudentChargePaymenView(userID, chargeYearID, chargeProjectID);
return Json(new ReturnMessage()
{
IsSuccess = true,
Data = result
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = ex.Message
});
}
}
///
/// 批量修改(重写)
///
///
///
///
///
public ActionResult BatchModifyControl(string studentChargePaymentIDs, decimal? amount)
{
try
{
string result = StudentChargePaymenServices.BatchModify(studentChargePaymentIDs, amount);
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "批量修改成功" + result + "。"
});
}
catch (Exception ex)
{
return Json(new ReturnMessage()
{
IsSuccess = false,
Message = "批量修改失败,原因:" + ex.Message + "。"
});
}
}
///
/// 删除
///
///
///
[HttpPost]
public ActionResult Delete(string studentChargePaymenIDs)
{
try
{
List list = new List();
for (int i = 0; i < studentChargePaymenIDs.Split(',').Length; i++)
{
string id = studentChargePaymenIDs.Split(',')[i];
if (!string.IsNullOrEmpty(id))
{
Guid chargeStandardID = new Guid(id);
list.Add(chargeStandardID);
}
}
StudentChargePaymenServices.StudentChargePaymenDelete(list);
return base.Json("删除成功。");
}
catch (Exception ex)
{
return base.Json("删除失败,原因:" + ex.Message);
}
}
///
/// 获取学生缴费备注信息
///
///
///
public ActionResult GetRemark(QueryParamsModel pararms)
{
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(pararms);
var Remark = pararms.getExtraString("DictionaryRemark");
return base.Json(StudentChargePaymenServices.GetRemarkViewGrid(configuretView, Remark, (int)pararms.page, (int)pararms.rows));
}
///
/// 验证
///
///
///
///
///
///
///
///
[HttpPost]
public ActionResult Verification(Guid? studentChargePaymentID, Guid? userID, int? chargeYearID,
Guid? chargeProjectID, decimal? amount, DateTime? chargeDate)
{
return Json(StudentChargePaymenServices.GetVerification(studentChargePaymentID, userID, chargeYearID,
chargeProjectID, amount, chargeDate));
}
///
/// 导出Excel
///
///
[HttpPost]
public ActionResult Excel()
{
NpoiExcelHelper neh = new NpoiExcelHelper();
ConfiguretView configuretView = ConfiguretExtensions.GetConfiguretermsView(null);
var collegeID = Request.Form["CollegeDropdown"].ParseStrTo();
var yearID = Request.Form["SchoolyearDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["SchoolyearDictionaryDropDown"].ParseStrTo();
var standardID = Request.Form["StandardDictionaryDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["StandardDictionaryDropDown"].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 chargeYearID = Request.Form["ChargeYearDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["ChargeYearDropDown"].ParseStrTo();
var chargeProjectID = Request.Form["ChargeProjectComboGrid"].ParseStrTo();
//在校状态
var inSchoolStatus = Request.Form["DictionaryInschoolStatus"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryInschoolStatus"].ParseStrTo();
//是否圆梦计划
var isDream = Request.Form["IsDreamDropDown"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["IsDreamDropDown"].ParseStrTo();
//缴费标记
var chargeTagID = Request.Form["DictionaryChargeTag"].ParseStrTo() == DropdownList.SELECT_ALL ? null : Request.Form["DictionaryChargeTag"].ParseStrTo();
//备注
var remark = Request.Form["DictionaryRemark"].ToString();
//统计
var amountCount = StudentChargePaymenServices.GetAmountCount(configuretView, collegeID, yearID, standardID,
educationID, learningFormID, learnSystem, chargeYearID, chargeProjectID,
inSchoolStatus, isDream, chargeTagID, remark, 1, 1);
var dt = StudentChargePaymenServices.GetStudentChargePaymenList(configuretView, collegeID, yearID, standardID, educationID,
learningFormID, learnSystem, chargeYearID, chargeProjectID, inSchoolStatus, isDream, chargeTagID, remark)
.Select(x => new
{
x.StudentNo,
x.UserName,
x.SexName,
x.ClassNo,
x.ClassName,
x.GradeMajorCode,
x.GradeMajorStr,
x.CollegeCode,
x.CollegeName,
x.ChargeYear,
x.ChargeProjectStr,
x.StandardAmount,
x.ChargeAmount,
x.ActualAmount,
x.ChargeTagName,
x.Amount,
x.ChargeDate,
x.GradeStr,
x.StandardID,
x.StandardCode,
x.MajorStr,
x.EducationName,
x.LearningformName,
x.LearnSystem,
x.IsDreamProject,
x.InSchoolStatusName,
x.StudentStatusName,
x.Remark
}).ToTable();
//追加统计列
DataRow newRow = dt.NewRow();
newRow[0] = "统计:";
newRow[15] = amountCount ?? 0;
dt.Rows.Add(newRow);
string[] liststring = { "学号", "姓名", "性别", "班级编号", "班级名称", "年级专业编号", "年级专业名称",
RSL.Get("CollegeCode"), RSL.Get("CollegeName"), "缴费学年", "收费项目",
"应收金额", "调整金额", "实收金额", "缴费标记", "缴费金额", "缴费日期",
"年级", "专业ID(Value)", "专业代码", "专业名称", RSL.Get("EducationID"), "学习形式",
"学制", "是否圆梦计划", "在校状态", "学籍状态", "备注"
};
neh.Export(dt, liststring, "学生缴费信息" + DateTime.Now.ToString("yyyyMMdd"));
return Json(new ReturnMessage()
{
IsSuccess = true,
Message = "导出成功。"
});
}
///
/// 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模板中的有效列
Dictionary cellheader = new Dictionary
{
{ "StudentNo", "学号" }, //学号
{ "ChargeProjectStr", "收费项目" }, //收费项目
{ "ChargeYearStr", "缴费学年" }, //缴费学年
{ "ChargeDateStr", "缴费日期" }, //缴费日期
{ "AmountStr", "缴费金额" }, //缴费金额
{ "Remark", "备注" }, //备注
{ "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; //失败个数
//导入
StudentChargePaymenServices.StudentChargePaymenImport(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"]
});
}
}
}
}