简体   繁体   中英

Create User Rights Screen in WPF/C#

I have a many-to-many relationship setup in MSSQL like this:

用户权限关系

(One user can have zero to many rights and one right can belong to zero to many users)

And I'm trying to create a screen to manage the rights for a single user like this using WPF and C#:

用户权限屏幕

But I'm struggling on how to represent a many-to-many database relationship in a screen that is is one-to-many relationship (one user, many rights). I wanted to be able to check/uncheck a right and have it added/removed from that user's rights array with as much WPF as possible without having to write a bunch of clunky/hacky C# code.

NOTE: I am using EDMX to convert my SQL tables to C# classes.

My current WPF for the data grid is just:

<DataGrid Name="dataGrid" MinHeight="100" ItemsSource="{Binding RightsList}" AutoGenerateColumns="False" CanUserResizeRows="False" CanUserReorderColumns="False" CanUserAddRows="False" CanUserDeleteRows="False" CanUserSortColumns="True" Margin="0,0,0,10"/>

If I was you I would have a rights control that uses its own UserRightsViewModel and have that ViewModel as a property in the UserViewModel. Assuming you have a UserViewModel.Save(), that would call a UserRightsViewModel.Save() to Save the rights correct. The DataGrid in UserRights would be a checked list, and you just save those that are checked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM