温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:51aspx修正版简单三层留言板源码
当前文件:
LeaveMessageMVC/MVC/BusinessLogicLayer/LMManage.cs,打开代码结构图
LeaveMessageMVC/MVC/BusinessLogicLayer/LMManage.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
using System.Data.OleDb; 12
13
using LeaveMessageMVC.MVC.BusinessLogicLayer.ParameterInformation; 14
using LeaveMessageMVC.MVC.DataBaseControlLayer; 15
16
namespace LeaveMessageMVC.MVC.BusinessLogicLayer 17
{ 18
/// <summary> 19
/// AddNewLM 的摘要说明 20
/// </summary> 21
public static class LMManage 22
{ 23
/// <summary> 24
/// 数据库中的留言表 25
/// </summary> 26
public static string Tables = "LM01"; //============================================================= 27
28
/// <summary> 29
/// 向数据库 添加 一个新的留言记录 30
/// </summary> 31
/// <param name="nlm"></param> 32
/// <returns>返回是否添加成功</returns> 33
public static bool AddNewLeaveMessage(LeaveMessagePara nlm) 34
{ 35
bool AddSuccess = true; 36
37
string NewLMsql = "INSERT INTO " + Tables + " VALUES(" //SQL 插入语句 38
+ "'" + nlm.ID + "'," 39
+ "'" + nlm.User + "'," 40
+ "'" + nlm.QQMSN + "'," 41
+ "'" + nlm.Title + "'," 42
+ "'" + nlm.Contents + "'," 43
+ "'" + nlm.WriteBack + "'," //回复信息,对新留言是空的 44
+ "'" + nlm.SubmitTime + "'," 45
+ "'" + nlm.Comment + "');"; 46
47
if (DBControl.DBExcuteIUD(NewLMsql) <= 0) //执行向 DB 插入语句 48
{ 49
AddSuccess = false; //插入失败 50
} 51
52
return AddSuccess; 53
} 54
55
/// <summary> 56
/// (1)更新留言信息——管理员更新信息 57
/// </summary> 58
/// <param name="wb"></param> 59
/// <returns>返回是否更新成功</returns> 60
public static bool UpdateLeaveMessageAll(LeaveMessagePara wb) 61
{ 62
bool UpdateSuccess = true; 63
64
string LMsql = "UPDATE " + Tables //SQL 更新语句 65
+ " SET Title = '" + wb.Title + "'," 66
+ " Contents = '" + wb.Contents + "'," 67
+ " WriteBack = '" + wb.WriteBack + "' " 68
+ " WHERE ID = '" + wb.ID + "';"; 69
70
if (DBControl.DBExcuteIUD(LMsql) <= 0) //执行向 DB 更新语句 71
UpdateSuccess = false; //更新失败 72
73
return UpdateSuccess; 74
} 75
76
/// <summary> 77
/// (2)更新留言信息——更新回复信息 78
/// </summary> 79
/// <param name="wb"></param> 80
/// <returns>返回是否更新成功</returns> 81
public static bool UpdateLeaveMessage(LeaveMessagePara wb) 82
{ 83
bool UpdateSuccess = true; 84
85
string LMsql = "UPDATE " + Tables //SQL 更新语句 86
+ " SET WriteBack = '" + wb.WriteBack + "' " 87
+ " WHERE ID = '" + wb.ID + "';"; 88
89
if (DBControl.DBExcuteIUD(LMsql) <= 0) //执行向 DB 更新语句 90
UpdateSuccess = false; //更新失败 91
92
return UpdateSuccess; 93
} 94
95
/// <summary> 96
/// 将一个已有的留言记录从数据库中 删除掉 97
/// </summary> 98
/// <param name="lmid"></param> 99
/// <returns>返回删除是否成功</returns> 100
public static bool DeleteLeaveMessage(params string[] lmid) 101
{ 102
bool DeleteSuccess = true; 103
104
string DeleteLMs = "create table #tempTable([ID] varchar(18)); "; 105
for (int i = 0; i < lmid.Length; i++) 106
{ 107
DeleteLMs += "insert into #tempTable values('" + lmid[i] + "'); "; 108
} 109
DeleteLMs += "delete from " + Tables + " where [ID] in (select * from #tempTable); drop table #tempTable;"; 110
111
if (DBControl.DBExcuteIUD(DeleteLMs) <= 0) //执行向 DB 更新语句 112
DeleteSuccess = false; 113
114
return DeleteSuccess; 115
} 116
117
//-------------------------------------------------------------- 118
119
/// <summary> 120
/// 获取(某表/具体页面)的所有留言记录信息 for SQL Server 121
/// </summary> 122
/// <param name="n">获取数据表前n行数据,0为获取全部</param> 123
/// <returns></returns> 124
public static SqlDataReader GetLeaveMessage(int n) 125
{ 126
SqlDataReader GetLMTable = null; 127
128
string GetLM = ""; 129
if (n > 0) 130
GetLM = "SELECT top " + n + " * FROM " + Tables + " ORDER BY SubmitTime DESC;"; 131
else 132
GetLM = "SELECT * FROM " + Tables + " ORDER BY SubmitTime DESC;"; 133
134
GetLMTable = DBControl.DBSelect(GetLM); 135
return GetLMTable; 136
} 137
138
/// <summary> 139
/// 获取(某表/具体页面)的所有留言记录信息 for Access 140
/// </summary> 141
/// <param name="n">获取数据表前n行数据,0为获取全部</param> 142
/// <returns></returns> 143
public static DataTable aGetLeaveMessage(int n) 144
{ 145
DataTable GetLMTable = new DataTable(); 146
147
string GetLM = ""; 148
if (n > 0) 149
GetLM = "SELECT top " + n + " * FROM " + Tables + " ORDER BY SubmitTime DESC;"; 150
else 151
GetLM = "SELECT * FROM " + Tables + " ORDER BY SubmitTime DESC;"; 152
153
GetLMTable = DBControl.aDBSelect(GetLM).Tables[0]; //DataTable获取DataSet中的数据 154
return GetLMTable; 155
} 156
157
//-------------------------------------------------------------- 158
159
/// <summary> 160
/// 从DB获取指定的留言记录信息 for SQL Server 161
/// </summary> 162
/// <returns></returns> 163
public static SqlDataReader GetLM(string OwnerID) 164
{ 165
SqlDataReader GetLMTable = null; 166
string GetLM = "SELECT * FROM " + Tables + " WHERE ID = '" + OwnerID + "';"; 167
GetLMTable = DBControl.DBSelect(GetLM); 168
return GetLMTable; 169
} 170
171
/// <summary> 172
/// 从DB获取指定的留言记录信息 for Access 173
/// </summary> 174
/// <returns></returns> 175
public static DataTable aGetLM(string OwnerID) 176
{ 177
DataTable GetLMTable = null; 178
string GetLM = "SELECT * FROM " + Tables + " WHERE ID = '" + OwnerID + "';"; 179
GetLMTable = DBControl.aDBSelect(GetLM).Tables[0]; //DataTable获取DataSet中的数据 180
return GetLMTable; 181
} 182
} 183
184
} 185
186
//该源码下载自www.51aspx.com(51aspx.com) 187
//edit by 51-aspx





}