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