温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:燕赵宽频点播系统V1.0源码
当前文件路径:hevod/DAL/Types.cs

1using System; 2
using System.Collections; 3
using System.Data.OleDb; 4
using System.Data; 5
6
namespace DAL 7
{ 8
/// <summary> 9
/// 电影类别 10
/// </summary> 11
public class Types 12
{ 13
public DBConn dbConn = new DBConn(); 14
/// <summary> 15
/// 读取全部类别列表 16
/// </summary> 17
public DataSet GetTypes() 18
{ 19
string sql = "select id,caption,order from types order by [order]"; 20
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 21
OleDbDataAdapter da = new OleDbDataAdapter(cmd); 22
DataSet ds = null; 23
try 24
{ 25
dbConn.Open(); 26
ds = new DataSet(); 27
da.Fill(ds); 28
} 29
catch (OleDbException ex) 30
{ 31
throw ex; 32
} 33
catch (Exception ex) 34
{ 35
throw ex; 36
} 37
finally 38
{ 39
dbConn.Close(); 40
} 41
return ds; 42
} 43
44
/// <summary> 45
/// 添加类别 46
/// </summary> 47
public bool AddType(string strCaption) 48
{ 49
bool isOK=false; 50
string sql = "insert into types (caption) values ('"+strCaption+"')"; 51
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 52
try 53
{ 54
dbConn.Open(); 55
if (cmd.ExecuteNonQuery() > 0) 56
isOK = true; 57
} 58
catch (OleDbException ex) 59
{ 60
throw ex; 61
} 62
catch (Exception ex) 63
{ 64
throw ex; 65
} 66
finally 67
{ 68
dbConn.Close(); 69
} 70
return isOK; 71
} 72
73
/// <summary> 74
/// 修改类别 75
/// </summary> 76
public bool ModifyType(int id,string strCaption,int order) 77
{ 78
bool isOK = false; 79
string sql = "update types set caption='"+strCaption+"',[order]="+order+" where id="+id; 80
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 81
try 82
{ 83
dbConn.Open(); 84
if (cmd.ExecuteNonQuery() > 0) 85
isOK = true; 86
} 87
catch (OleDbException ex) 88
{ 89
throw ex; 90
} 91
catch (Exception ex) 92
{ 93
throw ex; 94
} 95
finally 96
{ 97
dbConn.Close(); 98
} 99
return isOK; 100
} 101
102
/// <summary> 103
/// 删除类别 104
/// </summary> 105
public bool DelType(int id) 106
{ 107
bool isOK = false; 108
string sql = "delete from types where id="+id; 109
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 110
try 111
{ 112
dbConn.Open(); 113
if (cmd.ExecuteNonQuery() > 0) 114
isOK = true; 115
} 116
catch (OleDbException ex) 117
{ 118
throw ex; 119
} 120
catch (Exception ex) 121
{ 122
throw ex; 123
} 124
finally 125
{ 126
dbConn.Close(); 127
} 128
return isOK; 129
} 130
131
/// <summary> 132
/// 是否重名 133
/// </summary> 134
public bool isHasByCaption(string strCaption) 135
{ 136
bool isOK = false; 137
string sql = "select caption from types where caption='"+strCaption+"'"; 138
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 139
dbConn.Open(); 140
OleDbDataReader dr = cmd.ExecuteReader(); 141
if (dr.Read()) 142
{ 143
isOK = true; 144
} 145
dr.Close(); 146
dbConn.Close(); 147
return isOK; 148
} 149
150
/// <summary> 151
/// 修改显示顺序 152
/// </summary> 153
public bool ModifyOrder(int id, int order) 154
{ 155
bool isOK=false; 156
string sql = "update types set (order) values "+order+" where id="+id; 157
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 158
try 159
{ 160
dbConn.Open(); 161
if (cmd.ExecuteNonQuery() > 0) 162
isOK = true; 163
} 164
catch (OleDbException ex) 165
{ 166
throw ex; 167
} 168
catch (Exception ex) 169
{ 170
throw ex; 171
} 172
finally 173
{ 174
dbConn.Close(); 175
} 176
return isOK; 177
178
} 179
180
/// <summary> 181
/// 查询记录总数 182
/// </summary> 183
public int GetTypesCount() 184
{ 185
int i = 1; 186
string sql = "select id,caption from types"; 187
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 188
dbConn.Open(); 189
OleDbDataReader dr = cmd.ExecuteReader(); 190
while (dr.Read()) 191
{ 192
i++; 193
} 194
dr.Close(); 195
dbConn.Close(); 196
return i; 197
} 198
199
/// <summary> 200
/// 单条记录的详细信息(开始用Model) 201
/// </summary> 202
public Model.Types GetTypeInfo(int id) 203
{ 204
Model.Types modelType = new Model.Types(); 205
string sql = "select id,caption,order from types where id="+id; 206
OleDbCommand cmd = new OleDbCommand(sql, dbConn.conn); 207
dbConn.Open(); 208
OleDbDataReader dr=cmd.ExecuteReader(); 209
if(dr.Read()) 210
{ 211
modelType.Id=(int)dr["id"]; 212
modelType.Caption=dr["caption"].ToString(); 213
modelType.Order=(int)dr["order"]; 214
} 215
else 216
{ 217
modelType.Id = 0; 218
modelType.Caption = "全部"; 219
modelType.Order = 0; 220
} 221
dr.Close(); 222
dbConn.Close(); 223
return modelType; 224
} 225
} 226
227
} 228





}