123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media.Imaging;
- using Comal.Classes;
- using InABox.Core;
- using InABox.Wpf;
- using InABox.WPF;
- namespace PRSDesktop
- {
- /// <summary>
- /// Interaction logic for SecurityTokenPanel.xaml
- /// </summary>
- public partial class GlobalTokenWindow : ThemableWindow
- {
- private static readonly BitmapImage _key = PRSDesktop.Resources.key.AsBitmapImage();
- private readonly List<Tuple<Guid, string, BitmapImage>> _groups = new()
- {
- new Tuple<Guid, string, BitmapImage>(Guid.Empty, "All Groups", _key)
- };
- private Dictionary<Guid, BitmapImage> _images = new()
- {
- { Guid.Empty, _key }
- };
- public GlobalTokenWindow()
- {
- InitializeComponent();
- var query = new MultiQuery();
- query.Add(
- null,
- new Columns<SecurityGroup>(x => x.ID)
- .Add(x => x.Description),
- //.Add(x=>x.Image.ID),
- new SortOrder<SecurityGroup>(x => x.Description)
- );
- //SubQuery<SecurityGroup> secfilter = new SubQuery<SecurityGroup>(
- // new Filter<SecurityGroup>(x => x.Image.ID).IsNotEqualTo(Guid.Empty),
- // new Columns<SecurityGroup>(x => x.Image.ID)
- //);
- //query.Add<Document>(
- // new Filter<Document>(x => x.ID).InQuery(secfilter),
- // new Columns<Document>(x => x.ID).Add(x => x.Data)
- //);
- query.Add<GlobalSecurityToken>();
- query.Add<SecurityToken>();
- query.Add<UserSecurityToken>();
- query.Add(
- LookupFactory.DefineFilter<User>(),
- new Columns<User>(x => x.ID)
- .Add(x => x.UserID)
- .Add(x => x.SecurityGroup.ID)
- );
- query.Add(
- LookupFactory.DefineFilter<Employee>(),
- new Columns<Employee>(x => x.UserLink.ID)
- .Add(x => x.Name)
- );
- query.Query(q =>
- {
- //q.Get<Document>().IntoDictionary<Document, Guid, BitmapImage>(
- // _images,
- // x => x.ID,
- // (row) => ImageUtils.LoadImage(row.Get<Document, byte[]>(c => c.Data))
- //);
- _groups.AddRange(
- q.Get<SecurityGroup>().Rows.Select(
- r => new Tuple<Guid, string, BitmapImage>(
- r.Get<SecurityGroup, Guid>(x => x.ID),
- r.Get<SecurityGroup, string>(x => x.Description),
- _key
- //_images.ContainsKey(r.Get<SecurityGroup, Guid>(x => x.Image.ID))
- // ? _images[r.Get<SecurityGroup, Guid>(x => x.Image.ID)]
- // : _key
- )
- )
- );
- query.Get<SecurityGroup>().IntoDictionary<SecurityGroup, Guid, string>(
- Tokens.GroupNames,
- x => x.ID,
- r => r.Get<SecurityGroup, string>(c => c.Description)
- );
- foreach (var userrow in query.Get<User>().Rows)
- {
- var userid = userrow.Get<User, Guid>(x => x.ID);
- var emprow = query.Get<Employee>().Rows.FirstOrDefault(r => r.Get<Employee, Guid>(x => x.UserLink.ID) == userid);
- var usercode = emprow != null ? emprow.Get<Employee, string>(c => c.Name) : userrow.Get<User, string>(x => x.UserID);
- var groupid = userrow.Get<User, Guid>(x => x.SecurityGroup.ID);
- Tokens.UserNames[userid] = usercode;
- Tokens.UserGroups[userid] = groupid;
- }
- foreach (var row in query.Get<GlobalSecurityToken>().Rows)
- Tokens.Items.Add(new SecurityTokenItem
- {
- Descriptor = row.Get<GlobalSecurityToken, string>(c => c.Descriptor).Split('.').Last(),
- Type = SecurityTokenType.Global,
- RecordID = row.Get<GlobalSecurityToken, Guid>(x => x.ID),
- ID = Guid.Empty,
- Enabled = row.Get<GlobalSecurityToken, bool>(c => c.Enabled)
- });
- foreach (var row in query.Get<SecurityToken>().Rows)
- Tokens.Items.Add(new SecurityTokenItem
- {
- Descriptor = row.Get<SecurityToken, string>(c => c.Descriptor).Split('.').Last(),
- Type = SecurityTokenType.Group,
- RecordID = row.Get<SecurityToken, Guid>(x => x.ID),
- ID = row.Get<SecurityToken, Guid>(x => x.Group.ID),
- Enabled = row.Get<SecurityToken, bool>(c => c.Enabled)
- });
- foreach (var row in query.Get<UserSecurityToken>().Rows)
- {
- var userid = row.Get<UserSecurityToken, Guid>(c => c.User.ID);
- if (Tokens.UserGroups.ContainsKey(userid))
- {
- Tokens.Items.Add(new SecurityTokenItem
- {
- Descriptor = row.Get<UserSecurityToken, string>(c => c.Descriptor).Split('.').Last(),
- Type = SecurityTokenType.User,
- RecordID = row.Get<SecurityToken, Guid>(x => x.ID),
- ID = row.Get<UserSecurityToken, Guid>(x => x.User.ID),
- Enabled = row.Get<UserSecurityToken, bool>(c => c.Enabled)
- });
- }
- }
- Dispatcher.Invoke(() =>
- {
- Groups.ItemsSource = _groups;
- Groups.SelectedItem = _groups.FirstOrDefault();
- Groups.Visibility = Visibility.Visible;
- });
- });
- }
- private void Groups_SelectionChanged(object sender, SelectionChangedEventArgs e)
- {
- var selected = Groups.SelectedItem as Tuple<Guid, string, BitmapImage>;
- if (selected != null)
- {
- Tokens.GroupID = selected.Item1;
- Tokens.Refresh(true, true);
- }
- }
- }
- }
|