仓库管理系统26--权限设置

原创不易,打字不易,截图不易,多多点赞,送人玫瑰,留有余香,财务自由明日实现 

1、权限概述 

在应用软件中,通常将软件的功能分为若干个子程序,通过主程序调用。那么,通过众多客户来说,如果设置各人的权限呢?软件系统的权限控制几乎是非常常见且必备的,这篇文章整理下常见的九种模型,几乎基本够你用了,主流的权限模型主要有以下9种:

1、ACL模型

访问控制列表

2、DAC模型

自主访问控制

3、MAC模型

强制访问控制

4、ABAC模型

基于属性的访问控制,更灵活复杂

5、RBAC模型

基于角色的权限访问控制,最常用

6、TBAC模型

基于任务和工作流的访问控制

7、T-RBAC模型

基于任务和角色的访问控制

8、OBAC模型

基于对象的访问控制

9、UCON模型

使用控制模型 

2、权限实现

 本项目没有采用复杂的权限管理,只采用最简单的操作方法,具体是根据不同角色隐藏或显示菜单,具体实现方法是:

1)创建转换器对象

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Data;

namespace West.StoreMgr.Helper.Converter
{
    /// <summary>
    /// 菜单权限转换器
    /// </summary>
    public class AdminVisibleConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null) return Visibility.Collapsed;
            if (int.TryParse(value.ToString(), out int index))
            {
                return index == 0 ? Visibility.Visible : Visibility.Collapsed;
            }
            else
            {
                return Visibility.Collapsed;
            }
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}

 

2、主界面引入转换器  

