DayAndCostService.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 DayAndCostService
  11. {
  12. List<DayAndCost> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<DayAndCost>.excuteSql(new DayAndCost(), "DayAndCost", sql, CommandType.Text, param);
  15. }
  16. DayAndCost excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<DayAndCost> 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(DayAndCost Dov)
  29. {
  30. string sql = "insert into DayAndCost values(@Diid,@Type,@Days,@Place,@Cost,@Currency,@SubTotal,@OPer,@OPDate,@Isdel);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@Diid",Dov.Diid),
  33. new SqlParameter("@Type",Dov.Type),
  34. new SqlParameter("@Days",Dov.Days),
  35. new SqlParameter("@Place",Dov.Place),
  36. new SqlParameter("@Cost",Dov.Cost),
  37. new SqlParameter("@Currency",Dov.Currency),
  38. new SqlParameter("@SubTotal",Dov.SubTotal),
  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(DayAndCost Dov)
  49. {
  50. string sql = "update DayAndCost set Diid=@Diid,Type=@Type,Days=@Days,Place=@Place,Cost=@Cost,Currency=@Currency,SubTotal=@SubTotal,OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id";
  51. SqlParameter[] parameter = new SqlParameter[]{
  52. new SqlParameter("@Diid",Dov.Diid),
  53. new SqlParameter("@Type",Dov.Type),
  54. new SqlParameter("@Days",Dov.Days),
  55. new SqlParameter("@Place",Dov.Place),
  56. new SqlParameter("@Cost",Dov.Cost),
  57. new SqlParameter("@Currency",Dov.Currency),
  58. new SqlParameter("@SubTotal",Dov.SubTotal),
  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 DayAndCost 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. /// <param name="id"></param>
  79. /// <returns></returns>
  80. public bool Clean(int id)
  81. {
  82. string sql = "update DayAndCost set Place ='"+ "',Cost ='0.00',Currency='" + "',SubTotal='0.00' where Id = @Id";
  83. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, new SqlParameter("@Id", id)) > 0)
  84. return true;
  85. return false;
  86. }
  87. public DayAndCost GetById(string id)
  88. {
  89. return excuteType("select * from DayAndCost where Isdel=0 and Id =" + id);
  90. }
  91. public List<DayAndCost> Get(string Diid, int type)
  92. {
  93. return excuteSql("select * from DayAndCost where Isdel=0 and Diid =" + Diid + " and Type=" + type + " order by Days");
  94. }
  95. public bool DelAllDataByDiid(string diid)
  96. {
  97. string sql = "update DayAndCost set isdel = 1 where isdel = 0 and diid = '" + diid + "' ";
  98. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text) > 0)
  99. return true;
  100. return false;
  101. }
  102. }
  103. }