SysGroupManage.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Data.Common;
  5. using CB.Common;
  6. using CB.Entity;
  7. using CB.Interface.Infrastructure;
  8. namespace CB.Data.SqlServer
  9. {
  10. public class SysGroupManage : Repository<SysGroupInfo>, ISysGroupService
  11. {
  12. public SysGroupManage(string interfaceId)
  13. : base(interfaceId)
  14. {
  15. }
  16. public override bool Save(SysGroupInfo entity)
  17. {
  18. DbParameter[] pars =
  19. {
  20. DbHelper.MakeInParam(InterfaceId,"@statement",(DbType)SqlDbType.NVarChar,200,"INSERT INTO [SYS_SysGroup] ([GroupName],[Status]) VALUES (@GroupName,@Status)"),
  21. DbHelper.MakeInParam(InterfaceId,"@params",(DbType)SqlDbType.NVarChar,100,"@GroupName nchar(20),@Status bit"),
  22. DbHelper.MakeInParam(InterfaceId,"@GroupName",(DbType)SqlDbType.NChar,20,entity.GroupName),
  23. DbHelper.MakeInParam(InterfaceId,"@Status",(DbType)SqlDbType.Bit,1,entity.Status)
  24. };
  25. return DbHelper.ExecuteNonQuery(InterfaceId,CommandType.StoredProcedure, "dbo.sp_executesql", pars) > 0 ? true : false;
  26. }
  27. public override bool Update(SysGroupInfo entity)
  28. {
  29. DbParameter[] pars =
  30. {
  31. DbHelper.MakeInParam(InterfaceId,"@statement",(DbType)SqlDbType.NVarChar,200,"UPDATE [SYS_SysGroup] SET [GroupName]=@GroupName,[Status]=@Status WHERE [GroupId]=@gid"),
  32. DbHelper.MakeInParam(InterfaceId,"@params",(DbType)SqlDbType.NVarChar,100,"@GroupName nchar(20),@Status bit,@gid int"),
  33. DbHelper.MakeInParam(InterfaceId,"@GroupName",(DbType)SqlDbType.NChar,20,entity.GroupName),
  34. DbHelper.MakeInParam(InterfaceId,"@Status",(DbType)SqlDbType.Bit,1,entity.Status),
  35. DbHelper.MakeInParam(InterfaceId,"@gid",(DbType)SqlDbType.Int,4,entity.GroupId)
  36. };
  37. return DbHelper.ExecuteNonQuery(InterfaceId,CommandType.StoredProcedure, "dbo.sp_executesql", pars) > 0 ? true : false;
  38. }
  39. public override bool Delete(int Id)
  40. {
  41. DbParameter[] pars =
  42. {
  43. DbHelper.MakeInParam(InterfaceId,"@statement",(DbType)SqlDbType.NVarChar,200,"DELETE FROM [SYS_SysGroup] WHERE [GroupId]=@gid"),
  44. DbHelper.MakeInParam(InterfaceId,"@params",(DbType)SqlDbType.NVarChar,10,"@gid int"),
  45. DbHelper.MakeInParam(InterfaceId,"@gid",(DbType)SqlDbType.Int,4,Id)
  46. };
  47. return DbHelper.ExecuteNonQuery(InterfaceId,CommandType.StoredProcedure, "dbo.sp_executesql", pars) > 0 ? true : false;
  48. }
  49. public override SysGroupInfo Get<TKey>(TKey key)
  50. {
  51. throw new NotImplementedException();
  52. }
  53. public override IList<SysGroupInfo> ToList()
  54. {
  55. DbParameter[] pars =
  56. {
  57. DbHelper.MakeInParam(InterfaceId,"@statement",(DbType)SqlDbType.NVarChar,100,"SELECT [GroupId],[GroupName],[Status] FROM [SYS_SysGroup]")
  58. };
  59. IList<SysGroupInfo> list = new List<SysGroupInfo>();
  60. using (IDataReader reader = DbHelper.ExecuteReader(InterfaceId,CommandType.StoredProcedure, "dbo.sp_executesql", pars))
  61. {
  62. while (reader.Read())
  63. {
  64. list.Add(LoadEntity(reader));
  65. }
  66. reader.Dispose();
  67. }
  68. return list;
  69. }
  70. public override IList<SysGroupInfo> ToList(SysGroupInfo entity)
  71. {
  72. throw new NotImplementedException();
  73. }
  74. public override IList<SysGroupInfo> ToPaging(SysGroupInfo entity, int pageSize, int pageIndex, out int recordCount)
  75. {
  76. throw new NotImplementedException();
  77. }
  78. protected override SysGroupInfo LoadEntity(IDataReader reader)
  79. {
  80. return new SysGroupInfo
  81. {
  82. GroupId = TypeConverter.ObjectToInt(reader["GroupId"]),
  83. GroupName = reader["GroupName"].ToString().Trim(),
  84. Status = TypeConverter.ObjectToBool(reader["Status"], false)
  85. };
  86. }
  87. protected override SysGroupInfo LoadEntity(DataRow dr)
  88. {
  89. return new SysGroupInfo
  90. {
  91. GroupId = TypeConverter.ObjectToInt(dr["GroupId"]),
  92. GroupName = dr["GroupName"].ToString().Trim(),
  93. Status = TypeConverter.ObjectToBool(dr["Status"], false)
  94. };
  95. }
  96. }
  97. }