15 changed files with 205 additions and 16 deletions
@ -0,0 +1,40 @@ |
|||||
|
<UserControl x:Class="SunlightCentralizedControlManagement_SCCM_.View.LogView" |
||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
||||
|
xmlns:lang="clr-namespace:SunlightCentralizedControlManagement_SCCM_.Properties" |
||||
|
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" |
||||
|
xmlns:local="clr-namespace:SunlightCentralizedControlManagement_SCCM_.View" |
||||
|
mc:Ignorable="d" |
||||
|
d:DesignHeight="450" d:DesignWidth="1200"> |
||||
|
<Grid> |
||||
|
<Grid.ColumnDefinitions> |
||||
|
<ColumnDefinition Width="600"/> |
||||
|
<ColumnDefinition Width="5"/> |
||||
|
<ColumnDefinition/> |
||||
|
</Grid.ColumnDefinitions> |
||||
|
<ComboBox Height="45" x:Name="comboBox_log" VerticalAlignment="Top" FontSize="20" Background="#FF90BEFF" |
||||
|
DropDownClosed="comboBox_log_DropDownClosed" BorderBrush="#FF00204E" Padding="1,1,1,1"/> |
||||
|
<DataGrid Grid.Column="0" x:Name="gridLog" Margin="0,50,0,0" HeadersVisibility ="Column" |
||||
|
IsReadOnly="True" AutoGenerateColumns="False" MouseDoubleClick="DataGrid_gridLogClick" > |
||||
|
<DataGrid.Columns> |
||||
|
<!--列信息绑定--> |
||||
|
<DataGridTextColumn Binding="{Binding Name}" Header="Name" Width="195" MaxWidth="195" MinWidth="195" CanUserReorder="False"/> |
||||
|
<DataGridTextColumn Binding="{Binding Length}" Header="Volume" Width="50" MaxWidth="150" MinWidth="100" CanUserReorder="False"/> |
||||
|
<DataGridTextColumn Binding="{Binding CreationTimeUtc}" Header="Creation time" Width="150" MaxWidth="150" MinWidth="150" CanUserReorder="False"/> |
||||
|
<DataGridTextColumn Binding="{Binding LastWriteTimeUtc}" Header="Last modified time" Width="150" MaxWidth="150" MinWidth="150" CanUserReorder="False"/> |
||||
|
</DataGrid.Columns> |
||||
|
</DataGrid> |
||||
|
<GridSplitter Grid.Column="1" Width="5" HorizontalAlignment="Stretch" Background="#FF00204E"/> |
||||
|
<RichTextBox Grid.Column="2" x:Name="Logtext" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White" SelectionBrush="White"> |
||||
|
<FlowDocument> |
||||
|
<Paragraph> |
||||
|
<Run Text="LOG"/> |
||||
|
</Paragraph> |
||||
|
</FlowDocument> |
||||
|
</RichTextBox> |
||||
|
<!--遮罩--> |
||||
|
|
||||
|
</Grid> |
||||
|
</UserControl> |
||||
@ -0,0 +1,99 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Data; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Windows; |
||||
|
using System.Windows.Controls; |
||||
|
using System.Windows.Data; |
||||
|
using System.Windows.Documents; |
||||
|
using System.Windows.Input; |
||||
|
using System.Windows.Media; |
||||
|
using System.Windows.Media.Imaging; |
||||
|
using System.Windows.Navigation; |
||||
|
using System.Windows.Shapes; |
||||
|
|
||||
|
namespace SunlightCentralizedControlManagement_SCCM_.View |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// LogView.xaml 的交互逻辑
|
||||
|
/// </summary>
|
||||
|
public partial class LogView : UserControl |
||||
|
{ |
||||
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd"); |
||||
|
DataTable logdataTable = new DataTable(); //建立RRODUCT缓存
|
||||
|
|
||||
|
public LogView() |
||||
|
{ |
||||
|
InitializeComponent(); |
||||
|
|
||||
|
comboBox_log.ItemsSource = new string[3] { "Log", "ERR", "Exchange" }; |
||||
|
comboBox_log.Text = "Log"; |
||||
|
|
||||
|
logdataTable.Columns.Add("Name", typeof(string)); |
||||
|
logdataTable.Columns.Add("Length", typeof(int)); |
||||
|
logdataTable.Columns.Add("CreationTimeUtc", typeof(string)); |
||||
|
logdataTable.Columns.Add("LastWriteTimeUtc", typeof(string)); |
||||
|
|
||||
|
LOG_file(); |
||||
|
} |
||||
|
private void LOG_file()//建立列表
|
||||
|
{ |
||||
|
DirectoryInfo loginfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\"+comboBox_log.Text); //new文件夹
|
||||
|
logdataTable.Clear(); |
||||
|
foreach (var item in loginfo.GetFiles()) |
||||
|
{ |
||||
|
DataRow FileRow = logdataTable.NewRow(); |
||||
|
|
||||
|
FileRow["Name"] = item.Name; |
||||
|
FileRow["Length"] = item.Length / 1024; |
||||
|
FileRow["CreationTimeUtc"] = item.CreationTimeUtc; |
||||
|
FileRow["LastWriteTimeUtc"] = item.LastWriteTimeUtc; |
||||
|
logdataTable.Rows.Add(FileRow); |
||||
|
} |
||||
|
logdataTable.DefaultView.Sort = "Name DESC"; |
||||
|
gridLog.ItemsSource = logdataTable.DefaultView.ToTable().DefaultView; |
||||
|
} |
||||
|
|
||||
|
private void DataGrid_gridLogClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||
|
{ |
||||
|
int rownum = gridLog.SelectedIndex;//获取鼠标选中行并定义变量
|
||||
|
if (rownum != -1)//判断鼠标定位是否有效
|
||||
|
{ |
||||
|
/*定位选中行及指定列单元格文本信息*/ |
||||
|
LOGDATA_file((gridLog.Columns[0].GetCellContent(gridLog.Items[rownum]) as TextBlock).Text.TrimEnd());//
|
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void LOGDATA_file(string dat) //读取文件显示到前端
|
||||
|
{ |
||||
|
Logtext.Document = new FlowDocument(); |
||||
|
string filePath = System.Environment.CurrentDirectory + "\\"+comboBox_log.Text+"\\"; |
||||
|
try |
||||
|
{ |
||||
|
// 使用StreamReader读取文件
|
||||
|
using (StreamReader reader = new StreamReader(filePath + dat)) |
||||
|
{ |
||||
|
// 读取文件直到文件的末尾
|
||||
|
while (!reader.EndOfStream) |
||||
|
{ |
||||
|
// 添加文件的每一行到RichTextBox
|
||||
|
Logtext.AppendText(reader.ReadLine() + "\r\n"); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
// 处理可能发生的任何异常
|
||||
|
MessageBox.Show("Error reading file: " + ex.Message); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private void comboBox_log_DropDownClosed(object sender, EventArgs e) |
||||
|
{ |
||||
|
LOG_file(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue