using Cowain.Bake.BLL; using Cowain.Bake.Common; using Cowain.Bake.Common.Core; using Cowain.Bake.Common.Enums; using Cowain.Bake.Model; using HandyControl.Controls; using Prism.Commands; using Prism.Regions; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; using Unity; namespace Cowain.Bake.UI.ProductManagement.ViewModels { public class DBLogViewModel: ViewModelBase { public DBLogViewModel(IUnityContainer unityContainer, IRegionManager regionManager) : base(unityContainer, regionManager) { this.PageTitle = "日志查询"; SetCombox(); } private ObservableCollection logList; public ObservableCollection LogList { get => logList ?? (logList = new ObservableCollection()); set { SetProperty(ref logList, value); } } private DateTime _startTime = DateTime.Now.AddHours(-4); public DateTime StartDatetime { get { return _startTime; } set { SetProperty(ref _startTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); } } private DateTime _endTime = DateTime.Now.AddHours(4); public DateTime EndDatetime { get { return _endTime; } set { SetProperty(ref _endTime, DateTime.Parse(value.ToString("yyyy-MM-dd HH:mm:ss"))); } } private string _logText=string.Empty; public string LogText { get { return _logText; } set { SetProperty(ref _logText, value); } } public string selectLogLevel; public string SelectLogLevel { get => selectLogLevel; set => SetProperty(ref selectLogLevel, value); } private List listLogLevel; public List ListLogLevel { get => listLogLevel; set => SetProperty(ref listLogLevel, value); } private void SetCombox() { ListLogLevel = new List(); foreach (E_LogType level in System.Enum.GetValues(typeof(E_LogType))) { ListLogLevel.Add(level.GetDescription()); } SelectLogLevel = E_LogType.Operate.GetDescription(); } public DelegateCommand QueryCommand => new DelegateCommand((x) => { logList.Clear(); E_LogType logType = EnumHelper.GetValueByDescription(SelectLogLevel); //var list = EnumHelper.GetEnumList().Where(item => item.EnumDesc == SelectLogLevel); //string level = list.FirstOrDefault().EnumString; var logService = _unityContainer.Resolve(); List logListTemporary; //if (string.IsNullOrEmpty(level)) //{ // //logListTemporary = logService.QueryByTime(StartDatetime, EndDatetime); // LogHelper.Instance.Warn("日志级别不能为空",null, true); // return; //} //else { logListTemporary = logService.QueryByTimeAndText(StartDatetime, EndDatetime, logType); } if (logListTemporary.Count != 0) { logListTemporary.ForEach(item => logList.Add(item)); Growl.Success("查询完成!"); } else { Growl.Success("没有数据!"); } }); } }