using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using DllEapEntity; using Microsoft.AspNetCore.Mvc; using WebMainHsms.Models; using Cksoft.Unity; using DllEapDal; using DllLotServer; namespace WebMainHsms.Controllers { public class HomeController : Controller { public ILotServer CurrSec { get; set; } //自动注入服务 public HomeController(ILotServer psecs) { CurrSec = psecs; } public IActionResult Index() { //CurrSec.StartAll(); //List lists = CurrSec.GetMacOrder(); return View(); } public IActionResult About() { ViewData["Message"] = "Your application description page."; return View(); } public IActionResult Contact() { ViewData["Message"] = "Your contact page."; return View(); } public IActionResult Privacy() { return View(); } [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] public IActionResult Error() { return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); } public ActionResult GetStatus() { try { string temperrorinfo = ""; int result = CurrSec.GetStatus(ref temperrorinfo); return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson()); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } public ActionResult Start() { try { string temperrorinfo = ""; int result = CurrSec.Start(ref temperrorinfo); return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson()); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } public ActionResult GetInfo() { try { List info = CurrSec.GetInfo(); return Content(info.ToJson()); //Newtonsoft.Json.JsonSerializerSettings jsonformat = new Newtonsoft.Json.JsonSerializerSettings(); //jsonformat.DateFormatString = "yyyy-MM-dd hh:mm:ss"; //return Json(info, jsonformat); //return Json(info); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } [HttpPost] public ActionResult GetCount() { try { long result = CurrSec.GetAccount(); return Content(new { resultcode = 1, errorinfo = result }.ToJson()); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } public ActionResult Stop() { try { string temperrorinfo = ""; int result = CurrSec.Stop(ref temperrorinfo); return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson()); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } public ActionResult ClearInfo() { try { string temperrorinfo = ""; int result = CurrSec.ClearInfo(ref temperrorinfo); return Content(new { resultcode = result, errorinfo = temperrorinfo }.ToJson()); } catch (Exception ex) { return Content(new { resultcode = -1, errorinfo = ex.Message.ToString() }.ToJson()); } } } }