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. LeetCode Degree of an Array

    原题链接在这里:https://leetcode.com/problems/degree-of-an-array/description/ 题目: Given a non-empty array of ...

  2. LG3648 [APIO2014]序列分割

    题意 你正在玩一个关于长度为 \(n\) 的非负整数序列的游戏.这个游戏中你需要把序列分成 \(k+1\) 个非空的块.为了得到 \(k+1\) 块,你需要重复下面的操作 \(k\) 次: 选择一个有 ...

  3. Shell编程(二)——shell的基础知识及常用命令

    shell的基础知识 一.bash有以下特点: 1.记录命令历史 2.指令和文件名补全 3.别名 alias rm='rm -i' 4.通配符 * 0个或多个字符 ?​匹配一个字符 5 输入输出重定向 ...

  4. Jmeter ----关于上传图片接口

    转自:http://www.cnblogs.com/linglingyuese/p/4514808.html 需求 1 2 3 4 5 6 7 8 9 post上传   Request: { &quo ...

  5. STM32从boot跳转到app失败

    现象:在每次boot执行完跳转到APP时,都会跑飞 原因:在boot中使用到了USART和TIM,boot执行完没有关闭总中断 方法:在boot执行完跳转之前关闭中断,__disable_irq() ...

  6. DHCP(二)

    提供阶段:即DHCP服务器向DHCP客户端提供预分配IP地址的阶段.网络中的所有DHCP服务器接收到客户端的DHCP Discover报文后,都会根据自己地址池中IP地址分配的优先次序选出一个IP地址 ...

  7. FPGA市场潜力有几多?

    FPGA市场未来成长潜力 本文来源:DIGITIMES 2014年FPGA市场规模为52.7亿美元,据Green Mountain Outlook报导,研调机构Global Market Insigh ...

  8. FPGA前世今生(二)

    上期我们介绍了关于FPGA内部最基本的结构,在quartus下可以看到整体的结构. 这是在平面规划图下看到的结构,其中蓝色的小格代表一个LAB.四周边上浅棕色的小格代表IO口. 这是一个LAB的内部结 ...

  9. java中绘制长方形,椭圆形,圆形的方法

    总结:方法,main函数的作用你还没搞清楚 //画一个矩形 import java.awt.*; import javax.swing.*; public class Test2 extends JF ...

  10. mysql实战优化之三:表优化

    对于大多数的数据库引擎来说,硬盘操作可能是最重大的瓶颈.所以,把你的数据变得紧凑会对这种情况非常有帮助,因为这减少了对硬盘的访问. 如果一个表只会有几列罢了(比如说字典表,配置表),那么,我们就没有理 ...