/* 2008 4 25 更新 */
我的数据访问函数库的源码。整个类有1400行,原先就是分开来写的,现在更新后还是分开来发一下吧。
第三部分:返回结构

数组,这个是专门针对网页来设计的。就是在网页上更方便的显示一组数据。
1
//新增加的部分,返回结构数组用于绑定控件
2
3
函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle
4
/**//// <summary>
5
/// 运行SQl语句返回结构数组BaseTitle
6
/// </summary>
7
/// <param name="SQL">查询语句。比如select myName from tableName</param>
8
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
9
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
10
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
11
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
12
public BaseTitle[] RunSqlStructBaseTitle(string SQL,string SQLForCount,int TitleCount,string DateFormat,int IntroCount)
13
{
14
string strRowCount = RunSqlGetID(SQLForCount);
15
if (strRowCount == null)
16
return null;
17
18
int DataCount = Int32.Parse(strRowCount);
19
if (DataCount <1)
20
return null;
21
22
return RunSqlStructBT(SQL,DataCount,TitleCount,DateFormat,IntroCount);
23
}
24
#endregion
25
26
函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle
27
/**//// <summary>
28
/// 运行SQl语句返回结构数组BaseTitle
29
/// </summary>
30
/// <param name="SQL">查询语句。比如select myName from tableName</param>
31
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
32
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
33
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
34
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
35
public BaseTitle[] RunSqlStructBaseTitle(string SQL,int DataCount,int TitleCount,string DateFormat,int IntroCount)
36
{
37
if (DataCount <1)
38
return null;
39
40
return RunSqlStructBT(SQL,DataCount,TitleCount,DateFormat,IntroCount);
41
}
42
#endregion
43
44
函数实现 — — RunSqlStructBaseTitle#region 函数实现 — — RunSqlStructBaseTitle
45
/**//// <summary>
46
/// 运行SQl语句返回结构数组BaseTitle
47
/// </summary>
48
/// <param name="SQL">查询语句。比如select myName from tableName</param>
49
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
50
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
51
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
52
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
53
private BaseTitle[] RunSqlStructBT(string SQL,int DataCount,int TitleCount,string DateFormat,int IntroCount)
54
{
55
//返回ID 传入查询语句,返回第一条记录的第一的字段的值
56
SetCommand(SQL,1); //设置command
57
SqlDataReader r = null;
58
try
59
{
60
if (cm.Connection.State == ConnectionState.Broken || cm.Connection.State == ConnectionState.Closed )
61
cm.Connection.Open();
62
63
BaseTitle[] strValue = new BaseTitle[DataCount];
64
r = cm.ExecuteReader();
65
int i = 0;
66
while (r.Read())
67
{
68
//主键
69
strValue[i].ID = r[0].ToString();
70
//网址
71
strValue[i].URL = r[1].ToString();
72
//判断截取字符数
73
if (TitleCount == 0)
74
{
75
strValue[i].AllTitle = r[2].ToString();
76
strValue[i].Title = r[2].ToString();
77
}
78
else
79
{
80
strValue[i].AllTitle = r[2].ToString();
81
strValue[i].Title = Functions.strCal(r[2].ToString(),TitleCount);
82
}
83
84
//判断时间
85
if (DateFormat.Length == 0 )
86
strValue[i].AddedDate = r[3].ToString();
87
else
88
strValue[i].AddedDate = DateTime.Parse(r[3].ToString()).ToString(DateFormat);
89
90
//人气
91
strValue[i].Hits = r[4].ToString();
92
//图片路径
93
strValue[i].ImagePath = r[5].ToString();
94
//内容简介
95
if (IntroCount == 0)
96
strValue[i].Introduction = r[6].ToString();
97
else
98
strValue[i].Introduction = Functions.strCal(r[6].ToString(),IntroCount);
99
100
i++;
101
}
102
103
// if (i == 0)
104
// {
105
// //没有数据,返回空
106
// return null;
107
// }
108
// else if (i < DataCount )
109
// {
110
// //记录数不够用,修改数组大小
111
// BaseTitle[] tmp = new BaseTitle[i];
112
// int j = 0;
113
// foreach(BaseTitle tt in strValue)
114
// {
115
// tmp[j].Hits = tt.Hits ;
116
// tmp[j].ID = tt.ID ;
117
// tmp[j].ImagePath = tt.ImagePath ;
118
// tmp[j].Introduction = tt.Introduction ;
119
// tmp[j].Title = tt.Title ;
120
// tmp[j].URL = tt.URL ;
121
// j++;
122
// if (j == i )
123
// break;
124
// }
125
// return tmp;
126
// }
127
// else
128
// {
129
// return strValue;
130
// }
131
return strValue;
132
}
133
catch(Exception ex)
134
{
135
SetErrorMsg("RunSqlStructBT",SQL,ex.Message ); //处理错误
136
return null;
137
}
138
finally
139
{
140
if (r != null)
141
r.Close();
142
143
if (!isUseTrans)
144
cm.Connection.Close();
145
146
}
147
}
148
#endregion
149
150
//=====================================================================
151
152
函数实现 — — RunSqlStructCusTitle#region 函数实现 — — RunSqlStructCusTitle
153
/**//// <summary>
154
/// 运行SQl语句返回结构数组 CusTitle
155
/// </summary>
156
/// <param name="SQL">查询语句。比如select myName from tableName</param>
157
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
158
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
159
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
160
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
161
public CusTitle[] RunSqlStructCusTitle(string SQL,string SQLForCount)
162
{
163
string strRowCount = RunSqlGetID(SQLForCount);
164
if (strRowCount == null)
165
return null;
166
167
int DataCount = Int32.Parse(strRowCount);
168
if (DataCount <1)
169
return null;
170
171
return RunSqlStructCT(SQL,DataCount);
172
}
173
#endregion
174
175
函数实现 — — RunSqlStructCusTitle#region 函数实现 — — RunSqlStructCusTitle
176
/**//// <summary>
177
/// 运行SQl语句返回结构数组 CusTitle
178
/// </summary>
179
/// <param name="SQL">查询语句。比如select myName from tableName</param>
180
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
181
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
182
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
183