首次上传

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,258 @@
using System.Collections.ObjectModel;
using System.Linq;
using Caliburn.Micro.Core;
using MECF.Framework.Common.Account;
using MECF.Framework.Common.Account.Extends;
using MECF.Framework.Common.Account.Permissions;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RoleItem : PropertyChangedBase
{
#region Constructors
public RoleItem(Role role)
{
Role = role;
DisplayRoleName = RoleName;
DisplayAutoLogoutTime = AutoLogoutTime;
DisplayIsAutoLogout = IsAutoLogout;
DisplayDescription = Description;
}
public RoleItem(string roleId)
{
Role = new Role(roleId, string.Empty, false, 0, null, false, string.Empty);
}
#endregion
#region Properties
public Role Role { get; }
public string RoleId
{
get => Role.RoleId;
set => Role.RoleId = value;
}
public string RoleName
{
get => Role.RoleName;
set => Role.RoleName = value;
}
public int AutoLogoutTime
{
get => Role.LogoutTime;
set => Role.LogoutTime = value;
}
public string Description
{
get => Role.Description;
set => Role.Description = value;
}
public bool IsAutoLogout
{
get => Role.IsAutoLogout;
set => Role.IsAutoLogout = value;
}
public bool IsBuildIn
{
get => Role.IsBuildIn;
set => Role.IsBuildIn = value;
}
private string _displayRoleName;
public string DisplayRoleName
{
get => _displayRoleName;
set
{
_displayRoleName = value;
NotifyOfPropertyChange();
}
}
public int DisplayAutoLogoutTime
{
get;
set;
}
public bool DisplayIsAutoLogout
{
get;
set;
}
public string DisplayDescription
{
get;
set;
}
private bool _isSelected;
public bool IsSelected
{
get => _isSelected;
set { _isSelected = value; NotifyOfPropertyChange(); }
}
private bool _roleNameTextSaved = true;
public bool RoleNameTextSaved
{
get => _roleNameTextSaved;
set
{
if (_roleNameTextSaved != value)
{
_roleNameTextSaved = value;
NotifyOfPropertyChange();
}
}
}
private bool _timeTextSaved = true;
public bool TimeTextSaved
{
get => _timeTextSaved;
set
{
if (_timeTextSaved != value)
{
_timeTextSaved = value;
NotifyOfPropertyChange();
}
}
}
private bool _descriptionTextSaved = true;
public bool DescriptionTextSaved
{
get => _descriptionTextSaved;
set
{
if (_descriptionTextSaved != value)
{
_descriptionTextSaved = value;
NotifyOfPropertyChange();
}
}
}
public ObservableCollection<PermissionControlItem> MenuPermCollection { get; } = new();
public ObservableCollection<PermissionControlItem> RecipePermCollection { get; } = new();
public ObservableCollection<PermissionControlItem> RecipeStepPermCollection { get; } = new();
public ObservableCollection<PermissionControlItem> ContentPermCollection { get; } = new();
#endregion
#region Methods
public void AddMenuInfo(PermissionControlItem pInfo)
{
if (null == pInfo)
return;
MenuPermCollection.Add(pInfo);
}
public void AddRecipeInfo(PermissionControlItem pInfo)
{
if (null == pInfo)
return;
RecipePermCollection.Add(pInfo);
}
public void AddStepInfo(PermissionControlItem pInfo)
{
if (null == pInfo)
return;
RecipeStepPermCollection.Add(pInfo);
}
public void AddContentInfo(PermissionControlItem pInfo)
{
if (null == pInfo)
return;
ContentPermCollection.Add(pInfo);
}
public void UpdateRolePermissionControlItems()
{
foreach (var perm in MenuPermCollection)
{
Role.PermissionControlItems[perm.Name] = perm.Permission.EnumPermission;
}
foreach (var perm in RecipePermCollection)
{
Role.PermissionControlItems[perm.Name] = perm.Permission.EnumPermission;
}
foreach (var perm in RecipeStepPermCollection)
{
Role.PermissionControlItems[perm.Name] = perm.Permission.EnumPermission;
}
foreach (var perm in ContentPermCollection)
{
Role.PermissionControlItems[perm.Name] = perm.Permission.EnumPermission;
}
}
public bool IsRoleChanged()
{
if (DisplayRoleName != Role.RoleName)
return true;
if (DisplayAutoLogoutTime != Role.LogoutTime)
return true;
if (DisplayIsAutoLogout != Role.IsAutoLogout)
return true;
if (DisplayDescription != Role.Description)
return true;
if (MenuPermCollection.Any(item => item.IsChanged))
{
return true;
}
if (RecipePermCollection.Any(item => item.IsChanged))
{
return true;
}
if (RecipeStepPermCollection.Any(item => item.IsChanged))
{
return true;
}
if (ContentPermCollection.Any(item => item.IsChanged))
{
return true;
}
return false;
}
#endregion
}
}
@@ -0,0 +1,286 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Aitex.Core.RT.Log;
using Aitex.Core.Util;
using MECF.Framework.Common.Account.Extends;
using MECF.Framework.Common.Account.Permissions;
using MECF.Framework.Common.DataCenter;
using MECF.Framework.UI.Client.CenterViews.Editors;
using MECF.Framework.UI.Client.ClientBase;
using MECF.Framework.UI.Client.RecipeEditorLib.RecipeModel;
using MECF.Framework.UI.Core.Accounts;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RoleManagerClient : Singleton<RoleManagerClient>
{
#region Variables
private List<AppMenu> _appMenuPermSource;
private List<PermissionControlItem> _recipeColumnPermSource = new();
private List<PermissionControlItem> _recipeStepPermSource = new();
private List<PermissionControlItem> _contentPermSource = new();
private readonly RecipeFormatBuilder _recipeBuilder = new();
#endregion
#region Properties
public ObservableCollection<string> ChamberType { get; set; }
public ObservableCollection<ProcessTypeFileItem> ProcessTypeFileList { get; set; }
#endregion
#region Methods
public bool Initialize()
{
var menus = AccountClient.Instance.Service.GetAllMenus();
_appMenuPermSource = menus;
if (menus == null)
{
LOG.Error("GetMenus method failed,in RoleManagerClient");
return false;
}
//每个Role下再挂一个Recipe权限
//Recipe名称从RecipeFormat文件中获取
var chamberType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedChamberType");
if (chamberType == null)
{
ChamberType = new ObservableCollection<string>() { "Default" };
}
else
{
ChamberType = new ObservableCollection<string>(((string)(chamberType)).Split(','));
}
var processType = QueryDataClient.Instance.Service.GetConfig("System.Recipe.SupportedProcessType");
if (processType == null)
{
processType = "Process,Routine";
}
ProcessTypeFileList = new ObservableCollection<ProcessTypeFileItem>();
var recipeProcessType = ((string)processType).Split(',');
_recipeColumnPermSource = _recipeBuilder.GetRecipeColumnPermSource($"{ChamberType[0]}\\{recipeProcessType[0]}", "PM1");
_recipeStepPermSource = _recipeBuilder.GetRecipeStepPermSource();
_contentPermSource = _recipeBuilder.GetContentPermSource($"{ChamberType[0]}\\Content", "RecipeFormat");
return true;
}
/// <summary>
/// 返回包含所有角色的列表。
/// </summary>
/// <returns></returns>
public List<RoleItem> GetAllRoles()
{
return RoleAccountProvider.Instance.GetRoles().Select(Create).ToList();
}
private RoleItem Create(Role role)
{
var ri = new RoleItem(role);
var headerPerm = RolePermissionMapper.FromMenuPermissionEnum(role.PermissionControlItems["Header"]);
var mp = new PermissionControlItem("Header", headerPerm, "Header");
ri.AddMenuInfo(mp);
//Get Menu information
foreach (var topMenuItem in _appMenuPermSource)
{
foreach (var subMenuItem in topMenuItem.MenuItems)
{
var appName = topMenuItem.ResKey + "." + subMenuItem.ResKey;
var id = subMenuItem.MenuID;
var appPerm = RolePermissionMapper.FromMenuPermissionEnum(role.GetPermission(id));
var perm = new PermissionControlItem(appName, appPerm, id, subMenuItem.Description);
ri.AddMenuInfo(perm);
}
}
foreach (var recipeInfo in _recipeColumnPermSource)
{
var permType = RolePermissionMapper.FromMenuPermissionEnum(role.GetPermission(recipeInfo.Name));
var perm = new PermissionControlItem(recipeInfo.Name, permType, recipeInfo.Name, recipeInfo.Description);
ri.AddRecipeInfo(perm);
}
foreach (var stepInfo in _recipeStepPermSource)
{
var permType = RolePermissionMapper.FromMenuPermissionEnum(role.GetPermission(stepInfo.Name));
var perm = new PermissionControlItem(stepInfo.Name, permType, stepInfo.Name, stepInfo.Description);
ri.AddStepInfo(perm);
}
foreach (var contentInfo in _contentPermSource)
{
var permType = RolePermissionTrueFalseMapper.FromMenuPermissionEnum(role.GetPermission(contentInfo.Name));
var perm = new PermissionControlItem(contentInfo.Name, permType, contentInfo.Name, contentInfo.Description);
ri.AddContentInfo(perm);
}
return ri;
}
public RoleItem Create()
{
var newId = RoleAccountProvider.Instance.GetAvailableID();
if (string.IsNullOrEmpty(newId))
throw new InvalidOperationException("no available role ID.");
var r = new RoleItem(newId);
r.DisplayRoleName = r.RoleName = string.Empty;
r.DisplayAutoLogoutTime = r.AutoLogoutTime = 10;
r.DisplayIsAutoLogout = r.IsAutoLogout = false;
r.DisplayDescription = r.Description = string.Empty;
r.MenuPermCollection.Add(new PermissionControlItem( "Header", RolePermissionMapper.ReadWrite, "Header"));
foreach (var topMenuItem in _appMenuPermSource)
{
foreach (var subMenuItem in topMenuItem.MenuItems)
{
var mp = new PermissionControlItem(topMenuItem.ResKey + "." + subMenuItem.ResKey,
RolePermissionMapper.ReadWrite, subMenuItem.MenuID);
r.MenuPermCollection.Add(mp);
}
}
foreach (var perm in _recipeColumnPermSource)
{
var recipe = new PermissionControlItem(perm.Name, RolePermissionMapper.ReadWrite, perm.Name, perm.Description);
r.AddRecipeInfo(recipe);
}
foreach (var perm in _recipeStepPermSource)
{
var step = new PermissionControlItem(perm.Name, RolePermissionMapper.ReadWrite, perm.Name, perm.Description);
r.AddStepInfo(step);
}
foreach (var perm in _contentPermSource)
{
var permission = new PermissionControlItem(perm.Name, RolePermissionTrueFalseMapper.Yes, perm.Name, perm.Description);
r.AddContentInfo(permission);
}
return r;
}
public RoleItem Clone(RoleItem originRoleItem)
{
var newId = RoleAccountProvider.Instance.GetAvailableID();
var newRole = new RoleItem(newId)
{
RoleName = originRoleItem.RoleName,
AutoLogoutTime = originRoleItem.AutoLogoutTime,
IsAutoLogout = originRoleItem.IsAutoLogout,
Description = originRoleItem.Description,
DisplayRoleName = originRoleItem.DisplayRoleName,
DisplayAutoLogoutTime = originRoleItem.DisplayAutoLogoutTime,
DisplayIsAutoLogout = originRoleItem.DisplayIsAutoLogout,
DisplayDescription = originRoleItem.DisplayDescription
};
foreach (var mInfo in originRoleItem.MenuPermCollection)
{
newRole.AddMenuInfo((PermissionControlItem)mInfo.Clone());
}
foreach (var rInfo in originRoleItem.RecipePermCollection)
{
newRole.AddRecipeInfo((PermissionControlItem)rInfo.Clone());
}
foreach (var sInfo in originRoleItem.RecipeStepPermCollection)
{
newRole.AddStepInfo((PermissionControlItem)sInfo.Clone());
}
foreach (var pInfo in originRoleItem.ContentPermCollection)
{
newRole.AddContentInfo((PermissionControlItem)pInfo.Clone());
}
return newRole;
}
public bool CheckAvailable(RoleItem ri)
{
var available = AccountClient.Instance.Service.CheckRoleNotDuplicated(ri.RoleId, ri.RoleName);
if (!available)
LOG.Info("Check role fail because the ID or name already exists, in RoleManagerClient");
return available;
}
public bool SaveRole(RoleItem ri, out string reason)
{
reason = "";
if (!CheckAvailable(ri))
{
reason = "the role name duplicated.";
return false;
}
var role = new Role(
ri.RoleId,
ri.RoleName,
ri.IsAutoLogout,
ri.AutoLogoutTime,
PermissionHelper.PermissionToDictionary(ri.MenuPermCollection, ri.RecipePermCollection,
ri.ContentPermCollection, ri.RecipeStepPermCollection),
ri.Role.IsBuildIn,
ri.Description
);
if (RoleAccountProvider.Instance.UpdateRole(role))
{
// 如果当前登录用户的角色是刚才保存的角色,则需要从RT更新一次。
if (BaseApp.Instance.UserContext.Role.RoleId == role.RoleId)
{
var newestRole = AccountClient.Instance.Service.GetRoleByID(role.RoleId);
if (newestRole == null)
LOG.Error(
$"Unable to refresh the current role with ID {role.RoleId}, the role of current session does not updated.");
else
BaseApp.Instance.UserContext.Role = newestRole;
}
return true;
}
reason = "it failed to save/update role from RT side, see log for details.";
LOG.Error("UpdateRoles method failed, in RoleManagerClient");
return false;
}
public bool DeleteRole(string strRoleID)
{
var r = AccountClient.Instance.Service.GetRoleByID(strRoleID);
if (r != null)
{
if (RoleAccountProvider.Instance.DeleteRole(strRoleID))
return true;
LOG.Error("DeleteRole method failed, in RoleManagerClient");
return false;
}
LOG.Warning("Can not find the role to delete, in RoleManagerClient");
return false;
}
#endregion
}
}
@@ -0,0 +1,49 @@
using System.Collections.ObjectModel;
using System.Linq;
using Aitex.Core.Util;
using MECF.Framework.Common.Account;
using MECF.Framework.Common.Account.Permissions;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RolePermissionMapper : Singleton<RolePermissionMapper>
{
public static readonly PermissionMappedType None = new(MenuPermissionEnum.MP_NONE, "NONE");
public static readonly PermissionMappedType Read = new(MenuPermissionEnum.MP_READ, "READ");
public static readonly PermissionMappedType ReadWrite = new(MenuPermissionEnum.MP_READ_WRITE, "READ & WRITE");
#region Properties
public ObservableCollection<PermissionMappedType> PermissionDictionary { get; } = new()
{
None,
Read,
ReadWrite
};
#endregion
#region Methods
public static PermissionMappedType FromMenuPermissionEnum(MenuPermissionEnum perm)
{
return Instance.PermissionDictionary.FirstOrDefault(x => x.EnumPermission == perm) ?? None;
}
public string ToString(MenuPermissionEnum enumPermission)
{
foreach (var pd in PermissionDictionary)
{
if (pd.EnumPermission == enumPermission)
{
return pd.StringPermission;
}
}
return "";
}
#endregion
}
}
@@ -0,0 +1,56 @@
using System.Collections.ObjectModel;
using System.Linq;
using Aitex.Core.Util;
using MECF.Framework.Common.Account.Permissions;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RolePermissionTrueFalseMapper : Singleton<RolePermissionTrueFalseMapper>
{
public static readonly PermissionMappedType No = new(MenuPermissionEnum.MP_NONE, "NO");
public static readonly PermissionMappedType Yes = new(MenuPermissionEnum.MP_READ_WRITE, "YES");
#region Properties
public ObservableCollection<PermissionMappedType> PermissionDictionary { get; } = new()
{
No,
Yes
};
#endregion
#region Methods
public static PermissionMappedType FromMenuPermissionEnum(MenuPermissionEnum perm)
{
// 为兼容已存在的权限,将配置为MP_READ的项目更换为MP_READ_WRITE
if (perm == MenuPermissionEnum.MP_READ)
perm = MenuPermissionEnum.MP_READ_WRITE;
return Instance.PermissionDictionary.FirstOrDefault(x => x.EnumPermission == perm) ?? No;
}
public string ToString(MenuPermissionEnum enumPermission)
{
foreach (var pd in PermissionDictionary)
{
if (pd.EnumPermission == enumPermission)
{
return pd.StringPermission;
}
}
return "";
}
#endregion
}
}
@@ -0,0 +1,568 @@
<UserControl
x:Class="MECF.Framework.UI.Client.CenterViews.Configs.Roles.RoleView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:command="clr-namespace:OpenSEMI.ClientBase.Command"
xmlns:controls="clr-namespace:OpenSEMI.Ctrlib.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
xmlns:lex="http://wpflocalizeextension.codeplex.com"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:micro="clr-namespace:Caliburn.Micro"
lex:LocalizeDictionary.DesignCulture="zh"
lex:ResxLocalizationProvider.DefaultAssembly="Sicentury.Localization"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config">
<UserControl.Resources>
<Style
x:Key="ViewEnabledBtn"
BasedOn="{StaticResource ResourceKey={x:Type Button}}"
TargetType="{x:Type Button}">
<Setter Property="Button.IsEnabled" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Permission}" Value="2" />
<Condition Binding="{Binding ControlMode}" Value="VIEW" />
</MultiDataTrigger.Conditions>
<Setter Property="Button.IsEnabled" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
<Style
x:Key="EditEnabledBtn"
BasedOn="{StaticResource ResourceKey={x:Type Button}}"
TargetType="{x:Type Button}">
<Setter Property="Button.IsEnabled" Value="False" />
<Style.Triggers>
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding Permission}" Value="2" />
<Condition Binding="{Binding ControlMode}" Value="EDIT" />
</MultiDataTrigger.Conditions>
<Setter Property="Button.IsEnabled" Value="True" />
</MultiDataTrigger>
</Style.Triggers>
</Style>
</UserControl.Resources>
<Grid
x:Name="MainTable"
Width="1900"
MinWidth="1200"
MinHeight="450"
HorizontalAlignment="Left">
<Grid x:Name="MainField">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" MinWidth="250" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="40" />
</Grid.RowDefinitions>
<GridSplitter
Grid.Column="1"
Width="5"
HorizontalAlignment="Left"
BorderThickness="0,8">
<GridSplitter.Background>
<SolidColorBrush />
</GridSplitter.Background>
</GridSplitter>
<Border
Margin="0,20,0,0"
Padding="12"
Background="{DynamicResource Tab_BG}"
BorderBrush="{DynamicResource Tab_BD}"
BorderThickness="1"
SnapsToDevicePixels="True">
<TreeView
Name="RolesTree"
HorizontalAlignment="Left"
VerticalAlignment="Top">
<TreeView.Style>
<Style BasedOn="{StaticResource ResourceKey={x:Type TreeView}}" TargetType="{x:Type TreeView}">
<Setter Property="TreeView.IsEnabled" Value="False" />
<Style.Triggers>
<DataTrigger Binding="{Binding ControlMode}" Value="VIEW">
<Setter Property="TreeView.IsEnabled" Value="True" />
</DataTrigger>
</Style.Triggers>
</Style>
</TreeView.Style>
<TreeViewItem
Header="{lex:Loc ID_TXT_Role}"
IsExpanded="True"
ItemsSource="{Binding RoleList}">
<TreeViewItem.ItemContainerStyle>
<Style
x:Name="RoleTreeViewItem"
BasedOn="{StaticResource ResourceKey={x:Type TreeViewItem}}"
TargetType="{x:Type TreeViewItem}">
<Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=TwoWay}" />
<Style.Triggers>
<Trigger Property="VirtualizingStackPanel.IsVirtualizing" Value="true">
<Setter Property="ItemsPanel">
<Setter.Value>
<ItemsPanelTemplate>
<VirtualizingStackPanel />
</ItemsPanelTemplate>
</Setter.Value>
</Setter>
</Trigger>
</Style.Triggers>
</Style>
</TreeViewItem.ItemContainerStyle>
<TreeViewItem.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayRoleName}" />
</DataTemplate>
</TreeViewItem.ItemTemplate>
</TreeViewItem>
<command:CommandSource.Trigger>
<command:CommandTriggerGroup>
<command:EventCommandTrigger
Command="{Binding DataContext.RoleTreeSelectChangedCommand, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
CustomParameter="{Binding ElementName=RolesTree, Path=SelectedItem}"
RoutedEvent="TreeView.SelectedItemChanged" />
</command:CommandTriggerGroup>
</command:CommandSource.Trigger>
</TreeView>
</Border>
<Grid Grid.Column="1" Margin="10,0,0,0">
<Grid.RowDefinitions>
<RowDefinition Height="20" />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<TextBlock
Margin="5,0,0,0"
VerticalAlignment="Top"
FontFamily="Arial"
FontSize="14"
FontWeight="Bold"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Role_Property}"
TextWrapping="Wrap" />
<Grid
x:Name="Role_Property"
Grid.Row="1"
Margin="0,0,0,5"
IsEnabled="{Binding IsPermission}">
<Grid.RowDefinitions>
<RowDefinition Height="24" />
<RowDefinition Height="24" />
<RowDefinition Height="24" />
<RowDefinition Height="24" />
</Grid.RowDefinitions>
<Grid x:Name="Role_Name" Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="12"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Name}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<controls:TextBoxEx
x:Name="textBox1"
Width="150"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Stretch"
IsEnabled="{Binding IsEnabledRoleName}"
Text="{Binding TreeSelectedRole.DisplayRoleName, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.RoleNameTextSaved}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</controls:TextBoxEx>
</Border>
</Grid>
<Grid x:Name="Is_Auto_Logout" Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1,0,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="12"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Is_Auto_Logout}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<CheckBox
Name="checkBox1"
HorizontalAlignment="Left"
VerticalAlignment="Center"
Content=""
IsChecked="{Binding TreeSelectedRole.DisplayIsAutoLogout}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="Click">
<micro:ActionMessage MethodName="OnAutoLogoutTimeChecked">
<micro:Parameter Value="$source" />
</micro:ActionMessage>
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
</Border>
</Grid>
<Grid x:Name="Time" Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1,0,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="12"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Time(minutes)}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,0,1,1">
<controls:TextBoxEx
x:Name="textBox2"
Width="150"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Stretch"
EditBoxMode="UnSignInteger"
PreviewTextInput="TextBox2_PreviewTextInput"
Text="{Binding TreeSelectedRole.DisplayAutoLogoutTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.TimeTextSaved}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</controls:TextBoxEx>
</Border>
</Grid>
<Grid x:Name="Description" Grid.Row="3">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<Border
Padding="5,1"
Background="{DynamicResource Table_BG_Title}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="1,0,1,1">
<TextBlock
VerticalAlignment="Center"
FontFamily="Arial"
FontSize="12"
Foreground="{DynamicResource FG_Black}"
Text="{lex:Loc ID_TXT_Description}"
TextWrapping="Wrap" />
</Border>
<Border
Grid.Column="1"
Padding="5,1"
Background="{DynamicResource Table_BG_Content}"
BorderBrush="{DynamicResource Table_BD}"
BorderThickness="0,1,1,1">
<controls:TextBoxEx
x:Name="textBox3"
MinWidth="150"
HorizontalAlignment="Left"
VerticalAlignment="Center"
HorizontalContentAlignment="Stretch"
Text="{Binding TreeSelectedRole.DisplayDescription, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
TextSaved="{Binding Mode=TwoWay, Path=TreeSelectedRole.DescriptionTextSaved}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="TextChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</controls:TextBoxEx>
</Border>
</Grid>
</Grid>
<TabControl Grid.Row="2">
<TabItem>
<TabItem.Header>
<TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Page_Access_Permission}" />
</TabItem.Header>
<ListView
Name="RolesList"
VerticalAlignment="Top"
AlternationCount="2"
IsEnabled="{Binding IsPermission}"
ItemsSource="{Binding Path=TreeSelectedRole.MenuPermCollection}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn
Width="200"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
DisplayMemberBinding="{Binding Name}"
Header="{lex:Loc ID_TXT_Name}" />
<GridViewColumn
Width="200"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
Header="{lex:Loc ID_TXT_Permission_Configuration}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
x:Name="combPermission"
Width="140"
DisplayMemberPath="StringPermission"
ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Permission}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</TabItem>
<TabItem Visibility="Collapsed">
<TabItem.Header>
<TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Recipe_Parameter_Permission}" />
</TabItem.Header>
<ListView
Name="RecipeList"
VerticalAlignment="Top"
AlternationCount="2"
IsEnabled="{Binding IsPermission}"
ItemsSource="{Binding Path=TreeSelectedRole.RecipePermCollection}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn
Width="300"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
DisplayMemberBinding="{Binding Name}"
Header="{lex:Loc ID_TXT_Name}" />
<GridViewColumn
Width="200"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
Header="{lex:Loc ID_TXT_Permission_Configuration}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
x:Name="combPermission"
Width="140"
DisplayMemberPath="StringPermission"
ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Permission}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</TabItem>
<TabItem>
<TabItem.Header>
<TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Recipe_Step_Permission}" />
</TabItem.Header>
<ListView
Name="RecipeStepList"
VerticalAlignment="Top"
AlternationCount="2"
IsEnabled="{Binding IsPermission}"
ItemsSource="{Binding Path=TreeSelectedRole.RecipeStepPermCollection}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn
Width="300"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
DisplayMemberBinding="{Binding Name}"
Header="{lex:Loc ID_TXT_Name}" />
<GridViewColumn
Width="200"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
Header="{lex:Loc ID_TXT_Permission_Configuration}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
x:Name="combPermission"
Width="140"
DisplayMemberPath="StringPermission"
ItemsSource="{Binding DataContext.PermissionDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Permission}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</TabItem>
<TabItem>
<TabItem.Header>
<TextBlock FontWeight="Bold" Text="{lex:Loc ID_TXT_Content_Access_Permission}" />
</TabItem.Header>
<ListView
Name="ContentList"
VerticalAlignment="Top"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
AlternationCount="2"
IsEnabled="{Binding IsPermission}"
ItemsSource="{Binding Path=TreeSelectedRole.ContentPermCollection}"
ScrollViewer.CanContentScroll="True"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Auto">
<ListView.View>
<GridView>
<GridViewColumn
Width="300"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
DisplayMemberBinding="{Binding Name}"
Header="{lex:Loc ID_TXT_Name}" />
<GridViewColumn
Width="200"
lex:ResxLocalizationProvider.DefaultDictionary="lang_config"
Header="{lex:Loc ID_TXT_Permission_Configuration}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<ComboBox
x:Name="combPermission"
Width="140"
DisplayMemberPath="StringPermission"
ItemsSource="{Binding DataContext.PermissionTrueFalseDictionary, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}"
SelectedItem="{Binding Permission}">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<micro:ActionMessage MethodName="OnRoleChanged" />
</i:EventTrigger>
</i:Interaction.Triggers>
</ComboBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Description}" Header="{lex:Loc ID_TXT_Description}" />
</GridView>
</ListView.View>
</ListView>
</TabItem>
</TabControl>
</Grid>
<StackPanel
Grid.Row="1"
Grid.ColumnSpan="2"
HorizontalAlignment="Center"
VerticalAlignment="Center"
lex:ResxLocalizationProvider.DefaultDictionary="lang_common"
Orientation="Horizontal">
<Button
x:Name="ID_BTN_Create_Content"
Width="80"
Height="25"
Command="{Binding BtnAddRoleCommand}"
Content="{lex:Loc}"
Style="{StaticResource ViewEnabledBtn}"
ToolTip="{lex:Loc}" />
<Button
x:Name="ID_BTN_Delete_Content"
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding BtnDeleteRoleCommand}"
Content="{lex:Loc}"
Style="{StaticResource ViewEnabledBtn}"
ToolTip="{lex:Loc}" />
<Button
x:Name="ID_BTN_Clone_Content"
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding BtnCloneRoleCommand}"
Content="{lex:Loc}"
Style="{StaticResource ViewEnabledBtn}"
ToolTip="{lex:Loc}" />
<Button
x:Name="ID_BTN_Save_Content"
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding BtnSaveCommand}"
Content="{lex:Loc}"
Style="{StaticResource EditEnabledBtn}"
ToolTip="{lex:Loc}" />
<Button
x:Name="ID_BTN_Cancel_Content"
Width="80"
Height="25"
Margin="10,0,0,0"
Command="{Binding BtnCancelRoleCommand}"
Content="{lex:Loc}"
Style="{StaticResource EditEnabledBtn}"
ToolTip="{lex:Loc}" />
</StackPanel>
</Grid>
</Grid>
</UserControl>
@@ -0,0 +1,53 @@
using System;
using System.Windows.Controls;
using System.Windows.Input;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
/// <summary>
/// Interaction logic for RoleView.xaml
/// </summary>
public partial class RoleView : UserControl
{
public RoleView()
{
InitializeComponent();
}
private void TextBox2_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
string newText = textBox2.Text + e.Text;
if (int.TryParse(newText, out int number) && number < int.MaxValue)
{
e.Handled = false;
}
else
{
textBox2.Text = "0";
e.Handled = true;
}
}
//private void ScrollViewer_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
//{
// ScrollViewer viewer = scrollviewer_LotList;
// if (viewer == null)
// return;
// double num = Math.Abs((int)(e.Delta / 2));
// double offset = 0.0;
// if (e.Delta > 0)
// {
// offset = Math.Max((double)0.0, (double)(viewer.VerticalOffset - num));
// }
// else
// {
// offset = Math.Min(viewer.ScrollableHeight, viewer.VerticalOffset + num);
// }
// if (offset != viewer.VerticalOffset)
// {
// viewer.ScrollToVerticalOffset(offset);
// e.Handled = true;
// }
//}
}
}
@@ -0,0 +1,365 @@
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms.VisualStyles;
using System.Windows.Input;
using Aitex.Core.RT.Log;
using MECF.Framework.Common.Account;
using MECF.Framework.Common.Account.Extends;
using MECF.Framework.Common.Account.Permissions;
using MECF.Framework.UI.Client.ClientBase;
using OpenSEMI.ClientBase;
using OpenSEMI.ClientBase.Command;
namespace MECF.Framework.UI.Client.CenterViews.Configs.Roles
{
public class RoleViewModel : BaseModel
{
#region Variables
private bool _isEnabledRoleName;
private RoleItem _treeSelectedRole;
private CtrlMode _controlMode = CtrlMode.VIEW;
#endregion
#region Constructors
public RoleViewModel()
{
DisplayName = "Role";
}
#endregion
#region Properties
public bool IsEnabledRoleName
{
get => _isEnabledRoleName;
set
{
_isEnabledRoleName = value;
NotifyOfPropertyChange();
}
}
public ObservableCollection<PermissionMappedType> PermissionDictionary =>
RolePermissionMapper.Instance.PermissionDictionary;
public ObservableCollection<PermissionMappedType> PermissionTrueFalseDictionary =>
RolePermissionTrueFalseMapper.Instance.PermissionDictionary;
public ObservableCollection<RoleItem> RoleList { get; } = new();
public RoleItem TreeSelectedRole
{
get => _treeSelectedRole;
set
{
_treeSelectedRole = value;
NotifyOfPropertyChange();
}
}
public CtrlMode ControlMode
{
get => _controlMode;
set
{
_controlMode = value;
NotifyOfPropertyChange();
}
}
#endregion
#region Methods
protected override void OnInitialize()
{
base.OnInitialize();
RoleManagerClient.Instance.Initialize();
}
protected override void OnActivate()
{
RoleList.Clear();
_treeSelectedRole = null;
LoadRoleList();
base.OnActivate();
}
protected override void OnDeactivate(bool close)
{
if (ControlMode == CtrlMode.EDIT && IsPermission)
{
if (DialogBox.Confirm("The data has been modified. Do you want to save the change(s)?"))
{
if (SaveChanges(out var reason))
{
ControlMode = CtrlMode.VIEW;
DialogBox.ShowInfo("Operated successfully.");
}
else
{
DialogBox.ShowError($"Operated failed, {reason}");
}
}
}
base.OnDeactivate(close);
}
public void OnRoleChanged()
{
var roleNameList = new[] { "管理员", "设备工程师", "工艺工程师", "操作员" };
var roleName = roleNameList.Contains(TreeSelectedRole.DisplayRoleName)
? TreeSelectedRole.DisplayRoleName
: "";
IsEnabledRoleName = true;
if (!string.IsNullOrEmpty(roleName))
IsEnabledRoleName = false;
if (ControlMode == CtrlMode.EDIT)
{
if (!string.IsNullOrEmpty(TreeSelectedRole.DisplayRoleName) &&
TreeSelectedRole.DisplayRoleName.Length > 18)
TreeSelectedRole.DisplayRoleName = TreeSelectedRole.DisplayRoleName.Substring(0, 18);
return;
}
//check role to set the mode from view to edit
if (_treeSelectedRole != null && _treeSelectedRole.IsRoleChanged())
ControlMode = CtrlMode.EDIT;
}
public bool OnAutoLogoutTimeChecked(object sender)
{
ControlMode = CtrlMode.EDIT;
return ((CheckBox)(sender)).IsChecked.Value;
}
private bool SaveChanges(out string reason)
{
reason = "";
if (string.IsNullOrWhiteSpace(TreeSelectedRole.DisplayRoleName))
{
reason = "Role Name cannot be empty.";
return false;
}
if (IsRoleExists(TreeSelectedRole))
{
reason = "Role already exists.";
return false;
}
TreeSelectedRole.RoleName = TreeSelectedRole.DisplayRoleName;
TreeSelectedRole.IsAutoLogout = TreeSelectedRole.DisplayIsAutoLogout;
TreeSelectedRole.AutoLogoutTime = TreeSelectedRole.DisplayAutoLogoutTime;
TreeSelectedRole.RoleNameTextSaved = TreeSelectedRole.TimeTextSaved = true;
TreeSelectedRole.Description = TreeSelectedRole.DisplayDescription;
try
{
return RoleManagerClient.Instance.SaveRole(TreeSelectedRole, out reason);
}
catch (Exception ex)
{
reason = ex.Message;
LOG.Error(ex.Message, ex);
return false;
}
}
private bool IsRoleExists(RoleItem role)
{
if (RoleList == null || RoleList.Count == 0)
return false;
var sameNameList = RoleList.Where(t => t.DisplayRoleName == role.DisplayRoleName);
if (sameNameList.Count() <= 1)
return false;
return true;
}
private void LoadRoleList(string defaultSelectedRoleName = "")
{
RoleList.Clear();
var roles = RoleManagerClient.Instance.GetAllRoles();
if (roles == null || roles.Count == 0)
return;
foreach (var ri in roles)
RoleList.Add(ri);
if (string.IsNullOrEmpty(defaultSelectedRoleName))
{
TreeSelectedRole = RoleList.FirstOrDefault();
if (TreeSelectedRole != null)
TreeSelectedRole.IsSelected = true;
}
else
{
var roleToSelect = RoleList.FirstOrDefault(x => x.RoleName == defaultSelectedRoleName);
if (roleToSelect != null)
roleToSelect.IsSelected = true;
}
ControlMode = CtrlMode.VIEW;
}
private void OnRoleTreeSelectedChanged(EventCommandParameter<object, RoutedEventArgs> arg)
{
var roleItem = arg.CustomParameter as RoleItem;
if (roleItem == null)
return;
TreeSelectedRole = roleItem;
}
private void OnBtnAddRoleCommand(object arg)
{
try
{
var newRole = RoleManagerClient.Instance.Create();
if (newRole != null)
{
RoleList.Add(newRole);
TreeSelectedRole = newRole;
TreeSelectedRole.IsSelected = true;
}
ControlMode = CtrlMode.EDIT;
}
catch (Exception ex)
{
DialogBox.ShowError($"Unable to add role, {ex.Message}");
}
}
private void OnBtnDeleteRoleCommand(object arg)
{
if (TreeSelectedRole == null)
return;
if (TreeSelectedRole.IsBuildIn)
{
DialogBox.ShowError("Can not delete a build-in role");
return;
}
if (!DialogBox.Confirm("Are you sure that you want to delete this role?"))
{
return;
}
if (BaseApp.Instance.UserContext.Role.RoleId == TreeSelectedRole.RoleId)
{
DialogBox.ShowError("The action cannot be completed because {0} is currently in use.", "the role");
return;
}
try
{
var index = RoleList.IndexOf(TreeSelectedRole);
RoleList.Remove(TreeSelectedRole);
RoleManagerClient.Instance.DeleteRole(TreeSelectedRole.RoleId);
index = index > 1 ? index - 1 : 0;
TreeSelectedRole = RoleList?[index];
if (TreeSelectedRole != null)
TreeSelectedRole.IsSelected = true;
// DialogBox.ShowInfo("Operated successfully.");
}
catch (Exception ex)
{
LOG.Error(ex.StackTrace);
DialogBox.ShowError($"Deleting failed, {ex.Message}");
}
}
private void OnBtnCloneRoleCommand(object arg)
{
if (_treeSelectedRole != null)
{
var newRole = RoleManagerClient.Instance.Clone(_treeSelectedRole);
if (newRole != null)
{
newRole.DisplayRoleName = newRole.RoleName = "Copy of " + newRole.DisplayRoleName;
RoleList.Add(newRole);
TreeSelectedRole = newRole;
TreeSelectedRole.IsSelected = true;
ControlMode = CtrlMode.EDIT;
}
}
}
private void OnBtnSaveCommand(object arg)
{
try
{
if (SaveChanges(out var reason))
{
var lastSelectedRoleName = TreeSelectedRole?.RoleName ?? "";
LoadRoleList(lastSelectedRoleName);
ControlMode = CtrlMode.VIEW;
}
else
DialogBox.ShowInfo($"Saving failed, {reason}");
}
catch (Exception ex)
{
LOG.Error(ex.StackTrace);
DialogBox.ShowError($"Saving failed, {ex.Message}");
}
}
private void OnBtnCancelRoleCommand(object arg)
{
var lastSelectedRoleName = TreeSelectedRole.RoleName;
LoadRoleList(lastSelectedRoleName);
ControlMode = CtrlMode.VIEW;
}
#endregion
#region Commands
private ICommand _roleTreeSelectChangedCmd;
public ICommand RoleTreeSelectChangedCommand =>
_roleTreeSelectChangedCmd ??= new BaseCommand<EventCommandParameter<object, RoutedEventArgs>>(
OnRoleTreeSelectedChanged);
private ICommand _btnSaveCommand;
public ICommand BtnSaveCommand => _btnSaveCommand ??= new BaseCommand<object>(OnBtnSaveCommand);
private ICommand _btnAddRoleCommand;
public ICommand BtnAddRoleCommand => _btnAddRoleCommand ??= new BaseCommand<object>(OnBtnAddRoleCommand);
private ICommand _btnDeleteRoleCommand;
public ICommand BtnDeleteRoleCommand =>
_btnDeleteRoleCommand ??= new BaseCommand<object>(OnBtnDeleteRoleCommand);
private ICommand _btnCloneRoleCommand;
public ICommand BtnCloneRoleCommand => _btnCloneRoleCommand ??= new BaseCommand<object>(OnBtnCloneRoleCommand);
private ICommand _btnCancelRoleCommand;
public ICommand BtnCancelRoleCommand =>
_btnCancelRoleCommand ??= new BaseCommand<object>(OnBtnCancelRoleCommand);
#endregion
}
}