using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Common;
using HraWeb.Common;
using Trirand.Web.UI.WebControls;
using Aspose.Cells;
using System.Collections;
using System.Text.RegularExpressions;
using Elmah;

namespace WebApp.Common
{
public class JQEntityManage<T> : BasePage where T : Framework.Domain.Entity
{
protected Contract.IService.IEntityService<T> svc
{
get;
set;
}
protected virtual void SaveLog()
{
Contract.Domain.SysOplog op = new Contract.Domain.SysOplog();
op.CreateDate = DateTime.Now;
op.CreateOid = CurrentUser.OfficeId;
op.CreatePid = CurrentUser.PositionId;
op.CreateUid = CurrentUser.UserId;
op.CreateUname = CurrentUser.UserName;
op.Moudleid = Request["_menuId"];
if (!string.IsNullOrEmpty(op.Moudleid))
{
op.Moudleid = op.Moudleid.Split(new char[] {',' })[0];
}
op.Opcommand = "查询";
op.Entity = typeof(T).ToString();
op.State.MarkNew();
Dao.SaveOrUpdate(op);
}

protected virtual void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
switch (HttpContext.Current.Request["_method"])
{
case "search":
SaveLog();
GetList();
break;
default:
InitPage();
break;
case "export":
SaveExpertLog();
ArrayList list = new ArrayList();
list.Add("Id");
ExportGrid(jq.Columns, string.Empty, list, true);
break;
}
}
}
private void SaveExpertLog()
{
Contract.Domain.SysOplog op = new Contract.Domain.SysOplog();
op.CreateDate = DateTime.Now;
op.CreateOid = CurrentUser.OfficeId;
op.CreatePid = CurrentUser.PositionId;
op.CreateUid = CurrentUser.UserId;
op.CreateUname = CurrentUser.UserName;
op.Moudleid = Request["_menuId"];
op.Opcommand = "导出数据";
op.OpType = "导出数据";
op.Entity = typeof(T).ToString();
op.State.MarkNew();
Dao.SaveOrUpdate(op);
}
private JQGrid _jq = null;
protected virtual JQGrid jq
{
set
{
_jq = value;
}
get
{
if (_jq == null)
{
_jq = FindControl("jq") as JQGrid;
}
return _jq;
}
}

protected virtual void ExportGrid(JQGridColumnCollection Columns,string title,ArrayList ignorColList, bool showHeader)
{
info = SetInfo();
info.TotalCount = 0;
info.StartRecord = 0;
setDataSource();
ChangeList(info);
System.Data.DataTable table = null;
if (info.Transformer != null)
{
table = (info.Transformer as System.Data.DataSet).Tables[0];
}
else
{
table = ToJson.ToDataTable(info.List, Columns);
}
Workbook workbook = new Workbook(); //工作簿
Worksheet sheet = workbook.Worksheets[0]; //工作表
sheet.AutoFitColumns();
Cells cells = sheet.Cells;//单元格
Style styleTitle = workbook.Styles[workbook.Styles.Add()];//新增样式
styleTitle.HorizontalAlignment = TextAlignmentType.Center;//文字居中
styleTitle.Font.Name = "宋体";//文字字体
styleTitle.Font.Size = 14;//文字大小
styleTitle.Font.IsBold = false;//粗体
//样式2
Style style2 = workbook.Styles[workbook.Styles.Add()];//新增样式
style2.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style2.Font.Name = "宋体";//文字字体
style2.Font.Size = 10;//文字大小
style2.Font.IsBold = false;//粗体
style2.IsTextWrapped = true;//单元格内容自动换行
style2.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style2.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
Style style3 = workbook.Styles[workbook.Styles.Add()];//新增样式
style3.HorizontalAlignment = TextAlignmentType.Center;//文字居中
style3.Font.Name = "宋体";//文字字体
style3.Font.Size = 10;//文字大小
style3.Borders[BorderType.LeftBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.RightBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.TopBorder].LineStyle = CellBorderType.Thin;
style3.Borders[BorderType.BottomBorder].LineStyle = CellBorderType.Thin;
if (!string.IsNullOrEmpty(title))
{
int i = Columns.Count;
if (ignorColList != null)
{
i = i - ignorColList.Count;
}
cells.Merge(0, 0, 1,i);//合并单元格
cells[0, 0].PutValue(title);//填写内容
cells[0, 0].SetStyle(styleTitle);
}
int start = string.IsNullOrEmpty(title) ? 0 : 1;
int j = 0;
if (showHeader)
{
for (var i = 0; i < Columns.Count; i++)
{
var c = Columns[i];
if (ignorColList.Contains(c.DataField))
{
continue;
}
cells[start, j].PutValue(c.HeaderText);
cells[start, j].SetStyle(style2);
j++;
}
}
for (var q = 0; q < table.Rows.Count; q++)
{
j = 0;
var row = table.Rows[q];
for (var i = 0; i < Columns.Count; i++)
{
var c = Columns[i];
if (ignorColList.Contains(c.DataField))
{
continue;
}
cells[start + 1 + q, j].PutValue(row[c.DataField]);
cells[start + 1 + q, j].SetStyle(style3);
cells.SetRowHeight(start + 1 + q, 25);
j++;
}
}
workbook.Save(string.Format("report.xls"), Aspose.Cells.SaveType.OpenInExcel, Aspose.Cells.FileFormatType.Excel2003, Response);
Response.Flush();
Response.End();
}
//初始控件
protected virtual void InitPage()
{
}
private string _splitchar=string.Empty;
public string SplitChar
{
set
{
_splitchar = "_";
}
get
{
if (string.IsNullOrEmpty(_splitchar))
{
_splitchar = "_";
}
return _splitchar;
}
}
private static string regexCtlValObj = @"\w{3,5}?_(?<PROP>\w*)_(?<TAG>(\w\d{1,2})*)$";
public static Regex regEx = new Regex(regexCtlValObj, RegexOptions.IgnoreCase);
/// <summary>
/// 设置查询条件
/// </summary>
/// <returns></returns>

