温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码
当前文件路径:Votes/App_Code/Items.cs

1using System; 2
using System.Data; 3
using System.Configuration; 4
using System.Web; 5
using System.Web.Security; 6
using System.Web.UI; 7
using System.Web.UI.WebControls; 8
using System.Web.UI.WebControls.WebParts; 9
using System.Web.UI.HtmlControls; 10
using System.Data.SqlClient; 11
12
/// <summary> 13
/// Items 的摘要说明 14
/// </summary> 15
public interface IItems 16
{ 17
SqlDataReader GetItemBySubject(int sid); 18
SqlDataReader GetSumItemsBySubject(int sid); 19
int DeleteItem(int iid); 20
int AddItem(string iname, int isid); 21
int UpdateItem(string iname, int iid); 22
SqlDataReader GetSingleItem(int iid); 23
int AddItemCount(int iid); 24
SqlDataReader GetIsRepeat(); 25
int UpdateIsRepeat(string isRepeat); 26
} 27
28
public class Items : IItems 29
{ 30
public int UpdateIsRepeat(string isRepeat) 31
{ 32
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 33
string cmd = "update Profiles set p_IsRepeat='" + isRepeat + "'"; 34
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 35
int nResult; 36
try 37
{ 38
myConnection.Open(); 39
nResult = myCommand.ExecuteNonQuery(); 40
} 41
catch (SqlException ex) 42
{ 43
throw new Exception(ex.Message, ex); 44
} 45
finally 46
{ 47
myConnection.Close(); 48
} 49
return nResult; 50
} 51
52
public SqlDataReader GetIsRepeat() 53
{ 54
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 55
string cmd = "select * from Profiles"; 56
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 57
SqlDataReader dr = null; 58
try 59
{ 60
myConnection.Open(); 61
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 62
} 63
catch (SqlException ex) 64
{ 65
throw new Exception(ex.Message, ex); 66
} 67
return dr; 68
} 69
70
public int AddItemCount(int iid) 71
{ 72
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 73
string cmd = "update Items set i_count=i_count+1 where i_id='"+iid.ToString()+"'"; 74
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 75
int nResult; 76
try 77
{ 78
myConnection.Open(); 79
nResult = myCommand.ExecuteNonQuery(); 80
} 81
catch (SqlException ex) 82
{ 83
throw new Exception(ex.Message, ex); 84
} 85
finally 86
{ 87
myConnection.Close(); 88
} 89
return nResult; 90
} 91
92
public SqlDataReader GetSingleItem(int iid) 93
{ 94
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 95
string cmd = "select * from Items where i_id='" + iid.ToString() + "'"; 96
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 97
SqlDataReader dr = null; 98
try 99
{ 100
myConnection.Open(); 101
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 102
} 103
catch (SqlException ex) 104
{ 105
throw new Exception(ex.Message, ex); 106
} 107
return dr; 108
} 109
110
public int UpdateItem(string iname, int iid) 111
{ 112
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 113
string cmd = "update Items set i_name='" + iname.ToString() + "' where i_id='" + iid.ToString() + "'"; 114
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 115
int nResult; 116
try 117
{ 118
myConnection.Open(); 119
nResult = myCommand.ExecuteNonQuery(); 120
} 121
catch (SqlException ex) 122
{ 123
throw new Exception(ex.Message, ex); 124
} 125
finally 126
{ 127
myConnection.Close(); 128
} 129
return nResult; 130
} 131
132
public int AddItem(string iname, int isid) 133
{ 134
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 135
string cmd = "insert into Items(i_name,i_sid) values('" + iname.ToString() + "','" + isid.ToString() + "')"; 136
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 137
int nResult; 138
try 139
{ 140
myConnection.Open(); 141
nResult = myCommand.ExecuteNonQuery(); 142
} 143
catch (SqlException ex) 144
{ 145
throw new Exception(ex.Message, ex); 146
} 147
finally 148
{ 149
myConnection.Close(); 150
} 151
return nResult; 152
} 153
154
public int DeleteItem(int iid) 155
{ 156
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 157
string cmd = "delete from Items where i_id='" + iid.ToString() + "'"; 158
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 159
int nResult; 160
try 161
{ 162
myConnection.Open(); 163
nResult = myCommand.ExecuteNonQuery(); 164
} 165
catch (SqlException ex) 166
{ 167
throw new Exception(ex.Message, ex); 168
} 169
finally 170
{ 171
myConnection.Close(); 172
} 173
return nResult; 174
} 175
176
public SqlDataReader GetSumItemsBySubject(int sid) 177
{ 178
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 179
string cmd = "select sum(i_count) as SumVoteCount from Items where i_sid='" + sid.ToString() + "'"; 180
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 181
SqlDataReader dr = null; 182
try 183
{ 184
myConnection.Open(); 185
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 186
} 187
catch (SqlException ex) 188
{ 189
throw new Exception(ex.Message, ex); 190
} 191
return dr; 192
} 193
194
public SqlDataReader GetItemBySubject(int sid) 195
{ 196
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 197
string cmd = "select * from Items where i_sid='"+sid.ToString()+"'"; 198
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 199
SqlDataReader dr = null; 200
try 201
{ 202
myConnection.Open(); 203
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 204
} 205
catch (SqlException ex) 206
{ 207
throw new Exception(ex.Message, ex); 208
} 209
return dr; 210
} 211
} 212







}