easyUI+mvc權限管理後臺

經過按鈕和菜單,組合成基本的功能,菜單的功能能夠編碼修改,但瀏覽功能是菜單基本的入口,只有角色賦予了瀏覽功能,才能訪問。javascript

基本按鈕表html

菜單模塊java

菜單分配按鈕ajax

角色受權app

下面是對一張表的基本操做ui

模型this

 

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

DALurl

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 = 0;//操做類型
            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 = 11;//操做類型
            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 = 5;//操做類型
            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 = 4;//操做類型
            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 = 3;//操做類型
            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 = 6;//操做類型
            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 = 2;//操做類型
            SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.Int);
            p_Id.Value = obj.Id;//流水號
            SqlParameter p_BarCode = new SqlParameter("@BarCode", SqlDbType.NVarChar, 100);
            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, 50);
            p_Class.Value = obj.Class;//檔位
            SqlParameter p_Employee = new SqlParameter("@Employee", SqlDbType.NVarChar, 50);
            p_Employee.Value = obj.Employee;//人員
            SqlParameter p_LineTitle = new SqlParameter("@LineTitle", SqlDbType.NVarChar, 50);
            p_LineTitle.Value = obj.LineTitle;//線別
            SqlParameter p_StationTitle = new SqlParameter("@StationTitle", SqlDbType.NVarChar, 50);
            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 = 1;//操做類型
            SqlParameter p_Id = new SqlParameter("@Id", SqlDbType.Int);
            p_Id.Value = obj.Id;//流水號
            SqlParameter p_BarCode = new SqlParameter("@BarCode", SqlDbType.NVarChar, 100);
            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, 50);
            p_Class.Value = obj.Class;//檔位
            SqlParameter p_Employee = new SqlParameter("@Employee", SqlDbType.NVarChar, 50);
            p_Employee.Value = obj.Employee;//人員
            SqlParameter p_LineTitle = new SqlParameter("@LineTitle", SqlDbType.NVarChar, 50);
            p_LineTitle.Value = obj.LineTitle;//線別
            SqlParameter p_StationTitle = new SqlParameter("@StationTitle", SqlDbType.NVarChar, 50);
            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"]) : 0,
                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"]) : 0,
                Isc = (dr["Isc"] != DBNull.Value) ? Convert.ToSingle(dr["Isc"]) : 0,
                Voc = (dr["Voc"] != DBNull.Value) ? Convert.ToSingle(dr["Voc"]) : 0,
                Rs = (dr["Rs"] != DBNull.Value) ? Convert.ToSingle(dr["Rs"]) : 0,
                Rsh = (dr["Rsh"] != DBNull.Value) ? Convert.ToSingle(dr["Rsh"]) : 0,
                Pmax = (dr["Pmax"] != DBNull.Value) ? Convert.ToSingle(dr["Pmax"]) : 0,
                Vpm = (dr["Vpm"] != DBNull.Value) ? Convert.ToSingle(dr["Vpm"]) : 0,
                Ipm = (dr["Ipm"] != DBNull.Value) ? Convert.ToSingle(dr["Ipm"]) : 0,
                FF = (dr["FF"] != DBNull.Value) ? Convert.ToSingle(dr["FF"]) : 0,
                Sun = (dr["Sun"] != DBNull.Value) ? Convert.ToSingle(dr["Sun"]) : 0,
                Temp = (dr["Temp"] != DBNull.Value) ? Convert.ToSingle(dr["Temp"]) : 0,
                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() : ""
            };
        }
    }
}

Controllerspa

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 = 0;//當前頁
            int pagesize = 0;//頁面大小
            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 = 1;
                    pagesize = 20;
                }
            }

            //分頁轉換
            int startIndex = (pageindex - 1) * pagesize + 1;
            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 > 0)
            {
                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 > 0)
            {
                Id = Id.Substring(1);
                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 > 0)
            {
                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 > 0)
            {
                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(0);
            row1.CreateCell(0).SetCellValue("條碼");
            row1.CreateCell(1).SetCellValue("時間");
            row1.CreateCell(2).SetCellValue("Eff");
            row1.CreateCell(3).SetCellValue("Isc");
            row1.CreateCell(4).SetCellValue("Voc");
            row1.CreateCell(5).SetCellValue("Rs");
            row1.CreateCell(6).SetCellValue("Rsh");
            row1.CreateCell(7).SetCellValue("Pmax");
            row1.CreateCell(8).SetCellValue("Vpm");
            row1.CreateCell(9).SetCellValue("Ipm");
            row1.CreateCell(10).SetCellValue("FF");
            row1.CreateCell(11).SetCellValue("Sun");
            row1.CreateCell(12).SetCellValue("Temp");
            row1.CreateCell(13).SetCellValue("Class");
            row1.CreateCell(14).SetCellValue("人員");
            row1.CreateCell(15).SetCellValue("線別");
            row1.CreateCell(16).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(0, 100000, strSql, "order by Id desc");
            for (int i = 0; i < pageResult.Count; i++)
            {
                NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1);

                rowtemp.CreateCell(0).SetCellValue(pageResult[i].BarCode);
                rowtemp.CreateCell(1).SetCellValue(pageResult[i].DateTime);
                rowtemp.CreateCell(2).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Eff)));
                rowtemp.CreateCell(3).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Isc)));
                rowtemp.CreateCell(4).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Voc)));
                rowtemp.CreateCell(5).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rs)));
                rowtemp.CreateCell(6).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Rsh)));
                rowtemp.CreateCell(7).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Pmax)));
                rowtemp.CreateCell(8).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Vpm)));
                rowtemp.CreateCell(9).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Ipm)));
                rowtemp.CreateCell(10).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].FF)));
                rowtemp.CreateCell(11).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Sun)));
                rowtemp.CreateCell(12).SetCellValue(Convert.ToDouble(string.Format("{0:0.00000}", pageResult[i].Temp)));
                rowtemp.CreateCell(13).SetCellValue(pageResult[i].Class);
                rowtemp.CreateCell(14).SetCellValue(pageResult[i].Employee);
                rowtemp.CreateCell(15).SetCellValue(pageResult[i].LineTitle);
                rowtemp.CreateCell(16).SetCellValue(pageResult[i].StationTitle);

                rowtemp.GetCell(0).CellStyle = textStyle;
                rowtemp.GetCell(1).CellStyle = dateStyle;
                rowtemp.GetCell(2).CellStyle = numberStyle;
                rowtemp.GetCell(3).CellStyle = numberStyle;
                rowtemp.GetCell(4).CellStyle = numberStyle;
                rowtemp.GetCell(5).CellStyle = numberStyle;
                rowtemp.GetCell(6).CellStyle = numberStyle;
                rowtemp.GetCell(7).CellStyle = numberStyle;
                rowtemp.GetCell(8).CellStyle = numberStyle;
                rowtemp.GetCell(9).CellStyle = numberStyle;
                rowtemp.GetCell(10).CellStyle = numberStyle;
                rowtemp.GetCell(11).CellStyle = numberStyle;
                rowtemp.GetCell(12).CellStyle = numberStyle;
                rowtemp.GetCell(13).CellStyle = textStyle;
                rowtemp.GetCell(14).CellStyle = textStyle;
                rowtemp.GetCell(15).CellStyle = textStyle;
                rowtemp.GetCell(16).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" />
相關文章
相關標籤/搜索