首次上传

This commit is contained in:
hanqiangqiang
2026-06-15 10:56:30 +08:00
commit b0213b94d6
4160 changed files with 736101 additions and 0 deletions
@@ -0,0 +1,111 @@
<UserControl x:Class="Aitex.Core.UI.View.Frame.BottomView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="70" d:DesignWidth="300">
<UserControl.Resources>
<LinearGradientBrush x:Key="buttonNormal" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#0086cd" Offset="0" />
<GradientStop Color="#389cd0" Offset="1" />
</LinearGradientBrush>
<SolidColorBrush x:Key="buttonForground" Color="White"></SolidColorBrush>
<SolidColorBrush x:Key="buttonBorder" Color="#62b8e5"></SolidColorBrush>
<LinearGradientBrush x:Key="buttonHover" StartPoint="0.5,0" EndPoint="0.5,1">
<GradientStop Color="#668fa5" Offset="0" />
<GradientStop Color="#3c6982" Offset="1" />
</LinearGradientBrush>
<Style x:Key="exitButton" TargetType="Button">
<Setter Property="Background" Value="{StaticResource buttonNormal}"></Setter>
<Setter Property="Foreground" Value="{StaticResource buttonForground}"></Setter>
<Setter Property="BorderBrush" Value="{StaticResource buttonBorder}"></Setter>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Margin" Value="5"/>
<Setter Property="FontFamily" Value="Arial,SimSun" />
<Setter Property="FontSize" Value="22"/>
<Setter Property="Height" Value="45"></Setter>
<Setter Property="Width" Value="160"></Setter>
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
<Setter Property="VerticalAlignment" Value="Top"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}"
SnapsToDevicePixels="true" CornerRadius="3,3,3,3">
<ContentPresenter x:Name="contentPresenter"
Focusable="False"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
RecognizesAccessKey="True"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" TargetName="border" Value="{StaticResource buttonHover}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="Button" x:Key="navButton">
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Foreground" Value="{DynamicResource BtmnavButton_FG}" />
<Setter Property="BorderBrush" Value="Blue" />
<Setter Property="Margin" Value="5"/>
<Setter Property="FontFamily" Value="Arial,SimSun" />
<Setter Property="FontSize" Value="22"/>
<Setter Property="Height" Value="45"></Setter>
<Setter Property="Width" Value="160"></Setter>
<Setter Property="HorizontalAlignment" Value="Right"></Setter>
<Setter Property="VerticalAlignment" Value="Top"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ButtonBase">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<ContentPresenter Content="{TemplateBinding ContentControl.Content}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" Margin="{TemplateBinding Control.Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮.png">
</ImageBrush>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮_悬停.png">
</ImageBrush>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" >
<Setter.Value>
<ImageBrush ImageSource="pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮_点击.png">
</ImageBrush>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid x:Name="gridContent" Background="{StaticResource mainBackgroundColor}">
<!--<Button x:Name="btnBackward" Visibility="Hidden" Tag="Backward" VerticalAlignment="Center" Style="{StaticResource NavUpButton}" Click="btn_Click" Margin="82,0,0,0" />-->
<Button x:Name="btnExit" Tag="Exit" Content="{DynamicResource GlobalLableButtonExit}" VerticalAlignment="Center" Style="{StaticResource navButton}" Click="btn_Click" Margin="0,0,166,10" />
<!--<Image Width="34" Height="37" HorizontalAlignment="Left" Source="/MECF.Framework.Common;component/Resources/Main/下一个.png" Margin="82,0,0,10" />-->
<!--<Image Width="34" Height="37" HorizontalAlignment="Right" Source="/MECF.Framework.Common;component/Resources/Main/下一个.png" Margin="0,0,82,10" />-->
<!--<Button x:Name="btnForward" Visibility="Hidden" Tag="Forward" VerticalAlignment="Center" Style="{StaticResource NavBackButton}" Click="btn_Click" Margin="0,0,82,0"/>-->
</Grid>
</UserControl>
@@ -0,0 +1,134 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
namespace Aitex.Core.UI.View.Frame
{
/// <summary>
/// Interaction logic for BottomView.xaml
/// </summary>
///
partial class BottomView : UserControl
{
private int ButtonMarginLeft = 60;
Size ButtonSizeSelected = new Size(160, 45);
Size ButtonSizeUnselected = new Size(145, 38);
public event Action<string> ButtonClicked;
public BottomView()
{
InitializeComponent();
//btnBackward.Tag = new ViewItem()
//{
// Id = "backward",
//};
btnExit.Tag = new ViewItem()
{
Id = "exit",
};
//btnForward.Tag = new ViewItem()
//{
// Id = "forward",
//};
}
public void CreateMenu(List<ViewItem> items)
{
//double marginLeft = btnBackward.Margin.Left + btnBackward.Width + 50;
double marginLeft = ButtonSizeUnselected.Width;
foreach (ViewItem item in items)
{
Button btn = new Button();
btn.Style = Resources["navButton"] as Style;
btn.Margin = new Thickness(marginLeft, btnExit.Margin.Top, 0, 10);
btn.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btn.VerticalAlignment = System.Windows.VerticalAlignment.Center;
btn.Content = item.Name;
btn.Tag = item;
btn.Click += new RoutedEventHandler(btn_Click);
marginLeft += (btn.Width + ButtonMarginLeft);
gridContent.Children.Add(btn);
}
}
void btn_Click(object sender, RoutedEventArgs e)
{
if (ButtonClicked != null)
{
ButtonClicked(((sender as Button).Tag as ViewItem).Id);
}
}
public void SetSelection(string id)
{
ImageBrush NormalBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮150.png", UriKind.Absolute)));
ImageBrush SelectedBrush = new ImageBrush(new BitmapImage(new Uri("pack://application:,,,/MECF.Framework.Common;component/Resources/Main/主菜单按钮_选中150.png", UriKind.Absolute)));
foreach (var item in gridContent.Children)
{
Button btn = item as Button;
if ((btn==null) || ((btn.Tag as ViewItem).Name == null))
continue;
btn.Background = ((btn.Tag as ViewItem).Id == id) ? SelectedBrush : NormalBrush;
btn.Height = ((btn.Tag as ViewItem).Id == id) ? 45: 38;
btn.Width = ((btn.Tag as ViewItem).Id == id) ? 160 : 145;
}
}
public void Enable(string id, bool enable)
{
foreach (var item in gridContent.Children)
{
Button btn = item as Button;
if (btn == null)
continue;
if ((btn.Tag as ViewItem).Name == null)
continue;
if ((btn.Tag as ViewItem).Id != id)
continue;
btn.Visibility = !enable ? Visibility.Hidden : Visibility.Visible;
}
}
public void SetCulture(string culture)
{
foreach (var item in gridContent.Children)
{
Button btn = item as Button;
if (btn == null)
continue;
ViewItem info = btn.Tag as ViewItem;
if (info==null || info.Name==null || info.GlobalName==null || !info.GlobalName.ContainsKey(culture))
continue;
btn.Content = info.GlobalName[culture];
}
}
}
}
@@ -0,0 +1,15 @@
<UserControl x:Class="Aitex.Core.UI.View.Frame.CenterTabView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
Width="auto" Height="800">
<Grid Background="#FF2CA1DE">
<TabControl Background="{StaticResource mainCenterBackgroundColor}"
Padding="0,0,0,0"
x:Name="TabContainer"
Grid.Column="1"
BorderThickness="0">
</TabControl>
</Grid>
</UserControl>
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using Aitex.Core.Util;
namespace Aitex.Core.UI.View.Frame
{
/// <summary>
/// Interaction logic for CenterTabView.xaml
/// </summary>
public partial class CenterTabView : UserControl
{
UserControl _uc;
private Dictionary<string, ViewItem> _lstTabs = new Dictionary<string, ViewItem>();
public CenterTabView()
{
InitializeComponent();
}
public void Add(ViewItem item, UserControl view)
{
_uc = view;
TabContainer.Items.Add(new TabItem()
{
Content = view,
Header = item.Name,
IsSelected = false,
Tag = item.Id,
});
_lstTabs[item.Id] = item;
}
public UserControl GetContentView()
{
return _uc;
}
public UserControl FindView(string id)
{
foreach (TabItem item in TabContainer.Items)
if (item.Tag.ToString() == id)
return (UserControl)item.Content;
return null;
}
public TabItem FindTab(string id)
{
foreach (TabItem item in TabContainer.Items)
if (item.Tag.ToString() == id)
return item;
return null;
}
public void SetCulture(string culture)
{
foreach (TabItem item in TabContainer.Items)
{
ViewItem info = _lstTabs[item.Tag.ToString()];
if (info.GlobalName.ContainsKey(culture))
item.Header = info.GlobalName[culture];
}
}
}
}
@@ -0,0 +1,11 @@
<UserControl x:Class="Aitex.Core.UI.View.Frame.CenterView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
BorderThickness="0" Width="auto" Height="800">
<Grid x:Name="gridContent">
</Grid>
</UserControl>
@@ -0,0 +1,133 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using System.Reflection;
using Aitex.Core.RT.Log;
using MECF.Framework.UI.Core.Applications;
using Autofac;
namespace Aitex.Core.UI.View.Frame
{
/// <summary>
/// Interaction logic for CenterView.xaml
/// </summary>
public partial class CenterView : UserControl
{
Dictionary<string, CenterTabView> _views = new Dictionary<string,CenterTabView>();
public CenterView()
{
InitializeComponent();
}
public void CreateView(List<ViewItem> views )
{
foreach (ViewItem item in views)
{
if (item.SubView == null || item.SubView.Count == 0)
continue;
CenterTabView tab = new CenterTabView();
tab.Tag = item;
foreach (ViewItem subItem in item.SubView)
{
Type t = Assembly.Load(subItem.AssemblyName).GetType(subItem.ViewClass);
if (t == null)
throw new ApplicationException(string.Format("The ui layout config file not valid, can not find {0} at assembly {1}", subItem.ViewClass, subItem.AssemblyName));
UserControl uc;
try
{
using (var scope = UiApplication.Instance.Container.BeginLifetimeScope())
{
if (scope.TryResolve(t, out var target))
{
uc = target as UserControl;
}
else
{
uc = (UserControl)Activator.CreateInstance(t);
}
}
}
catch (Exception ex)
{
LOG.Write(ex);
throw new ApplicationException(string.Format("Failed to initialize UI window {0}, {1}", subItem.ViewClass, ex.Message));
}
tab.Add(subItem, uc);
}
_views[item.Id] = tab;
}
}
public void SetSelection(string id)
{
if (!_views.ContainsKey(id))
return;
_views[id].Height = this.Height ;
gridContent.Children.Clear();
gridContent.Children.Add(_views[id]);
}
public string GetCurrentViewName(string culture)
{
if (gridContent.Children.Count == 0)
return string.Empty;
ViewItem info = (gridContent.Children[0] as CenterTabView).Tag as ViewItem;
if (!string.IsNullOrEmpty(culture) && info.GlobalName.ContainsKey(culture))
return info.GlobalName[culture];
return info.Name;
}
public UserControl GetView(string id)
{
foreach (var item in _views)
{
if (item.Value.FindView(id) != null)
return item.Value.FindView(id);
}
return null;
}
public TabItem GetTab(string id)
{
foreach (var item in _views)
{
if (item.Value.FindTab(id) != null)
return item.Value.FindTab(id);
}
return null;
}
public void SetCulture(string culture)
{
foreach (var item in _views)
{
item.Value.SetCulture(culture);
}
}
}
}
@@ -0,0 +1,11 @@
<UserControl x:Class="MECF.Framework.UI.Core.E95Template.DefaultTopView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MECF.Framework.UI.Core.E95Template"
Width="1920" Height="80" Background="{StaticResource mainBackgroundColor}">
<Grid>
</Grid>
</UserControl>
@@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Linq;
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.Navigation;
using System.Windows.Shapes;
using Aitex.Core.UI.View.Frame;
namespace MECF.Framework.UI.Core.E95Template
{
/// <summary>
/// DefaultTopView.xaml 的交互逻辑
/// </summary>
public partial class DefaultTopView : UserControl, ITopView
{
public DefaultTopView()
{
InitializeComponent();
}
public void SetTitle(string title)
{
}
}
}
@@ -0,0 +1,13 @@
using Aitex.Core.UI.View.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Aitex.Core.UI.View.Frame
{
public interface ITopView : IBaseView
{
void SetTitle(string title);
}
}
@@ -0,0 +1,24 @@
<Window x:Class="Aitex.Core.UI.View.Frame.StandardFrameWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="980" d:DesignWidth="1920"
ShowInTaskbar="True"
WindowState="Maximized">
<Viewbox Stretch="Fill" >
<Border BorderBrush="Gray" BorderThickness="1" Margin="1" CornerRadius="4" Padding="1" >
<Grid x:Name="CenterGrid" Width="1920" Height="1020">
<Grid.RowDefinitions>
<RowDefinition x:Name="TopRow" Height="60" />
<RowDefinition x:Name="CenterRow" Height="890" />
<RowDefinition x:Name="BottomRow" Height="70" />
</Grid.RowDefinitions>
<Grid Grid.Row="0" x:Name="TopPanel" ></Grid>
<Grid Grid.Row="1" x:Name="CenterPanel" ></Grid>
<Grid Grid.Row="2" x:Name="BottomPanel" ></Grid>
</Grid>
</Border>
</Viewbox>
</Window>
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Navigation;
using System.Windows.Shapes;
using Aitex.Core.Util;
namespace Aitex.Core.UI.View.Frame
{
public partial class StandardFrameWindow : Window
{
public UserControl TopView { set; private get; }
public UserControl CenterView { set; private get; }
public UserControl BottomView { set; private get; }
public StandardFrameWindow()
{
InitializeComponent();
this.Loaded += new RoutedEventHandler(StandardFrameWindow_Loaded);
IsVisibleChanged += new DependencyPropertyChangedEventHandler(MainWindow_IsVisibleChanged);
}
void MainWindow_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
}
void StandardFrameWindow_Loaded(object sender, RoutedEventArgs e)
{
if (TopView != null)
TopPanel.Children.Add(TopView);
if (CenterView != null)
CenterPanel.Children.Add(CenterView);
if (BottomView != null)
BottomPanel.Children.Add(BottomView);
}
}
}
@@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
namespace Aitex.Core.UI.View.Frame
{
public class ViewItem
{
public string Id { get; set; }
public string Name { get; set; }
public string ViewClass { get; set; }
public string AssemblyName { get; set; }
public bool IsSelected { get; set; }
public List<ViewItem> SubView { get; set; }
public Dictionary<string, string> GlobalName
{
get; set; }
}
class UILayoutParser
{
public List<string> ViewIdList { get; set; }
public ViewItem TitleView { get; private set; }
public List<ViewItem> NavigationView { get; private set; }
public int PreferTopPanelHeight = -1;
public int PreferCenterPanelHeight = -1;
public int PreferBottomPanelHeight = -1;
public int PreferWidth = -1;
public UILayoutParser(string xmlFile)
{
ViewIdList = new List<string>();
ParseLayout(xmlFile);
}
void ParseLayout(string xmlFile)
{
if (String.IsNullOrEmpty(xmlFile))
throw new ApplicationException("The UI layout config filename is empty,can not initialize UI");
if (!File.Exists(xmlFile))
throw new ApplicationException("Did not find the UI layout config file, " + xmlFile);
XmlDocument doc = new XmlDocument();
try
{
doc.Load(xmlFile);
var node = doc.SelectSingleNode("/MECFUI") as XmlNode;
int parsed = -1;
if (node.Attributes["TopPanelHeight"] != null && int.TryParse(node.Attributes["TopPanelHeight"].Value, out parsed))
{
PreferTopPanelHeight = parsed;
}
if (node.Attributes["CenterPanelHeight"] != null && int.TryParse(node.Attributes["CenterPanelHeight"].Value, out parsed))
{
PreferCenterPanelHeight = parsed;
}
if (node.Attributes["BottomPanelHeight"] != null && int.TryParse(node.Attributes["BottomPanelHeight"].Value, out parsed))
{
PreferBottomPanelHeight = parsed;
}
if (node.Attributes["Width"] != null && int.TryParse(node.Attributes["Width"].Value, out parsed))
{
PreferWidth = parsed;
}
}
catch (Exception ex)
{
throw new ApplicationException("UI layout config file " + xmlFile + " is not valid, " + ex.Message);
}
TitleView = ParseNode(doc.SelectSingleNode("/MECFUI/Title"));
foreach (XmlNode nav in doc.SelectNodes("/MECFUI/Navigation"))
{
ViewItem menu = ParseNode(nav);
if (menu == null)
continue;
foreach (XmlNode ele in nav.SelectNodes("SubView"))
{
if (menu.SubView == null)
menu.SubView = new List<ViewItem>();
ViewItem item = ParseNode(ele);
if (item != null)
{
menu.SubView.Add(item);
ViewIdList.Add(item.Id);
}
}
if (NavigationView == null)
NavigationView = new List<ViewItem>();
NavigationView.Add(menu);
}
}
ViewItem ParseNode(XmlNode node)
{
if (node == null)
return null;
ViewItem item = new ViewItem();
item.GlobalName = new Dictionary<string, string>();
if (node.Attributes["Id"] != null)
item.Id = node.Attributes["Id"].Value;
if (node.Attributes["Name"] != null)
item.Name = node.Attributes["Name"].Value;
if (node.Attributes["Name.en-US"] != null)
item.GlobalName["en-US"] = node.Attributes["Name.en-US"].Value;
if (node.Attributes["Name.zh-CN"] != null)
item.GlobalName["zh-CN"] = node.Attributes["Name.zh-CN"].Value;
if (node.Attributes["ViewClass"] != null)
item.ViewClass = node.Attributes["ViewClass"].Value;
if (node.Attributes["Assembly"] != null)
item.AssemblyName = node.Attributes["Assembly"].Value;
return item;
}
}
}
@@ -0,0 +1,300 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Controls;
using System.Reflection;
using System.Windows;
using Aitex.Core.Account;
using MECF.Framework.Common.Properties;
using MECF.Framework.UI.Core.Properties;
using Autofac;
using Aitex.Core.UI.View.Common;
using MECF.Framework.UI.Core.Applications;
namespace Aitex.Core.UI.View.Frame
{
public class ViewManager
{
public const string Culture_CN = "zh-CN";
public const string Culture_EN = "en-US";
public List<string> GetAllViewList
{
get { return _views == null ? null : _views.ViewIdList; }
}
public string SystemName { get; set; }
public string UILayoutFile { get; set; }
public string ViewAssembly { get; set; }
public ImageSource SystemLogo { get; set; }
public Window MainWindow { get { return _mainWindow; } }
public event Action OnMainWindowLoaded;
public static Account.Account LoginAccount;
public bool MaxSizeShow { get; set; }
UILayoutParser _views;
ITopView _topView;
BottomView _bottomView = new BottomView();
CenterView _centerView = new CenterView();
StandardFrameWindow _mainWindow;
private bool _isLogoff;
private string _culture = "en-US";
public int PreferWidth { get; set; }
public int PreferHeight { get; set; }
public int PreferHeightTopPanel { get; set; }
public int PreferHeightCenterPanel { get; set; }
public int PreferHeightBottomPanel { get; set; }
public ViewManager()
{
PreferWidth = 1920;
PreferHeight = 1020;
PreferHeightTopPanel = 130;
PreferHeightCenterPanel = 800;
PreferHeightBottomPanel = 90;
MaxSizeShow = true;
}
public void InitWindow()
{
_views = new UILayoutParser(UILayoutFile);
if (_views.PreferWidth > 0)
PreferWidth = _views.PreferWidth;
if (_views.PreferTopPanelHeight > 0)
PreferHeightTopPanel = _views.PreferTopPanelHeight;
if (_views.PreferCenterPanelHeight > 0)
PreferHeightCenterPanel = _views.PreferCenterPanelHeight;
if (_views.PreferBottomPanelHeight > 0)
PreferHeightBottomPanel = _views.PreferBottomPanelHeight;
PreferHeight = PreferHeightTopPanel + PreferHeightCenterPanel + PreferHeightBottomPanel;
try
{
using (var scope = UiApplication.Instance.Container.BeginLifetimeScope())
{
var type = Assembly.Load(_views.TitleView.AssemblyName).GetType(_views.TitleView.ViewClass);
_topView = scope.Resolve(type) as ITopView;
}
}
catch (Exception )
{
throw new ApplicationException(string.Format("在程序集{0}中,没有找到{1},请检查UILayout配置文件中的设置", ViewAssembly, _views.TitleView.ViewClass));
}
UserControl uc = (UserControl)_topView;
_bottomView.CreateMenu(_views.NavigationView);
_bottomView.ButtonClicked += new Action<string>(_bottomView_ButtonClicked);
_centerView.CreateView(_views.NavigationView);
}
void _bottomView_ButtonClicked(string obj)
{
UpdateSelection(obj, "");
}
public void ShowMainWindow(bool visible)
{
InitWindow();
_mainWindow = new StandardFrameWindow()
{
TopView = _topView as UserControl,
BottomView = _bottomView,
CenterView = _centerView,
Icon = SystemLogo,
Title = SystemName,
WindowState = MaxSizeShow ? WindowState.Maximized : WindowState.Normal,
};
_mainWindow.CenterGrid.Width = PreferWidth;
_mainWindow.CenterGrid.Height = PreferHeight;
_mainWindow.TopRow.Height = new GridLength(PreferHeightTopPanel);
_mainWindow.CenterRow.Height = new GridLength(PreferHeightCenterPanel);
_mainWindow.BottomRow.Height = new GridLength(PreferHeightBottomPanel);
_centerView.Height = PreferHeightCenterPanel;
_bottomView.Height = PreferHeightBottomPanel;
_mainWindow.UpdateLayout();
UpdateSelection(_views.NavigationView[0].Id, "");
_mainWindow.Closing += new System.ComponentModel.CancelEventHandler(_mainWindow_Closing);
_mainWindow.Loaded += new RoutedEventHandler(_mainWindow_Loaded);
if (visible)
_mainWindow.Show();
}
public void Logoff()
{
_isLogoff = true;
_mainWindow.Close();
}
void _mainWindow_Loaded(object sender, RoutedEventArgs e)
{
if (OnMainWindowLoaded != null)
OnMainWindowLoaded();
}
void _mainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (_isLogoff)
{
e.Cancel = false;
System.Diagnostics.Process.Start(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Application.Current.Shutdown();
return;
}
e.Cancel = !Exit();
}
bool Exit()
{
return MessageBox.Show("Are you sure you want to exit system?", SystemName, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes;
}
void UpdateSelection(string navigationId, string subviewId)
{
if (navigationId == "exit")
{
_mainWindow.Close();
return;
}
_bottomView.SetSelection(navigationId);
_centerView.SetSelection(navigationId);
_topView.SetTitle(_centerView.GetCurrentViewName(_culture));
}
public UserControl FindView(string id)
{
return _centerView.GetView(id);
}
public TabItem FindTab(string id)
{
return _centerView.GetTab(id);
}
public void SetViewPermission(Account.Account account)
{
UserControl userControl;
TabItem tabItem;
LoginAccount = account;
foreach (var dic in account.Permission)
{
userControl = FindView(dic.Key);
tabItem = FindTab(dic.Key);
if (userControl == null)
continue;
switch (dic.Value)
{
case ViewPermission.FullyControl:
case ViewPermission.ProcessOPControl:
userControl.Visibility = Visibility.Visible;
userControl.IsEnabled = true;
break;
case ViewPermission.PartlyControl:
userControl.Visibility = Visibility.Visible;
userControl.IsEnabled = true;
break;
case ViewPermission.Readonly:
userControl.Visibility = Visibility.Visible;
userControl.IsEnabled = dic.Key == "recipe" ? true : false;
break;
case ViewPermission.Invisiable:
userControl.Visibility = Visibility.Hidden;
tabItem.Visibility = Visibility.Hidden;
tabItem.Width = 0;
break;
}
}
foreach (ViewItem item in _views.NavigationView)
{
bool enable = false;
foreach (ViewItem sub in item.SubView)
{
foreach (var dic in account.Permission)
{
if (dic.Key == sub.Id && dic.Value != ViewPermission.Invisiable)
{
enable = true;
break;
}
}
}
_bottomView.Enable(item.Id, enable);
}
}
public void SetCulture(string culture)
{
_culture = culture;
if (_topView != null)
_topView.SetTitle(_centerView.GetCurrentViewName(_culture));
_centerView.SetCulture(culture);
_bottomView.SetCulture(culture);
UpdateCultureResource(culture);
}
private void UpdateCultureResource(string culture)
{
//string culture = language == 2 ? "zh-CN" : "en-US";
//Copy all MergedDictionarys into a auxiliar list.
var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
//Search for the specified culture.
string requestedCulture = string.Format(@"/MECF.Framework.Common;component/Resources/Language/StringResources.{0}.xaml", culture);
var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
if (resourceDictionary == null)
{
//If not found, select our default language.
requestedCulture = "StringResources.xaml";
resourceDictionary = dictionaryList.
FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
}
//If we have the requested resource, remove it from the list and place at the end.
//Then this language will be our string table to use.
if (resourceDictionary != null)
{
Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
}
//Inform the threads of the new culture.
Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
}
}
}