| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 | 
							- using GenHTTP.Engine;
 
- using InABox.API;
 
- using InABox.Core;
 
- using InABox.DynamicGrid;
 
- using NPOI.SS.Formula.Functions;
 
- using System;
 
- using System.Collections.Generic;
 
- using System.Linq;
 
- using System.Text;
 
- using System.Threading.Tasks;
 
- using System.Windows;
 
- using System.Windows.Controls;
 
- namespace PRSServer.Forms
 
- {
 
-     internal class SMSProviderGrid : DynamicGrid<SMSProviderProperties>, IDynamicEditorPage
 
-     {
 
-         public DynamicEditorGrid EditorGrid { get; set; }
 
-         public List<SMSProviderProperties> WorkingList { get; set; }
 
-         public bool Ready { get; set; }
 
-         private bool _readOnly;
 
-         public bool ReadOnly
 
-         {
 
-             get => _readOnly;
 
-             set
 
-             {
 
-                 if (_readOnly != value)
 
-                 {
 
-                     _readOnly = value;
 
-                     Reconfigure();
 
-                 }
 
-             }
 
-         }
 
-         public PageType PageType => PageType.Other;
 
-         protected override void Init()
 
-         {
 
-         }
 
-         protected override void DoReconfigure(FluentList<DynamicGridOption> options)
 
-         {
 
-             options.BeginUpdate();
 
-             if (ReadOnly)
 
-             {
 
-                 options.Add(DynamicGridOption.EditRows);
 
-             }
 
-             else
 
-             {
 
-                 options.AddRange(DynamicGridOption.AddRows, DynamicGridOption.EditRows, DynamicGridOption.DeleteRows);
 
-             }
 
-             options.EndUpdate();
 
-         }
 
-         protected override DynamicGridColumns LoadColumns()
 
-         {
 
-             var result = new DynamicGridColumns();
 
-             result.Add<SMSProviderProperties, SMSProviderType>(x => x.ProviderType, 100, "Type", "", Alignment.MiddleCenter);
 
-             return result;
 
-         }
 
-         public void AfterSave(object item)
 
-         {
 
-             var serverProperties = item as DatabaseServerProperties;
 
-             serverProperties.SMSProviderProperties = WorkingList.ToDictionary(x => x.ProviderType, x => x.Properties);
 
-         }
 
-         public void BeforeSave(object item)
 
-         {
 
-         }
 
-         public string Caption()
 
-         {
 
-             return "2FA Providers";
 
-         }
 
-         protected override void DoAdd(bool OpenEditorOnDirectEdit = false)
 
-         {
 
-             var menu = new ContextMenu();
 
-             foreach(var item in Enum.GetValues(typeof(SMSProviderType)))
 
-             {
 
-                 if(!WorkingList.Any(x => x.ProviderType == (SMSProviderType)item))
 
-                 {
 
-                     var menuItem = new MenuItem();
 
-                     menuItem.Header = item.ToString();
 
-                     menuItem.Tag = item;
 
-                     menuItem.Click += MenuItem_Click;
 
-                     menu.Items.Add(menuItem);
 
-                 }
 
-             }
 
-             if(menu.Items.Count == 0)
 
-             {
 
-                 var emptyItem = new MenuItem();
 
-                 emptyItem.Header = "No more provider types";
 
-                 emptyItem.IsEnabled = false;
 
-                 menu.Items.Add(emptyItem);
 
-             }
 
-             menu.IsOpen = true;
 
-         }
 
-         private bool EditProperties(BaseSMSProviderProperties properties)
 
-         {
 
-             var editor = new DynamicEditorForm(properties.GetType());
 
-             editor.ReadOnly = ReadOnly;
 
-             editor.Items = new BaseObject[] { properties };
 
-             return editor.ShowDialog() == true;
 
-         }
 
-         private void MenuItem_Click(object sender, RoutedEventArgs e)
 
-         {
 
-             var smsProviderType = (SMSProviderType)(sender as MenuItem)!.Tag;
 
-             BaseSMSProviderProperties? properties = SMSProviderProperties.ToProperties(smsProviderType, null);
 
-             if(properties != null && EditProperties(properties))
 
-             {
 
-                 SaveItem(new SMSProviderProperties()
 
-                 {
 
-                     ProviderType = smsProviderType,
 
-                     Properties = Serialization.Serialize(properties)
 
-                 });
 
-                 Refresh(false, true);
 
-             }
 
-         }
 
-         public void Load(object item, Func<Type, CoreTable?>? PageDataHandler)
 
-         {
 
-             var data = PageDataHandler?.Invoke(typeof(SMSProviderProperties));
 
-             if (data != null)
 
-             {
 
-                 WorkingList = data.Rows.Select(x => x.ToObject<SMSProviderProperties>()).ToList();
 
-             }
 
-             else
 
-             {
 
-                 var serverProperties = item as DatabaseServerProperties;
 
-                 if(serverProperties?.SMSProviderProperties != null)
 
-                 {
 
-                     WorkingList = serverProperties.SMSProviderProperties.Select(
 
-                         x => new SMSProviderProperties() { ProviderType = x.Key, Properties = x.Value }).ToList();
 
-                 }
 
-                 else
 
-                 {
 
-                     WorkingList = new();
 
-                 }
 
-             }
 
-             Refresh(true, true);
 
-             Ready = true;
 
-         }
 
-         public Size MinimumSize()
 
-         {
 
-             return new Size(400, 400);
 
-         }
 
-         public int Order()
 
-         {
 
-             return int.MinValue;
 
-         }
 
-         protected override void DeleteItems(params CoreRow[] rows)
 
-         {
 
-             foreach(var row in rows)
 
-             {
 
-                 WorkingList.RemoveAll(x => x.ProviderType.ToString() == row["ProviderType"].ToString());
 
-             }
 
-         }
 
-         public override bool EditItems(SMSProviderProperties[] items, Func<Type, CoreTable> PageDataHandler = null, bool PreloadPages = false)
 
-         {
 
-             var item = items.FirstOrDefault();
 
-             if (item == null)
 
-                 return false;
 
-             BaseSMSProviderProperties? properties = item.ToProperties();
 
-             if (properties != null && EditProperties(properties))
 
-             {
 
-                 item.Properties = Serialization.Serialize(properties);
 
-                 return true;
 
-             }
 
-             return false;
 
-         }
 
-         protected override SMSProviderProperties LoadItem(CoreRow row)
 
-         {
 
-             return WorkingList[row.Index];
 
-         }
 
-         protected override void Reload(Filters<SMSProviderProperties> criteria, Columns<SMSProviderProperties> columns, ref SortOrder<SMSProviderProperties>? sort, Action<CoreTable?, Exception?> action)
 
-         {
 
-             var table = new CoreTable();
 
-             table.LoadColumns(typeof(SMSProviderProperties));
 
-             foreach(var item in WorkingList)
 
-             {
 
-                 table.LoadRow(item);
 
-             }
 
-             action(table, null);
 
-         }
 
-         public override void SaveItem(SMSProviderProperties item)
 
-         {
 
-             if (!WorkingList.Contains(item))
 
-                 WorkingList.Add(item);
 
-         }
 
-     }
 
- }
 
 
  |