AirCompanyServcies.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 AirCompanyServcies
  11. {
  12. List<AirCompany> excuteSql(string sql, params SqlParameter[] param)
  13. {
  14. return ServiceBase<AirCompany>.excuteSql(new AirCompany(), "AirCompany", sql, CommandType.Text, param);
  15. }
  16. AirCompany excuteType(string sql, params SqlParameter[] param)
  17. {
  18. //查询结果放入对象集合
  19. List<AirCompany> hdList = excuteSql(sql, param);
  20. AirCompany air = new AirCompany();
  21. //判断集合是否为空
  22. if (hdList == null || hdList.Count == 0)
  23. {
  24. //返回null
  25. air.CnName = "该航司尚未收录";
  26. return air;
  27. }
  28. //返回单个对象
  29. return hdList[0];
  30. }
  31. public AirCompany getByShortCode(string ShortCode)
  32. {
  33. return this.excuteType("select * from AirCompany where Isdel=0 and ShortCode=@ShortCode", new SqlParameter("@ShortCode", ShortCode.ToUpper()));
  34. }
  35. public AirCompany getById(string Id)
  36. {
  37. return this.excuteType("select * from AirCompany where Isdel=0 and Id=" + Id);
  38. }
  39. /// <summary>
  40. /// 查找所有数据 - 分页
  41. /// </summary>
  42. /// <returns></returns>
  43. public List<AirCompany> GetAll(int pageIndex, out int sumPage, out int totalRecord, string ShortCode)
  44. {
  45. string sqlwhere = "IsDel = 0 and ShortCode like '%" + ShortCode + "%'";
  46. return PageBase<AirCompany>.excutePageSql(new AirCompany(), "AirCompany", "AirCompany", "*", "id asc", sqlwhere, 10, pageIndex, out sumPage, out totalRecord);
  47. }
  48. /// <summary>
  49. /// 增加
  50. /// </summary>
  51. /// <param name="cd"></param>
  52. /// <returns></returns>
  53. public bool Add(AirCompany hd)
  54. {
  55. string sql = "insert into AirCompany values(@ShortCode,@CnName,@EnName,@OPer,@OPDate,@Isdel)";
  56. SqlParameter[] parameter = new SqlParameter[]{
  57. new SqlParameter("@ShortCode",hd.ShortCode),
  58. new SqlParameter("@CnName",hd.CnName),
  59. new SqlParameter("@EnName",hd.EnName),
  60. new SqlParameter("@OPer",hd.OPer),
  61. new SqlParameter("@OPDate",hd.OPDate),
  62. new SqlParameter("@Isdel",hd.Isdel)
  63. };
  64. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  65. return true;
  66. return false;
  67. }
  68. /// <summary>
  69. /// 编辑
  70. /// </summary>
  71. /// <param name="sdt"></param>
  72. /// <returns></returns>
  73. public bool Edit(AirCompany hd)
  74. {
  75. string sql = "update AirCompany set ShortCode=@ShortCode,CnName=@CnName,EnName=@EnName,"
  76. + "OPer=@OPer,OPDate=@OPDate,Isdel=@Isdel where Id = @Id";
  77. SqlParameter[] parameter = new SqlParameter[]{
  78. new SqlParameter("@ShortCode",hd.ShortCode),
  79. new SqlParameter("@CnName",hd.CnName),
  80. new SqlParameter("@EnName",hd.EnName),
  81. new SqlParameter("@OPer",hd.OPer),
  82. new SqlParameter("@OPDate",hd.OPDate),
  83. new SqlParameter("@Isdel",hd.Isdel),
  84. new SqlParameter("@Id",hd.Id)
  85. };
  86. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  87. return true;
  88. return false;
  89. }
  90. /// <summary>
  91. /// 删除
  92. /// </summary>
  93. /// <param name="id"></param>
  94. /// <returns></returns>
  95. public bool Del(int id)
  96. {
  97. if (SqlHelper.ExecuteNonQuery("update AirCompany set IsDel = 1 where Id = @Id", CommandType.Text, new SqlParameter("@Id", id)) > 0)
  98. return true;
  99. return false;
  100. }
  101. }
  102. }