添加项目文件。
This commit is contained in:
454
WPFWCSDemo/ViewModels/MainViewModel.cs
Normal file
454
WPFWCSDemo/ViewModels/MainViewModel.cs
Normal file
@@ -0,0 +1,454 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Serilog;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Threading;
|
||||
using System.Xml.Linq;
|
||||
using WPFWCSDemo.Models;
|
||||
using WPFWCSDemo.Models.Devices.CircleRGVStation;
|
||||
using WPFWCSDemo.Schedules;
|
||||
using WPFWCSDemo.Schedules.CircleRGV;
|
||||
using WPFWCSDemo.StateCode;
|
||||
using WPFWCSDemo.Utilities;
|
||||
using WPFWCSDemo.Views;
|
||||
using WPFWCSDemo.Views.CustomComponent;
|
||||
using WPFWCSDemo.Views.Devices;
|
||||
|
||||
namespace WPFWCSDemo.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// 母窗体
|
||||
public partial class MainViewModel : ObservableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// 用于监控请求值的定时器
|
||||
/// </summary>
|
||||
private readonly DispatcherTimer dispatcherTimer;
|
||||
|
||||
/// <summary>
|
||||
/// 用于接收View中导航用的Frame控件,此项目中使用Frame作为导航母控件
|
||||
/// </summary>
|
||||
private readonly Frame _navigationFrame;
|
||||
|
||||
/// </summary>
|
||||
public MainViewModel(Frame navigationFrame)
|
||||
{
|
||||
_menuBar = new ObservableCollection<MenuBar>();
|
||||
CreateMenu();
|
||||
|
||||
_navigationFrame = navigationFrame;
|
||||
|
||||
|
||||
// 设置定时器属性
|
||||
dispatcherTimer = new DispatcherTimer();
|
||||
dispatcherTimer.Interval = TimeSpan.FromSeconds(1); // 设置时间间隔为1秒
|
||||
dispatcherTimer.Tick += DispatcherTimer_Tick; // 添加事件处理程序
|
||||
dispatcherTimer.Start(); // 启动计时器
|
||||
|
||||
//ScheduleTask();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 定时执行的调度任务
|
||||
/// </summary>
|
||||
private static void ScheduleTask()
|
||||
{
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
|
||||
// //更新任务状态
|
||||
// CircleRGVSchedule.UpdateScheduleState();
|
||||
|
||||
//Excute.ExecuteTask();
|
||||
|
||||
//Update.UpdateDeviceNumber();
|
||||
|
||||
//Update.UpdateScheduleState();
|
||||
|
||||
//Generate.GenerateTask();
|
||||
|
||||
////Common.RecordRequestValue();
|
||||
//Log.Information($"-----------------设备调度-----------------");
|
||||
|
||||
// ////任务处理
|
||||
// TaskFinishSchedule.TaskFinish();
|
||||
|
||||
// TaskFinishSchedule.TaskDelete();
|
||||
|
||||
// TaskFinishSchedule.TaskForSendFailedHandler();
|
||||
|
||||
// TaskFinishSchedule.TaskExceptionHandler();
|
||||
|
||||
// //RGV调度
|
||||
// CircleRGVSchedule.GenerateTask();
|
||||
|
||||
// CircleRGVSchedule.ExecuteTask();
|
||||
|
||||
// Task.Delay(200).Wait();
|
||||
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
|
||||
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
//实时报警
|
||||
AlarmViewModel.RealTimeAlarm();
|
||||
|
||||
Task.Delay(1000).Wait();
|
||||
}
|
||||
}, TaskCreationOptions.LongRunning);
|
||||
|
||||
|
||||
//自动备份
|
||||
//Task.Run(() =>
|
||||
//{
|
||||
// while (true)
|
||||
// {
|
||||
// GlobalTask.SqlBackupForTime();
|
||||
|
||||
// Task.Delay(TimeSpan.FromHours(5)).Wait();
|
||||
// }
|
||||
//});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// ListBox选择项
|
||||
/// </summary>
|
||||
[ObservableProperty]
|
||||
MenuBar? _selectedMenuBar;
|
||||
|
||||
[ObservableProperty]
|
||||
ObservableCollection<MenuBar> _menuBar;
|
||||
|
||||
#region 输送口请求指示
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1001;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1003;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1005;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1007;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1008;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _getRequest_1013;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _putRequest_1002;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _putRequest_1004;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _putRequest_1006;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _putRequest_1009;
|
||||
|
||||
[ObservableProperty]
|
||||
bool _putRequest_1010;
|
||||
|
||||
|
||||
[ObservableProperty]
|
||||
int _permission_Station;
|
||||
|
||||
#endregion
|
||||
|
||||
#region 输送口请求 - 显隐性
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineA_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineB_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineC_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineD_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineAB_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _putRequest_LineB_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _getRequest_LineCD_Visible;
|
||||
|
||||
[ObservableProperty]
|
||||
Visibility _putRequest_LineC_Visible;
|
||||
|
||||
#endregion
|
||||
|
||||
private void DispatcherTimer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
using CircleRGVStationState circleRGVStationState = CircleRGVsViewModel.GetCircleRGVStaionState();
|
||||
|
||||
if (circleRGVStationState == null) return;
|
||||
|
||||
GetRequest_1001 = circleRGVStationState.Read_GetRequest_1001;
|
||||
GetRequest_1003 = circleRGVStationState.Read_GetRequest_1003;
|
||||
GetRequest_1005 = circleRGVStationState.Read_GetRequest_1005;
|
||||
GetRequest_1007 = circleRGVStationState.Read_GetRequest_1007;
|
||||
GetRequest_1008 = circleRGVStationState.Read_GetRequest_1008;
|
||||
|
||||
GetRequest_1007 = circleRGVStationState.Read_GetRequest_1007;
|
||||
GetRequest_1008 = circleRGVStationState.Read_GetRequest_1008;
|
||||
|
||||
GetRequest_1013 = circleRGVStationState.Read_GetRequest_1013;
|
||||
PutRequest_1002 = circleRGVStationState.Read_PutRequest_1002;
|
||||
PutRequest_1004 = circleRGVStationState.Read_PutRequest_1004;
|
||||
PutRequest_1006 = circleRGVStationState.Read_PutRequest_1006;
|
||||
|
||||
PutRequest_1009 = circleRGVStationState.Read_PutRequest_1009;
|
||||
PutRequest_1010 = circleRGVStationState.Read_PutRequest_1010;
|
||||
|
||||
Permission_Station = circleRGVStationState.Read_Permission;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool b = false;
|
||||
|
||||
/// <summary>
|
||||
/// ListBox按键导航
|
||||
/// </summary>
|
||||
/// <param name="name"></param>
|
||||
[RelayCommand]
|
||||
void Navigation(string name)
|
||||
{
|
||||
if (string.IsNullOrEmpty(name)) return;
|
||||
|
||||
//【设置】子页导航
|
||||
if (name == "SettingView")
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\Settings\\{name}.xaml", UriKind.Relative));
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
if (name == nameof(AlarmView) || name == nameof(TaskView)
|
||||
|| name == nameof(AlarmHistoryView) || name == nameof(TaskHistoryView))
|
||||
{
|
||||
if (!SqlHelper.IsDBConnected())
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\BlankView.xaml", UriKind.Relative));
|
||||
|
||||
b = true;
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
//导航页面
|
||||
_navigationFrame.Navigate(new Uri($"Views\\{name}.xaml", UriKind.Relative));
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 后退
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void GoBack()
|
||||
{
|
||||
if (b)
|
||||
{
|
||||
//删除【连接错误页面】的导航记录
|
||||
_navigationFrame.NavigationService.RemoveBackEntry();
|
||||
b = false;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
_navigationFrame.NavigationService.GoBack();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前进
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void GoForward()
|
||||
{
|
||||
try
|
||||
{
|
||||
_navigationFrame.NavigationService.GoForward();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 主页
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void Home()
|
||||
{
|
||||
//主页面
|
||||
_navigationFrame.Navigate(new Uri($"Views\\DataInfoView.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
|
||||
public void TaskPage()
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\TaskView.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
public void TaskHistoryPage()
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\TaskHistoryView.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
public void AlarmPage()
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\AlarmView.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设备测试
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void DeviceTest()
|
||||
{
|
||||
//ControllerView controllerView = new ControllerView();
|
||||
//controllerView.ShowDialog(1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 顶部工具栏打开日志文件夹
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void OpenLog()
|
||||
{
|
||||
string dirPath = @"D:\Logs";
|
||||
if (Directory.Exists(dirPath))
|
||||
{
|
||||
Process.Start("explorer.exe",dirPath);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 顶部工具栏打开设置页
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void OpenSetting()
|
||||
{
|
||||
_navigationFrame.Navigate(new Uri($"Views\\Settings\\SettingView.xaml", UriKind.Relative));
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 输送线管理
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void LineControl()
|
||||
{
|
||||
LineControlDialog dialog = new LineControlDialog();
|
||||
dialog.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 打开操作手册
|
||||
/// </summary>
|
||||
[RelayCommand]
|
||||
void Helper()
|
||||
{
|
||||
try
|
||||
{
|
||||
string dirPath = @"D:\滁州东鹏饮料二厂环穿WCS系统使用手册.doc";
|
||||
string processPath = @"C:\Program Files\Microsoft Office\Office16\WINWORD.exe";
|
||||
if (File.Exists(dirPath))
|
||||
{
|
||||
Process.Start(processPath,dirPath);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 导航菜单初始化
|
||||
/// </summary>
|
||||
void CreateMenu()
|
||||
{
|
||||
//生产类画面
|
||||
MenuBar.Add(new MenuBar() { Icon = "Home", Title = "生产看板", NameSpace = nameof(DataInfoView) });
|
||||
//MenuBar.Add(new MenuBar() { Icon = "MonitorScreenshot", Title = "生产监控", NameSpace = nameof(MonitorView) });
|
||||
//MenuBar.Add(new MenuBar() { Icon = "MonitorDashboard", Title = "设备信息", NameSpace = nameof(DevicesNavigationView) });
|
||||
MenuBar.Add(new MenuBar() { Icon = "MonitorDashboard", Title = "环穿状态", NameSpace = nameof(CircleRGVsView) });
|
||||
//报表类画面
|
||||
//MenuBar.Add(new MenuBar() { Icon = "Warehouse", Title = "库存信息", NameSpace = nameof(CargoView) });
|
||||
MenuBar.Add(new MenuBar() { Icon = "AlarmLightOutline", Title = "实时报警", NameSpace = nameof(AlarmView) });
|
||||
MenuBar.Add(new MenuBar() { Icon = "History", Title = "历史报警", NameSpace = nameof(AlarmHistoryView) });
|
||||
MenuBar.Add(new MenuBar() { Icon = "ClipboardTextOutline", Title = "调度任务", NameSpace = nameof(Views.TaskView) });
|
||||
MenuBar.Add(new MenuBar() { Icon = "ClipboardTextClockOutline", Title = "历史任务", NameSpace = nameof(TaskHistoryView) });
|
||||
//其他
|
||||
//MenuBar.Add(new MenuBar() { Icon = "Book", Title = "日志", NameSpace = nameof(LogView) });
|
||||
//MenuBar.Add(new MenuBar() { Icon = "Tools", Title = "设置", NameSpace = nameof(SettingView) });
|
||||
//MenuBar.Add(new MenuBar() { Icon = "CommentQuestionOutline", Title = "帮助", NameSpace = nameof(HelperView) });
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user