温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:MyShop网络商城源码(mvc开发)
当前文件路径:MyShop/BLL/Vote.cs

1using System; 2
using System.Collections.Generic; 3
using System.Data; 4
using MyShop.DALFactory; 5
using MyShop.IDAL; 6
using MyShop.Model; 7
8
namespace MyShop.BLL 9
...{ 10
public class Vote:VoteRules 11
...{ 12
private IVote dal = DataAccess.CreateVote(); 13
private int _id; 14
15
public Vote ()...{} 16
17
public Vote(int id) 18
...{ 19
this._id = id; 20
} 21
22
IVote#region IVote 23
24
public int Add(VoteInfo model) 25
...{ 26
if (model == null) 27
...{ 28
return 0; 29
} 30
return dal.Add(model); 31
} 32
33
public int Delete(string filter) 34
...{ 35
if (string.IsNullOrEmpty(filter)) 36
return 0; 37
return dal.Delete(filter); 38
} 39
40
public bool Exist(string filter) 41
...{ 42
filter = filter.Trim(); 43
if (string.IsNullOrEmpty(filter)) 44
return false; 45
return dal.Exist(filter); 46
} 47
public DataSet GetDataSet() 48
...{ 49
return dal.GetDataSet(); 50
} 51
52
public DataSet GetDataSet(string filter) 53
...{ 54
filter = filter.Trim(); 55
if (string.IsNullOrEmpty(filter)) 56
return null; 57
return dal.GetDataSet(filter); 58
} 59
60
public VoteInfo GetModel(DataRow dr) 61
...{ 62
if (dr == null) 63
return null; 64
return dal.GetModel(dr); 65
} 66
67
private DataSet Query(string sql) 68
...{ 69
sql = sql.Trim(); 70
if (string.IsNullOrEmpty(sql)) 71
return null; 72
return dal.Query(sql); 73
} 74
75
public int Update(VoteInfo model, string filter) 76
...{ 77
if (model == null) 78
return 0; 79
filter = filter.Trim(); 80
if (string.IsNullOrEmpty(filter)) 81
return 0; 82
return dal.Update(model, filter); 83
} 84
85
#endregion 86
87
88
common#region common 89
90
public int Add(VoteInfo model, out string msg) 91
...{ 92
msg = ""; 93
if (model == null) 94
...{ 95
msg = msg + "<li>数据不能为空</li>"; 96
return 0; 97
} 98
bool isErr = false; 99
100
if (string.IsNullOrEmpty(model.Title.Trim())) 101
...{ 102
msg = msg + "<li>主题不能为空</li>"; 103
isErr = true; 104
} 105
if (isErr) 106
return 0; 107
108
int count = 0; 109
count = Add(model); 110
if (count == 0) 111
msg = "<li>系统发生错误,请重新添加!</li>"; 112
if (count == 1) 113
msg = "<li>添加成功!</li>"; 114
return count; 115
} 116
117
public int Delete(int id) 118
...{ 119
if (string.IsNullOrEmpty(id.ToString())) 120
return 0; 121
string filer; 122
filer = " id =" + id; 123
return Delete(filer); 124
} 125
public int Update(VoteInfo model) 126
...{ 127
128
if (model == null) 129
...{ 130
return 0; 131
} 132
string filter; 133
filter = " id=" + model.ID; 134
return Update(model, filter); 135
} 136
137
public VoteInfo GetModel(int id) 138
...{ 139
DataSet dataset = new DataSet(); 140
dataset = GetDataSet(" id=" + id); 141
if (dataset != null && dataset.Tables[0].Rows.Count > 0) 142
return GetModel(dataset.Tables[0].Rows[0]); 143
return null; 144
} 145
146
#endregion 147
148
149
150
151
后台管理#region 后台管理 152
153
public DataSet GetDataSetDesc() 154
...{ 155
return GetDataSet(" [id] > 0 order by [Id] desc "); 156
} 157
158
/**//// <summary> 159
/// 得到调查项目选项的集合 160
/// </summary> 161
/// <param name="id"></param> 162
/// <returns></returns> 163
public VoteOption[] GetOptions(int id) 164
...{ 165
VoteInfo model = new VoteInfo(); 166
model = GetModel(id); 167
if (model == null) 168
return null; 169
string[] content = Utils.SplitString(model.Content, "§c§"); 170
171
VoteOption[] options = new VoteOption[content.Length]; 172
173
for (int i = 0; i < content.Length; i++) 174
...{ 175
string[] op = Utils.SplitString(content[i], "◎n◎"); 176
177
if (op.Length > 1) 178
...{ 179
//防止程序出错 180
options[i].content = op[0]; 181
options[i].number = Utils.StrToInt(op[1], 0); 182
} 183
else 184
options[i].content = op[0]; 185
} 186
187
return options; 188
} 189
190
191
/**//// <summary> 192
/// 返回最新调查 193
/// </summary> 194
/// <returns></returns> 195
public DataSet GetDataSetSelected 196
...{ 197
get 198
...{ 199
return GetDataSet(" [IsSelected] = 1 "); 200
} 201
} 202
203
/**//// <summary> 204
/// 返回最新调查 205
/// </summary> 206
/// <returns></returns> 207
public VoteInfo GetModelSelected 208
...{ 209
get 210
...{ 211
if (GetDataSetSelected.Tables[0].Rows.Count > 0) 212
return GetModel(GetDataSetSelected.Tables[0].Rows[0]); 213
else 214
return null; 215
} 216
} 217
218
/**//// <summary> 219
/// 得到最新调查项目选项的集合 220
/// </summary> 221
/// <returns></returns> 222
public VoteOption[] GetOptionsSelected 223
...{ 224
get 225
...{ 226
VoteInfo model = new VoteInfo(); 227
model = GetModelSelected; 228
if (model == null) 229
return null; 230
return GetOptions(model.ID); 231
} 232
} 233
234
/**//// <summary> 235
/// 把VoteOption[]数组转换为字符串 236
/// </summary> 237
/// <param name="options"></param> 238
/// <returns>content</returns> 239
public string OptionsToContent(VoteOption[] options) 240
...{ 241
string content = ""; 242
for (int i = 0; i < options.Length; i++) 243
...{ 244
content = content + options[i].content + "◎n◎" + options[i].number; 245
if (i < options.Length - 1) 246
content = content + "§c§"; 247
} 248
return content; 249
} 250
251
#endregion 252
253
以下过程要用Vote vote = new Vote(id)实例化后才能进行调用#region 以下过程要用Vote vote = new Vote(id)实例化后才能进行调用 254
255
256
/**//// <summary> 257
/// 增加票数 258
/// </summary> 259
/// <param name="optionIndex">在选项集合中的位置,从0开始算起</param> 260
/// <param name="num">要增加或减少的票数,加用正数,减用负数</param> 261
public void AddNumber(int optionIndex, int num) 262
...{ 263
VoteOption[] options = Options; 264
if (optionIndex > options.Length) 265
return; 266
options[optionIndex].number += num; 267
Options = options; 268
} 269
270
property#region property 271
272
/**//// <summary> 273
/// 获取当前项目ID 274
/// </summary> 275
public int ID 276
...{ 277
get 278
...{ 279
return this._id; 280
} 281
} 282
283
/**//// <summary> 284
/// 获取调查项目的实体 285
/// </summary> 286
public VoteInfo Model 287
...{ 288
get 289
...{ 290
return GetModel(this._id); 291
} 292
set 293
...{ 294
Update(value); 295
}





}