easyUI+mvc权限管理后台

时间:2022-08-16 13:17:06

通过按钮和菜单,组合成基本的功能,菜单的功能可以编码修改,但浏览功能是菜单基本的入口,只有角色赋予了浏览功能,才能访问。

基本按钮表

easyUI+mvc权限管理后台

easyUI+mvc权限管理后台

菜单模块

easyUI+mvc权限管理后台

easyUI+mvc权限管理后台

菜单分配按钮

easyUI+mvc权限管理后台

easyUI+mvc权限管理后台

角色授权

easyUI+mvc权限管理后台

easyUI+mvc权限管理后台

下面是对一张表的基本操作

模型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text; namespace MyRight.Model
{
/// <summary>
/// 流水号
/// </summary>
public partial class AkIv
{
/// <summary>
/// 流水号
/// </summary>
public int Id { get; set; }
/// <summary>
/// 条码
/// </summary>
public string BarCode { get; set; }
/// <summary>
/// 时间
/// </summary>
public DateTime DateTime { get; set; }
/// <summary>
/// 电池转换效率
/// </summary>
public float Eff { get; set; }
/// <summary>
/// 短路电流
/// </summary>
public float Isc { get; set; }
/// <summary>
/// 开路电压
/// </summary>
public float Voc { get; set; }
/// <summary>
/// 串联电阻
/// </summary>
public float Rs { get; set; }
/// <summary>
/// 并联电阻
/// </summary>
public float Rsh { get; set; }
/// <summary>
/// 最大功率
/// </summary>
public float Pmax { get; set; }
/// <summary>
/// 最大功率时的电压
/// </summary>
public float Vpm { get; set; }
/// <summary>
/// 最大功率时的电流
/// </summary>
public float Ipm { get; set; }
/// <summary>
/// 填充因子
/// </summary>
public float FF { get; set; }
/// <summary>
/// 光强
/// </summary>
public float Sun { get; set; }
/// <summary>
/// 温度
/// </summary>
public float Temp { get; set; }
/// <summary>
/// 档位
/// </summary>
public string Class { get; set; }
/// <summary>
/// 人员
/// </summary>
public string Employee { get; set; }
/// <summary>
/// 线别
/// </summary>
public string LineTitle { get; set; }
/// <summary>
/// 工位
/// </summary>
public string StationTitle { get; set; }
}
}

存储过程

