Commit 28b65b6f authored by 段廷瑞's avatar 段廷瑞

1、日志查看优化:增加路径历史记录

parent c0165201
namespace Tools.MyCommon.controls
{
partial class TextBoxEx
{
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
/// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region 组件设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要修改
/// 使用代码编辑器修改此方法的内容。
/// </summary>
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Tools.MyCommon.controls
{
/*
* FLAG:重写一个文本框,具备文本着色功能
*/
public partial class TextBoxEx : TextBox
{
public TextBoxEx()
{
InitializeComponent();
//绘制样式
this.SetStyle(
ControlStyles.UserPaint //控件将自行绘制,而不是通过操作系统来绘制,重写OnPaint()方法
| ControlStyles.OptimizedDoubleBuffer //该控件首先在缓冲区中绘制,而不是直接绘制到屏幕上,这样可以减少闪烁
| ControlStyles.AllPaintingInWmPaint //控件将忽略 WM_ERASEBKGND 窗口消息以减少闪烁
| ControlStyles.ResizeRedraw //在调整控件大小时重绘控件
| ControlStyles.SupportsTransparentBackColor //控件接受 alpha 组件小于 255 的 BackColor 以模拟透明
, true);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
}
}
}
......@@ -78,12 +78,6 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MyCommon\controls\TextBoxEx.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="MyCommon\controls\TextBoxEx.Designer.cs">
<DependentUpon>TextBoxEx.cs</DependentUpon>
</Compile>
<Compile Include="MyCommon\Log.cs" />
<Compile Include="MyCommon\UserLog.cs" />
<Compile Include="MyCommon\controls\MyTreeView.cs">
......
......@@ -29,16 +29,16 @@
private void InitializeComponent()
{
this.toolStrip1 = new System.Windows.Forms.ToolStrip();
this.toolStripLabel2 = new System.Windows.Forms.ToolStripLabel();
this.tscbEncoding = new System.Windows.Forms.ToolStripComboBox();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.toolStripLabel1 = new System.Windows.Forms.ToolStripLabel();
this.tstbLogPath = new System.Windows.Forms.ToolStripTextBox();
this.tsbSelectPath = new System.Windows.Forms.ToolStripButton();
this.listBox1 = new System.Windows.Forms.ListBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.toolStripLabel2 = new System.Windows.Forms.ToolStripLabel();
this.tscbEncoding = new System.Windows.Forms.ToolStripComboBox();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.tscbLogPath = new System.Windows.Forms.ToolStripComboBox();
this.toolStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
......@@ -53,7 +53,7 @@
this.tscbEncoding,
this.toolStripSeparator1,
this.toolStripLabel1,
this.tstbLogPath,
this.tscbLogPath,
this.tsbSelectPath});
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
......@@ -61,19 +61,29 @@
this.toolStrip1.TabIndex = 0;
this.toolStrip1.Text = "toolStrip1";
//
// toolStripLabel2
//
this.toolStripLabel2.Name = "toolStripLabel2";
this.toolStripLabel2.Size = new System.Drawing.Size(44, 22);
this.toolStripLabel2.Text = "编码:";
//
// tscbEncoding
//
this.tscbEncoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tscbEncoding.Name = "tscbEncoding";
this.tscbEncoding.Size = new System.Drawing.Size(75, 25);
//
// toolStripSeparator1
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
//
// toolStripLabel1
//
this.toolStripLabel1.Name = "toolStripLabel1";
this.toolStripLabel1.Size = new System.Drawing.Size(68, 22);
this.toolStripLabel1.Text = "日志路径:";
//
// tstbLogPath
//
this.tstbLogPath.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F);
this.tstbLogPath.Name = "tstbLogPath";
this.tstbLogPath.ReadOnly = true;
this.tstbLogPath.Size = new System.Drawing.Size(300, 25);
//
// tsbSelectPath
//
this.tsbSelectPath.Image = global::Tools.Properties.Resources.文件夹;
......@@ -129,22 +139,11 @@
this.progressBar1.Size = new System.Drawing.Size(535, 2);
this.progressBar1.TabIndex = 3;
//
// toolStripLabel2
//
this.toolStripLabel2.Name = "toolStripLabel2";
this.toolStripLabel2.Size = new System.Drawing.Size(44, 22);
this.toolStripLabel2.Text = "编码:";
//
// tscbEncoding
//
this.tscbEncoding.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tscbEncoding.Name = "tscbEncoding";
this.tscbEncoding.Size = new System.Drawing.Size(75, 25);
//
// toolStripSeparator1
// tscbLogPath
//
this.toolStripSeparator1.Name = "toolStripSeparator1";
this.toolStripSeparator1.Size = new System.Drawing.Size(6, 25);
this.tscbLogPath.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.tscbLogPath.Name = "tscbLogPath";
this.tscbLogPath.Size = new System.Drawing.Size(300, 25);
//
// wLogViewer
//
......@@ -173,7 +172,6 @@
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripLabel toolStripLabel1;
private System.Windows.Forms.ToolStripTextBox tstbLogPath;
private System.Windows.Forms.ToolStripButton tsbSelectPath;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.TextBox textBox1;
......@@ -182,5 +180,6 @@
private System.Windows.Forms.ToolStripLabel toolStripLabel2;
private System.Windows.Forms.ToolStripComboBox tscbEncoding;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator1;
private System.Windows.Forms.ToolStripComboBox tscbLogPath;
}
}
\ No newline at end of file
......@@ -17,8 +17,9 @@ namespace Tools.UI
{
public partial class wLogViewer : wBasic
{
List<string> pathList = new List<string>();
string LogPath { get => this.tstbLogPath.Text; set => this.tstbLogPath.Text = value; }
string LogPath { get => this.tscbLogPath.Text; set => this.tscbLogPath.Text = value; }
public wLogViewer()
{
......@@ -28,24 +29,26 @@ namespace Tools.UI
//窗体:加载
private void wLogViewer_Load(object sender, EventArgs e)
{
//初始化编码选择下拉框
var list = new List<string> {
Encoding.Default.HeaderName.ToUpper(),
Encoding.UTF8.HeaderName.ToUpper(),
};
this.tscbEncoding.Items.AddRange(list.Distinct().ToArray());
this.tscbEncoding.SelectedIndex = 0;
//初始化文件路径下拉框
pathList = Utils.GetJsonConfig<List<string>>();
this.tscbLogPath.Items.AddRange(pathList.Distinct().ToArray());
}
//窗体:显示完成
private void wLogViewer_Shown(object sender, EventArgs e)
{
this.tsbSelectPath.Click += TsbSelectPath_Click;
this.tstbLogPath.TextChanged += TstbLogPath_TextChanged;
this.tscbLogPath.SelectedIndexChanged += TscbLogPath_SelectedIndexChanged;
this.tscbEncoding.SelectedIndexChanged += TscbEncoding_SelectedIndexChanged;
this.listBox1.SelectedIndexChanged += ListBox1_SelectedIndexChanged;
}
/// <summary>
/// 选择路径
/// </summary>
......@@ -54,17 +57,22 @@ namespace Tools.UI
var folder = Utils.SelectFolder();
if (!string.IsNullOrEmpty(folder))
{
//路径下拉记录
if (!this.tscbLogPath.Items.Contains(folder))
this.tscbLogPath.Items.Add(folder);
//刷新下拉框文本
this.LogPath = folder;
//保存路径记录
Utils.SaveJsonConfig(this.tscbLogPath.Items.Cast<string>().ToList());
}
}
/// <summary>
/// 路径文本改变时,刷新列表框
/// </summary>
private void TstbLogPath_TextChanged(object sender, EventArgs e)
private void TscbLogPath_SelectedIndexChanged(object sender, EventArgs e)
{
this.InitListBox();
}
/// <summary>
/// 编码切换:重新解析日志文件
/// </summary>
......@@ -120,6 +128,8 @@ namespace Tools.UI
encode = Encoding.GetEncoding(this.tscbEncoding.Text);
//清空信息
this.textBox1.Text = string.Empty;
//生成文件路径
var logFileName = $@"{this.LogPath}\{fileName}";
//如果上一个任务还未结束,则取消
if (_task != null && !_task.IsCompleted)
{
......@@ -134,7 +144,7 @@ namespace Tools.UI
//读取日志内容
var initLength = 1024;
var buffer = new byte[initLength];
var fs = new FileStream($@"{this.LogPath}\{fileName}", FileMode.Open, FileAccess.Read);
var fs = new FileStream(logFileName, FileMode.Open, FileAccess.Read);
//初始化进度条
this.AsyncUI(() => {
this.progressBar1.Maximum = Math.Max(1, (int)(fs.Length / initLength));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment