温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:简单多功能投票/调查系统源码
当前文件路径:Votes/App_Code/Subjects.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
/// Subjects 的摘要说明 14
/// </summary> 15
public interface ISubjects 16
{ 17
SqlDataReader GetSubjectByTopic(int tid); 18
int DeleteSubject(int sid); 19
int AddSubject(string sname,int stid); 20
int UpdateSubject(string sname, int sid); 21
SqlDataReader GetSingleSubject(int sid); 22
int UpdateSubjectMode(int sid); 23
} 24
25
public class Subjects : ISubjects 26
{ 27
public int UpdateSubjectMode(int sid) 28
{ 29
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 30
string cmd = "update Subjects set s_mode=1 where s_id='" + sid.ToString() + "'"; 31
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 32
int nResult; 33
try 34
{ 35
myConnection.Open(); 36
nResult = myCommand.ExecuteNonQuery(); 37
} 38
catch (SqlException ex) 39
{ 40
throw new Exception(ex.Message, ex); 41
} 42
finally 43
{ 44
myConnection.Close(); 45
} 46
return nResult; 47
} 48
49
public SqlDataReader GetSingleSubject(int sid) 50
{ 51
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 52
string cmd = "select * from Subjects where s_id='" + sid.ToString() + "'"; 53
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 54
SqlDataReader dr = null; 55
try 56
{ 57
myConnection.Open(); 58
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 59
} 60
catch (SqlException ex) 61
{ 62
throw new Exception(ex.Message, ex); 63
} 64
return dr; 65
} 66
67
public int UpdateSubject(string sname, int sid) 68
{ 69
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 70
string cmd = "update Subjects set s_name='"+sname.ToString()+"' where s_id='"+sid.ToString()+"'"; 71
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 72
int nResult; 73
try 74
{ 75
myConnection.Open(); 76
nResult = myCommand.ExecuteNonQuery(); 77
} 78
catch (SqlException ex) 79
{ 80
throw new Exception(ex.Message, ex); 81
} 82
finally 83
{ 84
myConnection.Close(); 85
} 86
return nResult; 87
} 88
89
public int AddSubject(string sname, int stid) 90
{ 91
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 92
string cmd = "insert into Subjects(s_name,s_tid) values('"+sname.ToString()+"','"+stid.ToString()+"')"; 93
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 94
int nResult; 95
try 96
{ 97
myConnection.Open(); 98
nResult = myCommand.ExecuteNonQuery(); 99
} 100
catch (SqlException ex) 101
{ 102
throw new Exception(ex.Message, ex); 103
} 104
finally 105
{ 106
myConnection.Close(); 107
} 108
return nResult; 109
} 110
111
public int DeleteSubject(int sid) 112
{ 113
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 114
string cmd = "delete from Subjects where s_id='" + sid.ToString() + "'"; 115
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 116
int nResult; 117
try 118
{ 119
myConnection.Open(); 120
nResult = myCommand.ExecuteNonQuery(); 121
} 122
catch (SqlException ex) 123
{ 124
throw new Exception(ex.Message, ex); 125
} 126
finally 127
{ 128
myConnection.Close(); 129
} 130
return nResult; 131
} 132
133
public SqlDataReader GetSubjectByTopic(int tid) 134
{ 135
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SQLCONNECTIONSTRING"].ConnectionString); 136
string cmd = "select * from Subjects where s_tid='" + tid.ToString() + "'"; 137
SqlCommand myCommand = new SqlCommand(cmd, myConnection); 138
SqlDataReader dr = null; 139
try 140
{ 141
myConnection.Open(); 142
dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection); 143
} 144
catch (SqlException ex) 145
{ 146
throw new Exception(ex.Message, ex); 147
} 148
return dr; 149
} 150
151
}







}