USE [Suncome]
GO
/****** Object: StoredProcedure [dbo].[proc_AkIv] Script Date: 08/28/2015 11:09:36 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO ALTER PROCEDURE [dbo].[proc_AkIv]
(
@queryType tinyint=0,
@ID bigint=null,--流水号
@BarCode nvarchar(100)=null,--条码
@DateTime datetime=null,--时间
@Eff decimal=null,--电池转换效率
@Isc decimal=null,--为短路电流
@Voc decimal=null,--开路电压
@Rs decimal=null,--串联电阻
@Rsh decimal=null,--并联电阻
@Pmax decimal=null,--最大功率
@Vpm decimal=null,--最大功率时的电压
@Ipm decimal=null,--最大功率时的电流
@FF decimal=null,--填充因子
@Sun decimal=null,--光强
@Temp decimal=null,--温度
@Class nvarchar(50)=null,--档位
@Employee nvarchar(50)=null,--人员
@LineTitle nvarchar(50)=null,--线别
@StationTitle nvarchar(50)=null,--工位
@startIndex int=0,
@endIndex int=18,
@searchString nvarchar(1000)='',
@orderString nvarchar(1000)=''
)
AS if @searchString is null
set @searchString=''
if @orderString is null
set @orderString='' if @queryType=0 --查询单条记录
begin
select * from AkIv where ID=@ID
end
else if @queryType=1 --插入
begin
insert into AkIv (BarCode,DateTime,Eff,Isc,Voc,Rs,Rsh,Pmax,Vpm,Ipm,FF,Sun,Temp,Class,Employee,LineTitle,StationTitle)
values (@BarCode,@DateTime,@Eff,@Isc,@Voc,@Rs,@Rsh,@Pmax,@Vpm,@Ipm,@FF,@Sun,@Temp,@Class,@Employee,@LineTitle,@StationTitle)
end
else if @queryType=2 --更新
begin
update AkIv set
BarCode=@BarCode,
DateTime=@DateTime,
Eff=@Eff,
Isc=@Isc,
Voc=@Voc,
Rs=@Rs,
Rsh=@Rsh,
Pmax=@Pmax,
Vpm=@Vpm,
Ipm=@Ipm,
FF=@FF,
Sun=@Sun,
Temp=@Temp,
Class=@Class,
Employee=@Employee,
LineTitle=@LineTitle,
StationTitle=@StationTitle
where ID=@ID
end
else if @queryType=3 --删除
begin
delete from AkIv where ID=@ID
end
else if @queryType=6 --删除
begin
declare @selectStr nvarchar(1000)
set @selectStr='delete from AkIv ' + @searchString
exec (@selectStr)
end
else if @queryType=4 --查询记录数
begin
declare @countStr nvarchar(max)
set @countStr = 'select COUNT(1) from AkIv '+@searchString
execute(@countStr)
end
else if @queryType=5 --查询记录
begin
declare @select nvarchar(max)
set @select=
'
select * from
(
select ROW_NUMBER() OVER ('+@orderString+') AS Row,*
from AkIv
'+@searchString+'
)
as AkIvlist WHERE (Row BETWEEN '+cast(@startIndex as nvarchar)+' AND '+cast(@endIndex as nvarchar)+' )
'
execute(@select)
end
else if @queryType=11 --根据组件条码查询最新单条记录
begin
select top 1 * from AkIv where BarCode=@BarCode order by DateTime desc
end

DAL

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyRight.Model;
using MyRight.Common; namespace MyRight.DAL
{
public partial class AkIvRepository
{
private readonly string _connonnectionString;
public AkIvRepository(string connonnectionString)
{
_connonnectionString = connonnectionString;
}
public AkIv GetSingle(string Id)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.NVarChar);
p_Id.Value = Id;//主键
SqlParameter[] para = { p_queryType, p_Id };
SqlDataReader dr = SqlHelper.ExecuteReader(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
AkIv tabAkIv = new AkIv();
if (dr.Read())
tabAkIv = EntityLoad(dr);
dr.Close();
return tabAkIv;
} public AkIv GetSingleByBarcode(string Barcode)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_Barcode = new SqlParameter("@BarCode", SqlDbType.NVarChar);
p_Barcode.Value = Barcode;//主键
SqlParameter[] para = { p_queryType, p_Barcode };
SqlDataReader dr = SqlHelper.ExecuteReader(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
AkIv tabAkIv = new AkIv();
if (dr.Read())
tabAkIv = EntityLoad(dr);
dr.Close();
return tabAkIv;
} public List<AkIv> GetPageList(int startIndex, int endIndex, string searchString, string orderString)
{
List<AkIv> listAkIv = new List<AkIv>();
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_startIndex = new SqlParameter("@startIndex", SqlDbType.Int);
p_startIndex.Value = startIndex;//起始位置
SqlParameter p_endIndex = new SqlParameter("@endIndex", SqlDbType.Int);
p_endIndex.Value = endIndex;//结束位置
SqlParameter p_searchString = new SqlParameter("@searchString", SqlDbType.NVarChar);
p_searchString.Value = searchString;//查询条件
SqlParameter p_orderString = new SqlParameter("@orderString", SqlDbType.NVarChar);
p_orderString.Value = orderString;//排序条件 SqlParameter[] para = { p_queryType, p_startIndex, p_endIndex, p_searchString, p_orderString };
SqlDataReader dr = SqlHelper.ExecuteReader(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para); while (dr.Read())
{
AkIv tabAkIv = EntityLoad(dr);
listAkIv.Add(tabAkIv);
}
dr.Close();
return listAkIv;
}
public int GetCount(string searchString)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_searchString = new SqlParameter("@searchString", SqlDbType.NVarChar);
p_searchString.Value = searchString;//查询条件 SqlParameter[] para = { p_queryType, p_searchString }; return (int)SqlHelper.ExecuteScalar(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
}
public int DeleteSingle(string Id)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.NVarChar);
p_Id.Value = Id;//主键
SqlParameter[] para = { p_queryType, p_Id };
return SqlHelper.ExecuteNonQuery(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
}
public int DeleteMulti(string searchString)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_searchString = new SqlParameter("@searchString", SqlDbType.NVarChar);
p_searchString.Value = searchString;//查询条件
SqlParameter[] para = { p_queryType, p_searchString };
return SqlHelper.ExecuteNonQuery(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
}
public int Update(AkIv obj)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.Int);
p_Id.Value = obj.Id;//流水号
SqlParameter p_BarCode = new SqlParameter("@BarCode", SqlDbType.NVarChar, );
p_BarCode.Value = obj.BarCode;//条码
SqlParameter p_DateTime = new SqlParameter("@DateTime", SqlDbType.DateTime);
p_DateTime.Value = obj.DateTime;//时间
SqlParameter p_Eff = new SqlParameter("@Eff", SqlDbType.Float);
p_Eff.Value = obj.Eff;//电池转换效率
SqlParameter p_Isc = new SqlParameter("@Isc", SqlDbType.Float);
p_Isc.Value = obj.Isc;//短路电流
SqlParameter p_Voc = new SqlParameter("@Voc", SqlDbType.Float);
p_Voc.Value = obj.Voc;//开路电压
SqlParameter p_Rs = new SqlParameter("@Rs", SqlDbType.Float);
p_Rs.Value = obj.Rs;//串联电阻
SqlParameter p_Rsh = new SqlParameter("@Rsh", SqlDbType.Float);
p_Rsh.Value = obj.Rsh;//并联电阻
SqlParameter p_Pmax = new SqlParameter("@Pmax", SqlDbType.Float);
p_Pmax.Value = obj.Pmax;//最大功率
SqlParameter p_Vpm = new SqlParameter("@Vpm", SqlDbType.Float);
p_Vpm.Value = obj.Vpm;//最大功率时的电压
SqlParameter p_Ipm = new SqlParameter("@Ipm", SqlDbType.Float);
p_Ipm.Value = obj.Ipm;//最大功率时的电流
SqlParameter p_FF = new SqlParameter("@FF", SqlDbType.Float);
p_FF.Value = obj.FF;//填充因子
SqlParameter p_Sun = new SqlParameter("@Sun", SqlDbType.Float);
p_Sun.Value = obj.Sun;//光强
SqlParameter p_Temp = new SqlParameter("@Temp", SqlDbType.Float);
p_Temp.Value = obj.Temp;//温度
SqlParameter p_Class = new SqlParameter("@Class", SqlDbType.NVarChar, );
p_Class.Value = obj.Class;//档位
SqlParameter p_Employee = new SqlParameter("@Employee", SqlDbType.NVarChar, );
p_Employee.Value = obj.Employee;//人员
SqlParameter p_LineTitle = new SqlParameter("@LineTitle", SqlDbType.NVarChar, );
p_LineTitle.Value = obj.LineTitle;//线别
SqlParameter p_StationTitle = new SqlParameter("@StationTitle", SqlDbType.NVarChar, );
p_StationTitle.Value = obj.StationTitle;//工位
SqlParameter[] para = { p_queryType, p_Id, p_BarCode, p_DateTime, p_Eff, p_Isc, p_Voc, p_Rs, p_Rsh, p_Pmax, p_Vpm, p_Ipm, p_FF, p_Sun, p_Temp, p_Class, p_Employee, p_LineTitle, p_StationTitle };
return SqlHelper.ExecuteNonQuery(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
}
public int Insert(AkIv obj)
{
SqlParameter p_queryType = new SqlParameter("@queryType", SqlDbType.Int);
p_queryType.Value = ;//操作类型
SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.Int);
p_Id.Value = obj.Id;//流水号
SqlParameter p_BarCode = new SqlParameter("@BarCode", SqlDbType.NVarChar, );
p_BarCode.Value = obj.BarCode;//条码
SqlParameter p_DateTime = new SqlParameter("@DateTime", SqlDbType.DateTime);
p_DateTime.Value = obj.DateTime;//时间
SqlParameter p_Eff = new SqlParameter("@Eff", SqlDbType.Float);
p_Eff.Value = obj.Eff;//电池转换效率
SqlParameter p_Isc = new SqlParameter("@Isc", SqlDbType.Float);
p_Isc.Value = obj.Isc;//短路电流
SqlParameter p_Voc = new SqlParameter("@Voc", SqlDbType.Float);
p_Voc.Value = obj.Voc;//开路电压
SqlParameter p_Rs = new SqlParameter("@Rs", SqlDbType.Float);
p_Rs.Value = obj.Rs;//串联电阻
SqlParameter p_Rsh = new SqlParameter("@Rsh", SqlDbType.Float);
p_Rsh.Value = obj.Rsh;//并联电阻
SqlParameter p_Pmax = new SqlParameter("@Pmax", SqlDbType.Float);
p_Pmax.Value = obj.Pmax;//最大功率
SqlParameter p_Vpm = new SqlParameter("@Vpm", SqlDbType.Float);
p_Vpm.Value = obj.Vpm;//最大功率时的电压
SqlParameter p_Ipm = new SqlParameter("@Ipm", SqlDbType.Float);
p_Ipm.Value = obj.Ipm;//最大功率时的电流
SqlParameter p_FF = new SqlParameter("@FF", SqlDbType.Float);
p_FF.Value = obj.FF;//填充因子
SqlParameter p_Sun = new SqlParameter("@Sun", SqlDbType.Float);
p_Sun.Value = obj.Sun;//光强
SqlParameter p_Temp = new SqlParameter("@Temp", SqlDbType.Float);
p_Temp.Value = obj.Temp;//温度
SqlParameter p_Class = new SqlParameter("@Class", SqlDbType.NVarChar, );
p_Class.Value = obj.Class;//档位
SqlParameter p_Employee = new SqlParameter("@Employee", SqlDbType.NVarChar, );
p_Employee.Value = obj.Employee;//人员
SqlParameter p_LineTitle = new SqlParameter("@LineTitle", SqlDbType.NVarChar, );
p_LineTitle.Value = obj.LineTitle;//线别
SqlParameter p_StationTitle = new SqlParameter("@StationTitle", SqlDbType.NVarChar, );
p_StationTitle.Value = obj.StationTitle;//工位
SqlParameter[] para = { p_queryType, p_Id, p_BarCode, p_DateTime, p_Eff, p_Isc, p_Voc, p_Rs, p_Rsh, p_Pmax, p_Vpm, p_Ipm, p_FF, p_Sun, p_Temp, p_Class, p_Employee, p_LineTitle, p_StationTitle };
return SqlHelper.ExecuteNonQuery(_connonnectionString, CommandType.StoredProcedure, "proc_AkIv", para);
}
public AkIv EntityLoad(SqlDataReader dr)
{
return new AkIv
{
Id = (dr["Id"] != DBNull.Value) ? Convert.ToInt32(dr["Id"]) : ,
BarCode = (dr["BarCode"] != DBNull.Value) ? dr["BarCode"].ToString() : "",
DateTime = (dr["DateTime"] != DBNull.Value) ? Convert.ToDateTime(dr["DateTime"]) : DateTime.Now,
Eff = (dr["Eff"] != DBNull.Value) ? Convert.ToSingle(dr["Eff"]) : ,
Isc = (dr["Isc"] != DBNull.Value) ? Convert.ToSingle(dr["Isc"]) : ,
Voc = (dr["Voc"] != DBNull.Value) ? Convert.ToSingle(dr["Voc"]) : ,
Rs = (dr["Rs"] != DBNull.Value) ? Convert.ToSingle(dr["Rs"]) : ,
Rsh = (dr["Rsh"] != DBNull.Value) ? Convert.ToSingle(dr["Rsh"]) : ,
Pmax = (dr["Pmax"] != DBNull.Value) ? Convert.ToSingle(dr["Pmax"]) : ,
Vpm = (dr["Vpm"] != DBNull.Value) ? Convert.ToSingle(dr["Vpm"]) : ,
Ipm = (dr["Ipm"] != DBNull.Value) ? Convert.ToSingle(dr["Ipm"]) : ,
FF = (dr["FF"] != DBNull.Value) ? Convert.ToSingle(dr["FF"]) : ,
Sun = (dr["Sun"] != DBNull.Value) ? Convert.ToSingle(dr["Sun"]) : ,
Temp = (dr["Temp"] != DBNull.Value) ? Convert.ToSingle(dr["Temp"]) : ,
Class = (dr["Class"] != DBNull.Value) ? dr["Class"].ToString() : "",
Employee = (dr["Employee"] != DBNull.Value) ? dr["Employee"].ToString() : "",
LineTitle = (dr["LineTitle"] != DBNull.Value) ? dr["LineTitle"].ToString() : "",
StationTitle = (dr["StationTitle"] != DBNull.Value) ? dr["StationTitle"].ToString() : ""
};
}
}
}

Controller

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using fastJSON;
using MyRight.Common;
using MyRight.DAL;
using MyRight.Model; namespace MyRight.Web.Controllers
{
[MyAuthorize]
public class AkIvController : Controller
{
private readonly string _conn;
private readonly AkIvRepository _akIvRepository;
private readonly UserOperateLogRepository _userOperateLogRepository; public AkIvController()
{
_conn = ConnHelper.GetConnConfig(System.Web.HttpContext.Current); _akIvRepository = new AkIvRepository(_conn);
_userOperateLogRepository = new UserOperateLogRepository(_conn);
} public PartialViewResult List()
{
try
{
ViewBag.MenuCode = Request["menucode"];//菜单代码
ViewBag.MenuName = Request["menuname"];//菜单名称
}
catch { } return PartialView();
} public string ListProcess()
{
string searchString = "";//查询条件
searchString = "where BarCode like '%@param%' and (DateTime between '@begin' and '@end')";
searchString = searchString.Replace("@param", Request["searchString"]);
searchString = searchString.Replace("@begin", Request["begin"]);
searchString = searchString.Replace("@end", Request["end"]); string orderString = "order by Id desc";//排序条件
if (!string.IsNullOrEmpty(Request["sort"]) && !string.IsNullOrEmpty(Request["order"]))
{
orderString = "order by " + Request["sort"] + " " + Request["order"];
} int pageindex = ;//当前页
int pagesize = ;//页面大小
if (!string.IsNullOrEmpty(Request["page"]) && !string.IsNullOrEmpty(Request["rows"]))
{
try
{
pageindex = int.Parse(Request["page"]);
pagesize = int.Parse(Request["rows"]);
}
catch { } if (SqlInjection.GetString(Request["page"]) || SqlInjection.GetString(Request["rows"]))
{
SaveUserLog("AkIv分页条件注入", Request["page"] + " " + Request["rows"], true);
pageindex = ;
pagesize = ;
}
} //分页转换
int startIndex = (pageindex - ) * pagesize + ;
int endIndex = pageindex * pagesize; List<AkIv> pageResult = _akIvRepository.GetPageList(startIndex, endIndex, searchString, orderString);
string pageJsonResult = JSON.Instance.ToJSON(pageResult, JSONConfig.GetJSONParameters());
int count = _akIvRepository.GetCount(searchString);
return "{\"total\": " + count + ",\"rows\":" + pageJsonResult + "}";
} public PartialViewResult Add()
{
return PartialView();
} public string AddProcess(AkIv akIv)
{
ResponseMessage responseMessage = new ResponseMessage(); int result = _akIvRepository.Insert(akIv);
if (result > )
{
responseMessage.Message = "添加成功!";
responseMessage.Success = "true";
SaveUserLog("AkIv添加", JSON.Instance.ToJSON(akIv, JSONConfig.GetJSONParameters()), true);
}
else
{
responseMessage.Message = "添加失败!";
responseMessage.Success = "false";
SaveUserLog("AkIv添加", JSON.Instance.ToJSON(akIv, JSONConfig.GetJSONParameters()), false);
}
return JSON.Instance.ToJSON(responseMessage, JSONConfig.GetJSONParameters());
} public string DeleteProcess(string Id)
{
ResponseMessage responseMessage = new ResponseMessage(); string deleteString = "";//删除条件
if (Id.Length > )
{
Id = Id.Substring();
deleteString = "where Id in (" + Id + ")";
} if (string.IsNullOrEmpty(deleteString))
{
SaveUserLog("AkIv删除", "AkIv删除条件为空", false); responseMessage.Message = "删除失败!";
responseMessage.Success = "false";
return JSON.Instance.ToJSON(responseMessage, JSONConfig.GetJSONParameters());
} int result = _akIvRepository.DeleteMulti(deleteString);
if (result > )
{
responseMessage.Message = "删除成功!";
responseMessage.Success = "true";
SaveUserLog("AkIv删除", deleteString, true);
}
else
{
responseMessage.Message = "删除失败!";
responseMessage.Success = "false";
SaveUserLog("AkIv删除", deleteString, false);
}
return JSON.Instance.ToJSON(responseMessage, JSONConfig.GetJSONParameters());
} public PartialViewResult Edit()
{
return PartialView();
} public string EditProcess(AkIv akIv)
{
ResponseMessage responseMessage = new ResponseMessage(); int result = _akIvRepository.Update(akIv);
if (result > )
{
responseMessage.Message = "修改成功!";
responseMessage.Success = "true";
SaveUserLog("AkIv修改", JSON.Instance.ToJSON(akIv, JSONConfig.GetJSONParameters()), true);
}
else
{
responseMessage.Message = "修改失败!";
responseMessage.Success = "false";
SaveUserLog("AkIv修改", JSON.Instance.ToJSON(akIv, JSONConfig.GetJSONParameters()), false);
}
return JSON.Instance.ToJSON(responseMessage, JSONConfig.GetJSONParameters());
} public string GetIvDataUseBarcode()
{
string barcode = Request["barcode"];
AkIv akIv = _akIvRepository.GetSingleByBarcode(barcode);
return JSON.Instance.ToJSON(akIv, JSONConfig.GetJSONParameters());
} //导出
public void Export()
{
string searchString = Request["searchString"];
string begin = Request["begin"];
string end = Request["end"]; Response.Clear();
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AddHeader("Content-Disposition", string.Format("attachment;filename={0}", "IV.xlsx")); NPOI.XSSF.UserModel.XSSFWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook();
NPOI.SS.UserModel.ISheet sheet1 = workbook.CreateSheet("IV"); //excel格式化
NPOI.SS.UserModel.ICellStyle dateStyle = workbook.CreateCellStyle();
dateStyle.DataFormat = workbook.CreateDataFormat().GetFormat("yyyy/m/d h:mm:ss"); NPOI.SS.UserModel.ICellStyle numberStyle = workbook.CreateCellStyle();
numberStyle.DataFormat = workbook.CreateDataFormat().GetFormat("0.00000"); NPOI.SS.UserModel.ICellStyle textStyle = workbook.CreateCellStyle();
textStyle.DataFormat = workbook.CreateDataFormat().GetFormat("@"); //给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow();
row1.CreateCell().SetCellValue("条码");
row1.CreateCell().SetCellValue("时间");
row1.CreateCell().SetCellValue("Eff");
row1.CreateCell().SetCellValue("Isc");
row1.CreateCell().SetCellValue("Voc");
row1.CreateCell().SetCellValue("Rs");
row1.CreateCell().SetCellValue("Rsh");
row1.CreateCell().SetCellValue("Pmax");
row1.CreateCell().SetCellValue("Vpm");
row1.CreateCell().SetCellValue("Ipm");
row1.CreateCell().SetCellValue("FF");
row1.CreateCell().SetCellValue("Sun");
row1.CreateCell().SetCellValue("Temp");
row1.CreateCell().SetCellValue("Class");
row1.CreateCell().SetCellValue("人员");
row1.CreateCell().SetCellValue("线别");
row1.CreateCell().SetCellValue("工位"); //将数据逐步写入sheet1各个行
string strSql = "where BarCode like '%@param%' and (DateTime between '@begin' and '@end')";
strSql = strSql.Replace("@param", searchString);
strSql = strSql.Replace("@begin", begin);
strSql = strSql.Replace("@end", end); List<AkIv> pageResult = _akIvRepository.GetPageList(, , strSql, "order by Id desc");
for (int i = ; i < pageResult.Count; i++)
{
NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + ); rowtemp.CreateCell().SetCellValue(pageResult[i].BarCode);
rowtemp.CreateCell().SetCellValue(pageResult[i].DateTime);
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Eff)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Isc)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Voc)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rs)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rsh)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Pmax)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Vpm)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Ipm)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].FF)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Sun)));
rowtemp.CreateCell().SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Temp)));
rowtemp.CreateCell().SetCellValue(pageResult[i].Class);
rowtemp.CreateCell().SetCellValue(pageResult[i].Employee);
rowtemp.CreateCell().SetCellValue(pageResult[i].LineTitle);
rowtemp.CreateCell().SetCellValue(pageResult[i].StationTitle); rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = dateStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = numberStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
rowtemp.GetCell().CellStyle = textStyle;
}
//写入到客户端
System.IO.MemoryStream ms = new System.IO.MemoryStream();
workbook.Write(ms);
Response.BinaryWrite(ms.ToArray()); Response.Flush();
Response.End();
} private void SaveUserLog(string operateInfo, string description, bool ifSuccess)
{
User user = UserHelper.GetUser(System.Web.HttpContext.Current);
UserOperateLog userOperateLog = new UserOperateLog()
{
UserName = user.UserName,
UserIp = Request.UserHostAddress,
OperateInfo = operateInfo,
Description = description,
IfSuccess = ifSuccess,
OperateDate = DateTime.Now
};
_userOperateLogRepository.Insert(userOperateLog);
}
}
}

视图

<script type="text/javascript">
$(function () {
$.ajax({
type: "POST",
url: "Button/GetUserButton",
data: { menucode: '@(ViewBag.MenuCode)' },
success: function (data) {
if (data.search("<nimei></nimei>") > 0) {
$.show_warning("提示", "无权限,请联系管理员!");
$('#tabs').tabs('close', '@(ViewBag.MenuName)');
} else {
$("#akiv_toolbar").html(data);
//插入特殊按钮
var htm = _TEXT(function () {
/*
<td>
<span style="margin-left: 5px;">开始时间:</span>
<input class="easyui-datetimebox" id="akiv_begin" style="width:130px">
</td>
<td>
<span style="margin-left: 5px;">结束时间:</span>
<input class="easyui-datetimebox" id="akiv_end" style="width:130px">
</td>
<td flag="search">
<span style="margin-left: 5px;">条码:</span>
<span class="l-btn-left" style="margin-left: -10px;">
<input id="akiv_searchstring" style="width: 130px;text-transform: uppercase;">
</span>
</td>
*/
});
//修改菜单
$("#akiv_toolbar td[flag='search']").replaceWith(htm);
//为菜单控件赋值
$("#akiv_begin").datetimebox({ value: '@Html.Raw(string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now.AddHours(-3)))', showSeconds: false });
$("#akiv_end").datetimebox({ value: '@Html.Raw(string.Format("{0:yyyy-MM-dd HH:mm:ss}", DateTime.Now.AddYears(1)))', showSeconds: false });
akiv_databind();
}
}
});
}); function _TEXT(wrap) {
return wrap.toString().match(/\/\*\s([\s\S]*)\s\*\//)[1];
} function akiv_add() {
$("<div></div>").dialog({
id: "akiv_add_dialog",
href: "AkIv/Add",
title: "添加按钮",
height: 400,
width: 500,
modal: true,
buttons: [{
id: "akiv_add_btn",
text: '添 加',
handler: function () {
$("#akiv_addform").form("submit", {
url: "AkIv/AddProcess",
onSubmit: function () {
$('#akiv_add_btn').linkbutton('disable');
if ($(this).form('validate')) {
return true;
}
else {
$('#akiv_add_btn').linkbutton('enable');
return false;
}
},
success: function (data) {
var result = eval('(' + data + ')');
if (result.Success) {
$("#akiv_add_dialog").dialog('destroy');
$.show_warning("提示", result.Message);
akiv_databind();
} else {
$('#akiv_add_btn').linkbutton('enable');
$.show_warning("提示", result.Message);
}
}
});
}
}],
onClose: function () {
$("#akiv_add_dialog").dialog('destroy');
}
});
} function akiv_delete() {
var rows = $("#akiv_dg").datagrid("getChecked");
if (rows.length < 1) {
$.show_warning("提示", "请先勾选要删除的记录");
return;
}
$.messager.confirm('提示', '确定删除勾选的' + rows.length + '项?', function (rusult) {
if (rusult) {
var para = "";
$.each(rows, function (i, row) {
para += ",'" + row.Id + "'";
});
$.ajax({
type: "POST",
url: "AkIv/DeleteProcess",
data: { "Id": para },
success: function (data) {
var result = eval('(' + data + ')');
if (result.Success) {
$.show_warning("提示", result.Message);
akiv_databind();
} else {
$.show_warning("提示", result.Message);
}
}
});
}
});
} function akiv_edit() {
var rows = $("#akiv_dg").datagrid("getChecked");
if (rows.length < 1) {
$.show_warning("提示", "请先勾选要修改的记录");
return;
}
if (rows.length > 1) {
$.show_warning("提示", "不支持批量修改");
return;
}
$("<div></div>").dialog({
id: "akiv_edit_dialog",
href: "AkIv/Edit",
title: "修改按钮",
height: 400,
width: 500,
modal: true,
buttons: [{
id: "akiv_edit_btn",
text: '修 改',
handler: function () {
$("#akiv_editform").form("submit", {
url: "AkIv/EditProcess",
onSubmit: function () {
$('#akiv_edit_btn').linkbutton('disable');
if ($(this).form('validate')) {
return true;
}
else {
$('#akiv_edit_btn').linkbutton('enable');
return false;
}
},
success: function (data) {
var result = eval('(' + data + ')');
if (result.Success) {
$("#akiv_edit_dialog").dialog('destroy');
$.show_warning("提示", result.Message);
akiv_databind();
} else {
$('#akiv_edit_btn').linkbutton('enable');
$.show_warning("提示", result.Message);
}
}
});
}
}],
onLoad: function () {
$("#akiv_editform").find('[name=Id]').val(rows[0].Id);
$("#akiv_editform").find('[name=BarCode]').val(rows[0].BarCode);
$("#akiv_editform").find('[name=DateTime]').datetimebox({ value: rows[0].DateTime, showSeconds: false });
$("#akiv_editform").find('[name=Eff]').val(rows[0].Eff);
$("#akiv_editform").find('[name=Isc]').val(rows[0].Isc);
$("#akiv_editform").find('[name=Voc]').val(rows[0].Voc);
$("#akiv_editform").find('[name=Rs]').val(rows[0].Rs);
$("#akiv_editform").find('[name=Rsh]').val(rows[0].Rsh);
$("#akiv_editform").find('[name=Pmax]').val(rows[0].Pmax);
$("#akiv_editform").find('[name=Vpm]').val(rows[0].Vpm);
$("#akiv_editform").find('[name=Ipm]').val(rows[0].Ipm);
$("#akiv_editform").find('[name=FF]').val(rows[0].FF);
$("#akiv_editform").find('[name=Sun]').val(rows[0].Sun);
$("#akiv_editform").find('[name=Temp]').val(rows[0].Temp);
$("#akiv_editform").find('[name=Class]').val(rows[0].Class);
$("#akiv_editform").find('[name=Employee]').val(rows[0].Employee);
$("#akiv_editform").find('[name=LineTitle]').val(rows[0].LineTitle);
$("#akiv_editform").find('[name=StationTitle]').val(rows[0].StationTitle);
},
onClose: function () {
$("#akiv_edit_dialog").dialog('destroy'); //销毁dialog对象
}
});
} function akiv_databind() {
var searchString = $('#akfqc_searchstring').val();
var begin = $('#akiv_begin').datetimebox('getValue');
var end = $('#akiv_end').datetimebox('getValue'); $("#akiv_dg").datagrid({
url: "AkIv/ListProcess",
queryParams: { searchString: searchString, begin: begin, end: end },
striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true,
idField: 'Id',
sortName: 'Id',
sortOrder: 'desc',
pageList: [20, 40, 60, 80, 100],
columns: [
[
{ field: 'ck', checkbox: true },
{ field: 'Id', title: '流水号', hidden: true },
{ field: 'BarCode', title: '条码', width: 150 },
{ field: 'DateTime', title: '时间', width: 150 },
{ field: 'Eff', title: 'Eff', width: 100 },
{ field: 'Isc', title: 'Isc', width: 100 },
{ field: 'Voc', title: 'Voc', width: 100 },
{ field: 'Rs', title: 'Rs', width: 100 },
{ field: 'Rsh', title: 'Rsh', width: 100 },
{ field: 'Pmax', title: 'Pmax', width: 100 },
{ field: 'Vpm', title: 'Vpm', width: 100 },
{ field: 'Ipm', title: 'Ipm ', width: 100 },
{ field: 'FF', title: 'FF', width: 100 },
{ field: 'Sun', title: 'Sun', width: 100 },
{ field: 'Temp', title: 'Temp ', width: 100 },
{ field: 'Class', title: 'Class', width: 100 },
{ field: 'Employee', title: '人员', width: 100 },
{ field: 'LineTitle', title: '线别', width: 100 },
{ field: 'StationTitle', title: '工位', width: 100 }
]
],
toolbar: '#akiv_toolbar'
});
} //导出
function akiv_export() {
var searchString = $('#akiv_searchstring').val();
var begin = encodeURIComponent($('#akiv_begin').datetimebox('getValue'));
var end = encodeURIComponent($('#akiv_end').datetimebox('getValue')); var href = "/AkIv/Export?searchString=" + searchString + "&begin=" + begin + "&end=" + end;
$("#akiv_export_href").attr("href", href);
var a = document.getElementById("akiv_export_href");
akfqc_invokeClick(a);
}
function akfqc_invokeClick(element) {
if (element.click)
element.click(); //判断是否支持click() 事件
else if (element.fireEvent)
element.fireEvent('onclick'); //触发click() 事件
else if (document.createEvent) {
var evt = document.createEvent("MouseEvents"); //创建click() 事件
evt.initEvent("click", true, true); //初始化click() 事件
element.dispatchEvent(evt); //分发click() 事件
}
}
</script> <div id="akiv_layout" class="easyui-layout" data-options="fit:true,border:false">
<div data-options="region:'center',border:false">
<table id="akiv_dg" data-options="fit:true,border:false"></table>
</div>
</div>
<div id="akiv_toolbar" class="datagrid-toolbar">
</div>
<a id="akiv_export_href" href="" style="display: none;" target="_blank" />