CtrlSvrLog.cs 3.8 KB

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