AskDataService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using Models;
  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. namespace DAL
  9. {
  10. public class AskDataService
  11. {
  12. List<AskData> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<AskData>.excuteSql(new AskData(), "AskData", sql, CommandType.Text, param);
  15. }
  16. AskData excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<AskData> hdList = excuteSql(sql, param);
  20. //判断集合是否为空
  21. if (hdList == null || hdList.Count == 0)
  22. //返回null
  23. return null;
  24. //返回单个对象
  25. return hdList[0];
  26. }
  27. //增Add
  28. public bool Add(AskData Dov)
  29. {
  30. string sql = "insert into AskData values(@Diid,@DeleName,@Country,@Area,@UnitName,@Field,@TalkCase,@Oper,@OpDate,@Isdel);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@Diid",Dov.Diid),
  33. new SqlParameter("@DeleName",Dov.DeleName),
  34. new SqlParameter("@Country",Dov.Country),
  35. new SqlParameter("@Area",Dov.Area),
  36. new SqlParameter("@UnitName",Dov.UnitName),
  37. new SqlParameter("@Field",Dov.Field),
  38. new SqlParameter("@TalkCase",Dov.TalkCase),
  39. new SqlParameter("@Oper",Dov.Oper),
  40. new SqlParameter("@OpDate",Dov.OpDate),
  41. new SqlParameter("@Isdel",Dov.Isdel)
  42. };
  43. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  44. return true;
  45. return false;
  46. }
  47. //改Update
  48. public bool Edit(AskData Dov)
  49. {
  50. string sql = "update AskData set Diid=@Diid,DeleName=@DeleName,Country=@Country,Area=@Area,UnitName=@UnitName,Field=@Field,TalkCase=@TalkCase,Oper=@Oper,OpDate=@OpDate,Isdel=@Isdel where Id = @Id";
  51. SqlParameter[] parameter = new SqlParameter[]{
  52. new SqlParameter("@Diid",Dov.Diid),
  53. new SqlParameter("@DeleName",Dov.DeleName),
  54. new SqlParameter("@Country",Dov.Country),
  55. new SqlParameter("@Area",Dov.Area),
  56. new SqlParameter("@UnitName",Dov.UnitName),
  57. new SqlParameter("@Field",Dov.Field),
  58. new SqlParameter("@TalkCase",Dov.TalkCase),
  59. new SqlParameter("@Oper",Dov.Oper),
  60. new SqlParameter("@OpDate",Dov.OpDate),
  61. new SqlParameter("@Isdel",Dov.Isdel),
  62. new SqlParameter("@Id",Dov.Id)
  63. };
  64. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  65. return true;
  66. return false;
  67. }
  68. //删
  69. public bool delOA(int id)
  70. {
  71. if (SqlHelper.ExecuteNonQuery("update AskData set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  72. return true;
  73. return false;
  74. }
  75. /// <summary>
  76. /// 查找所有数据 - 分页
  77. /// </summary>
  78. /// <returns></returns>
  79. public List<AskData> GetAllAskData(int pageIndex, out int sumPage, out int totalRecord, string Country, string Area, string Field)
  80. {
  81. string sqlwhere = "IsDel = 0 and Country like '%" + Country + "%' and Area like '%" + Area + "%' and Field like '%" + Field + "%'";
  82. return PageBase<AskData>.excutePageSql(new AskData(), "AskData", "AskData", "*", "id asc", sqlwhere, 15, pageIndex, out sumPage, out totalRecord);
  83. }
  84. public AskData getById(int id)
  85. {
  86. return excuteType("select * from AskData where Isdel=0 and Id=@id", new SqlParameter("@id", id));
  87. }
  88. /// <summary>
  89. /// 根据ID集合查询数据
  90. /// 20210831 贾文滔
  91. /// </summary>
  92. /// <param name="id"></param>
  93. /// <returns></returns>
  94. public List<AskData> getByIdlist(string id)
  95. {
  96. return excuteSql("select * from AskData where Isdel=0 and Id in (" + id + ") order by Country", new SqlParameter("@id", id));
  97. }
  98. }
  99. }