Exchange页面完成
This commit is contained in:
commit
3bffc936be
3 files changed
+69
-27
No files matched your search
+10
-10
@@ -45,12 +45,11 @@ namespace formula_manage
|
|||||||
}
|
}
|
||||||
|
|
||||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录
|
string logpath = System.Environment.CurrentDirectory + "\\Log\\ERR";//日志文件目录
|
||||||
//string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
//string logPathtxt = "" + System.Environment.CurrentDirectory + "\\Log\\"+ Log_time + "Log.txt";//日志文件
|
||||||
|
|
||||||
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
private void App_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
|
||||||
{
|
{
|
||||||
|
|
||||||
e.Handled = true;
|
e.Handled = true;
|
||||||
if (e.Exception.InnerException == null)
|
if (e.Exception.InnerException == null)
|
||||||
{
|
{
|
||||||
@@ -74,24 +73,25 @@ namespace formula_manage
|
|||||||
|
|
||||||
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录
|
||||||
string log_path = logpath +"\\ERR" +Log_time + ".txt";
|
string log_path = logpath +"\\ERR" +Log_time + ".txt";
|
||||||
|
string Log_timehms = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||||||
if (!File.Exists(log_path))//检查日志文件并写入启动日志
|
if (!File.Exists(log_path))//检查日志文件并写入启动日志
|
||||||
{
|
{
|
||||||
FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
FileStream fs = new FileStream(log_path, FileMode.CreateNew, FileAccess.Write);//创建写入文件
|
||||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
wr.WriteLine("[" + Log_time + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Error area] ||" + e.Exception.StackTrace.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString());
|
||||||
wr.Close();
|
wr.Close();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
FileStream fs = new FileStream(log_path, FileMode.Append, FileAccess.Write);//创建写入文件
|
||||||
StreamWriter wr = new StreamWriter(fs);//创建文件
|
StreamWriter wr = new StreamWriter(fs);//创建文件
|
||||||
wr.WriteLine("[" + Log_time + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error source] ||" + e.Exception.Source.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error message] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Detailed] ||" + e.Exception.Message.ToString() + Environment.NewLine.ToString());
|
||||||
wr.WriteLine("[" + Log_time + "];[Error area] ||" + e.Exception.StackTrace.ToString());
|
wr.WriteLine("[" + Log_timehms + "];[Error area] ||" + e.Exception.StackTrace.ToString());
|
||||||
wr.Close();
|
wr.Close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-7
@@ -7,23 +7,27 @@
|
|||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
Title="Exchange" Height="720" Width="1280" MinHeight="720" MinWidth="1280" Background="#FFE0E0E0">
|
Title="Exchange" Height="720" Width="1280" MinHeight="720" MinWidth="1280" Background="#FFE0E0E0">
|
||||||
<Grid>
|
<Grid>
|
||||||
<DataGrid x:Name="gridLog" Margin="5,5,0,5" HorizontalAlignment="Left" Width="250" HeadersVisibility ="Column" Background="White" BorderBrush="White"
|
<DataGrid x:Name="gridLog" Margin="5,5,0,5" HorizontalAlignment="Left" Width="245" HeadersVisibility ="Column" Background="White" BorderBrush="White"
|
||||||
CanUserResizeRows="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserReorderColumns="False"
|
IsReadOnly="True" AutoGenerateColumns="False" MouseDoubleClick="DataGrid_gridLogClick" >
|
||||||
CanUserResizeColumns="False" CanUserSortColumns="False" >
|
|
||||||
<DataGrid.Columns>
|
<DataGrid.Columns>
|
||||||
<!--列信息绑定-->
|
<!--列信息绑定-->
|
||||||
<DataGridTextColumn Binding="{Binding Name}" Header="文件" Width="200" MaxWidth="200" MinWidth="100"/>
|
<DataGridTextColumn Binding="{Binding Name}" Header="文件" Width="195" MaxWidth="195" MinWidth="195" CanUserReorder="False"/>
|
||||||
<DataGridTextColumn Binding="{Binding Length}" Header="容量" Width="50" MaxWidth="50" MinWidth="50"/>
|
<DataGridTextColumn Binding="{Binding Length}" Header="大小" Width="50" MaxWidth="50" MinWidth="50" CanUserReorder="False"/>
|
||||||
|
<DataGridTextColumn Binding="{Binding CreationTimeUtc}" Header="创建时间" Width="150" MaxWidth="150" MinWidth="150" CanUserReorder="False"/>
|
||||||
|
<DataGridTextColumn Binding="{Binding LastWriteTimeUtc}" Header="最后修改时间" Width="150" MaxWidth="150" MinWidth="150" CanUserReorder="False"/>
|
||||||
</DataGrid.Columns>
|
</DataGrid.Columns>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
|
|
||||||
<RichTextBox x:Name="Log" Margin="255,5,5,5" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White" SelectionBrush="White">
|
<RichTextBox x:Name="Logtext" Margin="255,5,5,5" IsReadOnly="True" VerticalScrollBarVisibility="Visible" Background="White" SelectionBrush="White">
|
||||||
<FlowDocument>
|
<FlowDocument>
|
||||||
<Paragraph>
|
<Paragraph>
|
||||||
<Run Text="LOG"/>
|
<Run Text="LOG"/>
|
||||||
</Paragraph>
|
</Paragraph>
|
||||||
</FlowDocument>
|
</FlowDocument>
|
||||||
</RichTextBox>
|
</RichTextBox>
|
||||||
|
<!--遮罩-->
|
||||||
|
<Grid Grid.Column="1" x:Name="logR" Margin="0,0,0,0" Background="White" Opacity="0.8" Visibility="Hidden">
|
||||||
|
<TextBlock Height="50" Margin="0,0,0,150" TextWrapping="Wrap" Text="文件读取中请稍后..." Width="300" FontSize="34" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
+48
-10
@@ -4,6 +4,7 @@ using System.Data;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
@@ -13,6 +14,7 @@ using System.Windows.Input;
|
|||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.Windows.Threading;
|
||||||
|
|
||||||
namespace formula_manage.EX
|
namespace formula_manage.EX
|
||||||
{
|
{
|
||||||
@@ -22,39 +24,75 @@ namespace formula_manage.EX
|
|||||||
public partial class Exchange : Window
|
public partial class Exchange : Window
|
||||||
{
|
{
|
||||||
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
string Log_time = DateTime.Now.ToString("yyyy-MM-dd");
|
||||||
DataTable logdataTable = new DataTable(); //建立log缓存
|
|
||||||
|
DataTable logdataTable = new DataTable(); //建立RRODUCT缓存
|
||||||
|
|
||||||
public Exchange()
|
public Exchange()
|
||||||
{
|
{
|
||||||
|
WindowStartupLocation = WindowStartupLocation.CenterScreen;
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
logdataTable.Columns.Add("Name", typeof(string));
|
logdataTable.Columns.Add("Name", typeof(string));
|
||||||
logdataTable.Columns.Add("Length", typeof(int));
|
logdataTable.Columns.Add("Length", typeof(int));
|
||||||
|
logdataTable.Columns.Add("CreationTimeUtc", typeof(string));
|
||||||
|
logdataTable.Columns.Add("LastWriteTimeUtc", typeof(string));
|
||||||
|
|
||||||
LOG_file();
|
LOG_file();
|
||||||
}
|
}
|
||||||
private void LOG_file()//建立列表
|
private void LOG_file()//建立列表
|
||||||
{
|
{
|
||||||
DirectoryInfo loginfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\Exchange"); //new文件夹
|
DirectoryInfo loginfo = new DirectoryInfo(System.Environment.CurrentDirectory + "\\Exchange"); //new文件夹
|
||||||
DataRow FileRow = logdataTable.NewRow();
|
|
||||||
foreach (var item in loginfo.GetFiles())
|
foreach (var item in loginfo.GetFiles())
|
||||||
{
|
{
|
||||||
// DataRow FileRow = logdataTable.NewRow();
|
DataRow FileRow = logdataTable.NewRow();
|
||||||
|
|
||||||
FileRow["Name"] = item.Name;
|
FileRow["Name"] = item.Name;
|
||||||
FileRow["Length"] = item.Length/1024;
|
FileRow["Length"] = item.Length/1024;
|
||||||
|
FileRow["CreationTimeUtc"] = item.CreationTimeUtc;
|
||||||
|
FileRow["LastWriteTimeUtc"] = item.LastWriteTimeUtc;
|
||||||
logdataTable.Rows.Add(FileRow);
|
logdataTable.Rows.Add(FileRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
gridLog.ItemsSource = logdataTable.DefaultView;
|
gridLog.ItemsSource = logdataTable.DefaultView;
|
||||||
// FileInfo[] logFile = loginfo.GetFiles("*.log");//生成文件夹中的文件名合集
|
}
|
||||||
//gridLog.ItemsSource = logFile;//加载合集
|
|
||||||
// DataRow row = logdataTable.NewRow(); //ID列
|
|
||||||
//logdataTable. =
|
|
||||||
// logFile.fill()
|
|
||||||
// //gridLog.DataContext = "Name"; // 显示文件名
|
|
||||||
|
|
||||||
// gridLog.ItemsSource = logFile;//加载合集
|
private void DataGrid_gridLogClick(object sender, MouseButtonEventArgs e)//数据表双击事件
|
||||||
|
{
|
||||||
|
int rownum = gridLog.SelectedIndex;//获取鼠标选中行并定义变量
|
||||||
|
logR.Visibility = Visibility.Visible; //开启页面遮罩
|
||||||
|
|
||||||
|
if (rownum != -1)//判断鼠标定位是否有效
|
||||||
|
{
|
||||||
|
/*定位选中行及指定列单元格文本信息*/
|
||||||
|
LOGDATA_file((gridLog.Columns[0].GetCellContent(gridLog.Items[rownum]) as TextBlock).Text.TrimEnd());//
|
||||||
|
}
|
||||||
|
|
||||||
|
logR.Visibility = Visibility.Hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LOGDATA_file(string dat) //读取文件显示到前端
|
||||||
|
{
|
||||||
|
Logtext.Document = new FlowDocument();
|
||||||
|
string filePath = System.Environment.CurrentDirectory + "\\Exchange\\";
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user