WinMain.xaml.cs
3.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using HHECS.Bll;
using HHECS.Controls;
using HHECS.Model;
using HHECS.View.Win;
using S7.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Remoting;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace HHECS.View
{
/// <summary>
/// Main.xaml 的交互逻辑
/// </summary>
public partial class WinMain : BaseWindow
{
#region 属性
/// <summary>
/// 时钟同步锁
/// </summary>
private object locker = new object();
/// <summary>
/// 子窗体
/// </summary>
public Dictionary<string, Window> ChildrenWin { get; set; } = new Dictionary<string, Window>();
/// <summary>
/// 主控时钟
/// </summary>
private System.Timers.Timer timer = new System.Timers.Timer();
/// <summary>
/// 结束时钟标志
/// </summary>
private bool stop = false;
/// <summary>
/// 用于创建设备PLC
/// </summary>
public List<Plc> PLCs { get; set; }
#endregion
public WinMain()
{
InitializeComponent();
this.WindowState = WindowState.Maximized;
this.Lab1.Content = $"欢迎:{AppSession.User.UserName} {DateTime.Now.ToLocalTime()}";
this.GridMain.Children.Add(new StockerMonitor(32, 4, false, 900, 150));
}
#region 时钟逻辑
private void Timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (locker)
{
#region 是否结束处理
if (stop)
{
}
#endregion
}
}
#endregion
#region 窗体事件
private void InitTimer()
{
timer.Interval = AppSession.Interval; //1秒触发一次
timer.Elapsed += Timer_Elapsed; ;
timer.AutoReset = true;//每到指定时间Elapsed事件是到时间就触发
timer.Enabled = false; //指示 Timer 是否应引发 Elapsed 事件。
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
AppSession.Bll.Combine(AppSession.MenuOperations.Where(t => t.ParentId == null).ToList(), AppSession.Bll.GetAllMenuOperation().Data.Where(t => t.MenuType == "catalog" || t.MenuType == "menu").ToList());
MenuMain.ItemsSource = AppSession.MenuOperations.Where(t => t.ParentId == null).OrderBy(t=>t.OrderNum).ToList();
}
private void Window_Closed(object sender, EventArgs e)
{
Application.Current.Shutdown();
}
private void MenuMain_Checked(object sender, RoutedEventArgs e)
{
try
{
MenuOperation menu = (MenuOperation)((MenuItem)e.OriginalSource).Header;
var win = ChildrenWin.FirstOrDefault(t => t.Key == menu.Url).Value;
if (String.IsNullOrWhiteSpace(menu?.Url) || menu.Url == "#")
{
return;
}
if (win == null)
{
win = (Window)Activator.CreateInstance(null, menu.Url).Unwrap();
ChildrenWin.Add(menu.Url, win);
}
win.Show();
if (win.WindowState == WindowState.Minimized)
win.WindowState = WindowState.Normal;
win.Activate();
}
catch (Exception ex)
{
LogExecute.WriteExceptionLog("打开菜单", ex);
MessageBox.Show("打开菜单出现异常!");
}
}
#endregion
}
}