b6a1e40dbcce7170880f8ef8b48e0e8fd1ed618e.svn-base 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Data;
  5. using System.Data.Entity;
  6. using System.Data.Entity.Infrastructure;
  7. using System.Linq;
  8. using System.Net;
  9. using System.Net.Http;
  10. using System.Web.Http;
  11. using System.Web.Http.Description;
  12. using System.Web.Http.OData;
  13. using iBemsDataService;
  14. using iBemsDataService.Model;
  15. namespace iBemsDataService.Controllers
  16. {
  17. public class FmsEquipmentExController : ODataController
  18. {
  19. private iBemsEntities db = new iBemsEntities();
  20. // GET: odata/FmsEquipmentEx
  21. [Queryable]
  22. public List<FmsEquipmentEx> GetFmsEquipmentEx()
  23. {
  24. var query = (
  25. from fe in db.FmsEquipment
  26. from cu in db.CmUser
  27. from fec in db.FmsEquipmentCodeType
  28. join fw in db.FmsMaterialWarehouse on fe.WarehouseId equals fw.WarehouseId into gw
  29. from subWarehouse in gw.DefaultIfEmpty()
  30. join eh in db.FmsEquipmentHistory on fe.EquipmentId equals eh.EquipmentId into gh
  31. from subHistory in gh.DefaultIfEmpty().OrderByDescending(a => a.EquipmentHistoryId).Take(1)
  32. where fe.RegisterUserId == cu.UserId &&
  33. fe.EquipmentTypeId == fec.EquipmentTypeId &&
  34. fe.SiteId == cu.SiteId
  35. select new FmsEquipmentEx
  36. {
  37. AddDate = fe.AddDate,
  38. EquipmentId = fe.EquipmentId,
  39. EquipmentTypeId = fe.EquipmentTypeId,
  40. Name = fe.Name,
  41. RegisterUserId = fe.RegisterUserId,
  42. RegisterUserName = cu.Name,
  43. SiteId = fe.SiteId,
  44. Standard = fe.Standard,
  45. SupplierName = fe.SupplierName,
  46. SupplierPhoneNo = fe.SupplierPhoneNo,
  47. Unit = fe.Unit,
  48. UpdateDate = fe.UpdateDate,
  49. WarehouseId = fe.WarehouseId,
  50. WarehouseName = subWarehouse.Name,
  51. ImageFileId = fe.ImageFileId,
  52. EquipmentCodeTypeName = fec.Name,
  53. TotalStockCount = subHistory.TotalStockCount == null ? 0 : subHistory.TotalStockCount,
  54. CurrentStockCount = subHistory.CurrentStockCount == null ? 0 : subHistory.CurrentStockCount,
  55. //CurrentStoredCount = subHistory.StoredCount == null ? 0 : subHistory.StoredCount,
  56. //CurrentReturnCount = subHistory.ReturnCount == null ? 0 : subHistory.ReturnCount,
  57. //CurrentLossCount = subHistory.LossCount == null ? 0 : subHistory.LossCount,
  58. CurrentStoredCount = db.FmsEquipmentHistory.Where(a => a.EquipmentId == fe.EquipmentId).Sum(a => a.StoredCount),
  59. CurrentReturnCount = db.FmsEquipmentHistory.Where(a => a.EquipmentId == fe.EquipmentId).Sum(a => a.ReturnCount),
  60. CurrentLossCount = db.FmsEquipmentHistory.Where(a => a.EquipmentId == fe.EquipmentId).Sum(a => a.LossCount)
  61. });
  62. var list = query.ToList();
  63. foreach (var item in list)
  64. {
  65. item.CurrentRentCount = item.TotalStockCount.Value - item.CurrentStockCount.Value;
  66. }
  67. return list;
  68. }
  69. protected override void Dispose(bool disposing)
  70. {
  71. if (disposing)
  72. {
  73. db.Dispose();
  74. }
  75. base.Dispose(disposing);
  76. }
  77. }
  78. }