123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Windows;
- using InABox.Configuration;
- using InABox.Core;
- using InABox.DynamicGrid;
- using InABox.Wpf;
- using InABox.WPF;
- namespace PRSDesktop
- {
- public class ModuleItem : BaseObject
- {
- public string Description { get; set; }
- public bool Checked { get; set; }
- }
- public class ModuleGrid : DynamicGrid<ModuleItem>
- {
- private List<ModuleItem> Items;
- public ModuleGrid()
- {
- Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.FilterRows);
- Configuration = new Dictionary<string, bool>();
- var tick = PRSDesktop.Resources.tick.AsBitmapImage();
- var disabled = PRSDesktop.Resources.disabled.AsBitmapImage();
- ActionColumns.Add(new DynamicTickColumn<ModuleItem, bool>(x => x.Checked, tick, tick, disabled, CheckClick) { AllowHeaderClick = true });
- HiddenColumns.Add(x => x.Description);
- HiddenColumns.Add(x => x.Checked);
- }
- public Dictionary<string, bool> Configuration { get; set; }
- public List<Type> Modules { get; private set; }
- protected override void DeleteItems(params CoreRow[] rows)
- {
- }
- public override void SaveItem(ModuleItem item)
- {
- }
- protected override ModuleItem LoadItem(CoreRow row)
- {
- return Items[row.Index];
- }
- protected override void Reload(Filters<ModuleItem> criteria, Columns<ModuleItem> columns, ref SortOrder<ModuleItem> sort,
- Action<CoreTable, Exception> action)
- {
- if (Items == null)
- {
- Items = new List<ModuleItem>();
- var types = CoreUtils.Entities.Where(x => x.GetInterfaces().Contains(typeof(IPersistent))).OrderBy(x => x.EntityName());
- foreach (var type in types)
- {
- var moduleitem = new ModuleItem { Description = type.EntityName() };
- if (Configuration.ContainsKey(type.EntityName()))
- moduleitem.Checked = Configuration[type.EntityName()];
- else
- moduleitem.Checked = true;
- Items.Add(moduleitem);
- }
- }
- var table = new CoreTable();
- foreach (var column in columns.Items)
- table.Columns.Add(new CoreColumn { ColumnName = column.ToString() });
- table.LoadRows(Items);
- action.Invoke(table, null);
- }
- private bool CheckClick(CoreRow row)
- {
- var result = false;
- var rows = row == null ? Data.Rows.ToArray() : new[] { row };
- foreach (var corrow in rows)
- {
- var desc = corrow.Get<ModuleItem, string>(x => x.Description);
- var item = Items.FirstOrDefault(x => x.Description.Equals(desc));
- item.Checked = !item.Checked;
- Configuration[desc] = item.Checked;
- result = true;
- }
- return result;
- }
- protected override DynamicGridColumns LoadColumns()
- {
- var columns = new DynamicGridColumns();
- columns.Add(new DynamicGridColumn { ColumnName = "Description", Caption = "Description", Width = 0, Alignment = Alignment.MiddleLeft });
- return columns;
- }
- }
- /// <summary>
- /// Interaction logic for ModuleConfigurationWindow.xaml
- /// </summary>
- public partial class ModuleConfigurationWindow : ThemableWindow
- {
- private readonly ModuleConfiguration _config;
- private readonly string _database = "";
- public ModuleConfigurationWindow(string database)
- {
- InitializeComponent();
- _database = database.ToLower();
- _config = new LocalConfiguration<ModuleConfiguration>(Path.GetDirectoryName(_database), Path.GetFileName(_database)).Load();
- Modules.Configuration = _config;
- Modules.Refresh(true, true);
- }
- private void OK_Click(object sender, RoutedEventArgs e)
- {
- new LocalConfiguration<ModuleConfiguration>(Path.GetDirectoryName(_database), Path.GetFileName(_database)).Save(_config);
- DialogResult = true;
- Close();
- }
- private void Cancel_Click(object sender, RoutedEventArgs e)
- {
- DialogResult = false;
- Close();
- }
- private class ModuleConfiguration : Dictionary<string, bool>, ILocalConfigurationSettings
- {
- }
- }
- }
|