using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Media; using System.Windows.Media.Imaging; using Comal.Classes; using InABox.Clients; using InABox.Core; using InABox.DynamicGrid; using InABox.WPF; using Color = System.Drawing.Color; namespace PRSDesktop { public partial class JobDocumentSetPanel : UserControl, IJobControl, IDataModelSource, IPanel { public Guid JobID { get; set; } public JobDocumentSetPanel() { InitializeComponent(); // Dictionary images = new Dictionary() // { // { "Sample", PRSDesktop.Resources.localfile.AsBitmapImage() }, // { "Another File", PRSDesktop.Resources.tick.AsBitmapImage() } // }; // preview.ItemsSource = images; } public string SectionName => "Job Document Set"; public DataModel DataModel(Selection selection) { var ids = Documents.Data != null ? Documents.Data.ExtractValues(x => x.ID).ToArray() : new Guid[] { }; return new AutoDataModel(new Filter(x => x.ID).InList(ids)); } public event DataModelUpdateEvent OnUpdateDataModel; public void Setup() { } public void Shutdown() { } public void Refresh() { Folders.JobID = this.JobID; Documents.JobID = this.JobID; Folders.Refresh(); Documents.Refresh(); } public bool IsReady { get; set; } public void CreateToolbarButtons(IPanelHost host) { // Check In // Check Out // Issue } public Dictionary Selected() { return new Dictionary(); } public void Heartbeat(TimeSpan time) { } private Guid _folderid = Guid.Empty; private void Folders_OnOnSelectItem(DynamicTreeNode node) { _folderid = node != null ? node.ID : Guid.Empty; Documents.FolderID = _folderid; Documents.Refresh(); } private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelChangedArgs e) { if (e.View == DynamicSplitPanelView.Detail) Documents.FolderID = Guid.Empty; else Documents.FolderID = _folderid; Documents.Refresh(); } private void Preview_OnSizeChanged(object sender, SizeChangedEventArgs e) { //throw new NotImplementedException(); } private void Documents_OnMileStoneSelected(JobDocumentSetMileStoneBlock block) { if (block != null && block.Attachments > 0) { var id = block.ID; var files = new Client().Query( new Filter(x => x.EntityLink.ID).IsEqualTo(block.ID), new Columns(x => x.ID) .Add(x => x.DocumentLink.FileName) .Add(x => x.Thumbnail), new SortOrder(x => x.DocumentLink.FileName) ); preview.ItemsSource = files.Rows .Select(r => new Tuple( r.Get(c => c.ID), r.Get(c => c.DocumentLink.FileName), r.Get(c=>c.Thumbnail) != null ? String.IsNullOrWhiteSpace(block.Watermark) ? ImageUtils.LoadImage(r.Get(c => c.Thumbnail)) : ImageUtils.LoadImage(r.Get(c => c.Thumbnail)) .AsBitmap().WatermarkImage(block.Watermark,Color.LightSalmon) .AsBitmapImage() : ImageUtils.BitmapFromColor(Color.White,256, 192, Color.Transparent) .WatermarkImage("No Preview\nAvailable", Color.LightGray).AsBitmapImage() ) ).ToList(); } else preview.ItemsSource = new List>(); } } }