TravelDetailsService.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 TravelDetailsService
  11. {
  12. List<TravelDetails> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<TravelDetails>.excuteSql(new TravelDetails(), "TravelDetails", sql, CommandType.Text, param);
  15. }
  16. TravelDetails excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<TravelDetails> 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(TravelDetails Dov)
  29. {
  30. string sql = "insert into TravelDetails values(@Diid,@OrderNum,@Date,@Time,@ActivityType,@Activity,@Address,@Remark,@OPer,@Opdate,@Isdel);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@Diid",Dov.Diid),
  33. new SqlParameter("@OrderNum",Dov.OrderNum),
  34. new SqlParameter("@Date",Dov.Date),
  35. new SqlParameter("@Time",Dov.Time),
  36. new SqlParameter("@ActivityType",Dov.ActivityType),
  37. new SqlParameter("@Activity",Dov.Activity),
  38. new SqlParameter("@Address",Dov.Address),
  39. new SqlParameter("@Remark",Dov.Remark),
  40. new SqlParameter("@OPer",Dov.OPer),
  41. new SqlParameter("@Opdate",Dov.Opdate),
  42. new SqlParameter("@Isdel",Dov.Isdel)
  43. };
  44. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  45. return true;
  46. return false;
  47. }
  48. //改Update
  49. public bool Edit(TravelDetails Dov)
  50. {
  51. string sql = "update TravelDetails set Diid=@Diid,OrderNum=@OrderNum,Date=@Date,Time=@Time,ActivityType=@ActivityType,Activity=@Activity,"
  52. + "Address=@Address,Remark=@Remark,Oper=@Oper,Opdate=@Opdate,Isdel=@Isdel where Id = @Id";
  53. SqlParameter[] parameter = new SqlParameter[]{
  54. new SqlParameter("@Diid",Dov.Diid),
  55. new SqlParameter("@OrderNum",Dov.OrderNum),
  56. new SqlParameter("@Date",Dov.Date),
  57. new SqlParameter("@Time",Dov.Time),
  58. new SqlParameter("@ActivityType",Dov.ActivityType),
  59. new SqlParameter("@Activity",Dov.Activity),
  60. new SqlParameter("@Remark",Dov.Remark),
  61. new SqlParameter("@Address",Dov.Address),
  62. new SqlParameter("@OPer",Dov.OPer),
  63. new SqlParameter("@Opdate",Dov.Opdate),
  64. new SqlParameter("@Isdel",Dov.Isdel),
  65. new SqlParameter("@Id",Dov.Id)
  66. };
  67. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  68. return true;
  69. return false;
  70. }
  71. //删
  72. public bool delOA(int id)
  73. {
  74. if (SqlHelper.ExecuteNonQuery("update TravelDetails set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  75. return true;
  76. return false;
  77. }
  78. public List<TravelDetails> GetByDiid(int diid)
  79. {
  80. return excuteSql("select * from TravelDetails where Isdel=0 and Diid=" + diid + " order by OrderNum");
  81. }
  82. /// <summary>
  83. /// GEN
  84. /// </summary>
  85. /// <param name="diid"></param>
  86. /// <returns></returns>
  87. public List<TravelDetails> GetByDiidAndDate(int diid, string date)
  88. {
  89. return excuteSql("select * from TravelDetails where Isdel=0 and Diid=" + diid + " and Date='" + date + "' order by OrderNum");
  90. }
  91. public TravelDetails getById(int id)
  92. {
  93. return excuteType("select * from TravelDetails where Isdel=0 and Id=@id", new SqlParameter("@id", id));
  94. }
  95. /// <summary>
  96. /// 删除指定范围
  97. /// </summary>
  98. /// <param name="Diid"></param>
  99. /// <param name="start"></param>
  100. /// <param name="end"></param>
  101. /// <returns></returns>
  102. public bool DelOld(int Diid, int start, int end)
  103. {
  104. if (SqlHelper.ExecuteNonQuery("delete from TravelDetails where Diid=" + Diid + " and ( Id>=" + start + " and Id<=" + end + ")", CommandType.Text) > 0)
  105. return true;
  106. return false;
  107. }
  108. }
  109. }