TankDetailsController.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNetCore.Mvc;
  5. using Microsoft.AspNetCore.Http;
  6. using Edge.WebHost.Models.TankMonitor;
  7. using Edge.WebHost.Models.VeederRoot_ATG_Console_Handler_Models;
  8. using Edge.Core.IndustryStandardInterface.ATG;
  9. using Edge.WebHost.Models.SmartFuel;
  10. namespace Edge.WebHost.Controllers
  11. {
  12. public class TankDetailsController : Controller
  13. {
  14. CurrentTank currenttank = new CurrentTank();
  15. public IActionResult Index()
  16. {
  17. var smartFuelInfo = new SmartFuelViewInfo();
  18. smartFuelInfo.queryString = Request.Query["q"].ToString();
  19. return View("../WebConsole/TankDetails/Index", smartFuelInfo);
  20. }
  21. public IActionResult TankOverviewFnav()
  22. {
  23. return PartialView("/Views/WebConsole/TankDetails/TankOverviewFnav.cshtml");
  24. }
  25. public IActionResult TankDevicesOverview()
  26. {
  27. return PartialView("/Views/WebConsole/TankDetails/TankDevicesOverview.cshtml");
  28. }
  29. public IActionResult TankDetailFnav()
  30. {
  31. return PartialView("/Views/WebConsole/TankDetails/TankDetailFnav.cshtml");
  32. }
  33. public IActionResult TankDeviceDetails(int index)
  34. {
  35. ViewBag.tankIndex = index;
  36. return PartialView("/Views/WebConsole/TankDetails/TankDeviceDetails.cshtml");
  37. }
  38. public IActionResult AlarmHistoryFnav()
  39. {
  40. return PartialView("/Views/WebConsole/TankDetails/AlarmHistoryFnav.cshtml");
  41. }
  42. public IActionResult AlarmHistory()
  43. {
  44. return PartialView("/Views/WebConsole/TankDetails/AlarmHistory.cshtml");
  45. }
  46. public IActionResult FuelInventoryFnav()
  47. {
  48. return PartialView("/Views/WebConsole/TankDetails/FuelInventoryFnav.cshtml");
  49. }
  50. public IActionResult FuelInventoryList()
  51. {
  52. return PartialView("/Views/WebConsole/TankDetails/FuelInventoryList.cshtml");
  53. }
  54. public IActionResult ActiveAlarm()
  55. {
  56. return View("/Views/WebConsole/TankDetails/ActiveAlarm");
  57. }
  58. public IActionResult InStockFuelReport()
  59. {
  60. return View("/Views/WebConsole/TankDetails/InStockFuelReport");
  61. }
  62. public IActionResult NewInStockFuel()
  63. {
  64. return View("/Views/WebConsole/TankDetails/NewInStockFuel");
  65. }
  66. public IActionResult NewFuelInventory()
  67. {
  68. return View("/Views/WebConsole/TankDetails/NewFuelInventory");
  69. }
  70. public IActionResult Test(int index)
  71. {
  72. ViewBag.tankIndex = index;
  73. return View("../WebConsole/TankDetails/Index");
  74. }
  75. //public IActionResult TankDeviceDetails()
  76. ////public IActionResult TankDeviceDetails(string tankID, string fuelID, string fuelKind)
  77. //{
  78. // if (currenttank.currentTankID == null)
  79. // {
  80. // currenttank.currentTankID = "1";
  81. // currenttank.currentFuelID = "92";//"#92";
  82. // currenttank.currentFuelKind = "汽油";//"GasOil";
  83. // }
  84. // ViewBag.CurrentTankID = currenttank.currentTankID.ToString();
  85. // ViewBag.CurrentFuelID = currenttank.currentFuelID.ToString();
  86. // ViewBag.CurrentFuelKind = currenttank.currentFuelKind.ToString();
  87. // return View("TankDeviceDetails");
  88. //}
  89. private static MockAutoTankGaugeController mockAtgController;
  90. // GET: /<controller>/
  91. //public IActionResult Index()
  92. static TankDetailsController()
  93. {
  94. //return "This is my default action...";
  95. //return View();
  96. var tank1 = new Tank()
  97. {
  98. TankNumber = 1,
  99. Diameter = 1800,
  100. Product = new Product()
  101. {
  102. ProductCode = "02",
  103. ProductLabel = "92#"
  104. },
  105. Limit = new TankLimit() { },
  106. Probe = new Probe()
  107. {
  108. ProbeLength = 1800,
  109. State = "",
  110. }
  111. };
  112. var tank2 = new Tank()
  113. {
  114. TankNumber = 2,
  115. Diameter = 1800,
  116. Product = new Product()
  117. {
  118. ProductCode = "05",
  119. ProductLabel = "95#"
  120. },
  121. Limit = new TankLimit()
  122. {
  123. },
  124. Probe = new Probe()
  125. {
  126. ProbeLength = 2800,
  127. State = "",
  128. }
  129. };
  130. var tank3 = new Tank()
  131. {
  132. TankNumber = 3,
  133. Diameter = 1800,
  134. Product = new Product()
  135. {
  136. ProductCode = "08",
  137. ProductLabel = "98#"
  138. },
  139. Limit = new TankLimit()
  140. {
  141. },
  142. Probe = new Probe()
  143. {
  144. ProbeLength = 1800,
  145. State = "",
  146. }
  147. };
  148. var tank4 = new Tank()
  149. {
  150. TankNumber = 4,
  151. Diameter = 1800,
  152. Product = new Product()
  153. {
  154. ProductCode = "09",
  155. ProductLabel = "0#"
  156. },
  157. Limit = new TankLimit()
  158. {
  159. },
  160. Probe = new Probe()
  161. {
  162. ProbeLength = 1800,
  163. State = "",
  164. }
  165. };
  166. var tank5 = new Tank()
  167. {
  168. TankNumber = 5,
  169. Diameter = 1800,
  170. Product = new Product()
  171. {
  172. ProductCode = "11",
  173. ProductLabel = "-35#"
  174. },
  175. Limit = new TankLimit()
  176. {
  177. },
  178. Probe = new Probe()
  179. {
  180. ProbeLength = 1800,
  181. State = "",
  182. }
  183. };
  184. mockAtgController =
  185. new MockAutoTankGaugeController(
  186. new List<Tank>()
  187. {
  188. tank1,tank2,tank3,tank4,tank5
  189. }, SystemUnit.Metric);
  190. }
  191. //
  192. // GET: /HelloWorld/Welcome/
  193. // GET: VeederRoot_ATG_Console_Handler_/Create
  194. public ActionResult Create()
  195. {
  196. return View();
  197. }
  198. // GET: VeederRoot_ATG_Console_Handler_/Details/5
  199. public async Task<ActionResult> Details(int? tankNumber)
  200. {
  201. if (tankNumber.HasValue)
  202. {
  203. var reading = await mockAtgController.GetTankReadingAsync(tankNumber.Value);
  204. if (reading == null) return NotFound();
  205. return Ok(new[]
  206. {
  207. new TankReadingDto(){
  208. tankNumber= tankNumber.Value,
  209. Height= reading.Height,
  210. Water= reading.Water,
  211. Temperature= reading.Temperature,
  212. Volume= reading.Volume,
  213. WaterVolume= reading.WaterVolume,
  214. TimeStamp = DateTime.Now.ToString("HH:mm:ss"),
  215. }
  216. });
  217. }
  218. else
  219. {
  220. List<TankReadingDto> tankReadings = new List<TankReadingDto>();
  221. foreach (var t in mockAtgController.Tanks)
  222. {
  223. var reading = await mockAtgController.GetTankReadingAsync(t.TankNumber);
  224. if (reading == null) continue;
  225. var dto = new TankReadingDto()
  226. {
  227. tankNumber = t.TankNumber,
  228. Height = reading.Height,
  229. Water = reading.Water,
  230. Temperature = reading.Temperature,
  231. Volume = reading.Volume,
  232. WaterVolume = reading.WaterVolume,
  233. TimeStamp = DateTime.Now.ToString("HH:mm:ss"),
  234. };
  235. tankReadings.Add(dto);
  236. }
  237. return Ok(tankReadings);
  238. }
  239. }
  240. // POST: VeederRoot_ATG_Console_Handler_/Create
  241. [HttpPost]
  242. [ValidateAntiForgeryToken]
  243. public ActionResult Create(IFormCollection collection)
  244. {
  245. try
  246. {
  247. // TODO: Add insert logic here
  248. return RedirectToAction(nameof(Index));
  249. }
  250. catch
  251. {
  252. return View();
  253. }
  254. }
  255. }
  256. }