Role.cs
上传用户:cha0314
上传日期:2014-03-02
资源大小:12522k
文件大小:4k
源码类别:

C#编程

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Data.SqlClient;
  4. namespace UDS.Components
  5. {
  6. /// <summary>
  7. /// Role 的摘要说明。
  8. /// </summary>
  9. public class Role
  10. {
  11. public Role()
  12. {
  13. }
  14. /// <summary>
  15. /// 添加角色
  16. /// </summary>
  17. /// <param name="rolename">角色名</param>
  18. /// <param name="roledescription">角色描述</param>
  19. /// <returns>角色ID</returns>
  20. public static int Add(string rolename,string roledescription)
  21. {
  22. UDS.Components.Database db = new UDS.Components.Database();
  23. SqlParameter[] prams = {
  24. db.MakeInParam("@Role_Name",SqlDbType.VarChar,300,rolename.Trim()),
  25. db.MakeInParam("@Role_Description",SqlDbType.VarChar,300,roledescription.Trim())
  26.    };
  27. return(db.RunProc("sp_AddMyRole",prams));
  28. }
  29. /// <summary>
  30. /// 删除角色
  31. /// </summary>
  32. /// <param name="roleid">角色ID</param>
  33. /// <returns>0成功1不成功</returns>
  34. public static int Delete(int roleid)
  35. {
  36. UDS.Components.Database db = new UDS.Components.Database();
  37. SqlParameter[] prams = {
  38.    db.MakeInParam("@role_id",SqlDbType.Int,4,roleid)
  39.    };
  40. return(db.RunProc("sp_DeleteRole",prams));
  41. }
  42. /// <summary>
  43. /// 修改角色信息
  44. /// </summary>
  45. /// <param name="roleid">角色ID</param>
  46. /// <param name="rolename">角色名称</param>
  47. /// <param name="roledescription">角色描述</param>
  48. /// <returns>返回值(0成功1不成功)</returns>
  49. public static int Modify(int roleid,string rolename,string roledescription)
  50. {
  51. UDS.Components.Database db = new UDS.Components.Database();
  52. SqlParameter[] prams = {
  53. db.MakeInParam("@role_id",SqlDbType.Int ,4,roleid),
  54. db.MakeInParam("@role_name",SqlDbType.VarChar,300,rolename.Trim()),
  55. db.MakeInParam("@role_description",SqlDbType.VarChar,300,roledescription.Trim())
  56.    };
  57. return(db.RunProc("sp_UpdateRoleInfo",prams));
  58. }
  59. /// <summary>
  60. /// 从角色中删除成员
  61. /// </summary>
  62. /// <param name="roleid">角色id</param>
  63. /// <param name="staffid">成员id</param>
  64. /// <returns>返回值</returns>
  65. public static int DelStaffFromRole(int roleid,string staffid)
  66. {
  67. UDS.Components.Database db = new UDS.Components.Database();
  68. SqlParameter[] prams = {
  69. db.MakeInParam("@Role_ID",SqlDbType.Int,4,roleid),
  70. db.MakeInParam("@StaffIDS",SqlDbType.VarChar,3000,staffid)
  71.    };
  72. return(db.RunProc("sp_DeleteStaffFromRole",prams));
  73. }
  74. /// <summary>
  75. /// 从角色中添加成员
  76. /// </summary>
  77. /// <param name="roleid">角色id</param>
  78. /// <param name="staffid">非成员id</param>
  79. /// <returns>返回值</returns>
  80. public static int AddStaffFromRole(int roleid,string staffid)
  81. {
  82. UDS.Components.Database db = new UDS.Components.Database();
  83. SqlParameter[] prams = {
  84. db.MakeInParam("@Role_ID",SqlDbType.Int,4,roleid),
  85. db.MakeInParam("@StaffIDS",SqlDbType.VarChar,3000,staffid)
  86.    };
  87. return(db.RunProc("sp_AddStaffToRole",prams));
  88. }
  89. /// <summary>
  90. /// 根据rolename得到roleid
  91. /// </summary>
  92. /// <param name="rolename">角色名称</param>
  93. /// <returns>角色id</returns>
  94. public static int GetRoleIDByName(string rolename)
  95. {
  96. UDS.Components.Database db = new UDS.Components.Database();
  97. int roleid = 0;
  98. SqlDataReader dr = null;
  99. SqlParameter[] prams = {
  100.    db.MakeInParam("@rolename",SqlDbType.VarChar,100,rolename),
  101.    };
  102. db.RunProc("sp_GetRoleIDFromName",prams,out dr);
  103. while(dr.Read())
  104. {
  105. roleid = Int32.Parse(dr["role_id"].ToString());
  106. }
  107. return(roleid);
  108. }
  109. public SqlDataReader GetRoleInfo(long RoleID)
  110. {
  111. UDS.Components.Database db = new UDS.Components.Database();
  112. SqlDataReader dr = null;
  113. SqlParameter[] prams = {
  114.    db.MakeInParam("@RoleID",SqlDbType.Int ,4,RoleID),
  115. };
  116. db.RunProc("sp_GetRoleInfo",prams,out dr);
  117. return(dr);
  118. }
  119. public string GetRoleInfo(long RoleID,string FiledName)
  120. {
  121. UDS.Components.Database db = new UDS.Components.Database();
  122. SqlDataReader dr = null;
  123. SqlParameter[] prams = {
  124.    db.MakeInParam("@RoleID",SqlDbType.Int ,4,RoleID),
  125. };
  126. db.RunProc("sp_GetRoleInfo",prams,out dr);
  127. try
  128. {
  129. if(dr.Read())
  130. {
  131. try
  132. {
  133. return dr[FiledName].ToString();
  134. }
  135. catch
  136. {
  137. return "";
  138. }
  139. }
  140. else
  141. return "";
  142. }
  143. finally
  144. {
  145. dr = null;
  146. db = null;
  147. }
  148. }
  149. }
  150. }