| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 | using System;using System.Collections.Generic;using System.Linq;using System.Windows;using Comal.Classes;using InABox.Clients;using InABox.Core;using InABox.DynamicGrid;namespace PRSDesktop{    internal class DigitalKeyGrid : DynamicDataGrid<DigitalKey>    {        public DigitalKeyGrid()        {            //OnCustomiseEditor += CustomiseEditor;            ActionColumns.Add(new DynamicMenuColumn(KeyMenu, (row) => DynamicMenuStatus.Enabled));        }                private void KeyMenu(DynamicMenuColumn column, CoreRow row)        {            column.AddItem("Connect Key", PRSDesktop.Resources.key, (row) => Activate_Key(row), null, String.IsNullOrWhiteSpace(row.Get<DigitalKey,String>(c=>c.MacAddress)));            column.AddSeparator();            column.AddItem("Disconnect Key", PRSDesktop.Resources.key, (row) => Remove_Key(row), null, !String.IsNullOrWhiteSpace(row.Get<DigitalKey,String>(c=>c.MacAddress)));        }                private void Activate_Key(CoreRow row)        {            var key = row.ToObject<DigitalKey>();            var form = new DigitalKeyForm(key);            if (form.ShowDialog() == true)                new Client<DigitalKey>().Save(key, "Key Connected");            Refresh(false, true);        }                private void Remove_Key(CoreRow row)        {            var confirm = MessageBox.Show(                "Are you sure you wish to disonnect this key?\n\nThis will render the key inoperable until it is reconnected.",                "Confirm Disconnect",                MessageBoxButton.YesNo            ) == MessageBoxResult.Yes;            if (confirm)            {                var key = row.ToObject<DigitalKey>();                key.Model = "";                key.MacAddress = "";                key.Service = "";                                key.Characteristic = "";                key.Key = "";                new Client<DigitalKey>().Save(key, "Key Disconnected");                Refresh(false, true);            }        }        //private void CustomiseEditor(IDynamicEditorForm sender, DigitalKey[] items, DynamicGridColumn column, BaseEditor editor)        // {        //     if (column.ColumnName.Equals("Model") && editor is CodeEditor)        //     {        //         var ce = editor as CodeEditor;        //         ce.Editable = Editable.Enabled;        //         ce.Buttons = new[]        //         {        //             new(items.FirstOrDefault(), "Connect", 100, ConnectClick, true),        //             new EditorButton(items.FirstOrDefault(), "Clear", 100, ClearClick, true)        //         };        //     }        // }        // protected override Dictionary<string, object> EditorValueChanged(DynamicEditorForm editor, DigitalKey[] items, string name, object value)        // {        //     if (name.Equals("Model"))        //         editor.FindEditor("DeviceID")?.SetValue(items.First().DeviceID);        //     return base.EditorValueChanged(editor, items, name, value);        // }        // private void ConnectClick(object editor, object item)        // {        //     var ce = editor as CodeEditorControl;        //     var key = item as DigitalKey;        //     var form = new DigitalKeyForm(key);        //     if (form.ShowDialog() == true)        //         ce.SetValue(key.Model);        // }        //        // private void ClearClick(object editor, object item)        // {        //     var ce = editor as CodeEditorControl;        //     var key = item as DigitalKey;        //     key.Model = "";        //     key.DeviceID = "";        //     key.PublicKey = "";        //     key.PrivateKey = "";        //     ce.SetValue(key.Model);        // }    }}
 |