CtrlSvrLog.cs 4.2 KB

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