终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

443 lines
20 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(1, 0, 0, 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. break;
  206. case MenuAlignment.底部:
  207. //左边菜单栏
  208. PageList.HorizontalAlignment = HorizontalAlignment.Stretch;
  209. PageList.VerticalAlignment = VerticalAlignment.Bottom;
  210. PageList.Margin = new Thickness(140, 0, 120, 0);
  211. PageList.Padding = new Thickness(0, 0, 0, 0);
  212. _StackPanel.SetValue(StackPanel.OrientationProperty, Orientation.Horizontal);
  213. //标题栏
  214. TitleName.LayoutTransform = new RotateTransform() { Angle = 0 };
  215. TitleName.Margin = new Thickness(10, 10, 10, 10);
  216. TitleName.HorizontalAlignment = HorizontalAlignment.Left;
  217. TitleName.VerticalAlignment = VerticalAlignment.Center;
  218. TitleName.Width = 110;
  219. border0.Margin = new Thickness(130, 0, 0, 0);
  220. border0.HorizontalAlignment = HorizontalAlignment.Left;
  221. border0.VerticalAlignment = VerticalAlignment.Stretch;
  222. border0.LayoutTransform = new RotateTransform() { Angle = 90 };
  223. border1.Margin = new Thickness(0, 0, 110, 0);
  224. border1.HorizontalAlignment = HorizontalAlignment.Right;
  225. border1.VerticalAlignment = VerticalAlignment.Stretch;
  226. border1.LayoutTransform = new RotateTransform() { Angle = 90 };
  227. //内部Grid
  228. wrapanl_main.HorizontalAlignment = HorizontalAlignment.Stretch;
  229. wrapanl_main.VerticalAlignment = VerticalAlignment.Bottom;
  230. wrapanl_main.Margin = new Thickness(0, 0, 0, 0);
  231. //外部Stackpanl
  232. waibustack.Orientation = Orientation.Vertical;
  233. waibustack.VerticalAlignment = VerticalAlignment.Bottom;
  234. //拉出按钮
  235. lachu.HorizontalAlignment = HorizontalAlignment.Stretch;
  236. lachu.VerticalAlignment = VerticalAlignment.Bottom;
  237. lachu.LayoutTransform = new RotateTransform() { Angle = 270 };
  238. lachu.BorderThickness = new Thickness(0, 0, 1, 0);
  239. //closeGrid
  240. closeGrid.HorizontalAlignment = HorizontalAlignment.Right;
  241. closeGrid.VerticalAlignment = VerticalAlignment.Center;
  242. closeGrid.Margin = new Thickness(10, 0, 10, 0);
  243. ButClose.Margin = new Thickness(0, 5, 0, 0);
  244. break;
  245. default:
  246. break;
  247. }
  248. if(canvas.IsVisibility)
  249. waibustack.Visibility = Visibility.Visible;
  250. else
  251. waibustack.Visibility = Visibility.Collapsed;
  252. itemsPanelTemplate.VisualTree = _StackPanel;
  253. PageList.ItemsPanel = itemsPanelTemplate;
  254. menuRunCanvasModel.MenuModel = canvas;
  255. menuRunCanvasModel.border = main;
  256. menuRunCanvasModel.MenuModel?.pageModels?.ToList().ForEach(par =>
  257. {
  258. List<FrameworkElement> Children = new List<FrameworkElement>();
  259. par.visual = new CanvasPanel();
  260. par?.ChildrenStr?.ForEach(k =>
  261. {
  262. FrameworkElement item = XamlReader.Parse(k) as FrameworkElement;
  263. par.visual.Children.Add(item);
  264. FrameworkElement item1 = XamlReader.Parse(k) as FrameworkElement;
  265. Children.Add(item1);
  266. });
  267. RunCanvas runCanvas = new RunCanvas();
  268. runCanvas.Init(Children);
  269. par.runCanvas = runCanvas;
  270. });
  271. if (menuRunCanvasModel.MenuModel.pageModels.Count > 0)
  272. {
  273. menuRunCanvasModel.MenuModel.SelectPageModels = menuRunCanvasModel.MenuModel.pageModels[0];
  274. main.Child = menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas;
  275. menuRunCanvasModel.MenuModel.SelectPageModels.runCanvas.RunSelect();
  276. }
  277. }
  278. /// <summary>
  279. /// 父窗体控制事件
  280. /// </summary>
  281. /// <param name="obj"></param>
  282. public void PandClick(Window obj)
  283. {
  284. this.ButClose.Click += (o, e) =>
  285. {
  286. MessageBoxResult res = MessageBox.Show("确定关闭上位机软件?", "警告", MessageBoxButton.OKCancel);
  287. if (res == MessageBoxResult.OK)
  288. {
  289. obj.Close();
  290. }
  291. };
  292. this.waibustack.MouseLeftButtonDown += (o, e) =>
  293. {
  294. if (e.ClickCount > 1)
  295. {
  296. if (obj.WindowState == WindowState.Maximized)
  297. obj.WindowState = WindowState.Normal;
  298. else if (obj.WindowState == WindowState.Normal)
  299. obj.WindowState = WindowState.Maximized;
  300. }
  301. if (e.LeftButton == MouseButtonState.Pressed) obj.DragMove();
  302. };
  303. }
  304. bool ismove = true;
  305. int times = 0;
  306. /// <summary>
  307. /// 鼠标移动
  308. /// </summary>
  309. /// <param name="sender"></param>
  310. /// <param name="e"></param>
  311. private void wrapanl_main_MouseMove(object sender, MouseEventArgs e)
  312. {
  313. if (times < 1)
  314. {
  315. return;
  316. }
  317. if (ismove)
  318. {
  319. ismove = false;
  320. MenuBig();
  321. }
  322. times = 0;
  323. }
  324. /// <summary>
  325. /// 鼠标离开
  326. /// </summary>
  327. /// <param name="sender"></param>
  328. /// <param name="e"></param>
  329. private void wrapanl_main_MouseLeave(object sender, MouseEventArgs e)
  330. {
  331. menuWidthDefault = 0;
  332. if (!ismove)
  333. {
  334. ismove = true;
  335. MenuSmall();
  336. }
  337. times = 0;
  338. }
  339. private int menuWidthDefault = 0;
  340. private double menuWidth = 86;
  341. private void MenuBig()
  342. {
  343. DoubleAnimation da = new DoubleAnimation();
  344. da.From = menuWidthDefault;
  345. da.To = menuWidth;
  346. da.Duration = TimeSpan.FromSeconds(0.1);
  347. if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
  348. {
  349. wrapanl_main.BeginAnimation(WidthProperty, da);
  350. if (languageResDic.Contains("image左1"))
  351. lachuStyle.Style = languageResDic["image左1"] as Style;
  352. }
  353. else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
  354. {
  355. wrapanl_main.BeginAnimation(HeightProperty, da);
  356. if (languageResDic.Contains("image右1"))
  357. lachuStyle.Style = languageResDic["image右1"] as Style;
  358. }
  359. }
  360. private void MenuSmall()
  361. {
  362. DoubleAnimation da = new DoubleAnimation();
  363. da.From = menuWidth;
  364. da.To = menuWidthDefault;
  365. da.Duration = TimeSpan.FromSeconds(0.1);
  366. if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.左边 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.右边)
  367. {
  368. if (languageResDic.Contains("image右1"))
  369. lachuStyle.Style = languageResDic["image右1"] as Style;
  370. wrapanl_main.BeginAnimation(WidthProperty, da);
  371. }
  372. else if (menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.顶部 || menuRunCanvasModel.MenuModel.Alignment == MenuAlignment.底部)
  373. {
  374. wrapanl_main.BeginAnimation(HeightProperty, da);
  375. if (languageResDic.Contains("image左1"))
  376. lachuStyle.Style = languageResDic["image左1"] as Style;
  377. }
  378. }
  379. }
  380. /// <summary>
  381. /// 运行Model
  382. /// </summary>
  383. public class MenuRunCanvasModel : ObservableObject
  384. {
  385. /// <summary>
  386. /// 菜单Model
  387. /// </summary>
  388. private MenuModel _MenuModel;
  389. public MenuModel MenuModel
  390. {
  391. get
  392. {
  393. return _MenuModel;
  394. }
  395. set
  396. {
  397. _MenuModel = value;
  398. OnPropertyChanged("MenuModel");
  399. }
  400. }
  401. public RelayCommand<object> MenSelectPageCommand { get; set; }
  402. public Border border { get; set; }
  403. public MenuRunCanvasModel()
  404. {
  405. MenuModel = new MenuModel();
  406. MenuModel.pageModels = new ObservableCollection<PageModel>();
  407. MenuModel.pageModels.Add(new PageModel { Name = "首页面", Sort = 0 });
  408. MenuModel.SelectPageModels = MenuModel.pageModels[0];
  409. MenSelectPageCommand = new RelayCommand<object>(new Action<object?>(SelectPageHeader));
  410. }
  411. /// <summary>
  412. /// 选中该页
  413. /// </summary>
  414. /// <param name="obj"></param>
  415. public void SelectPageHeader(object obj)
  416. {
  417. try
  418. {
  419. //MenuModel.SelectPageModels.runCanvas.Destory();
  420. MenuModel.SelectPageModels = obj as PageModel;
  421. border.Child = MenuModel.SelectPageModels.runCanvas;
  422. MenuModel.SelectPageModels.runCanvas.RunSelect();
  423. }
  424. catch (Exception ex)
  425. {
  426. }
  427. }
  428. }
  429. }