예제 #1
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            ShowInTaskbar = false;
            #region 日志
            LogModel log1 = new LogModel()
            {
                Origin       = "汽车衡_" + ClientInfo.Name,
                FunctionName = "称点主窗体_MainWindow_Loaded",
                Level        = LogConstParam.LogLevel_Info,
                CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Direction    = LogConstParam.Directions_Out,
                Msg          = "系统启动成功"
            };
            Talent.ClinetLog.SysLog.Log(JsonConvert.SerializeObject(log1));
            #endregion
            //SoundReading sr = new SoundReading("测试12121212");
            //sr.Voice();
            //检查更新……
            CheckUpdate();
            #region 是否显示测试内容
            isTest = ConfigurationManager.AppSettings["IsTest"].ToString().Trim() == "1" ? true : false;
            if (isTest)
            {
                canvas1.Visibility         = System.Windows.Visibility.Visible;
                testCardNoBtn.Visibility   = System.Windows.Visibility.Visible;
                testCardNoTxt.Visibility   = System.Windows.Visibility.Visible;
                TestSendTaskBtn.Visibility = System.Windows.Visibility.Visible;
            }
            else
            {
                canvas1.Visibility         = System.Windows.Visibility.Hidden;
                testCardNoBtn.Visibility   = System.Windows.Visibility.Hidden;
                testCardNoTxt.Visibility   = System.Windows.Visibility.Hidden;
                TestSendTaskBtn.Visibility = System.Windows.Visibility.Hidden;
            }
            #endregion
            //版本
            txtVer.Text = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString().Substring(0, 3);
            //展示系统当前时间
            firstStartTime = DateTime.Now;
            timer          = new DispatcherTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += timer_Tick;
            timer.Start();
            // ErrorAutoStart();
            CarMeasureClientViewModel viewModel = this.DataContext as CarMeasureClientViewModel;
            viewModel.std               = std;
            viewModel.gridReader        = rendergv;
            viewModel.gridSupplier      = gridSupplier;
            viewModel.gridMeasure       = gridMeasure;
            viewModel.gridMeasureWeight = gridMeasureWeight;
            viewModel.isTest            = isTest;//是否测试模式
            viewModel.window            = this;
            TestWeightviewModel         = viewModel;
            this.KeyDown += Window_KeyDown;
            //启动文件同步程序
            if (_enableFileSync == true)
            {
                string    processName = "Talent.FIleSync";
                Process[] procList    = Process.GetProcessesByName(processName);
                if (procList != null && procList.Length > 0)
                {
                    proSync = procList[0];
                }
                else
                {
                    proSync = new Process();
                    string syncExePath = System.IO.Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, processName + ".exe");
                    proSync.StartInfo.FileName    = syncExePath;
                    proSync.StartInfo.WindowStyle = ProcessWindowStyle.Minimized;
                    try
                    {
                        proSync.Start();
                        LogModel log = new LogModel()
                        {
                            Origin       = "汽车衡_" + ClientInfo.Name,
                            FunctionName = "称点主窗体_MainWindow_Loaded",
                            Level        = LogConstParam.LogLevel_Info,
                            CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            Direction    = LogConstParam.Directions_Out,
                            Msg          = "启动文件同步程序成功。"
                        };
                        Talent.ClinetLog.SysLog.Log(JsonConvert.SerializeObject(log));
                    }
                    catch (Win32Exception err)
                    {
                        #region log
                        LogModel log = new LogModel()
                        {
                            Origin       = "汽车衡_" + ClientInfo.Name,
                            FunctionName = "称点主窗体_MainWindow_Loaded",
                            Level        = LogConstParam.LogLevel_Error,
                            CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                            Direction    = LogConstParam.Directions_Out,
                            Msg          = "启动文件同步程序失败。原因:" + err.Message
                        };
                        Talent.ClinetLog.SysLog.Log(JsonConvert.SerializeObject(log));
                        #endregion
                    }
                }
            }
            FileHelpClass fHClass = new FileHelpClass();
            fHClass.FileLogDelete(15, false);

            this.WindowState = System.Windows.WindowState.Normal;
            this.WindowStyle = System.Windows.WindowStyle.None;
            this.ResizeMode  = System.Windows.ResizeMode.NoResize;
            //this.Topmost = true;
            this.Activate();
            this.Left   = 0.0;
            this.Top    = 0.0;
            this.Width  = System.Windows.SystemParameters.PrimaryScreenWidth;
            this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
            #region log
            LogModel log11 = new LogModel()
            {
                Origin       = "汽车衡_" + ClientInfo.Name,
                FunctionName = "称点主窗体_MainWindow",
                Level        = LogConstParam.LogLevel_Info,
                CreateTime   = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
                Direction    = LogConstParam.Directions_Out,
                Msg          = "程序运行超过设定时间" + viewModel.AutoRunTime.ToString()
            };
            Talent.ClinetLog.SysLog.Log(JsonConvert.SerializeObject(log11));
            #endregion
        }
예제 #2
0
파일: Login.xaml.cs 프로젝트: rcw0125/-
        /// <summary>
        /// 定时删除日志
        /// </summary>
        private void DelteLogFile()
        {
            FileHelpClass fHClass = new FileHelpClass();

            fHClass.FileLogDelete(10, false);
        }