protected virtual Framework.QueryInfo SetInfo()
{
info = new Framework.QueryInfo();
info.Parameters.Clear();
System.Collections.Hashtable aa = new System.Collections.Hashtable();

foreach (string key in Request.QueryString.Keys)
{
if (regEx.IsMatch(key))
{
Match m = regEx.Match(key);
string g = m.Groups["TAG"].Value;
if (string.IsNullOrEmpty(Request.QueryString[key]))
{
continue;
}
if (string.IsNullOrEmpty(g))
{
if (!aa.Contains(m.Groups["PROP"].Value))
{
aa.Add(m.Groups["PROP"].Value, Request.QueryString[key]);
}
}
else
{
if (!aa.Contains(m.Groups["PROP"].Value + "_" + g))
{
aa.Add(m.Groups["PROP"].Value + "_" + g, Request.QueryString[key]);
}

}
}
}
info.AddParam(aa);
// info.AddParam(WebHelper.Web.UI.BindingPanel.SaveData<System.Collections.Hashtable>(Request.QueryString, 0));
info = ExceptRecord(info);
return info;
}
/// <summary>
/// 排除默认值记录
/// </summary>
/// <param name="info"></param>
/// <returns></returns>
protected virtual Framework.QueryInfo ExceptRecord(Framework.QueryInfo info)
{
if (!string.IsNullOrEmpty(Request["defaultId"]))
{
info.AddParam("defaultId", Request["defaultId"], " and Id!=:defaultId");
}
return info;
}
public virtual void ChangeList(Framework.QueryInfo infoList)
{

}
protected virtual void setDataSource()
{
if ((string.IsNullOrEmpty(info.QueryObject) && string.IsNullOrEmpty(info.CustomSQL)))
{

info.QueryObject = typeof(T).Name;

}
if (svc == null)
{
info = Dao.FindByQueryInfo(info);
}
else
{
info = svc.FindByQueryInfo(info);
}
}
public virtual void SetPositionCondition(Framework.QueryInfo tinfo)
{
if (!CurrentUser.IsSuperUser)
{
if (CurrentUser.PositionUserIds != null && CurrentUser.PositionUserIds.Length > 0)
{
if (CurrentUser.PositionUserIds.Length == 1)
{
tinfo.AddParam("CreateUid", CurrentUser.PositionUserIds[0]);
}
else
{
tinfo.AddParam("CreateUid", CurrentUser.PositionUserIds, " and CreateUid in(:CreateUid) ");
}
}
else
{
tinfo.CancelList = true;
}
}
}
/// <summary>
/// 获取列表信息
/// </summary>
protected virtual void GetList()
{
try
{
info = SetInfo();
if (info.CheckPosition)
{
//设置岗位过滤
SetPositionCondition(info);
}
info.TotalCount = 1;
#region 分页信息

int pageIndex = 0;
try
{
info.PageSize = int.Parse(HttpContext.Current.Request["rows"]);
pageIndex = int.Parse(HttpContext.Current.Request["page"]);
info.StartRecord = (pageIndex - 1) * info.PageSize;
if (!string.IsNullOrEmpty(Request["sidx"]))
{
info.OrderBy.Add(Request["sidx"] + " " + Request["sord"]);
}
}
catch (Exception ex)
{

}
#endregion

if (!info.CancelList)
{
setDataSource();
ChangeList(info);
}
else
{
info.List = new ArrayList();
}
if (info.Transformer != null)
{
System.Data.DataSet ds = info.Transformer as System.Data.DataSet;
string s = ToJson.JQDataset2Json(ds, info.PageSize, info.TotalCount, pageIndex);
HttpContext.Current.Response.Write(s);
}
else
{
int totalPage = info.TotalCount / info.PageSize;
if (info.TotalCount % info.PageSize != 0)
{
totalPage++;
}

JGridJson d = new JGridJson(totalPage, info.List, pageIndex,info.TotalCount);

HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(d));
}
// HttpContext.Current.ApplicationInstance.CompleteRequest();

}
catch (Exception ex)
{
System.Collections.ArrayList list = new System.Collections.ArrayList();
list.Add(new
{
ErrorCode = -999,
Message = ex.Message
});
Utility.JSUtil.log(ex);
ErrorSignal.FromCurrentContext().Raise(ex);
DataGridJson d = new DataGridJson(0, list);
HttpContext.Current.Response.Write(Newtonsoft.Json.JsonConvert.SerializeObject(d));
}
finally
{
HttpContext.Current.Response.End();
}
}
}
}

