diff --git a/EX/ExProgram.xaml.cs b/EX/ExProgram.xaml.cs index e7e1fcb..5ad566b 100644 --- a/EX/ExProgram.xaml.cs +++ b/EX/ExProgram.xaml.cs @@ -23,7 +23,7 @@ namespace formula_manage.EX public ExProgram() { InitializeComponent(); - Log.SetTextControl(textLog); + LogDataRead.SetTextControl(textLog); } } } diff --git a/Login.xaml.cs b/Login.xaml.cs index 85dd183..dfbeb2f 100644 --- a/Login.xaml.cs +++ b/Login.xaml.cs @@ -27,11 +27,6 @@ namespace formula_manage /// public partial class Login : Window { - - string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录 - string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件 - string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:"; - public string INIPath = Convert.ToString(System.AppDomain.CurrentDomain.BaseDirectory) + "formula.ini"; //配置文件路径 DataTable logindataTable = new DataTable(); //建立login缓存 @@ -41,31 +36,12 @@ namespace formula_manage WindowStartupLocation = WindowStartupLocation.CenterScreen; InitializeComponent(); - System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录 - if (!File.Exists(logPath))//检查日志文件并写入启动日志 - { - FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件 - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine(Log_time + "FORMULA_start"); - wr.Close(); - } - else - { - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine(Log_time + "FORMULA_start"); - wr.Close(); - } - + UserClass.LogGing.LogGingDATA("FORMULA_start"); } private void Button_Click(object sender, RoutedEventArgs e) //退出按钮事件 { - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine(Log_time + "FORMULA_LogStop"); - wr.Close(); - this.Close(); + UserClass.LogGing.LogGingDATA("FORMULA_LogStop"); } private void Button_Click_1(object sender, RoutedEventArgs e) //登录按钮事件 @@ -87,10 +63,7 @@ namespace formula_manage MainWindow Main = new MainWindow(); window.Close(); - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine(Log_time + "LOGon = ENGINEER"); - wr.Close(); + UserClass.LogGing.LogGingDATA("LOGon = ENGINEER"); Main.ShowDialog();//实例化并置顶打开窗口 } @@ -111,10 +84,7 @@ namespace formula_manage MainWindow Main = new MainWindow(); window.Close(); - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine(Log_time + "LOGon = " + user); - wr.Close(); + UserClass.LogGing.LogGingDATA("LOGon = " + user); Main.ShowDialog();//实例化并置顶打开窗口 } @@ -166,10 +136,7 @@ namespace formula_manage { EXLINK.Background = Brushes.Red; System.Windows.MessageBox.Show("扩展程序未启动"); - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "EX = FALL_TO_START"); - wr.Close(); + UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "EX = FALL_TO_START"); } } try @@ -207,10 +174,7 @@ namespace formula_manage //Windows.Sql sql = new Windows.Sql(); //sql.ShowDialog();//实例化并置顶打开数据库设置窗口 - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DISPENLINK = ConnectFailed"); - wr.Close(); + UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DISPENLINK = ConnectFailed"); return; } @@ -244,10 +208,7 @@ namespace formula_manage //Windows.Sql sql = new Windows.Sql(); //sql.ShowDialog();//实例化并置顶打开数据库设置窗口 - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DBCLINK = ConnectFailed"); - wr.Close(); + UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "DBCLINK = ConnectFailed"); return; } @@ -275,10 +236,7 @@ namespace formula_manage catch (Exception) { System.Windows.MessageBox.Show("请求信息失败,检查连接"); - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - wr.WriteLine("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "USER = NoData"); - wr.Close(); + UserClass.LogGing.LogGingDATA("[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:" + "USER = NoData"); return; } } diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 5912fe8..3eee09e 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -248,10 +248,6 @@ namespace formula_manage } private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) //窗口关闭事件 { - string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录 - string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\Log.txt";//日志文件 - string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:"; - if (!quit) { MessageBoxResult result = System.Windows.MessageBox.Show("您确定要退出吗?", "SUNLIGHT", MessageBoxButton.OKCancel, MessageBoxImage.None, MessageBoxResult.Cancel); @@ -262,13 +258,10 @@ namespace formula_manage } } - System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录 - FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); - StreamWriter wr = new StreamWriter(fs);//创建文件 - // wr.WriteLine(Log_time + "HttpSERVER_STOP"); + // UserClass.LogGing.LogGingDATA(Log_time + "HttpSERVER_STOP"); // UserClass.HttpSERVER.Stop(); //停止网络通信 - wr.WriteLine(Log_time + "FORMULA_STOP"); - wr.Close(); + UserClass.LogGing.LogGingDATA("FORMULA_STOP"); + } private void SearchBox_OnKeyDownd(object sender, System.Windows.Input.KeyEventArgs e) //回车跳转功能 { diff --git a/UserClass/DataTableForToObservableCollection.cs b/UserClass/DataTableForToObservableCollection.cs index 0a5e68b..af30c45 100644 --- a/UserClass/DataTableForToObservableCollection.cs +++ b/UserClass/DataTableForToObservableCollection.cs @@ -9,7 +9,7 @@ using System.Threading.Tasks; namespace formula_manage.UserClass { - internal class DataTableToObservableCollection + internal class DataTableToObservableCollection //数据表到可观察集合 { public ObservableCollection ToObservableCollection(DataTable dt) where T : class, new() { diff --git a/UserClass/Log.cs b/UserClass/LogDataRead.cs similarity index 98% rename from UserClass/Log.cs rename to UserClass/LogDataRead.cs index d37577c..ad62fb6 100644 --- a/UserClass/Log.cs +++ b/UserClass/LogDataRead.cs @@ -9,7 +9,7 @@ using System.Windows.Media; namespace formula_manage.UserClass { - public static class Log + public static class LogDataRead { private const int MaxCount = 1000; private static int Count = 0; diff --git a/UserClass/LogGing.cs b/UserClass/LogGing.cs new file mode 100644 index 0000000..47d9e25 --- /dev/null +++ b/UserClass/LogGing.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace formula_manage.UserClass +{ + public class LogGing + { + public static void LogGingDATA(string dat) + { + string logpath = System.Environment.CurrentDirectory + "\\Log";//日志文件目录 + string logPath = "" + System.Environment.CurrentDirectory + "\\Log\\"+ DateTime.Now.ToString("yyyy-MM-dd") + ".txt";//日志文件 + string Log_time = "[" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "]:"; + + System.IO.DirectoryInfo log = new System.IO.DirectoryInfo(@logpath);//生成日志文件目录 + if (!File.Exists(logPath))//检查日志文件并写入启动日志 + { + FileStream fs = new FileStream(logPath, FileMode.CreateNew, FileAccess.Write);//创建写入文件 + StreamWriter wr = new StreamWriter(fs);//创建文件 + wr.WriteLine(Log_time + dat); + wr.Close(); + } + else + { + FileStream fs = new FileStream(logPath, FileMode.Append, FileAccess.Write); + StreamWriter wr = new StreamWriter(fs);//创建文件 + wr.WriteLine(Log_time + dat); + wr.Close(); + } + + } + } +} diff --git a/UserClass/get_local_ip_address.cs b/UserClass/get_local_ip_address.cs new file mode 100644 index 0000000..85f8968 --- /dev/null +++ b/UserClass/get_local_ip_address.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net.Sockets; +using System.Net; +using System.Text; +using System.Threading.Tasks; +using System.Net.NetworkInformation; + +namespace formula_manage.UserClass +{ + public class get_local_ip_address + { + public static string getLocalIPAddressWithNetworkInterface(NetworkInterfaceType _type)//获取本机ip并以字符串方式返回 + { + string output = ""; + foreach (NetworkInterface item in NetworkInterface.GetAllNetworkInterfaces()) + { + if (item.NetworkInterfaceType == _type && item.OperationalStatus == OperationalStatus.Up) + { + foreach (UnicastIPAddressInformation ip in item.GetIPProperties().UnicastAddresses) + { + if (ip.Address.AddressFamily == AddressFamily.InterNetwork) + { + output = ip.Address.ToString(); + } + } + } + } + return output; + } + } +} diff --git a/formula_manage.csproj b/formula_manage.csproj index 83321c5..2028b82 100644 --- a/formula_manage.csproj +++ b/formula_manage.csproj @@ -443,10 +443,12 @@ + + - +