我的数据访问函数库的源代码(三)——返回结构数组
2006-08-16 04:34 金色海洋(jyk) 阅读(1394) 评论(1) 编辑 收藏 举报
数据访问函数库 —— 返回结构数组,用于在网页上显示数据
/* 2008 4 25 更新 */
我的数据访问函数库的源码。整个类有1400行,原先就是分开来写的,现在更新后还是分开来发一下吧。
第三部分:返回结构
数组,这个是专门针对网页来设计的。就是在网页上更方便的显示一组数据。
我的数据访问函数库的源码。整个类有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
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
184
public CusTitle[] RunSqlStructCusTitle(string SQL,int DataCount)
185
{
186
if (DataCount <1)
187
return null;
188
189
return RunSqlStructCT(SQL,DataCount);
190
}
191
#endregion
192
193
函数实现 — — RunSqlStructCT#region 函数实现 — — RunSqlStructCT
194
/**//// <summary>
195
/// 运行SQl语句返回结构数组 CusTitle
196
/// </summary>
197
/// <param name="SQL">查询语句。比如select myName from tableName</param>
198
/// <param name="SQLForCount">用于统计记录数的SQL语句。如果传入数字的话,则直接使用数字作为记录数。</param>
199
/// <param name="TitleCount">标题的字符数,一个汉字按照两个字符计算。传入“0”则表示不截取标题。</param>
200
/// <param name="DateFormat">时间格式。比如“yyyy-MM-dd HH:mm:ss dddd”</param>
201
/// <returns>返回BaseTitle结构的数组。URL,标题,时间,人气</returns>
202
private CusTitle[] RunSqlStructCT(string SQL,int DataCount)
203
{
204
//返回ID 传入查询语句,返回第一条记录的第一的字段的值
205
SetCommand(SQL,1); //设置command
206
SqlDataReader r = null;
207
try
208
{
209
if (cm.Connection.State == ConnectionState.Broken || cm.Connection.State == ConnectionState.Closed )
210
cm.Connection.Open();
211
212
CusTitle[] strValue = new CusTitle[DataCount];
213
r = cm.ExecuteReader();
214
int i = 0;
215
int ArrLength = r.FieldCount-2;
216
while (r.Read())
217
{
218
//ID
219
strValue[i].ID = r[0].ToString();
220
//标题
221
strValue[i].Title = r[1].ToString();
222
223
//其他
224
strValue[i].str = new string[ArrLength];
225
for(int j=0;j<ArrLength;j++)
226
strValue[i].str[j] = r.GetValue(j+2).ToString();
227
228
i++;
229
}
230
return strValue;
231
232
}
233
catch(Exception ex)
234
{
235
SetErrorMsg("RunSqlStrs",SQL,ex.Message ); //处理错误
236
return null;
237
}
238
finally
239
{
240
if (r != null)
241
r.Close();
242
243
if (!isUseTrans)
244
cm.Connection.Close();
245
246
}
247
}
248
#endregion
249
250
//===========================end==============================
251

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



140

141

142

143

144

145

146

147

148

149

150

151

152


153


154

155

156

157

158

159

160

161

162



163

164

165

166

167

168

169

170

171

172

173

174

175


176


177

178

179

180

181

182

183

184

185



186

187

188

189

190

191

192

193


194


195

196

197

198

199

200

201

202

203



204

205

206

207

208



209

210

211

212

213

214

215

216

217



218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234



235

236

237

238

239



240

241

242

243

244

245

246

247

248

249

250

251

下载全部源文件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!