eb726b3d43d261aee56252345c1d8d794319d873.svn-base 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data.Entity;
  5. using System.Data.Entity.Infrastructure;
  6. using System.Linq;
  7. using System.Net;
  8. using System.Web;
  9. using System.Web.Http;
  10. using System.Web.Http.Description;
  11. using DevExpress.Office.Utils;
  12. using iBemsDataService.Model;
  13. using iBemsDataService.Util;
  14. using System.Web.Http.OData;
  15. namespace iBemsDataService.Controllers
  16. {
  17. public class MonitoringPointController : ODataController
  18. {
  19. private iBemsEntities db = new iBemsEntities();
  20. [Queryable]
  21. public IQueryable<MonitoringPointEx> GetMonitoringPoint()
  22. {
  23. var query = from p in db.BemsMonitoringPoint
  24. from facility in db.CmFacility
  25. where p.SiteId == facility.SiteId && p.FacilityCode == facility.FacilityCode
  26. join b in db.CmBuilding on p.BuildingId equals b.BuildingId into groupBuilding
  27. from subBuilding in groupBuilding.DefaultIfEmpty() where p.SiteId == subBuilding.SiteId
  28. join z in db.CmZone on p.ZoneId equals z.ZoneId into groupZone
  29. from subZone in groupZone.DefaultIfEmpty()
  30. join f in db.CmFloor on p.FloorId equals f.FloorId into groupFloor
  31. from subFloor in groupFloor.DefaultIfEmpty()
  32. select new MonitoringPointEx
  33. {
  34. SiteId = p.SiteId,
  35. FacilityTypeId = p.FacilityTypeId,
  36. FacilityCode = p.FacilityCode,
  37. PropertyId = p.PropertyId,
  38. ValueType = p.ValueType,
  39. ServiceTypeId = p.ServiceTypeId,
  40. FuelTypeId = p.FuelTypeId,
  41. BuildingId = p.BuildingId ?? 0,
  42. FloorId = p.FloorId ?? 0,
  43. ZoneId = p.ZoneId ?? 0,
  44. Name = p.Name,
  45. Description = p.Description,
  46. FacilityName = facility.Name ,
  47. BuildingName = (subBuilding == null) ? string.Empty : subBuilding.Name ,
  48. ZoneName = (subZone == null) ? string.Empty : subZone.Name ,
  49. FloorName = (subFloor == null) ? string.Empty : subFloor.Name,
  50. Location = ((subBuilding == null) ? string.Empty : subBuilding.Name) + " " +
  51. ((subZone == null) ? string.Empty : subZone.Name) + " " +
  52. ((subFloor == null) ? string.Empty : subFloor.Name)
  53. };
  54. return query;
  55. }
  56. protected override void Dispose(bool disposing)
  57. {
  58. if (disposing)
  59. {
  60. db.Dispose();
  61. }
  62. base.Dispose(disposing);
  63. }
  64. }
  65. public class MonitoringPointEx
  66. {
  67. public int SiteId { get; set; }
  68. public int FacilityTypeId { get; set; }
  69. public int FacilityCode { get; set; }
  70. public int PropertyId { get; set; }
  71. public int ValueType { get; set; }
  72. public Nullable<short> ServiceTypeId { get; set; }
  73. public Nullable<short> FuelTypeId { get; set; }
  74. public int BuildingId { get; set; }
  75. public int FloorId { get; set; }
  76. public int ZoneId { get; set; }
  77. public string Name { get; set; }
  78. public string FacilityName { get; set; }
  79. public string BuildingName { get; set; }
  80. public string FloorName { get; set; }
  81. public string ZoneName { get; set; }
  82. public string Location { get; set; }
  83. public string Description{ get; set; }
  84. };
  85. }