forked from xuxiaowei007/FoxOne
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListControlBase.cs
139 lines (130 loc) · 4.57 KB
/
ListControlBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using FoxOne.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Web;
using FoxOne.Core;
using System.Threading;
namespace FoxOne.Controls
{
public abstract class NoPagerListControlBase : PageControlBase, IListDataSourceControl
{
public override object Clone()
{
var result = base.Clone() as NoPagerListControlBase;
if (result.DataSource != null)
{
result.DataSource.Parameter = null;
result.DataSource.SortExpression = "";
}
return result;
}
/// <summary>
/// 表格数据源
/// </summary>
[DisplayName("表格数据源")]
public IListDataSource DataSource
{
get;
set;
}
private void InitDataSourceParameter()
{
if (DataSource != null)
{
var param = DataSource.Parameter;
if (param == null)
{
param = new FoxOneDictionary<string, object>(StringComparer.OrdinalIgnoreCase);
}
foreach (var key in HttpContext.Current.Request.QueryString.AllKeys)
{
if (!HttpContext.Current.Request.QueryString[key].IsNullOrEmpty())
{
param[key] = HttpUtility.UrlDecode(HttpContext.Current.Request.QueryString[key]);
}
}
foreach (var key in HttpContext.Current.Request.Form.AllKeys)
{
if (!HttpContext.Current.Request.Form[key].IsNullOrEmpty())
{
param[key] = HttpUtility.UrlDecode(HttpContext.Current.Request.Form[key]);
}
}
DataSource.Parameter = param;
}
}
protected virtual IEnumerable<IDictionary<string, object>> GetDataInner()
{
if (DataSource == null)
{
throw new FoxOneException("Need_DataSource",this.Id);
}
return DataSource.GetList();
}
public virtual IEnumerable<IDictionary<string, object>> GetData()
{
InitDataSourceParameter();
var entities = GetDataInner();
return entities;
}
}
public abstract class ListControlBase : NoPagerListControlBase
{
/// <summary>
/// 是否翻页
/// </summary>
[DisplayName("是否翻页")]
public bool AllowPaging { get; set; }
/// <summary>
/// 翻页显示位置
/// </summary>
[DisplayName("翻页显示位置")]
public PagerPosition PagerPosition { get; set; }
/// <summary>
/// 翻页配置
/// </summary>
[DisplayName("翻页配置")]
public Pager Pager { get; set; }
protected override IEnumerable<IDictionary<string, object>> GetDataInner()
{
if (DataSource == null)
{
throw new FoxOneException("Need_DataSource",this.Id);
}
int recordCount = 0;
IEnumerable<IDictionary<string, object>> entities = null;
if (AllowPaging)
{
string pageIndex=HttpContext.Current.Request[NamingCenter.PARAM_PAGE_INDEX];
string pageSize = HttpContext.Current.Request[NamingCenter.PARAM_PAGE_SIZE];
string sortExpression = HttpContext.Current.Request[NamingCenter.PARAM_SORT_EXPRESSION];
if (!pageIndex.IsNullOrEmpty())
{
Pager.CurrentPageIndex = pageIndex.ConvertTo<int>();
}
else
{
Pager.CurrentPageIndex = 1;
}
if (!pageSize.IsNullOrEmpty())
{
Pager.PageSize = pageSize.ConvertTo<int>();
}
if (!sortExpression.IsNullOrEmpty())
{
DataSource.SortExpression = sortExpression;
}
entities = DataSource.GetList(Pager.CurrentPageIndex, Pager.PageSize, out recordCount);
Pager.RecordCount = recordCount;
}
else
{
entities = DataSource.GetList();
}
return entities;
}
}
}