CtrlSvrLog.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using DevExpress.Mvvm.Native;
  2. using DevExpress.Utils;
  3. using DevExpress.Utils.Html;
  4. using DevExpress.XtraEditors;
  5. using DxHelper;
  6. using ExtensionsDev;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Linq;
  13. using System.Text;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. using System.Windows.Controls;
  17. using System.Windows.Documents;
  18. using System.Windows.Forms;
  19. using DW5S.App.EditForms;
  20. using DW5S.App.Model;
  21. using DW5S.DTO;
  22. using DW5S.Repostory;
  23. using Microsoft.Extensions.Logging;
  24. namespace DW5S.App.UserControl
  25. {
  26. public partial class CtrlSvrLog : DevExpress.XtraEditors.XtraUserControl
  27. {
  28. [Autowired]
  29. private readonly ILogger logger;
  30. List<LogInfo> list = new List<LogInfo>();
  31. public CtrlSvrLog()
  32. {
  33. InitializeComponent();
  34. this.txtStart.UseDefault();
  35. this.txtEnd.UseDefault();
  36. }
  37. private async void CtrlSvrs_Load(object sender, EventArgs e)
  38. {
  39. gridLog.UseDefault(list).UseEmptyText("无结果").UseRowNumber().UseDeleteAsync<LogInfo>(async data =>
  40. {
  41. var delItems = data.Select(t => new LogDeleteDto(t.ID));
  42. var rsp = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("Log/Delete"), delItems);
  43. return rsp.code == 200;
  44. }).UseExportCsv().SetLogImageColumn(nameof(LogInfo.LogType), typeof(EnumLogType));
  45. gridView1.Columns[nameof(LogInfo.LogType)].MaxWidth = 100;
  46. gridView1.Columns[nameof(LogInfo.LogTime)].MaxWidth = 160;
  47. gridView1.Columns[nameof(LogInfo.Msg)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  48. this.txtLogModules.Properties.Items.Add("全部", "全部", -1);
  49. var res = await HttpHelper.PostRequestAsync<List<LogModulesResDto>>(SysConfig.GetUrl("Log/GetModules"), null);
  50. if (res.data != null && res.data.Any())
  51. {
  52. foreach (var item in res.data)
  53. {
  54. this.txtLogModules.Properties.Items.Add(item.Module, item.Module, -1);
  55. }
  56. }
  57. this.txtLogModules.SelectedIndex = 0;
  58. }
  59. private async void btnQuery_Click(object sender, EventArgs e)
  60. {
  61. btnQuery.Enabled = false;
  62. this.list.Clear();
  63. try
  64. {
  65. LogQueryDto dto = new LogQueryDto()
  66. {
  67. Module = this.txtLogModules.Text,
  68. LogTimeBegin = txtStart.DateTime,
  69. LogTimeEnd = txtEnd.DateTime,
  70. };
  71. var res = await HttpHelper.PostRequestAsync<List<LogInfoDto>>(SysConfig.GetUrl("Log/Query"), dto);
  72. if (res.code != 200)
  73. {
  74. MsgBoxHelper.ShowError(res.msg);
  75. }
  76. else
  77. {
  78. var items = res.data.Select(t => new LogInfo()
  79. {
  80. ID = t.ID,
  81. LogTime = t.LogTime,
  82. LogType = (Model.EnumLogType)(int)t.LogType,
  83. Module = t.Module,
  84. Msg = t.Msg
  85. });
  86. this.list.AddRange(items);
  87. if (!list.Any())
  88. {
  89. await Task.Delay(200);
  90. }
  91. this.BeginInvoke(new Action(() =>
  92. {
  93. gridView1.RefreshData();
  94. }));
  95. }
  96. }
  97. catch (Exception ex)
  98. {
  99. logger.LogError(ex,"查询日志出错");
  100. MsgBoxHelper.ShowError("查询日志出错");
  101. }
  102. btnQuery.Enabled = true;
  103. }
  104. }
  105. }