using BPASmartClient.Academy._50L; using BPASmartClient.CustomResource.UserControls; using LiveCharts; using System.Collections.Specialized; using System.Configuration; using System.Data; using System.Linq.Expressions; using System.Windows; namespace BPASmartClient.Academy { /// /// Interaction logic for App.xaml /// public partial class App : Application { public static Window MainWindow; public EventWaitHandle ProgramStarted { get; set; } protected override void OnStartup(StartupEventArgs e) { bool createNew; MessageLog.GetInstance.NotifyShow = new Action(o => { DebugLogViewModel.MessageModels.Add(new MessageModel() { LogInfo = o, Forground = System.Windows.Media.Brushes.DeepSkyBlue }); }); MessageLog.GetInstance.NotifyShowEx = new Action(o => { DebugLogViewModel.MessageModels.Add(new MessageModel() { LogInfo = o, Forground = System.Windows.Media.Brushes.Red }); }); //AlarmViewModel.AlarmInfos = MessageNotify.GetInstance.alarmLogs; ProgramStarted = new EventWaitHandle(false, EventResetMode.AutoReset, "Academy", out createNew); if (!createNew) { MessageBox.Show("程序已启动"); App.Current.Shutdown(); Environment.Exit(0); } base.OnStartup(e); //SystemHelper.GetInstance.CreateDesktopShortcut(); DataInit(); MenuInit(); MainView mv = new MainView(); string typeName = Json.Data.ProjectTypeName == ProjectType.HKYF20240916.ToString() ? "50L" : "10L"; mv.TitleName = $"{typeName} 反应釜焖制系统 V1.0.1"; //#if !DEBUG // LoginView lv = new LoginView(); // var res = lv.ShowDialog(); // if (res != null && res == true) // { // #region 更新测试 // //string directory = $"{AppDomain.CurrentDomain.BaseDirectory}AccessFile\\JSON\\UpdateModel.json"; // //if (File.Exists(directory)) // // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] {Json.Data.UpgradeVersion}"; // //else // //{ // // mv.TitleName = $"味魔方管理系统软件[简称:味魔方] V1.0.1"; // // Task.Run(() => // // { // // Thread.Sleep(3000); // // var tt = MessageNotify.GetInstance.ShowDialog("检测到新版本,请问是否现在更新?", DialogType.Information); // // if (tt) // // { // // string directory = AppDomain.CurrentDomain.BaseDirectory; // // Process.Start($"{directory}BPASmartClient.Update.exe"); // // App.Current.Dispatcher.Invoke(() => { mv.Close(); }); // // } // // }); // //} // #endregion // BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.ShowUserLog("用户登录"); // mv.Show(); // } // else // mv.Close(); //#else mv.Show(); //#endif MainWindow = mv; } protected override void OnExit(ExitEventArgs e) { base.OnExit(e); Json.Save(); Json.Save(); Json.Save(); BPASmartClient.CustomResource.Pages.Model.MessageNotify.GetInstance.LogSave(); TaskManage.GetInstance.Dispose(); switch (Json.Data.ProjectTypeName) { case "HKYF20240916": if (PlcControl.GetInstance.IsConnect) { PlcControl.GetInstance.Write(BoolAddEnum.系统启动, false); } break; default: if (Simens_PLC.GetInstance.IsConnected) { Simens_PLC.GetInstance.id = ""; Simens_PLC.GetInstance.siemens.Write("DB1.DBX1002.0", false); Simens_PLC.GetInstance.siemens.Write("DB1.DBX1002.1", false); } break; } App.Current.Shutdown(); Environment.Exit(0); //Process.GetCurrentProcess().Kill(); } private void MenuInit() { #region 配方管理菜单 //ObservableCollection RecipeManage = new ObservableCollection(); //RecipeManage.Add(new SubMenumodel() //{ // SubMenuName = "配方管理", // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, // AssemblyName = "BPASmartClient.Academy", // ToggleWindowPath = "View.RecipeSettingsView" //}); //RecipeManage.Add(new SubMenumodel() //{ // SubMenuName = "配方下发", // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, // AssemblyName = "BPASmartClient.Academy", // ToggleWindowPath = "View.RecipeControlView" //}); //MenuManage.GetInstance.menuModels.Add(new MenuModel() //{ // MainMenuIcon = "", // MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, // MainMenuName = "配方管理", // Alias = "Recipe Management", // subMenumodels = RecipeManage, //}); #endregion #region 硬件设备监控 bool Is10L = Json.Data.ProjectTypeName == ProjectType.HKYF20240714.ToString(); int num = 0; if (Enum.TryParse(typeof(ProjectType), Json.Data.ProjectTypeName,out var enmuvalue)) { num = (int) enmuvalue; } ObservableCollection DeviceMonitor = new ObservableCollection(); DeviceMonitor.Add(new SubMenumodel() { SubMenuName = "设备控制", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.Academy", ToggleWindowPath = num==0 ? "View.DeviceMotionView" :num==1? "View.ReactionKettle50LView": "View.DeviceMotion_2View" }); //DeviceMonitor.Add(new SubMenumodel() //{ // SubMenuName = "设备控制模板1", // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, // AssemblyName = "BPASmartClient.Academy", // ToggleWindowPath = "View.DeviceMotionView" //}); //DeviceMonitor.Add(new SubMenumodel() //{ // SubMenuName = "设备控制模板2", // SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, // AssemblyName = "BPASmartClient.Academy", // ToggleWindowPath = "View.DeviceMotion_2View" //}); DeviceMonitor.Add(new SubMenumodel() { SubMenuName = "数据曲线", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.Academy", ToggleWindowPath = num==0 ? "View.DeviceChartView" :num==1? "View.DeviceChart50LView": "View.DeviceChartView" }); ; DeviceMonitor.Add(new SubMenumodel() { SubMenuName = "历史曲线", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.Academy", ToggleWindowPath = num==0 ? "View.HistoryChartView" : num==1?"View.HistoryChart50LView": "View.HistoryChartView" }); MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", MainMenuName = "设备监控", MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "Device Monitor", subMenumodels = DeviceMonitor, }); #endregion #region 用户管理 ObservableCollection UserManager = new ObservableCollection(); UserManager.Add(new SubMenumodel() { SubMenuName = "用户登录", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.SubPagLoginView" }); UserManager.Add(new SubMenumodel() { SubMenuName = "密码修改", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.PasswordChangeView" }); UserManager.Add(new SubMenumodel() { SubMenuName = "用户管理", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.UserManagerView" }); MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", MainMenuName = "用户管理", MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "User Management", subMenumodels = UserManager, }); #endregion #region 消息日志 ObservableCollection InfoLog = new ObservableCollection(); InfoLog.Add(new SubMenumodel() { SubMenuName = "操作日志", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.UserLogView" }); InfoLog.Add(new SubMenumodel() { SubMenuName = "运行日志", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.RunLogView" }); InfoLog.Add(new SubMenumodel() { SubMenuName = "报警记录", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.AlarmView" }); InfoLog.Add(new SubMenumodel() { SubMenuName = "调试日志", SubMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, AssemblyName = "BPASmartClient.CustomResource", ToggleWindowPath = "Pages.View.DebugLogView" }); MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", MainMenuName = "消息日志", MainMenuPermission = new Permission[] { Permission.管理员, Permission.操作员, Permission.观察员, Permission.技术员 }, Alias = "Message Log", subMenumodels = InfoLog, }); #endregion #region 系统设置 ObservableCollection SystemSet = new ObservableCollection(); SystemSet.Add(new SubMenumodel() { SubMenuName = "系统设置", SubMenuPermission = new Permission[] { Permission.管理员, Permission.技术员 }, AssemblyName = "BPASmartClient.Academy", ToggleWindowPath = "View.ParameterSetView" }); MenuManage.GetInstance.menuModels.Add(new MenuModel() { MainMenuIcon = "", MainMenuName = "系统设置", MainMenuPermission = new Permission[] { Permission.管理员, Permission.技术员 }, Alias = "System Set", subMenumodels = SystemSet, }); #endregion } private void DataInit() { Json.Read(); //Json.Read(); //Json.Read(); if (Json.Data.ProjectTypeName.TryToEnum(out ProjectType pt)) { switch (pt) { case ProjectType.HKYF20240714: Sqlite.GetInstance.Init(); Simens_PLC.GetInstance.Init(); Simens_PLC.GetInstance.Connect(); break; case ProjectType.HKYF20240714_2: Sqlite.GetInstance.Init(); Simens_PLC.GetInstance.Init(); Simens_PLC.GetInstance.Connect(); break; case ProjectType.HKYF20240916: SqliteOperate.GetInstance.Init(); PlcControl.GetInstance.Init(); break; default: break; } } } } }