TrainingExpensesService.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Models;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Data.SqlClient;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace DAL
  10. {
  11. /// <summary>
  12. /// 培训费用数据访问层
  13. /// </summary>
  14. public class TrainingExpensesService
  15. {
  16. List<TrainingExpenses> excuteSql(string sql, params SqlParameter[] param)
  17. {
  18. return ServiceBase<TrainingExpenses>.excuteSql(new TrainingExpenses(), "TrainingExpenses", sql, CommandType.Text, param);
  19. }
  20. TrainingExpenses excuteType(string sql, params SqlParameter[] param)
  21. {
  22. //查询结果放入对象集合
  23. List<TrainingExpenses> hdList = excuteSql(sql, param);
  24. //判断集合是否为空
  25. if (hdList == null || hdList.Count == 0)
  26. {
  27. //返回null
  28. return null;
  29. }
  30. //返回单个对象
  31. return hdList[0];
  32. }
  33. public List<TrainingExpenses> GetAll()
  34. {
  35. return excuteSql(" select * from TrainingExpenses where isdel = 0 ");
  36. }
  37. public TrainingExpenses GetByCountry(string country)
  38. {
  39. return excuteType(string.Format(" select * from TrainingExpenses where isdel = 0 and country = '{0}' ",country));
  40. }
  41. public List<TrainingExpenses> GetLikeByCountry(string country)
  42. {
  43. return excuteSql(string.Format(" select * from TrainingExpenses where isdel = 0 and country like '%{0}%' ", country));
  44. }
  45. public bool Add(TrainingExpenses TE)
  46. {
  47. string sql = "insert into TrainingExpenses values(@continent,@country,@currency,@expense,@operationTime,@operationUser,@Isdel)";
  48. SqlParameter[] parameter = new SqlParameter[]{
  49. new SqlParameter("@continent",TE.continent),
  50. new SqlParameter("@country",TE.country),
  51. new SqlParameter("@currency",TE.currency),
  52. new SqlParameter("@expense",TE.expense),
  53. new SqlParameter("@operationTime",TE.operationTime),
  54. new SqlParameter("@operationUser",TE.operationUser),
  55. new SqlParameter("@Isdel","0")
  56. };
  57. if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
  58. return true;
  59. return false;
  60. }
  61. }
  62. }