AirGoodsService.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 AirGoodsService
  11. {
  12. List<AirGoods> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<AirGoods>.excuteSql(new AirGoods(), "AirGoods", sql, CommandType.Text, param);
  15. }
  16. AirGoods excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<AirGoods> 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(AirGoods Dov)
  29. {
  30. string sql = "insert into AirGoods values(@Diid,@Goods,@Price,@Num,@SubPrices,@Remark,@Oper,@Opdate,@Isdel);SELECT @@IDENTITY";
  31. SqlParameter[] parameter = new SqlParameter[]{
  32. new SqlParameter("@Diid",Dov.Diid),
  33. new SqlParameter("@Goods",Dov.Goods),
  34. new SqlParameter("@Price",Dov.Price),
  35. new SqlParameter("@Num",Dov.Num),
  36. new SqlParameter("@SubPrices",Dov.SubPrices),
  37. new SqlParameter("@Remark",Dov.Remark),
  38. new SqlParameter("@Oper",Dov.Oper),
  39. new SqlParameter("@Opdate",Dov.Opdate),
  40. new SqlParameter("@Isdel",Dov.Isdel)
  41. };
  42. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  43. return true;
  44. return false;
  45. }
  46. //改Update
  47. public bool Edit(AirGoods Dov)
  48. {
  49. string sql = "update AirGoods set Diid=@Diid,Goods=@Goods,Price=@Price,Num=@Num,SubPrices=@SubPrices,Remark=@Remark,"
  50. + "Oper=@Oper,Opdate=@Opdate,Isdel=@Isdel where Id = @Id";
  51. SqlParameter[] parameter = new SqlParameter[]{
  52. new SqlParameter("@Diid",Dov.Diid),
  53. new SqlParameter("@Goods",Dov.Goods),
  54. new SqlParameter("@Price",Dov.Price),
  55. new SqlParameter("@Num",Dov.Num),
  56. new SqlParameter("@SubPrices",Dov.SubPrices),
  57. new SqlParameter("@Remark",Dov.Remark),
  58. new SqlParameter("@Oper",Dov.Oper),
  59. new SqlParameter("@Opdate",Dov.Opdate),
  60. new SqlParameter("@Isdel",Dov.Isdel),
  61. new SqlParameter("@Id",Dov.Id)
  62. };
  63. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  64. return true;
  65. return false;
  66. }
  67. //删
  68. public bool delOA(int id)
  69. {
  70. if (SqlHelper.ExecuteNonQuery("update AirGoods set Isdel=1 where Id=@Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  71. return true;
  72. return false;
  73. }
  74. /// <summary>
  75. /// 查找所有数据 - 分页
  76. /// </summary>
  77. /// <returns></returns>
  78. public List<AirGoods> GetAll(int diid)
  79. {
  80. return excuteSql("select * from AirGoods where Isdel=0 and Diid="+diid);
  81. }
  82. public AirGoods getById(int id)
  83. {
  84. return excuteType("select * from AirGoods where Isdel=0 and Id=@id", new SqlParameter("@id", id));
  85. }
  86. }
  87. }