using Cowain.Bake.BLL; using Cowain.Bake.Common; using Cowain.Bake.Common.Core; using Cowain.Bake.Common.Enums; using Cowain.Bake.Model; using Prism.Commands; using Prism.Regions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using Unity; namespace Cowain.Bake.UI.ProductManagement.ViewModels { public class EleTableViewModel : ViewModelBase { public string selectStationId; public string SelectStationId { get => selectStationId; set => SetProperty(ref selectStationId, value); } private List listStationId; public List ListStationId { get => listStationId; set => SetProperty(ref listStationId, value); } private ObservableCollection eleList; public ObservableCollection EellList { get => eleList ?? (eleList = new ObservableCollection()); set { SetProperty(ref eleList, value); } } //IUnityContainer _unityContainer ; List queryData = null; List _stations = null; public EleTableViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager) { _unityContainer = unityContainer; _stations = _unityContainer.Resolve().GetStationsByType((int)EStationType.Stove); this.PageTitle = "电表查询"; SetCombox(); } private void SetCombox() { ListStationId = new List(); foreach (var station in _stations) { ListStationId.Add(station.Desc); } selectStationId = ListStationId[0]; } public DelegateCommand QueryCommand => new DelegateCommand((x) => { EellList.Clear(); var station = _stations.Where(s=>s.Desc == selectStationId).FirstOrDefault(); queryData = _unityContainer.Resolve().Query(station.Id, StartTime, EndTime); if (0 == queryData.Count) { HandyControl.Controls.MessageBox.Warning("查询数据为空!"); return; } queryData.ForEach(item => EellList.Add(item)); }); public DelegateCommand ExportCommand => new DelegateCommand((x) => { if (0 == queryData.Count) { HandyControl.Controls.MessageBox.Warning("数据为空,请先查询数据!"); return; } CSVHelper.WriteDataTableToCsv(queryData, new List() { "序号", "烤箱编号", "A相电流" , "B相电流", "C相电流","A相电压", "B相电压", "C相电压", "电能","创建时间" }); }); } }