using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media.Imaging; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; namespace PRSDesktop; internal class CostSheetGrid : DynamicDataGrid { private bool bShowAll; private readonly BitmapImage docs = PRSDesktop.Resources.doc_png.AsBitmapImage(); public CostSheetGrid() { Options.AddRange(DynamicGridOption.RecordCount, DynamicGridOption.AddRows, DynamicGridOption.DeleteRows, DynamicGridOption.EditRows, DynamicGridOption.FilterRows, DynamicGridOption.SelectColumns, DynamicGridOption.MultiSelect); HiddenColumns.Add(x => x.Code); HiddenColumns.Add(x => x.LastUpdate); HiddenColumns.Add(x => x.Documents); ActionColumns.Add(new DynamicImageColumn(DocumentsImage, DocumentsClick) { Position = DynamicActionColumnPosition.Start }); AddButton("Clone", PRSDesktop.Resources.clone.AsBitmapImage(), CloneCostSheet); AddButton("Show All", null, ToggleVisible); } private bool CloneCostSheet(Button sender, CoreRow[] rows) { if (rows == null || rows.Length != 1) { MessageBox.Show("Please select a single cost sheet to duplicate!"); return false; } return Duplicate(rows.First(), x => x.Code, new[] { typeof(CostSheetKit), typeof(CostSheetDocument) }); } private bool DocumentsClick(CoreRow arg) { if (arg == null) return false; var docs = new List(); using (new WaitCursor()) { var deliveryid = arg.Get(x => x.ID); var table = new Client().Query( new Filter(x => x.EntityLink.ID).IsEqualTo(deliveryid) ); foreach (var row in table.Rows) docs.Add(row.ToObject()); } if (docs.Any()) { var editor = new DocumentEditor(docs.ToArray()); //editor.PrintAllowed = Security.IsAllowed(); editor.SaveAllowed = Security.IsAllowed(); editor.ShowDialog(); } else { MessageBox.Show("No Documents Available!"); } return false; } private BitmapImage DocumentsImage(CoreRow arg) { if (arg == null) return docs; return arg.Get(x => x.Documents) > 0 ? docs : null; } private bool ToggleVisible(Button arg1, CoreRow[] arg2) { bShowAll = !bShowAll; arg1.Content = bShowAll ? "Active Only" : "Show All"; return true; } protected override void Reload(Filters criteria, Columns columns, ref SortOrder sort, Action action) { if (!bShowAll) criteria.Add(new Filter(x => x.Active).IsEqualTo(true)); base.Reload(criteria, columns, ref sort, action); } }