Aucune description

T_Sys_RoleFunction.cs 9.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. using CallCenterApi.DB;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace CallCenterApi.DAL
  10. {
  11. /// <summary>
  12. /// 数据访问类:T_Sys_RoleFunction
  13. /// </summary>
  14. public partial class T_Sys_RoleFunction
  15. {
  16. public T_Sys_RoleFunction()
  17. { }
  18. #region BasicMethod
  19. /// <summary>
  20. /// 得到最大ID
  21. /// </summary>
  22. public int GetMaxId()
  23. {
  24. return DbHelperSQL.GetMaxID("F_RoleId", "T_Sys_RoleFunction");
  25. }
  26. /// <summary>
  27. /// 是否存在该记录
  28. /// </summary>
  29. public bool Exists(int F_RoleId, int F_FunctionId)
  30. {
  31. StringBuilder strSql = new StringBuilder();
  32. strSql.Append("select count(1) from T_Sys_RoleFunction");
  33. strSql.Append(" where F_RoleId=@F_RoleId and F_FunctionId=@F_FunctionId ");
  34. SqlParameter[] parameters = {
  35. new SqlParameter("@F_RoleId", SqlDbType.Int,4),
  36. new SqlParameter("@F_FunctionId", SqlDbType.Int,4) };
  37. parameters[0].Value = F_RoleId;
  38. parameters[1].Value = F_FunctionId;
  39. return DbHelperSQL.Exists(strSql.ToString(), parameters);
  40. }
  41. /// <summary>
  42. /// 增加一条数据
  43. /// </summary>
  44. public bool Add(Model.T_Sys_RoleFunction model)
  45. {
  46. StringBuilder strSql = new StringBuilder();
  47. strSql.Append("insert into T_Sys_RoleFunction(");
  48. strSql.Append("F_RoleId,F_FunctionId,F_IsKey)");
  49. strSql.Append(" values (");
  50. strSql.Append("@F_RoleId,@F_FunctionId,@F_IsKey)");
  51. SqlParameter[] parameters = {
  52. new SqlParameter("@F_RoleId", SqlDbType.Int,4),
  53. new SqlParameter("@F_FunctionId", SqlDbType.Int,4),
  54. new SqlParameter("@F_IsKey", SqlDbType.Int,4)};
  55. parameters[0].Value = model.F_RoleId;
  56. parameters[1].Value = model.F_FunctionId;
  57. parameters[2].Value = model.F_IsKey;
  58. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  59. if (rows > 0)
  60. {
  61. return true;
  62. }
  63. else
  64. {
  65. return false;
  66. }
  67. }
  68. /// <summary>
  69. /// 更新一条数据
  70. /// </summary>
  71. public bool Update(Model.T_Sys_RoleFunction model)
  72. {
  73. StringBuilder strSql = new StringBuilder();
  74. strSql.Append("update T_Sys_RoleFunction set ");
  75. strSql.Append("F_IsKey=@F_IsKey");
  76. strSql.Append(" where F_RoleId=@F_RoleId and F_FunctionId=@F_FunctionId ");
  77. SqlParameter[] parameters = {
  78. new SqlParameter("@F_IsKey", SqlDbType.Int,4),
  79. new SqlParameter("@F_RoleId", SqlDbType.Int,4),
  80. new SqlParameter("@F_FunctionId", SqlDbType.Int,4)};
  81. parameters[0].Value = model.F_IsKey;
  82. parameters[1].Value = model.F_RoleId;
  83. parameters[2].Value = model.F_FunctionId;
  84. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  85. if (rows > 0)
  86. {
  87. return true;
  88. }
  89. else
  90. {
  91. return false;
  92. }
  93. }
  94. /// <summary>
  95. /// 删除一条数据
  96. /// </summary>
  97. public bool Delete(int F_RoleId, int F_FunctionId)
  98. {
  99. StringBuilder strSql = new StringBuilder();
  100. strSql.Append("delete from T_Sys_RoleFunction ");
  101. strSql.Append(" where F_RoleId=@F_RoleId and F_FunctionId=@F_FunctionId ");
  102. SqlParameter[] parameters = {
  103. new SqlParameter("@F_RoleId", SqlDbType.Int,4),
  104. new SqlParameter("@F_FunctionId", SqlDbType.Int,4) };
  105. parameters[0].Value = F_RoleId;
  106. parameters[1].Value = F_FunctionId;
  107. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  108. if (rows > 0)
  109. {
  110. return true;
  111. }
  112. else
  113. {
  114. return false;
  115. }
  116. }
  117. /// <summary>
  118. /// 删除一条数据
  119. /// </summary>
  120. public bool Delete1(int F_RoleId)
  121. {
  122. StringBuilder strSql = new StringBuilder();
  123. strSql.Append("delete from T_Sys_RoleFunction ");
  124. strSql.Append(" where F_RoleId=@F_RoleId ");
  125. SqlParameter[] parameters = {
  126. new SqlParameter("@F_RoleId", SqlDbType.Int,4) };
  127. parameters[0].Value = F_RoleId;
  128. int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
  129. if (rows > 0)
  130. {
  131. return true;
  132. }
  133. else
  134. {
  135. return false;
  136. }
  137. }
  138. /// <summary>
  139. /// 得到一个对象实体
  140. /// </summary>
  141. public Model.T_Sys_RoleFunction GetModel(int F_RoleId, int F_FunctionId)
  142. {
  143. StringBuilder strSql = new StringBuilder();
  144. strSql.Append("select top 1 F_RoleId,F_FunctionId,F_IsKey from T_Sys_RoleFunction ");
  145. strSql.Append(" where F_RoleId=@F_RoleId and F_FunctionId=@F_FunctionId ");
  146. SqlParameter[] parameters = {
  147. new SqlParameter("@F_RoleId", SqlDbType.Int,4),
  148. new SqlParameter("@F_FunctionId", SqlDbType.Int,4) };
  149. parameters[0].Value = F_RoleId;
  150. parameters[1].Value = F_FunctionId;
  151. Model.T_Sys_RoleFunction model = new Model.T_Sys_RoleFunction();
  152. DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
  153. if (ds.Tables[0].Rows.Count > 0)
  154. {
  155. return DataRowToModel(ds.Tables[0].Rows[0]);
  156. }
  157. else
  158. {
  159. return null;
  160. }
  161. }
  162. /// <summary>
  163. /// 得到一个对象实体
  164. /// </summary>
  165. public Model.T_Sys_RoleFunction DataRowToModel(DataRow row)
  166. {
  167. Model.T_Sys_RoleFunction model = new Model.T_Sys_RoleFunction();
  168. if (row != null)
  169. {
  170. if (row["F_RoleId"] != null && row["F_RoleId"].ToString() != "")
  171. {
  172. model.F_RoleId = int.Parse(row["F_RoleId"].ToString());
  173. }
  174. if (row["F_FunctionId"] != null && row["F_FunctionId"].ToString() != "")
  175. {
  176. model.F_FunctionId = int.Parse(row["F_FunctionId"].ToString());
  177. }
  178. if (row["F_IsKey"] != null && row["F_IsKey"].ToString() != "")
  179. {
  180. model.F_IsKey = int.Parse(row["F_IsKey"].ToString());
  181. }
  182. }
  183. return model;
  184. }
  185. /// <summary>
  186. /// 获得数据列表
  187. /// </summary>
  188. public DataSet GetList(string strWhere)
  189. {
  190. StringBuilder strSql = new StringBuilder();
  191. strSql.Append("select F_RoleId,F_FunctionId,F_IsKey ");
  192. strSql.Append(" FROM T_Sys_RoleFunction ");
  193. if (strWhere.Trim() != "")
  194. {
  195. strSql.Append(" where " + strWhere);
  196. }
  197. return DbHelperSQL.Query(strSql.ToString());
  198. }
  199. /// <summary>
  200. /// 获得前几行数据
  201. /// </summary>
  202. public DataSet GetList(int Top, string strWhere, string filedOrder)
  203. {
  204. StringBuilder strSql = new StringBuilder();
  205. strSql.Append("select ");
  206. if (Top > 0)
  207. {
  208. strSql.Append(" top " + Top.ToString());
  209. }
  210. strSql.Append(" F_RoleId,F_FunctionId,F_IsKey ");
  211. strSql.Append(" FROM T_Sys_RoleFunction ");
  212. if (strWhere.Trim() != "")
  213. {
  214. strSql.Append(" where " + strWhere);
  215. }
  216. strSql.Append(" order by " + filedOrder);
  217. return DbHelperSQL.Query(strSql.ToString());
  218. }
  219. /// <summary>
  220. /// 获取记录总数
  221. /// </summary>
  222. public int GetRecordCount(string strWhere)
  223. {
  224. StringBuilder strSql = new StringBuilder();
  225. strSql.Append("select count(1) FROM T_Sys_RoleFunction ");
  226. if (strWhere.Trim() != "")
  227. {
  228. strSql.Append(" where " + strWhere);
  229. }
  230. object obj = DbHelperSQL.GetSingle(strSql.ToString());
  231. if (obj == null)
  232. {
  233. return 0;
  234. }
  235. else
  236. {
  237. return Convert.ToInt32(obj);
  238. }
  239. }
  240. /// <summary>
  241. /// 分页获取数据列表
  242. /// </summary>
  243. public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
  244. {
  245. StringBuilder strSql = new StringBuilder();
  246. strSql.Append("SELECT * FROM ( ");
  247. strSql.Append(" SELECT ROW_NUMBER() OVER (");
  248. if (!string.IsNullOrEmpty(orderby.Trim()))
  249. {
  250. strSql.Append("order by T." + orderby);
  251. }
  252. else
  253. {
  254. strSql.Append("order by T.F_FunctionId desc");
  255. }
  256. strSql.Append(")AS Row, T.* from T_Sys_RoleFunction T ");
  257. if (!string.IsNullOrEmpty(strWhere.Trim()))
  258. {
  259. strSql.Append(" WHERE " + strWhere);
  260. }
  261. strSql.Append(" ) TT");
  262. strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
  263. return DbHelperSQL.Query(strSql.ToString());
  264. }
  265. #endregion BasicMethod
  266. #region ExtensionMethod
  267. #endregion ExtensionMethod
  268. }
  269. }