CtrlSvrLog.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 Serilog;
  24. using DW5S.Service;
  25. using DW5S.ViewModel;
  26. using DW5S.Entity;
  27. namespace DW5S.App.UserControl
  28. {
  29. public partial class CtrlSvrLog : DevExpress.XtraEditors.XtraUserControl
  30. {
  31. List<LogResViewModel> list = new List<LogResViewModel>();
  32. public CtrlSvrLog()
  33. {
  34. InitializeComponent();
  35. this.txtStart.UseDefault();
  36. this.txtEnd.UseDefault();
  37. }
  38. private async void CtrlSvrs_Load(object sender, EventArgs e)
  39. {
  40. gridLog.UseDefault(list).UseEmptyText("无结果").UseRowNumber().UseDeleteAsync<LogResViewModel>(async data =>
  41. {
  42. var delItems = data.Select(t => new LogDeleteDto(t.Id));
  43. var rsp = await HttpHelper.PostRequestAsync(SysConfig.GetUrl("Log/Delete"), delItems);
  44. return rsp.code == 200;
  45. }).UseExportCsv().SetLogImageColumn(nameof(LogResViewModel.LogType), typeof(EnumLogType));
  46. gridView1.Columns[nameof(LogResViewModel.LogType)].MaxWidth = 100;
  47. gridView1.Columns[nameof(LogResViewModel.LogTime)].MaxWidth = 160;
  48. gridView1.Columns[nameof(LogResViewModel.Msg)].AppearanceCell.TextOptions.HAlignment = HorzAlignment.Near;
  49. this.txtLogModules.Properties.Items.Add("全部", "全部", -1);
  50. var res = await HttpHelper.PostRequestAsync<List<LogModulesResDto>>(SysConfig.GetUrl("Log/GetModules"), null);
  51. if (res.data != null && res.data.Any())
  52. {
  53. foreach (var item in res.data)
  54. {
  55. this.txtLogModules.Properties.Items.Add(item.Module, item.Module, -1);
  56. }
  57. }
  58. this.txtLogModules.SelectedIndex = 0;
  59. }
  60. private async void btnQuery_Click(object sender, EventArgs e)
  61. {
  62. btnQuery.Enabled = false;
  63. this.list.Clear();
  64. try
  65. {
  66. LogQueryDto dto = new LogQueryDto()
  67. {
  68. Module = this.txtLogModules.Text,
  69. LogTimeBegin = txtStart.DateTime,
  70. LogTimeEnd = txtEnd.DateTime,
  71. };
  72. var res = await HttpHelper.PostRequestAsync<List<LogInfoDto>>(SysConfig.GetUrl("Log/Query"), dto);
  73. if (res.code != 200)
  74. {
  75. MsgBoxHelper.ShowError(res.msg);
  76. }
  77. else
  78. {
  79. var items = res.data.Select(t => new LogResViewModel()
  80. {
  81. Id = t.ID,
  82. LogTime = t.LogTime,
  83. LogType = (EnumLogType)(int)t.LogType,
  84. Module = t.Module,
  85. Msg = t.Msg
  86. });
  87. this.list.AddRange(items);
  88. if (!list.Any())
  89. {
  90. await Task.Delay(200);
  91. }
  92. this.BeginInvoke(new Action(() =>
  93. {
  94. gridView1.RefreshData();
  95. }));
  96. }
  97. }
  98. catch (Exception ex)
  99. {
  100. IocContainer.Logger.Error(ex,"查询日志出错");
  101. MsgBoxHelper.ShowError("查询日志出错");
  102. }
  103. btnQuery.Enabled = true;
  104. }
  105. }
  106. }