<Window x:Class="West.StoreMgr.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:West.StoreMgr" 
        xmlns:Control="clr-namespace:West.StoreMgr.Control"
        mc:Ignorable="d"
        DataContext="{Binding  Source={StaticResource Locator},Path=Main}"
        WindowStartupLocation="CenterScreen"
        xmlns:converter="clr-namespace:West.StoreMgr.Helper.Converter"
        Title="欢迎使用仓库管理系统" Height="720" Width="1380">
    <Window.Resources>
        <converter:AdminVisibleConverter x:Key="AdminVisibleConverter"/>
    </Window.Resources>
    <Grid>
        <!--整体布局分为2行2列-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="276"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="61"/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <!--第1行第1列标识名称-->
        <Grid Grid.Row="0" Grid.Column="0" Tag="标志" Background="#367FA8">
            <TextBlock Text="企业仓库管理系统" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="#F6A518" FontSize="28"/>
        </Grid>
        <!--第1行第2列帐号信息-->
        <Grid Grid.Row="0" Grid.Column="1" Tag="顶栏" Background="#3C8DBB">
            <Grid.ColumnDefinitions>
                <ColumnDefinition/>
                <ColumnDefinition/>
            </Grid.ColumnDefinitions>
            <StackPanel Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" Orientation="Horizontal">
                <TextBlock Margin="10" FontSize="16" Text="&#xf039;" FontFamily="Fonts/#FontAwesome" Foreground="White" VerticalAlignment="Center"/>
                <TextBlock Margin="0 10 0 10" FontSize="16" Text="欢迎"  Foreground="White" VerticalAlignment="Center"/>
                <TextBlock Margin="5 10 0 10" FontSize="16" Text="{Binding AppData.User.Name}"  Foreground="White" VerticalAlignment="Center" Style="{StaticResource TextBoxBanberStyle}" MouseUp="TextBlock_MouseUp_2"/>
            </StackPanel>
            <StackPanel Grid.Column="1" HorizontalAlignment="Right" VerticalAlignment="Center" Orientation="Horizontal" Margin="0 0 20 0">
                <TextBlock Margin="10" FontSize="16" Text="&#xf023;" FontFamily="Fonts/#FontAwesome" Foreground="White" VerticalAlignment="Center"/>
                <TextBlock Margin="0 10 0 10" FontSize="16" Text="修改密码"  Foreground="White" VerticalAlignment="Center" Style="{StaticResource TextBoxBanberStyle}" MouseUp="TextBlock_MouseUp_1"/>
                <TextBlock Margin="10" FontSize="16" Text="&#xf08b;" FontFamily="Fonts/#FontAwesome" Foreground="White" VerticalAlignment="Center"/>
                <TextBlock Margin="0 10 0 10" FontSize="16" Text="退出系统"  Foreground="White" Style="{StaticResource TextBoxBanberStyle}" MouseUp="TextBlock_MouseUp" />
            </StackPanel>
        </Grid>
        <!--第2行1列菜单-->
        <Grid Grid.Row="1" Grid.Column="0" Tag="菜单">
            <Grid.RowDefinitions>
                <RowDefinition Height="auto"/>
                <RowDefinition/>
            </Grid.RowDefinitions>
            <Border Height="41" Background="#1A2327" VerticalAlignment="Center">
                <TextBlock Text="导航菜单" FontSize="20" Foreground="AntiqueWhite" VerticalAlignment="Center"/>
            </Border>
            <!--左侧主菜单-->
            <ScrollViewer Grid.Row="1" VerticalScrollBarVisibility="Auto">
                <StackPanel Background="#222C32">
                    <RadioButton x:Name="IndexView"  Click="StoreView_Checked"  Height="50" Content="控制台首页" FontSize="16" Tag="&#xf17a;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                    <!--基础数据菜单,加上权限设置-->
                    <Expander Background="#1D282B" ExpandDirection="Down"  SnapsToDevicePixels="True" 
                              VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}" 
                              Visibility="{Binding AppData.User.Role,Converter={StaticResource AdminVisibleConverter}}">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal" Height="50" Background="Transparent">
                                <TextBlock Width="auto" Margin="10 0 10 0" Text="&#xf170;" FontFamily="Fonts/#FontAwesome" FontSize="22"  Foreground="Red" VerticalAlignment="Center"></TextBlock>
                                <TextBlock Width="200" FontSize="18" Text="基础数据" Foreground="#918C8C" VerticalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Expander.Header>
                        <Expander.Content>
                            <StackPanel Background="#F6F8F8">
                                <RadioButton x:Name="GoodsTypeView" Click="StoreView_Checked"   Height="30" Content="物资设置" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="GoodsView"  Click="StoreView_Checked"   Height="30" Content="物资登记" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton Name="SupplierView" Click="StoreView_Checked"   Height="30" Content="供应商设置" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton Name="CustomerView" Click="StoreView_Checked"    Height="30" Content="客户管理" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="StoreView" Click="StoreView_Checked"  Height="30" Content="仓库设置" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="SpecView"  Click="StoreView_Checked"   Height="30" Content="规格设置" FontSize="16" Tag="&#xf069;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                            </StackPanel>
                        </Expander.Content>
                    </Expander>
                    <!--物品管理菜单-->
                    <Expander Background="#1D282B" ExpandDirection="Down"  SnapsToDevicePixels="True" VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal" Height="50" Background="Transparent">
                                <TextBlock Width="auto" Margin="10 0 10 0" Text="&#xf170;" FontFamily="Fonts/#FontAwesome" FontSize="22"  Foreground="Red" VerticalAlignment="Center"></TextBlock>
                                <TextBlock Width="200" FontSize="18" Text="物品管理" Foreground="#918C8C" VerticalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Expander.Header>
                        <Expander.Content>
                            <StackPanel Background="#F6F8F8">
                                <RadioButton x:Name="InStoreView" Click="StoreView_Checked" Height="30" Content="入库管理" FontSize="16" Tag="&#xf172;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="OutStoreView" Click="StoreView_Checked" Height="30" Content="出库管理" FontSize="16" Tag="&#xf172;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="InventoryView" Click="StoreView_Checked"    Height="30" Content="盘存管理" FontSize="16" Tag="&#xf172;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                            </StackPanel>
                        </Expander.Content>
                    </Expander>
                    <!--查询统计菜单-->
                    <Expander Background="#1D282B" ExpandDirection="Down"  SnapsToDevicePixels="True" VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal" Height="50" Background="Transparent">
                                <TextBlock Width="auto" Margin="10 0 10 0" Text="&#xf170;" FontFamily="Fonts/#FontAwesome" FontSize="22"  Foreground="Red" VerticalAlignment="Center"></TextBlock>
                                <TextBlock Width="200" FontSize="18" Text="查询统计" Foreground="#918C8C" VerticalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Expander.Header>
                        <Expander.Content>
                            <StackPanel Background="#F6F8F8">
                                <RadioButton x:Name="QueryStockView"  Click="StoreView_Checked"  Height="30" Content="库存查询" FontSize="16" Tag="&#xf080;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="QueryInStoreView"   Click="StoreView_Checked"  Height="30" Content="入库查询" FontSize="16" Tag="&#xf080;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="QueryOutStoreView"  Click="StoreView_Checked"    Height="30" Content="出库查询" FontSize="16" Tag="&#xf080;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                                <RadioButton x:Name="LiveChartView"  Click="StoreView_Checked"  Height="30" Content="报表统计" FontSize="16" Tag="&#xf080;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                            </StackPanel>
                        </Expander.Content>
                    </Expander>
                    <!--系统维护菜单-->
                    <Expander Background="#1D282B" ExpandDirection="Down"  SnapsToDevicePixels="True" VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}" Visibility="{Binding AppData.User.Role,Converter={StaticResource AdminVisibleConverter}}">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal" Height="50" Background="Transparent">
                                <TextBlock Width="auto" Margin="10 0 10 0" Text="&#xf170;" FontFamily="Fonts/#FontAwesome" FontSize="22"  Foreground="Red" VerticalAlignment="Center"></TextBlock>
                                <TextBlock Width="200" FontSize="18" Text="系统维护" Foreground="#918C8C" VerticalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Expander.Header>
                        <Expander.Content>
                            <StackPanel Background="#F6F8F8">
                                <RadioButton x:Name="DataExportView"    Click="StoreView_Checked"    Height="30" Content="数据导出" FontSize="16" Tag="&#xf073;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F"  />
                            </StackPanel>
                        </Expander.Content>
                    </Expander>
                    <!--系统应用菜单-->
                    <Expander Background="#1D282B" ExpandDirection="Down"  SnapsToDevicePixels="True" VerticalAlignment="Top" Style="{DynamicResource ExpanderStyle}">
                        <Expander.Header>
                            <StackPanel Orientation="Horizontal" Height="50" Background="Transparent">
                                <TextBlock Width="auto" Margin="10 0 10 0" Text="&#xf170;" FontFamily="Fonts/#FontAwesome" FontSize="22"  Foreground="Red" VerticalAlignment="Center"></TextBlock>
                                <TextBlock Width="200" FontSize="18" Text="系统应用" Foreground="#918C8C" VerticalAlignment="Center"></TextBlock>
                            </StackPanel>
                        </Expander.Header>
                        <Expander.Content>
                            <StackPanel Background="#F6F8F8">
                                <!--权限设置-->
                                <RadioButton x:Name="UserInfoView"  Click="StoreView_Checked"  Height="30" Content="用户管理" FontSize="16" Tag="&#xf2bb;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" Visibility="{Binding AppData.User.Role,Converter={StaticResource AdminVisibleConverter}}" />
                                <RadioButton Click="RadioButton_Click"    Height="30" Content="退出系统"  FontSize="16" Tag="&#xf2bb;" Style="{DynamicResource RadioButtonMenuStyle}" Foreground="#85979F" />
                            </StackPanel>
                        </Expander.Content>
                    </Expander>
                </StackPanel>
            </ScrollViewer>
        </Grid>
        <!--第2行2列内容-->
        <Grid Grid.Row="1" Grid.Column="1" Tag="舞台" Background="#E4ECEF">
            <ContentControl x:Name="container">
                <!--<Control:ButtonCard Logo="&#xf1ae;" Title="入库管理" Content="这是一个可以入库的快捷操作"></Control:ButtonCard>-->
            </ContentControl>
        </Grid>
    </Grid>
</Window>

3)使用转换器 

   3、运行效果

 

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hqwest

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值