using System; using System.Collections.Generic; using System.Linq; using InABox.Clients; using InABox.Core; namespace InABox.DynamicGrid { public class FormControlGrid : DynamicGrid where T : DFLayoutControl, new() { public FormControlGrid() { Items = new List(); Options.AddRange(DynamicGridOption.RecordCount); } public List Items { get; set; } protected override void DeleteItems(params CoreRow[] rows) { var items = new List(); foreach (var row in rows) items.Add(Items[row.Index]); Items.RemoveAll(x => items.Contains(x)); } protected override T LoadItem(CoreRow row) { return Items[row.Index]; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { var table = new CoreTable(); table.LoadColumns(typeof(T)); table.LoadRows(Items.OrderBy(x => x.Sequence)); action?.Invoke(table, null); } protected override void SaveItem(T item) { if (!Items.Contains(item)) Items.Add(item); } protected override Document LoadDocument(Guid id) { Document doc = null; if (id == Guid.Empty) doc = new Client().Load(new Filter(x => x.ID).IsEqualTo(id)).FirstOrDefault(); if (doc == null) doc = new Document(); return doc; } protected override Document FindDocument(string filename) { return new Client().Load(new Filter(x => x.FileName).IsEqualTo(filename)).FirstOrDefault(); } protected override void SaveDocument(Document document) { new Client().Save(document, ""); } } }