jqentitydetail的更多相关文章

随机推荐

  1. WCF日志跟踪SvcTraceViewer.exe

    参考: https://msdn.microsoft.com/zh-cn/library/ms732023.aspx https://msdn.microsoft.com/zh-cn/library/ ...

  2. 学习动态性能表(1)--v$sysstat

    由动态性能表学到的 第一篇--v$sysstat  2007.5.23 按照OracleDocument中的描述,v$sysstat存储自数据库实例运行那刻起就开始累计全实例(instance-wid ...

  3. Spring aop 记录操作日志 Aspect 自定义注解

    时间过的真快,转眼就一年了,没想到随手写的笔记会被这么多人浏览,不想误人子弟,于是整理了一个优化版,在这里感谢智斌哥提供的建议和帮助,话不多说,进入正题 所需jar包 :spring4.3相关联以及a ...

  4. Aes加密算法加密模式介绍

    本文转自:https://www.jianshu.com/p/582d3a47729a AES,高级加密标准(英语:Advanced Encryption Standard,缩写:AES),在密码学中 ...

  5. hdu 5730 Shell Necklace——多项式求逆+拆系数FFT

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5730 可以用分治FFT.但自己只写了多项式求逆. 和COGS2259几乎很像.设A(x),指数是长度,系数 ...

  6. Maven构建跳过测试步骤

    有时候我们不想再执行maven的package或者install命令时每次都执行test,那么可以在pom.xml里的build->pluginManagement->plugins新增如 ...

  7. 【Python学习笔记】在OSX下搭建opencv+python环境

    https://jjyap.wordpress.com/2014/05/24/installing-opencv-2-4-9-on-mac-osx-with-python-support/ 参照以上b ...

  8. BroadcastReceiver用法

    动态注册广播接收器 1.创建一个Receiver继承BroadcastReceiver,并重写onReceiver() 2.在Activity的OnCreate()中添加广播接收器想要接收的actio ...

  9. 平台调用之如何利用VS2013 C#调试C++DLL库

    对于托管代码调用非托管DLL文件,已经是非常普遍的事情,下面写一下如何通过托管代码(C#)像调试托管代码一样调试DLL中的代码. 注意:(1)[dll工程和调用dll的exe工程需要在同一个解决方案中 ...

  10. java的Swing编程====实现鼠标双击一下==画图===getMouseClicked的方法

    总结: 使用匿名类,但是用实现接口的方式呢??? package com.aa; import java.awt.Color; import java.awt.Graphics; import jav ...