1在下载的时候,需要把当前月份传递进去,供下载指定月份的数据,在这个时候,我们这样子做 在div的点击事件中,进行获取时间控件的时间,然后重定向方法。这样就能下载了。下载是返回一个地址路径的。
<div class="btn btn-primary btn-sm" onclick="Load_DownLoadWelfare();"><a href="#" style="color:white;">下载nc信息</a></div>
function Load_DownLoadWelfare() {
var CreateMonthSalaryTime = $("#ShowSelectTime").val();
window.location.href = "DownLoadWelfare?time="+CreateMonthSalaryTime;
}
/// <summary>
/// 下载社保信息
/// </summary>
/// <returns></returns>
public ActionResult DownLoadWelfare(string time) {
IWorkbook books = new HSSFWorkbook();//生成xls格式excel
ISheet Sheet1 = books.CreateSheet("Sheet1");
IRow Sheet1row1 = Sheet1.CreateRow(0);
Sheet1row1.CreateCell(0).SetCellValue("序号");
Sheet1row1.CreateCell(1).SetCellValue("类型");
Sheet1row1.CreateCell(2).SetCellValue("城市");
Sheet1row1.CreateCell(3).SetCellValue("姓名");
Sheet1row1.CreateCell(4).SetCellValue("证件号码");
Sheet1row1.CreateCell(5).SetCellValue("户口性质");
Sheet1row1.CreateCell(6).SetCellValue("费用月份");
Sheet1row1.CreateCell(7).SetCellValue("五险基数");
Sheet1row1.CreateCell(8).SetCellValue("养老企业");
Sheet1row1.CreateCell(9).SetCellValue("养老个人");
Sheet1row1.CreateCell(10).SetCellValue("失业企业");
Sheet1row1.CreateCell(11).SetCellValue("失业个人");
Sheet1row1.CreateCell(12).SetCellValue("工伤企业");
Sheet1row1.CreateCell(13).SetCellValue("生育企业");
Sheet1row1.CreateCell(14).SetCellValue("医疗企业");
Sheet1row1.CreateCell(15).SetCellValue("医疗个人");
Sheet1row1.CreateCell(16).SetCellValue("公积金基数");
Sheet1row1.CreateCell(17).SetCellValue("公积金企业");
Sheet1row1.CreateCell(18).SetCellValue("公积金个人");
ISheet Sheet2 = books.CreateSheet("Sheet2");
IRow Sheet2row1 = Sheet2.CreateRow(0);
//Sheet2row1.CreateCell(0).SetCellValue(true);
//Sheet2row1.CreateCell(1).SetCellValue(System.DateTime.Now.ToString());
//Sheet2row1.CreateCell(2).SetCellValue(10.13);
//Sheet2row1.CreateCell(3).SetCellValue("第2页码数据");
ISheet Sheet3 = books.CreateSheet("Sheet3");
IRow Sheet3row1 = Sheet3.CreateRow(0);
//Sheet3row1.CreateCell(0).SetCellValue(true);
//Sheet3row1.CreateCell(1).SetCellValue(System.DateTime.Now.ToString());
//Sheet3row1.CreateCell(2).SetCellValue(10.13);
//Sheet3row1.CreateCell(3).SetCellValue("第3页码数据");
#region 社保信息的部分下载
string CheckTime = DateTime.Now.ToString("yyyy-MM") + "-01";
Models.SalaryModel salary = new Models.SalaryModel();
var salaryBaseInfo = salary.SalaryBaseInfoes.Where(n => n.UserSalaryStatus == 1 && n.SalaryInType == "工资明细" && n.IsPractice != "实习生").OrderBy(n => n.Department);
#region 根据用户表 进行生成社保信息 1用户正常未停薪 排除劳务 实习生
int Index = 0;
foreach (var item in salaryBaseInfo)
{
Index += 1;
//根据用户的id 找到 社保的信息,然后取社保的信息然后存放出来
int Id = item.Id;
Models.CompanyWelfareSalary CompanyWelfareSalary = salary.CompanyWelfareSalaries.FirstOrDefault(n=>n.BaseInfoId == Id && n.CompanyWelfareTime.ToString() == CheckTime);
if (CompanyWelfareSalary != null)
{
#region 获取需要信息
string WelfareType = CompanyWelfareSalary.WelfareType;//类型
string PaymentCity = CompanyWelfareSalary.PaymentCity;//城市
string UserName = item.UserName;//姓名
string IdentityTypeCard = item.IdentityTypeCard;//证件号码
string ResidenceBooklet = item.ResidenceBooklet;// 户口性质
string SaveCheckTime = CheckTime.ToString();//费用月份
string FiveIndustrialInjuryInsuranceBase = CompanyWelfareSalary.IndustrialInjuryInsuranceBase.ToString();//五险基数
string PensionEnterpriseQuota = CompanyWelfareSalary.PensionEnterpriseQuota.ToString(); //养老企业
string PensionPersonalQuota = CompanyWelfareSalary.PensionPersonalQuota.ToString();//养老个人
string UnemploymentInsuranceEnterpriseQuota = CompanyWelfareSalary.UnemploymentInsuranceEnterpriseQuota.ToString(); //失业企业
string UnemploymentInsurancePersonalQuota = CompanyWelfareSalary.UnemploymentInsurancePersonalQuota.ToString(); //失业个人
string IndustrialInjuryInsurancePayBack = CompanyWelfareSalary.IndustrialInjuryInsurancePayBack.ToString(); //工伤企业
string BirthInsurancePayBack = CompanyWelfareSalary.BirthInsurancePayBack.ToString(); //生育企业
string MedicalEnterpriseQuota = CompanyWelfareSalary.MedicalEnterpriseQuota.ToString(); //医疗企业
string MedicalPersonalQuota = CompanyWelfareSalary.MedicalPersonalQuota.ToString(); //医疗个人
string HousingPublicAccumulationSalaryBase = CompanyWelfareSalary.HousingPublicAccumulationSalaryBase.ToString(); //公积金基数
string HousingPublicAccumulationSalaryEnterpriseQuota = CompanyWelfareSalary.HousingPublicAccumulationSalaryEnterpriseQuota.ToString();//公积金企业
string HousingPublicAccumulationSalaryPersonalQuota = CompanyWelfareSalary.HousingPublicAccumulationSalaryPersonalQuota.ToString(); //公积金个人
decimal c = decimal.Round(decimal.Parse(HousingPublicAccumulationSalaryPersonalQuota),2);
//
string Save_FiveIndustrialInjuryInsuranceBase = BLL.CheckValues.RevertDecimal(FiveIndustrialInjuryInsuranceBase);
string Save_PensionEnterpriseQuota = BLL.CheckValues.RevertDecimal(PensionEnterpriseQuota);
string Save_PensionPersonalQuota = BLL.CheckValues.RevertDecimal(PensionPersonalQuota);
string Save_UnemploymentInsuranceEnterpriseQuota = BLL.CheckValues.RevertDecimal(UnemploymentInsuranceEnterpriseQuota);
string Save_UnemploymentInsurancePersonalQuota = BLL.CheckValues.RevertDecimal(UnemploymentInsurancePersonalQuota);
string Save_IndustrialInjuryInsurancePayBack = BLL.CheckValues.RevertDecimal(IndustrialInjuryInsurancePayBack);
string Save_BirthInsurancePayBack = BLL.CheckValues.RevertDecimal(BirthInsurancePayBack);
string Save_MedicalEnterpriseQuota = BLL.CheckValues.RevertDecimal(MedicalEnterpriseQuota);
string Save_MedicalPersonalQuota = BLL.CheckValues.RevertDecimal(MedicalPersonalQuota);
string Save_HousingPublicAccumulationSalaryBase = BLL.CheckValues.RevertDecimal(HousingPublicAccumulationSalaryBase);
string Save_HousingPublicAccumulationSalaryEnterpriseQuota = BLL.CheckValues.RevertDecimal(HousingPublicAccumulationSalaryEnterpriseQuota);
string Save_HousingPublicAccumulationSalaryPersonalQuota = BLL.CheckValues.RevertDecimal(HousingPublicAccumulationSalaryPersonalQuota);
IRow Sheet1row_Index = Sheet1.CreateRow(Index);
Sheet1row_Index.CreateCell(0).SetCellValue(Index);
Sheet1row_Index.CreateCell(1).SetCellValue(WelfareType);
Sheet1row_Index.CreateCell(2).SetCellValue(PaymentCity);
Sheet1row_Index.CreateCell(3).SetCellValue(UserName);
Sheet1row_Index.CreateCell(4).SetCellValue(IdentityTypeCard);
Sheet1row_Index.CreateCell(5).SetCellValue(ResidenceBooklet);
Sheet1row_Index.CreateCell(6).SetCellValue(SaveCheckTime);
Sheet1row_Index.CreateCell(7).SetCellValue(Save_FiveIndustrialInjuryInsuranceBase);
Sheet1row_Index.CreateCell(8).SetCellValue(Save_PensionEnterpriseQuota);
Sheet1row_Index.CreateCell(9).SetCellValue(Save_PensionPersonalQuota);
Sheet1row_Index.CreateCell(10).SetCellValue(Save_UnemploymentInsuranceEnterpriseQuota);
Sheet1row_Index.CreateCell(11).SetCellValue(Save_UnemploymentInsurancePersonalQuota);
Sheet1row_Index.CreateCell(12).SetCellValue(Save_IndustrialInjuryInsurancePayBack);
Sheet1row_Index.CreateCell(13).SetCellValue(Save_BirthInsurancePayBack);
Sheet1row_Index.CreateCell(14).SetCellValue(Save_MedicalEnterpriseQuota);
Sheet1row_Index.CreateCell(15).SetCellValue(Save_MedicalPersonalQuota);
Sheet1row_Index.CreateCell(16).SetCellValue(Save_HousingPublicAccumulationSalaryBase);
Sheet1row_Index.CreateCell(17).SetCellValue(Save_HousingPublicAccumulationSalaryEnterpriseQuota);
Sheet1row_Index.CreateCell(18).SetCellValue(Save_HousingPublicAccumulationSalaryPersonalQuota);
#endregion
}
else {
string name = item.UserName;
}
}
#endregion
#endregion
MemoryStream m = new MemoryStream();
MemoryStream stream = new MemoryStream();
books.Write(m);
var byteArray = m.ToArray();
books.Write(stream);
return File(byteArray, "application/vnd.ms-excel", @""+ CheckTime + "工资.xls");//通过字节流进行输出
}