NBTypeCodeService.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using LeaRun.Application.Entity.NBManage;
  2. using LeaRun.Data;
  3. using LeaRun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace LeaRun.Application.Service.NBManage
  11. {
  12. public class NBTypeCodeService
  13. {
  14. SqlHelper sqlHelper = new SqlHelper("NBDB");
  15. /// <summary>
  16. /// 保存NBTypeCode
  17. /// </summary>
  18. /// <param name="entity"></param>
  19. /// <returns> </returns>
  20. public bool SaveNBTypeCode(NBTypeCodeEntity entity)
  21. {
  22. try
  23. {
  24. string insertSql = DataHelper.ModelToInsertSql<NBTypeCodeEntity>(entity, "RMRS_NBTypeCode");
  25. return sqlHelper.ExecuteNoParams(insertSql, CommandType.Text) > 0;
  26. }
  27. catch (Exception)
  28. {
  29. throw;
  30. }
  31. }
  32. /// <summary>
  33. /// 更新设备类型
  34. /// </summary>
  35. /// <param name="entity"></param>
  36. /// <returns></returns>
  37. public bool UpdateNBTypeCode(NBTypeCodeEntity entity)
  38. {
  39. try
  40. {
  41. string updateSql = DataHelper.ModelToUpdateSql<NBTypeCodeEntity>(entity, "RMRS_NBTypeCode");
  42. return sqlHelper.ExecuteNoParams(updateSql, CommandType.Text) > 0;
  43. }
  44. catch (Exception)
  45. {
  46. throw;
  47. }
  48. }
  49. /// <summary>
  50. /// 删除设备类型
  51. /// </summary>
  52. /// <param name="NBTypeCodeID"></param>
  53. /// <returns>3 不可删除 1 删除成功 0删除失败</returns>
  54. public int DeleteNBTypeCode(string NBTypeCodeID)
  55. {
  56. try
  57. {
  58. //判断次类型下有无表
  59. string sqlMeter = "SELECT * FROM RMRS_MeterInfo WHERE NBTypeCode = " + NBTypeCodeID;
  60. DataTable dtMeter = sqlHelper.ExecuteDataTable(sqlMeter, CommandType.Text, null);
  61. if (dtMeter.Rows.Count > 0)
  62. {
  63. return 3;
  64. }
  65. string delSql = "DELETE FROM RMRS_NBTypeCode WHERE NBTypeCodeID = " + NBTypeCodeID;
  66. return sqlHelper.ExecuteNoParams(delSql, CommandType.Text) > 0 ? 1 : 0;
  67. }
  68. catch (Exception)
  69. {
  70. throw;
  71. }
  72. }
  73. /// <summary>
  74. /// 获取类型
  75. /// </summary>
  76. /// <param name="NBTypeCodeID"></param>
  77. /// <returns></returns>
  78. public NBTypeCodeEntity GetEntityById(string NBTypeCodeID)
  79. {
  80. try
  81. {
  82. string sqlNBTypeCode = "SELECT * FROM RMRS_NBTypeCode WHERE NBTypeCodeID = " + NBTypeCodeID;
  83. DataTable dtResult = sqlHelper.ExecuteDataTable(sqlNBTypeCode, CommandType.Text, null);
  84. List<NBTypeCodeEntity> lists = DataHelper.DataTableToT<NBTypeCodeEntity>(dtResult);
  85. if (lists != null)
  86. {
  87. return lists[0];
  88. }
  89. return new NBTypeCodeEntity();
  90. }
  91. catch (Exception)
  92. {
  93. throw;
  94. }
  95. }
  96. }
  97. }