using DevExpress.Mvvm.Native; using DevExpress.Utils; using DevExpress.Utils.Html; using DevExpress.XtraEditors; using DxHelper; using ExtensionsDev; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Forms; using DW5S.App.Controllers; using DW5S.App.EditForms; using DW5S.App.Model; using DW5S.DTO; using DW5S.Repostory; namespace DW5S.App.UserControl { public partial class CtrlSvrLog : DevExpress.XtraEditors.XtraUserControl { List list = new List(); public CtrlSvrLog() { InitializeComponent(); this.txtStart.UseDefault(); this.txtEnd.UseDefault(); } private async void CtrlSvrs_Load(object sender, EventArgs e) { gridLog.UseDefault(list).UseEmptyText("无结果").UseRowNumber().UseDeleteAsync(async data => { var delItems = data.Select(t => new LogDeleteDto(t.ID)); var rsp = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("Log/Delete"), delItems); return rsp.code == 200; }).UseExportCsv().SetLogImageColumn(nameof(LogInfo.LogType), typeof(EnumLogType)); gridView1.Columns[nameof(LogInfo.LogType)].MaxWidth = 100; gridView1.Columns[nameof(LogInfo.LogTime)].MaxWidth = 160; gridView1.Columns[nameof(LogInfo.Msg)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near; this.txtLogModules.Properties.Items.Add("全部", "全部", -1); var res = await HttpHelper.PostRequestAsync>(SysConfig.GetUrl("Log/GetModules"), null); if (res.data != null && res.data.Any()) { foreach (var item in res.data) { this.txtLogModules.Properties.Items.Add(item.Module, item.Module, -1); } } this.txtLogModules.SelectedIndex = 0; } private async void btnQuery_Click(object sender, EventArgs e) { btnQuery.Enabled = false; this.list.Clear(); try { LogQueryDto dto = new LogQueryDto() { Module = this.txtLogModules.Text, LogTimeBegin = txtStart.DateTime, LogTimeEnd = txtEnd.DateTime, }; var res = await HttpHelper.PostRequestAsync>(SysConfig.GetUrl("Log/Query"), dto); if (res.code != 200) { MsgBoxHelper.ShowError(res.msg); } else { var items = res.data.Select(t => new LogInfo() { ID = t.ID, LogTime = t.LogTime, LogType = (Model.EnumLogType)(int)t.LogType, Module = t.Module, Msg = t.Msg }); this.list.AddRange(items); if (!list.Any()) { await Task.Delay(200); } this.BeginInvoke(new Action(() => { gridView1.RefreshData(); })); } } catch (Exception ex) { DW5S.Framework.LogHelper.Error("查询日志出错", ex); MsgBoxHelper.ShowError("查询日志出错"); } btnQuery.Enabled = true; } } }