TopicClassManage.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data.Common;
  4. using System.Linq;
  5. using System.Text;
  6. using CB.Entity;
  7. using CB.Interface.Infrastructure;
  8. using System.Data;
  9. using CB.Common;
  10. namespace CB.Data.SqlServer
  11. {
  12. public class TopicClassManage : Repository<TopicClassInfo>, ITopicClassService
  13. {
  14. public TopicClassManage(string interfaceId)
  15. : base(interfaceId)
  16. {
  17. }
  18. public override bool Save(TopicClassInfo entity)
  19. {
  20. DbParameter[] pars ={
  21. DbHelper.MakeInParam(InterfaceId,"@Cid",(DbType)SqlDbType.Int,4,entity.Cid),
  22. DbHelper.MakeInParam(InterfaceId,"@Name",(DbType)SqlDbType.NVarChar,100,entity.Name),
  23. DbHelper.MakeInParam(InterfaceId,"@pid",(DbType)SqlDbType.Int,4,entity.ParentId),
  24. DbHelper.MakeInParam(InterfaceId,"@rid",(DbType)SqlDbType.Int,4,entity.RootId),
  25. DbHelper.MakeInParam(InterfaceId,"@depth",(DbType)SqlDbType.Int,4,(int)entity.Depth),
  26. };
  27. return TypeConverter.ObjectToInt(DbHelper.ExecuteScalar(InterfaceId,CommandType.StoredProcedure, "usp_TopClass_save", pars)) > 0;
  28. }
  29. public override bool Update(TopicClassInfo entity)
  30. {
  31. throw new NotImplementedException();
  32. }
  33. public override bool Delete(int id)
  34. {
  35. return DbHelper.ExecuteNonQuery(InterfaceId, CommandType.Text, "DELETE FROM [DT_TopicClass] WHERE [Cid]="+id.ToString()) > 0;
  36. }
  37. public override TopicClassInfo Get<TKey>(TKey key)
  38. {
  39. TopicClassInfo Entity = null;
  40. DbParameter[] para =
  41. {
  42. DbHelper.MakeInParam(InterfaceId,"@Id",(DbType)SqlDbType.Int,4,key)
  43. };
  44. using (IDataReader reader = DbHelper.ExecuteReader(InterfaceId,CommandType.Text,
  45. "SELECT TOP 1 [Cid],[Name],[ParentId],[RootId],[Depth],[Addtime] FROM [DT_TopicClass] WHERE Cid= @Id", para))
  46. {
  47. if (reader.Read())
  48. {
  49. Entity = LoadEntity(reader);
  50. }
  51. reader.Dispose();
  52. }
  53. return Entity;
  54. }
  55. public override IList<TopicClassInfo> ToList()
  56. {
  57. IList<TopicClassInfo> list = new List<TopicClassInfo>();
  58. StringBuilder strSql = new StringBuilder();
  59. strSql.Append("SELECT [Cid],[Name],[ParentId],[RootId],[Depth],[Addtime]");
  60. strSql.Append(" FROM dbo.DT_TopicClass ORDER BY Cid ASC");
  61. using (DataTable dt = DbHelper.ExecuteDatatable(InterfaceId,strSql.ToString()))
  62. {
  63. if (null != dt && 0 < dt.Rows.Count)
  64. {
  65. foreach (DataRow dr in dt.Rows)
  66. { list.Add(LoadEntity(dr)); }
  67. }
  68. dt.Dispose();
  69. }
  70. return list;
  71. }
  72. public override IList<TopicClassInfo> ToList(TopicClassInfo entity)
  73. {
  74. IList<TopicClassInfo> list = new List<TopicClassInfo>();
  75. StringBuilder strSql = new StringBuilder();
  76. strSql.Append("SELECT [Cid],[Name],[ParentId],[RootId],[Depth],[Addtime]");
  77. strSql.Append(" FROM dbo.DT_TopicClass where 1=1 ORDER BY Cid ASC");
  78. using (DataTable dt = DbHelper.ExecuteDatatable(InterfaceId,strSql.ToString()))
  79. {
  80. if (null != dt && 0 < dt.Rows.Count)
  81. {
  82. foreach (DataRow dr in dt.Rows)
  83. { list.Add(LoadEntity(dr)); }
  84. }
  85. dt.Dispose();
  86. }
  87. return list;
  88. }
  89. public override IList<TopicClassInfo> ToPaging(TopicClassInfo entity, int pageSize, int pageIndex, out int recordCount)
  90. {
  91. string where = "1=1 ";
  92. if (!string.IsNullOrEmpty(entity.Name))
  93. {
  94. where += "and [Name] like '%" + entity.Name + "%'";
  95. }
  96. recordCount = 0;
  97. string field = "[Cid],[Name],[ParentId],[RootId],[Depth],[Addtime]"
  98. , orderField = "Cid"
  99. , tableName = "DT_TopicClass";
  100. DbParameter[] para =
  101. {
  102. DbHelper.MakeInParam(InterfaceId,"@pageSize",(DbType)SqlDbType.Int,4,pageSize),
  103. DbHelper.MakeInParam(InterfaceId,"@page",(DbType)SqlDbType.Int,4,pageIndex),
  104. DbHelper.MakeInParam(InterfaceId,"@tableName",(DbType)SqlDbType.NVarChar,500,tableName),
  105. DbHelper.MakeInParam(InterfaceId,"@field",(DbType)SqlDbType.NVarChar,1000,field),
  106. DbHelper.MakeInParam(InterfaceId,"@orderField",(DbType)SqlDbType.NVarChar,50,orderField),
  107. DbHelper.MakeInParam(InterfaceId,"@where",(DbType)SqlDbType.NVarChar,2000,where)
  108. };
  109. IList<TopicClassInfo> list = new List<TopicClassInfo>();
  110. using (IDataReader reader = DbHelper.ExecuteReader(InterfaceId,CommandType.StoredProcedure, "usp_st_page", para))
  111. {
  112. while (reader.Read())
  113. {
  114. list.Add(LoadEntity(reader));
  115. }
  116. if (reader.NextResult() && reader.Read())
  117. {
  118. recordCount = reader.GetInt32(0);
  119. }
  120. reader.Dispose();
  121. }
  122. return list;
  123. }
  124. protected override TopicClassInfo LoadEntity(DataRow dr)
  125. {
  126. return new TopicClassInfo
  127. {
  128. Cid = TypeConverter.ObjectToInt(dr["Cid"]),
  129. Name = dr["Name"].ToString().Trim(),
  130. ParentId = TypeConverter.ObjectToInt(dr["ParentId"]),
  131. RootId = TypeConverter.ObjectToInt(dr["RootId"]),
  132. Depth = TypeConverter.ObjectToInt(dr["Depth"]),
  133. Addtime = TypeConverter.ObjectToDateTime(dr["Addtime"], DateTime.MinValue),
  134. };
  135. }
  136. protected override TopicClassInfo LoadEntity(IDataReader reader)
  137. {
  138. return new TopicClassInfo
  139. {
  140. Cid = TypeConverter.ObjectToInt(reader["Cid"]),
  141. Name = reader["Name"].ToString().Trim(),
  142. ParentId = TypeConverter.ObjectToInt(reader["ParentId"]),
  143. RootId = TypeConverter.ObjectToInt(reader["RootId"]),
  144. Depth = TypeConverter.ObjectToInt(reader["Depth"]),
  145. Addtime = TypeConverter.ObjectToDateTime(reader["Addtime"], DateTime.MinValue),
  146. };
  147. }
  148. }
  149. }