DeviceService.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Configuration;
  6. using System.Threading.Tasks;
  7. using System.Data;
  8. using LeaRun.Application.Entity.WaterWellManage;
  9. using LeaRun.Util;
  10. using LeaRun.Data;
  11. namespace LeaRun.Application.Service.WaterWellManage
  12. {
  13. public class DeviceService
  14. {
  15. SqlHelper sqlHelper = new SqlHelper("BaseDb");
  16. /// <summary>
  17. /// 获取根节点
  18. /// </summary>
  19. /// <param name="parentId"></param>
  20. /// <returns></returns>
  21. public IEnumerable<DeviceEntity> GetList(string parentId)
  22. {
  23. try
  24. {
  25. var strSql = "SELECT * FROM Base_Organize WHERE ParentId='" + parentId + "'";
  26. DataTable dtResult = sqlHelper.ExecuteDataTable(strSql, CommandType.Text, null);
  27. var modelList = new List<DeviceEntity>();
  28. for (int rowIndex = 0; rowIndex < dtResult.Rows.Count; rowIndex++)
  29. {
  30. DeviceEntity model = new DeviceEntity();
  31. model.OrganizeId = dtResult.Rows[rowIndex]["OrganizeId"].ToString();
  32. model.ShortName = dtResult.Rows[rowIndex]["ShortName"].ToString();
  33. model.ParentId = dtResult.Rows[rowIndex]["ParentId"].ToString();
  34. model.EnCode = dtResult.Rows[rowIndex]["EnCode"].ToString();
  35. modelList.Add(model);
  36. }
  37. return modelList;
  38. }
  39. catch (Exception ex)
  40. {
  41. throw ex;
  42. }
  43. }
  44. /// <summary>
  45. /// 获取根节点
  46. /// </summary>
  47. /// <returns></returns>
  48. public string GetAllList()
  49. {
  50. try
  51. {
  52. var strSql = "SELECT * FROM Base_Organize";
  53. DataTable dtResult = sqlHelper.ExecuteDataTable(strSql, CommandType.Text, null);
  54. var modelList = new List<DeviceEntity>();
  55. for (int rowIndex = 0; rowIndex < dtResult.Rows.Count; rowIndex++)
  56. {
  57. DeviceEntity model = new DeviceEntity();
  58. model.OrganizeId = dtResult.Rows[rowIndex]["OrganizeId"].ToString();
  59. model.ShortName = dtResult.Rows[rowIndex]["ShortName"].ToString();
  60. model.ParentId = dtResult.Rows[rowIndex]["ParentId"].ToString();
  61. model.EnCode = dtResult.Rows[rowIndex]["EnCode"].ToString();
  62. modelList.Add(model);
  63. }
  64. return Json.ToJson(modelList);
  65. }
  66. catch (Exception e)
  67. {
  68. throw e;
  69. }
  70. }
  71. }
  72. }