TankDetailsController.cs 8.0 KB

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