Folder.cs
上传用户:simon2hong
上传日期:2021-11-18
资源大小:16746k
文件大小:5k
源码类别:

OA系统

开发平台:

C#

  1. using 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. public interface IFolder
  12. {
  13. /// <summary>
  14. /// 获取所有邮箱
  15. /// </summary>
  16. /// <returns></returns>
  17. SqlDataReader GetFolders();
  18. /// <summary>
  19. /// 获取单个邮箱
  20. /// </summary>
  21. /// <param name="nFolderID"></param>
  22. /// <returns></returns>
  23. SqlDataReader GetSingleFolder(int nFolderID);
  24. /// <summary>
  25. /// 新建邮箱
  26. /// </summary>
  27. /// <param name="sName"></param>
  28. /// <returns></returns>
  29. int NewFolder(string sName);
  30. /// <summary>
  31. /// 重命名邮箱
  32. /// </summary>
  33. /// <param name="nFolderID"></param>
  34. /// <param name="sName"></param>
  35. /// <returns></returns>
  36. int RenameFolder(int nFolderID,string sName);
  37. /// <summary>
  38. /// 删除邮箱
  39. /// </summary>
  40. /// <param name="nFolderID"></param>
  41. /// <returns></returns>
  42. int DeleteFolder(int nFolderID);
  43. }
  44. /// <summary>
  45. /// Folder 的摘要说明
  46. /// </summary>
  47. public class Folder:IFolder
  48. {
  49. #region IFolder 成员
  50. public SqlDataReader GetFolders()
  51. {
  52. ///创建链接
  53. SqlConnection myConnection = new SqlConnection(
  54. ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
  55. ///定义SQL语句
  56. string cmdText = "SELECT * FROM Folders  ";
  57. ///创建Command
  58. SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
  59. ///定义DataReader
  60. SqlDataReader dr = null;
  61. try
  62. {
  63. ///打开链接
  64. myConnection.Open();
  65. ///读取数据
  66. dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
  67. }
  68. catch(SqlException ex)
  69. {
  70. ///抛出异常
  71. throw new Exception(ex.Message,ex);
  72. }
  73. ///返回DataReader
  74. return dr;
  75. }
  76. public SqlDataReader GetSingleFolder(int nFolderID)
  77. {
  78. ///创建链接
  79. SqlConnection myConnection = new SqlConnection(
  80. ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
  81. ///定义SQL语句
  82. string cmdText = "SELECT * FROM Folders WHERE FolderID='" + nFolderID.ToString() + "'";
  83. ///创建Command
  84. SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
  85. ///定义DataReader
  86. SqlDataReader dr = null;
  87. try
  88. {
  89. ///打开链接
  90. myConnection.Open();
  91. ///读取数据
  92. dr = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
  93. }
  94. catch(SqlException ex)
  95. {
  96. ///抛出异常
  97. throw new Exception(ex.Message,ex);
  98. }
  99. ///返回DataReader
  100. return dr;
  101. }
  102. public int NewFolder(string sName)
  103. {
  104. ///创建链接
  105. SqlConnection myConnection = new SqlConnection(
  106. ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
  107. ///定义SQL语句
  108. string cmdText = "INSERT INTO Folders (Name,Total,NoReader,Contain,Flag,CreateDate)VALUES("
  109. + "'" + sName + "',"
  110. + "'0" + "',"
  111. + "'0" + "',"
  112. + "'0" + "',"
  113. + "'1" + "',"
  114. + "GetDate()"
  115. + ")";
  116. ///创建Command
  117. SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
  118. ///定义返回值
  119. int nResult = -1;
  120. try
  121. {
  122. ///打开链接
  123. myConnection.Open();
  124. ///执行SQL语句
  125. nResult = myCommand.ExecuteNonQuery();
  126. }
  127. catch(SqlException ex)
  128. {
  129. ///抛出异常
  130. throw new Exception(ex.Message,ex);
  131. }
  132. finally
  133. {   ///关闭链接
  134. myConnection.Close();
  135. }
  136. ///返回nResult
  137. return nResult;
  138. }
  139. public int RenameFolder(int nFolderID,string sName)
  140. {
  141. ///创建链接
  142. SqlConnection myConnection = new SqlConnection(
  143. ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
  144. ///定义SQL语句
  145. string cmdText = "UPDATE Folders SET Name ="
  146. + "'" + sName + "'"
  147. + " WHERE FolderID='" + nFolderID.ToString() + "'";
  148. ///创建Command
  149. SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
  150. ///定义返回值
  151. int nResult = -1;
  152. try
  153. {
  154. ///打开链接
  155. myConnection.Open();
  156. ///执行SQL语句
  157. nResult = myCommand.ExecuteNonQuery();
  158. }
  159. catch(SqlException ex)
  160. {
  161. ///抛出异常
  162. throw new Exception(ex.Message,ex);
  163. }
  164. finally
  165. {   ///关闭链接
  166. myConnection.Close();
  167. }
  168. ///返回nResult
  169. return nResult;
  170. }
  171. public int DeleteFolder(int nFolderID)
  172. {
  173. ///创建链接
  174. SqlConnection myConnection = new SqlConnection(
  175. ConfigurationManager.ConnectionStrings["DB"].ConnectionString);
  176. ///定义SQL语句
  177. string cmdText = "Delete Folders "
  178. + " WHERE FolderID='" + nFolderID.ToString() + "'";
  179. ///创建Command
  180. SqlCommand myCommand = new SqlCommand(cmdText,myConnection);
  181. ///定义返回值
  182. int nResult = -1;
  183. try
  184. {
  185. ///打开链接
  186. myConnection.Open();
  187. ///执行SQL语句
  188. nResult = myCommand.ExecuteNonQuery();
  189. }
  190. catch(SqlException ex)
  191. {
  192. ///抛出异常
  193. throw new Exception(ex.Message,ex);
  194. }
  195. finally
  196. {   ///关闭链接
  197. myConnection.Close();
  198. }
  199. ///返回nResult
  200. return nResult;
  201. }
  202. #endregion
  203. }