916a0c3aca3d47383b46f35d8fc653e91816dd9b.svn-base 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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 System.Web.Http.OData;
  12. using DevExpress.Office.Utils;
  13. using iBemsDataService.Model;
  14. using iBemsDataService.Util;
  15. namespace iBemsDataService.Controllers
  16. {
  17. public class FmsBudgetDetailExecution2Controller : ODataController
  18. {
  19. private iBemsEntities db2 = new iBemsEntities();
  20. // GET: odata/FmsBudgetCodeClassEx
  21. [Queryable]
  22. public List<FmsBudgetDetailExecution2> GetFmsBudgetDetailExecution2()
  23. {
  24. var codeList = db2.FmsBudgetCodeClass.ToList();
  25. // 2019.07.12
  26. Uri uri = Request.RequestUri;
  27. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  28. int siteId;
  29. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false)
  30. {
  31. throw new Exception("Not Found Parameters.");
  32. }
  33. var list = (
  34. from e in db2.FmsBudgetDetailExecution.Where(x => x.SiteId == siteId)
  35. //join cc in db2.FmsBudgetCodeClass on e.BudgetClassId equals cc.BudgetClassId
  36. select new FmsBudgetDetailExecution2
  37. {
  38. BudgetClassId = e.BudgetClassId,
  39. BudgetSeq =e.FmsBudgetDetail.FmsBudgetCodeClass.BudgetSeq,
  40. Depth = 2,
  41. Month = e.Month,
  42. Name = e.FmsBudgetDetail.FmsBudgetCodeClass.Name,
  43. ParentBudgetClassId = e.ParentBudgetClassId,
  44. //ParentBudgetName = e.FmsBudgetDetail.FmsBudgetCodeClass.Name
  45. //RootBudgetName = codeList.Where(a => a.BudgetClassId == e.RootBudgetClassId).FirstOrDefault().Name,
  46. RootBudgetClassId = e.RootBudgetClassId,
  47. SiteId = e.SiteId,
  48. Year = e.Year,
  49. YearlyBudget = e.YearlyBudget,
  50. YearlyExecution = e.YearlyExecution,
  51. MonthlyBudget = e.MonthlyBudget,
  52. MonthlyExecution = e.MonthlyExecution
  53. }).ToList();
  54. foreach (var item in list)
  55. {
  56. if(item.RootBudgetClassId != null)
  57. {
  58. item.RootBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.RootBudgetClassId).FirstOrDefault().Name;
  59. }
  60. if(item.ParentBudgetClassId > 0)
  61. {
  62. item.ParentBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.ParentBudgetClassId).FirstOrDefault().Name;
  63. }
  64. }
  65. return list;
  66. }
  67. protected override void Dispose(bool disposing)
  68. {
  69. if (disposing)
  70. {
  71. db2.Dispose();
  72. }
  73. base.Dispose(disposing);
  74. }
  75. }
  76. public class FmsBudgetDetailExecutionController : ApiController
  77. {
  78. private iBemsEntities db = new iBemsEntities();
  79. // GET: odata/FmsBudgetCodeClassEx
  80. [Queryable]
  81. public List<FmsBudgetDetailExecution> GetFmsBudgetDetailExecution()
  82. {
  83. var list = db.FmsBudgetDetailExecution.ToList() ;
  84. // 2019.07.12
  85. Uri uri = Request.RequestUri;
  86. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  87. int siteId;
  88. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false)
  89. {
  90. throw new Exception("Not Found Parameters.");
  91. }
  92. var codeList = db.FmsBudgetCodeClass.ToList();
  93. foreach (var item in list)
  94. {
  95. item.RootBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.RootBudgetClassId).FirstOrDefault().Name;
  96. item.ParentBudgetName = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.ParentBudgetClassId).FirstOrDefault().Name;
  97. item.Name = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.BudgetClassId).FirstOrDefault().Name;
  98. item.BudgetSeq = codeList.Where(a => a.SiteId == siteId && a.BudgetClassId == item.BudgetClassId).FirstOrDefault().BudgetSeq;
  99. item.Depth = 2;
  100. }
  101. return list;
  102. }
  103. // POST: api/FmsFmsBudgetDetail
  104. [ResponseType(typeof(void))]
  105. [ActionName("Save")]
  106. public IHttpActionResult PostFmsBudgetDetailExecution(List<FmsBudgetDetailExecution> budgetList)
  107. {
  108. Uri uri = Request.RequestUri;
  109. var uriQuery = HttpUtility.ParseQueryString(uri.Query);
  110. int siteId, year, month;
  111. if (int.TryParse(uriQuery.Get("SiteId"), out siteId) == false ||
  112. int.TryParse(uriQuery.Get("Year"), out year) == false ||
  113. int.TryParse(uriQuery.Get("Month"), out month) == false
  114. )
  115. {
  116. return BadRequest("Not Found Parameters.");
  117. }
  118. try
  119. {
  120. foreach (var item in budgetList)
  121. {
  122. db.FmsBudgetDetailExecution.Attach(item);
  123. var entry = db.Entry(item);
  124. entry.State = System.Data.EntityState.Modified;
  125. }
  126. db.SaveChanges();
  127. }
  128. catch (Exception) { throw; }
  129. return StatusCode(HttpStatusCode.NoContent);
  130. }
  131. protected override void Dispose(bool disposing)
  132. {
  133. if (disposing)
  134. {
  135. db.Dispose();
  136. }
  137. base.Dispose(disposing);
  138. }
  139. }
  140. }
  141. namespace iBemsDataService.Model
  142. {
  143. public partial class FmsBudgetDetailExecution
  144. {
  145. public string RootBudgetName { get; set; }
  146. public string ParentBudgetName { get; set; }
  147. public string Name { get; set; }
  148. public string BudgetSeq { get; set; }
  149. public int Depth { get; set; }
  150. }
  151. public partial class FmsBudgetDetailExecution2 : FmsBudgetDetailExecution
  152. {
  153. }
  154. }