CtrlSvrLog.cs 4.2 KB

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