温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码
当前文件路径:Votes/App_Code/Topics.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
//5-1-aspx 12
/// <summary> 13
/// Topics 的摘要说明 14
/// </summary> 15
public interface ITopics 16
{ 17
SqlDataReader GetCurrentTopic(); 18
SqlDataReader GetAllTopic(); 19
int AddTopic(string tname, string tcontent); 20
int UpdateTopic(string tname,string tcontent,int tid); 21
int DeleteTopic(int tid); 22
SqlDataReader GetTopic(int tid); 23
int UpdateCurrentTopicByProc(int tid); 24
} 25
26
public class Topics : ITopics 27
{ 28
public int UpdateCurrentTopicByProc(int tid) 29
{ 30
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 31
32
SqlCommand myCommand = new SqlCommand("Pro_UpdateCurrentTopic", myConnection); 33
myCommand.CommandType = CommandType.StoredProcedure; 34
SqlParameter pCurrent = new SqlParameter("@t_id", SqlDbType.Int, 4); 35
pCurrent.Value=tid; 36
myCommand.Parameters.Add(pCurrent); 37
int nResult; 38
try 39
{ 40
myConnection.Open(); 41
nResult = myCommand.ExecuteNonQuery(); 42
} 43
catch (SqlException ex) 44
{ 45
throw new Exception(ex.Message, ex); 46
} 47
finally 48
{ 49
myConnection.Close(); 50
} 51
return nResult; 52
} 53
54
public SqlDataReader GetTopic(int tid) 55
{ 56
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 57
string cmd = "select * from Topics where t_id='"+tid.ToString()+"'"; 58
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 59
SqlDataReader dr = null; 60
try 61
{ 62
myConnection.Open(); 63
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 64
} 65
catch (SqlException ex) 66
{ 67
throw new Exception(ex.Message, ex); 68
} 69
return dr; 70
} 71
72
public int DeleteTopic(int tid) 73
{ 74
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 75
string cmd = "delete from Topics where t_id='"+tid.ToString()+"'"; 76
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 77
int nResult; 78
try 79
{ 80
myConnection.Open(); 81
nResult = myCommand.ExecuteNonQuery(); 82
} 83
catch (SqlException ex) 84
{ 85
throw new Exception(ex.Message, ex); 86
} 87
finally 88
{ 89
myConnection.Close(); 90
} 91
return nResult; 92
} 93
94
public int UpdateTopic(string tname, string tcontent,int tid) 95
{ 96
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 97
string cmd = "update Topics set t_name='"+tname.ToString()+"',t_content='"+tcontent.ToString()+"' where t_id='"+tid.ToString()+"'"; 98
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 99
int nResult; 100
try 101
{ 102
myConnection.Open(); 103
nResult = myCommand.ExecuteNonQuery(); 104
} 105
catch (SqlException ex) 106
{ 107
throw new Exception(ex.Message, ex); 108
} 109
finally 110
{ 111
myConnection.Close(); 112
} 113
return nResult; 114
} 115
116
public int AddTopic(string tname,string tcontent) 117
{ 118
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 119
string cmd = "insert into Topics(t_name,t_content) values('"+tname.ToString()+"','"+tcontent.ToString()+"')"; 120
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 121
int nResult; 122
try 123
{ 124
myConnection.Open(); 125
nResult = myCommand.ExecuteNonQuery(); 126
} 127
catch (SqlException ex) 128
{ 129
throw new Exception(ex.Message, ex); 130
} 131
finally 132
{ 133
myConnection.Close(); 134
} 135
return nResult; 136
} 137
138
public SqlDataReader GetAllTopic() 139
{ 140
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 141
string cmd = "select * from Topics"; 142
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 143
SqlDataReader dr = null; 144
try 145
{ 146
myConnection.Open(); 147
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 148
} 149
catch (SqlException ex) 150
{ 151
throw new Exception(ex.Message, ex); 152
} 153
return dr; 154
} 155
156
public SqlDataReader GetCurrentTopic() 157
{ 158
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 159
string cmd = "select * from Topics where t_IsCurrent=1"; 160
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 161
SqlDataReader dr = null; 162
try 163
{ 164
myConnection.Open(); 165
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 166
} 167
catch (SqlException ex) 168
{ 169
throw new Exception(ex.Message, ex); 170
} 171
return dr; 172
} 173
} 174







}