ApprovalTravelDetailsService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. using System.Collections;
  10. namespace DAL
  11. {
  12. /// <summary>
  13. /// 公务出访详情
  14. /// </summary>
  15. public class ApprovalTravelDetailsService
  16. {
  17. List<ApprovalTravelDetails> excuteSql(string sql, params SqlParameter[] param)
  18. {
  19. return ServiceBase<ApprovalTravelDetails>.excuteSql(new ApprovalTravelDetails(), "ApprovalTravelDetails", sql, CommandType.Text, param);
  20. }
  21. ApprovalTravelDetails excuteType(string sql, params SqlParameter[] param)
  22. {
  23. //查询结果放入对象集合
  24. List<ApprovalTravelDetails> hdList = excuteSql(sql, param);
  25. ApprovalTravelDetails air = new ApprovalTravelDetails();
  26. //判断集合是否为空
  27. if (hdList == null || hdList.Count == 0)
  28. {
  29. return air;
  30. }
  31. //返回单个对象
  32. return hdList[0];
  33. }
  34. public List<ApprovalTravelDetails> GetByParentID(int ParentID)
  35. {
  36. return excuteSql($"select * from ApprovalTravelDetails where ParentId= {ParentID} and isdel = 0");
  37. }
  38. public int AddList(List<ApprovalTravelDetails> list)
  39. {
  40. int rows = 0;
  41. SqlCommand cmd = SqlHelper.createCon().CreateCommand();
  42. cmd.Connection.Open();
  43. SqlTransaction trans = cmd.Connection.BeginTransaction();
  44. cmd.Transaction = trans;
  45. try
  46. {
  47. foreach (var item in list)
  48. {
  49. string sql = string.Format("insert into ApprovalTravelDetails values('{0}',{1},'{2}',0)",item.Time,item.ParentId,item.Details);
  50. cmd.CommandText = sql;
  51. rows += cmd.ExecuteNonQuery();
  52. }
  53. trans.Commit();
  54. cmd.Connection.Close();
  55. return rows;
  56. }
  57. catch
  58. {
  59. trans.Rollback();
  60. cmd.Connection.Close();
  61. return rows;
  62. }
  63. }
  64. public bool DeleteByDiiD(int diid)
  65. {
  66. if (SqlHelper.ExecuteNonQuery($@"update ApprovalTravelDetails set Isdel=1 where id in (select a.id from ApprovalTravelDetails a, ApprovalTravel b where
  67. a.parentId = b.Id and b.Diid = {diid} ) ", CommandType.Text) > 0)
  68. {
  69. return true;
  70. }
  71. return false;
  72. }
  73. }
  74. }