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 { 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(c=>c.MacAddress))); column.AddSeparator(); column.AddItem("Disconnect Key", PRSDesktop.Resources.key, (row) => Remove_Key(row), null, !String.IsNullOrWhiteSpace(row.Get(c=>c.MacAddress))); } private void Activate_Key(CoreRow row) { var key = row.ToObject(); var form = new DigitalKeyForm(key); if (form.ShowDialog() == true) new Client().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(); key.Model = ""; key.MacAddress = ""; key.Service = ""; key.Characteristic = ""; key.Key = ""; new Client().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 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); // } } }