终端一体化运控平台
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

462 lines
21 KiB

  1. using BeDesignerSCADA.Common;
  2. using BPASmartClient.Compiler;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using System.Windows;
  13. using System.Windows.Controls;
  14. using System.Windows.Data;
  15. using System.Windows.Documents;
  16. using System.Windows.Input;
  17. using System.Windows.Markup;
  18. using System.Windows.Media;
  19. using System.Windows.Media.Animation;
  20. using System.Windows.Media.Imaging;
  21. using System.Windows.Navigation;
  22. using System.Windows.Shapes;
  23. using System.Windows.Threading;
  24. namespace BeDesignerSCADA.Controls
  25. {
  26. /// <summary>
  27. /// MenuRunCanvas.xaml 的交互逻辑
  28. /// </summary>
  29. public partial class MenuRunCanvas : UserControl
  30. {
  31. MenuRunCanvasModel menuRunCanvasModel = null;
  32. ResourceDictionary languageResDic = new ResourceDictionary();
  33. DispatcherTimer timer1;//控制菜单显示隐藏功能
  34. public MenuRunCanvas()
  35. {
  36. InitializeComponent();
  37. languageResDic.Source = new Uri(@"/BPASmartClient.SCADAControl;component/Themes/Generic.xaml", UriKind.RelativeOrAbsolute);
  38. menuRunCanvasModel =new MenuRunCanvasModel();
  39. this.DataContext=menuRunCanvasModel;
  40. timer1 = new DispatcherTimer();
  41. timer1.Tick += new System.EventHandler(timer1_Tick);
  42. timer1.Interval = new TimeSpan(0, 0, 0, 0, 1000);
  43. timer1.Start();
  44. this.Loaded += MenuRunCanvas_Loaded;
  45. }
  46. private void MenuRunCanvas_Loaded(object sender, RoutedEventArgs e)
  47. {
  48. if (menuRunCanvasModel.MenuModel != null)
  49. {
  50. switch (menuRunCanvasModel.MenuModel.Alignment)
  51. {
  52. case MenuAlignment.左边:
  53. menuWidth = wrapanl_main.ActualWidth;
  54. break;
  55. case MenuAlignment.顶部:
  56. menuWidth = wrapanl_main.ActualHeight;
  57. break;
  58. case MenuAlignment.右边:
  59. menuWidth = wrapanl_main.ActualWidth;
  60. break;
  61. case MenuAlignment.底部:
  62. menuWidth = wrapanl_main.ActualHeight;
  63. break;
  64. default:
  65. break;
  66. }
  67. MenuSmall();
  68. }
  69. }
  70. private void timer1_Tick(object sender, EventArgs e)
  71. {
  72. times += 1;
  73. }
  74. /// <summary>
  75. /// 根据路径运行程序
  76. /// </summary>
  77. public void LoadingData(string path)
  78. {
  79. RunMenu(BinaryFile.ReadBinary<MenuModel>(path) as MenuModel);
  80. }
  81. /// <summary>
  82. /// 运行菜单
  83. /// </summary>
  84. /// <param name="canvas"></param>
  85. public void RunMenu(MenuModel canvas)
  86. {
  87. int k = 0;
  88. ItemsPanelTemplate itemsPanelTemplate = new ItemsPanelTemplate();
  89. FrameworkElementFactory _StackPanel = new FrameworkElementFactory(typeof(StackPanel));
  90. switch (canvas.Alignment)
  91. {
  92. case MenuAlignment.左边:
  93. if(!string.IsNullOrEmpty(canvas.Name))
  94. k = (canvas.Name.Length / 5 -1+ (canvas.Name.Length % 5 > 0 ? 1 : 0))*15;
  95. //左边菜单栏
  96. PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
  97. PageList.VerticalAlignment = VerticalAlignment.Top;
  98. PageList.Margin = new Thickness(10,70+ k, 10,110);
  99. PageList.Padding = new Thickness(0,0,0,0);
  100. _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
  101. //标题栏
  102. TitleName.Margin = new Thickness(0, 10, 0, 10);
  103. TitleName.HorizontalAlignment = HorizontalAlignment.Stretch;
  104. TitleName.VerticalAlignment = VerticalAlignment.Top;
  105. border0.Margin = new Thickness(0, 60+k, 0, 0);
  106. border0.LayoutTransform = new RotateTransform() { Angle = 0 };
  107. border0.HorizontalAlignment = HorizontalAlignment.Stretch;
  108. border0.VerticalAlignment = VerticalAlignment.Top;
  109. border1.Margin = new Thickness(0, 0, 0, 100);
  110. border1.LayoutTransform = new RotateTransform() { Angle = 0 };
  111. border1.HorizontalAlignment = HorizontalAlignment.Stretch;
  112. border1.VerticalAlignment = VerticalAlignment.Bottom;
  113. //内部Grid
  114. wrapanl_main.HorizontalAlignment = HorizontalAlignment.Left;
  115. wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch;
  116. wrapanl_main.Margin = new Thickness(0, 0, 0, 25);
  117. //外部Stackpanl
  118. waibustack.Orientation = Orientation.Horizontal;
  119. waibustack.HorizontalAlignment = HorizontalAlignment.Left;
  120. //拉出按钮
  121. lachu.HorizontalAlignment = HorizontalAlignment.Left;
  122. lachu.VerticalAlignment = VerticalAlignment.Stretch;
  123. lachu.BorderThickness = new Thickness(1, 0, 0, 0);
  124. //closeGrid
  125. closeGrid.HorizontalAlignment = HorizontalAlignment.Center;
  126. closeGrid.VerticalAlignment = VerticalAlignment.Bottom;
  127. closeGrid.Margin = new Thickness(10);
  128. ButClose.Margin = new Thickness(0, 5, 0, 0);
  129. break;
  130. case MenuAlignment.顶部:
  131. //左边菜单栏
  132. PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
  133. PageList.VerticalAlignment = VerticalAlignment.Top;
  134. PageList.Margin = new Thickness(140,0 , 120, 0);
  135. PageList.Padding = new Thickness(0, 0, 0, 0);
  136. _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
  137. //标题栏
  138. TitleName.LayoutTransform = new RotateTransform() { Angle = 0 };
  139. TitleName.Margin = new Thickness(10, 10, 10, 10);
  140. TitleName.HorizontalAlignment = HorizontalAlignment.Left;
  141. TitleName.VerticalAlignment = VerticalAlignment.Center;
  142. TitleName.Width = 110;
  143. border0.Margin = new Thickness(130, 0, 0, 0);
  144. border0.HorizontalAlignment = HorizontalAlignment.Left;
  145. border0.VerticalAlignment = VerticalAlignment.Stretch;
  146. border0.LayoutTransform = new RotateTransform() { Angle = 90 };
  147. border1.Margin = new Thickness(0, 0, 110,0 );
  148. border1.HorizontalAlignment = HorizontalAlignment.Right;
  149. border1.VerticalAlignment = VerticalAlignment.Stretch;
  150. border1.LayoutTransform = new RotateTransform() { Angle = 90 };
  151. //内部Grid
  152. wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch;
  153. wrapanl_main.VerticalAlignment = VerticalAlignment.Top;
  154. wrapanl_main.Margin = new Thickness(0, 0, 0, 0);
  155. //外部Stackpanl
  156. waibustack.Orientation = Orientation.Vertical;
  157. waibustack.VerticalAlignment = VerticalAlignment.Top;
  158. //拉出按钮
  159. lachu.HorizontalAlignment = HorizontalAlignment.Stretch;
  160. lachu.VerticalAlignment = VerticalAlignment.Top;
  161. lachu.LayoutTransform = new RotateTransform() { Angle = 270 };
  162. lachu.BorderThickness = new Thickness(0, 0, 1, 0);
  163. //closeGrid
  164. closeGrid.HorizontalAlignment = HorizontalAlignment.Right;
  165. closeGrid.VerticalAlignment = VerticalAlignment.Center;
  166. closeGrid.Margin = new Thickness(10, 0, 10, 0);
  167. ButClose.Margin = new Thickness(0,5, 0, 0);
  168. break;
  169. case MenuAlignment.右边:
  170. k = (canvas.Name.Length / 5 - 1 + (canvas.Name.Length % 5 > 0 ? 1 : 0)) * 15;
  171. //左边菜单栏
  172. PageList.HorizontalAlignment = HorizontalAlignment.Right;
  173. PageList.VerticalAlignment = VerticalAlignment.Stretch;
  174. PageList.Margin = new Thickness(10, 70 + k, 10, 110);
  175. PageList.Padding = new Thickness(0, 0, 0, 0);
  176. _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Vertical);
  177. //标题栏
  178. TitleName.Margin = new Thickness(0, 10, 0, 10);
  179. TitleName.HorizontalAlignment = HorizontalAlignment.Stretch;
  180. TitleName.VerticalAlignment = VerticalAlignment.Top;
  181. border0.Margin = new Thickness(0, 60 + k, 0, 0);
  182. border0.LayoutTransform = new RotateTransform() { Angle = 0 };
  183. border0.HorizontalAlignment = HorizontalAlignment.Stretch;
  184. border0.VerticalAlignment = VerticalAlignment.Top;
  185. border1.Margin = new Thickness(0, 0, 0, 100);
  186. border1.LayoutTransform = new RotateTransform() { Angle = 0 };
  187. border1.HorizontalAlignment = HorizontalAlignment.Stretch;
  188. border1.VerticalAlignment = VerticalAlignment.Bottom;
  189. //内部Grid
  190. wrapanl_main.HorizontalAlignment = HorizontalAlignment.Right;
  191. wrapanl_main.VerticalAlignment = VerticalAlignment.Stretch;
  192. wrapanl_main.Margin = new Thickness(0, 0, 0, 25);
  193. //外部Stackpanl
  194. waibustack.Orientation = Orientation.Horizontal;
  195. waibustack.HorizontalAlignment = HorizontalAlignment.Right;
  196. //拉出按钮
  197. lachu.HorizontalAlignment = HorizontalAlignment.Right;
  198. lachu.VerticalAlignment = VerticalAlignment.Stretch;
  199. lachu.BorderThickness = new Thickness(0, 0, 1, 0);
  200. //closeGrid
  201. closeGrid.HorizontalAlignment = HorizontalAlignment.Center;
  202. closeGrid.VerticalAlignment = VerticalAlignment.Bottom;
  203. closeGrid.Margin = new Thickness(10);
  204. ButClose.Margin = new Thickness(0, 5, 0, 0);
  205. FrameworkElement border = null;
  206. foreach (FrameworkElement item in waibustack.Children)
  207. {
  208. if (item is Border)
  209. border = item;
  210. }
  211. waibustack.Children.Remove(border);
  212. waibustack.Children.Insert(0,border);
  213. break;
  214. case MenuAlignment.底部:
  215. //左边菜单栏
  216. PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
  217. PageList.VerticalAlignment = VerticalAlignment.Bottom;
  218. PageList.Margin = new Thickness(140, 0, 120, 0);
  219. PageList.Padding = new Thickness(0, 0, 0, 0);
  220. _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
  221. //标题栏
  222. TitleName.LayoutTransform = new RotateTransform() { Angle = 0 };
  223. TitleName.Margin = new Thickness(10, 10, 10, 10);
  224. TitleName.HorizontalAlignment = HorizontalAlignment.Left;
  225. TitleName.VerticalAlignment = VerticalAlignment.Center;
  226. TitleName.Width = 110;
  227. border0.Margin = new Thickness(130, 0, 0, 0);
  228. border0.HorizontalAlignment = HorizontalAlignment.Left;
  229. border0.VerticalAlignment = VerticalAlignment.Stretch;
  230. border0.LayoutTransform = new RotateTransform() { Angle = 90 };
  231. border1.Margin = new Thickness(0, 0, 110, 0);
  232. border1.HorizontalAlignment = HorizontalAlignment.Right;
  233. border1.VerticalAlignment = VerticalAlignment.Stretch;
  234. border1.LayoutTransform = new RotateTransform() { Angle = 90 };
  235. //内部Grid
  236. wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch;
  237. wrapanl_main.VerticalAlignment = VerticalAlignment.Bottom;
  238. wrapanl_main.Margin = new Thickness(0, 0, 0, 0);
  239. //外部Stackpanl
  240. waibustack.Orientation = Orientation.Vertical;
  241. waibustack.VerticalAlignment = VerticalAlignment.Bottom;
  242. waibustack.Margin = new Thickness(0, 0, 0, 25);
  243. //拉出按钮
  244. lachu.HorizontalAlignment = HorizontalAlignment.Stretch;
  245. lachu.VerticalAlignment = VerticalAlignment.Bottom;
  246. lachu.LayoutTransform = new RotateTransform() { Angle = 270 };
  247. lachu.BorderThickness = new Thickness(1, 0, 0, 0);
  248. lachu.Margin = new Thickness(0, 0, 0, 0);
  249. //closeGrid
  250. closeGrid.HorizontalAlignment = HorizontalAlignment.Right;
  251. closeGrid.VerticalAlignment = VerticalAlignment.Center;
  252. closeGrid.Margin = new Thickness(10, 0, 10, 0);
  253. ButClose.Margin = new Thickness(0, 5, 0, 0);
  254. border = null;
  255. foreach (FrameworkElement item in waibustack.Children)
  256. {
  257. if (item is Border)
  258. border = item;
  259. }
  260. waibustack.Children.Remove(border);
  261. waibustack.Children.Insert(0, border);
  262. break;
  263. default:
  264. break;
  265. }
  266. if(canvas.IsVisibility)
  267. waibustack.Visibility = Visibility.Visible;
  268. else
  269. waibustack.Visibility = Visibility.Collapsed;
  270. itemsPanelTemplate.VisualTree = _StackPanel;
  271. PageList.ItemsPanel = itemsPanelTemplate;
  272. menuRunCanvasModel.MenuModel = canvas;
  273. menuRunCanvasModel.border = main;
  274. menuRunCanvasModel.MenuModel?.pageModels?.ToList().ForEach(par =>
  275. {
  276. List<FrameworkElement> Children = new List<FrameworkElement>();
  277. par.visual = new CanvasPanel();
  278. par?.ChildrenStr?.ForEach(k =>
  279. {
  280. FrameworkElement item = XamlReader.Parse(k) as FrameworkElement;
  281. par.visual.Children.Add(item);
  282. FrameworkElement item1 = XamlReader.Parse(k) as FrameworkElement;
  283. Children.Add(item1);
  284. });
  285. RunCanvas runCanvas = new RunCanvas();
  286. runCanvas.Init(Children);
  287. par.runCanvas = runCanvas;
  288. });
  289. if (menuRunCanvasModel.MenuModel.pageModels.Count > 0)
  290. {
  291. menuRunCanvasModel.MenuModel.SelectPageModels = menuRunCanvasModel.MenuModel.pageModels[0];
  292. main.Child = menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas;
  293. menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas.RunSelect();
  294. }
  295. }
  296. /// <summary>
  297. /// 父窗体控制事件
  298. /// </summary>
  299. /// <param name="obj"></param>
  300. public void PandClick(Window obj)
  301. {
  302. this.ButClose.Click += (o, e) =>
  303. {
  304. MessageBoxResult res = MessageBox.Show("确定关闭上位机软件?", "警告", MessageBoxButton.OKCancel);
  305. if (res == MessageBoxResult.OK)
  306. {
  307. obj.Close();
  308. }
  309. };
  310. this.waibustack.MouseLeftButtonDown += (o, e) =>
  311. {
  312. if (e.ClickCount > 1)
  313. {
  314. if (obj.WindowState == WindowState.Maximized)
  315. obj.WindowState = WindowState.Normal;
  316. else if (obj.WindowState == WindowState.Normal)
  317. obj.WindowState = WindowState.Maximized;
  318. }
  319. if (e.LeftButton == MouseButtonState.Pressed) obj.DragMove();
  320. };
  321. }
  322. bool ismove = true;
  323. int times = 0;
  324. /// <summary>
  325. /// 鼠标移动
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. /// <param name="e"></param>
  329. private void wrapanl_main_MouseMove(object sender, MouseEventArgs e)
  330. {
  331. if (times < 1)
  332. {
  333. return;
  334. }
  335. if (ismove)
  336. {
  337. ismove = false;
  338. MenuBig();
  339. }
  340. times = 0;
  341. }
  342. /// <summary>
  343. /// 鼠标离开
  344. /// </summary>
  345. /// <param name="sender"></param>
  346. /// <param name="e"></param>
  347. private void wrapanl_main_MouseLeave(object sender, MouseEventArgs e)
  348. {
  349. menuWidthDefault = 0;
  350. if (!ismove)
  351. {
  352. ismove = true;
  353. MenuSmall();
  354. }
  355. times = 0;
  356. }
  357. private int menuWidthDefault = 0;
  358. private double menuWidth = 86;
  359. private void MenuBig()
  360. {
  361. DoubleAnimation da = new DoubleAnimation();
  362. da.From = menuWidthDefault;
  363. da.To = menuWidth;
  364. da.Duration = TimeSpan.FromSeconds(0.1);
  365. if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
  366. {
  367. wrapanl_main.BeginAnimation(WidthProperty, da);
  368. if (languageResDic.Contains("image左1"))
  369. lachuStyle.Style = languageResDic["image左1"] as Style;
  370. }
  371. else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
  372. {
  373. wrapanl_main.BeginAnimation(HeightProperty, da);
  374. if (languageResDic.Contains("image右1"))
  375. lachuStyle.Style = languageResDic["image右1"] as Style;
  376. }
  377. }
  378. private void MenuSmall()
  379. {
  380. DoubleAnimation da = new DoubleAnimation();
  381. da.From = menuWidth;
  382. da.To = menuWidthDefault;
  383. da.Duration = TimeSpan.FromSeconds(0.1);
  384. if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
  385. {
  386. if (languageResDic.Contains("image右1"))
  387. lachuStyle.Style = languageResDic["image右1"] as Style;
  388. wrapanl_main.BeginAnimation(WidthProperty, da);
  389. }
  390. else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
  391. {
  392. wrapanl_main.BeginAnimation(HeightProperty, da);
  393. if (languageResDic.Contains("image左1"))
  394. lachuStyle.Style = languageResDic["image左1"] as Style;
  395. }
  396. }
  397. }
  398. /// <summary>
  399. /// 运行Model
  400. /// </summary>
  401. public class MenuRunCanvasModel : ObservableObject
  402. {
  403. /// <summary>
  404. /// 菜单Model
  405. /// </summary>
  406. private MenuModel _MenuModel;
  407. public MenuModel MenuModel
  408. {
  409. get
  410. {
  411. return _MenuModel;
  412. }
  413. set
  414. {
  415. _MenuModel = value;
  416. OnPropertyChanged("MenuModel");
  417. }
  418. }
  419. public RelayCommand<object> MenSelectPageCommand { get; set; }
  420. public Border border { get; set; }
  421. public MenuRunCanvasModel()
  422. {
  423. MenuModel = new MenuModel();
  424. MenuModel.pageModels = new ObservableCollection<PageModel>();
  425. MenuModel.pageModels.Add(new PageModel { Name = "首页面", Sort = 0 });
  426. MenuModel.SelectPageModels = MenuModel.pageModels[0];
  427. MenSelectPageCommand = new RelayCommand<object>(new Action<object?>(SelectPageHeader));
  428. }
  429. /// <summary>
  430. /// 选中该页
  431. /// </summary>
  432. /// <param name="obj"></param>
  433. public void SelectPageHeader(object obj)
  434. {
  435. try
  436. {
  437. //MenuModel.SelectPageModels.runCanvas.Destory();
  438. MenuModel.SelectPageModels = obj as PageModel;
  439. border.Child = MenuModel.SelectPageModels.runCanvas;
  440. MenuModel.SelectPageModels.runCanvas.RunSelect();
  441. }
  442. catch (Exception ex)
  443. {
  444. }
  445. }
  446. }
  447. }