jqentitydetail
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的更多相关文章
随机推荐
- HWOJ-求字符串最后一个单词的长度
题目:给定一个字符串,求最后一个单词的长度,每个单词中间有空格. 例如:输入:hello world 输出:5 C代码:通过. #include <stdio.h> #define m ...
- 剑指Offer-第一章面试细节总结
面试细节:行为面试(20%)+技术面试(70%)+应聘者提问(10%) * 行为面试:跳槽者(不要抱怨老板,不要抱怨同事,只为追寻自己的理想而站斗) * 技术面试:1.基础知识点(编程语言,数据结构( ...
- miniofs 配置使用
1. rpm // RPM 包下载 https://github.com/minio/minfs/releases/tag/RELEASE.2017-02-26T20-20-56Z // 安装 yu ...
- OpenWRT mt7620n 系统升级引起的问题
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qianguozheng/article/details/27237175 OpenWRT系统升级採用 ...
- Oracle的闪回特性之恢复truncate删除表的数据
Oracle的闪回特性之恢复truncate删除表的数据 SQL> show parameter flashback NAME T ...
- substr的学习(PHP学习)
substr的用法: 首先看PHP手册 ,手册上是这样说的 string substr ( string $string , int $start [, int $length ] ) 执行subst ...
- (转)Oracle中动态SQL详解
本文转载自:http://www.cnblogs.com/gaolonglong/archive/2011/05/31/2064790.html 1.静态SQLSQL与动态SQL Oracle编译PL ...
- 【转】JMeter入门
一.JMeter概述 JMeter就是一个测试工具,相比于LoadRunner等测试工具,此工具免费,且比较好用,但是前提当然是安装Java环境: JMeter可以做 (1)压力测试及性能测试: (2 ...
- 命令行调用远程dubbo服务
有时需要对dubbo服务做个简单的测试,或者想看下某个dubbo服务类所提供的方法,可以直接在命令行通过telnet的方式来查看和调用dubbo服务,方法如下: telnet 127.0.0.1 20 ...
- 解决maven构建工程错误:Failure to transfer org.apache.maven.plugins:maven-jar-plugin:pom:2.4 from错误
问题描述: mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=myapp -DarchetypeArtifactId=ma ...