using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Web; using System.Web.Mvc; using Domain; using Service; namespace WebSite.Controllers { public class CoulometricStatisticsController : BaseController { public IOverviewManager OverviewManager { get; set; } public IEnergyConsumptionStatisticsManager EnergyConsumptionStatisticsManager { get; set; } #region Actions public ActionResult Index() { return View(); } public ActionResult LoadRoomNumbers() { IList result = new List(); IList roomNumbers = EnergyConsumptionStatisticsManager.LoadRoomNumbers(); foreach (string roomNumber in roomNumbers) { result.Add(new { Value = roomNumber, Name = roomNumber }); } return Json(result, JsonRequestBehavior.AllowGet); } public ActionResult LoadModals(string roomNumber, DeviceType? deviceType) { var table = EnergyConsumptionStatisticsManager.LoadModals(roomNumber, deviceType); var list = new List(); foreach (DataRow row in table.Rows) { list.Add(new { RoomType = row["RoomType"], ModalAddress = row["ModalAddress"], Outlet = row["Outlet"], Name = (Language == Language.CN) ? row["Name"] : row["EnglishName"] }); } return Json(new { total = list.Count, rows = list }); } /// /// 加载图表数据 /// /// /// /// /// /// public ActionResult LoadChartData(string roomNumbers, DateTimeUnit dateUnit, string startDate, string endDate, DeviceType? deviceType, string modalIds) { try { var table = OverviewManager.LoadEnergyStatitics(roomNumbers, dateUnit, startDate, endDate, deviceType, modalIds); IList legend = new List(); IList data = new List(); IList xAxis = new List(); for (int i = 1; i < table.Columns.Count; i++) { xAxis.Add(table.Columns[i].ToString()); } foreach (DataRow row in table.Rows) { string name = row["回路"].ToString(); legend.Add(name); IList data1 = new List(); for (int i = 1; i < table.Columns.Count; i++) { data1.Add(Convert.ToSingle(row[i])); } data.Add(new { name = name, data = data1 }); } return Json(new { IsSuccess = true, Legend = legend, XAxis = xAxis, Data = data }); } catch (Exception ex) { if (ex.GetType() == typeof(IndexOutOfRangeException)) { return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("NotFoundData") }); } return Json(new { IsSuccess = false, Message = HttpContext.InnerLanguage("LoadDataFailedBecause") + ex.Message }); } } #endregion } }