CtrlSvrLog.cs 3.5 KB

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