using System; using System.Collections.Generic; using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Input; 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 Inflector; using Color = System.Drawing.Color; namespace PRSDesktop { public partial class JobDocumentSetPanel : UserControl, IJobControl, IDataModelSource, IPanel { private enum Suppress { This } public Guid ParentID { get; set; } public JobPanelSettings Settings { get; set; } public JobDocumentSetPanel() { using (new EventSuppressor(Suppress.This)) 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; private bool GetAreas(CoreTable areas, ComboBox target) //, RowDefinition row) { using (new EventSuppressor(Suppress.This)) { Dictionary result = new Dictionary() { { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" } }; areas.IntoDictionary(result, x => x.ID, (r) => $"{r.Get(c => c.Code)}: {r.Get(c => c.Description)}"); // row.Height = result.Count > 1 // ? new GridLength(1, GridUnitType.Auto) // : new GridLength(0, GridUnitType.Pixel); var value = target.SelectedValue; target.ItemsSource = result; target.SelectedValue = value; return result.Count > 1; } } private bool GetTags(CoreTable tags, JobDocumentSetTagType type, ComboBox target) //, RowDefinition row) { using (new EventSuppressor(Suppress.This)) { Dictionary result = new Dictionary() { { Guid.Empty, "" } //$"All {type.ToString().Pluralize()}" } }; foreach (var tag in tags.Rows.Where(x => x.Get(x => x.Type).Equals(type))) result[tag.Get(c => c.ID)] = tag.Get(c => c.Description); // row.Height = result.Count > 1 // ? new GridLength(1, GridUnitType.Auto) // : new GridLength(0, GridUnitType.Pixel); var value = target.SelectedValue; target.ItemsSource = result; target.SelectedValue = value; return result.Count > 1; } } public void Setup() { tasks.Refresh(true, false); } public void Shutdown() { } public void Refresh() { LoadDocumentTags(); Folders.JobID = this.ParentID; Folders.Refresh(); Documents.JobID = this.ParentID; Documents.Refresh(); } private void LoadDocumentTags() { MultiQuery query = new MultiQuery(); query.Add( new Filter(x => x.Job.ID).IsEqualTo(ParentID).Or(x => x.Job.ID).IsEqualTo(Guid.Empty), null, new SortOrder(x => x.Description) ); query.Add( new Filter(x => x.Job.ID).IsEqualTo(ParentID), new Columns(x => x.ID).Add(x => x.Code).Add(x => x.Description), new SortOrder(x => x.Code) ); query.Query(); var tags = query.Get(); /* Documents.DisciplineVisible = */ GetTags(tags, JobDocumentSetTagType.Discipline, Discipline); //, DisciplineRow); /* Documents.TypeVisible = */ GetTags(tags, JobDocumentSetTagType.Type, Type); //, TypeRow); /* Documents.CategoryVisible = */ GetTags(tags, JobDocumentSetTagType.Category, Category); //, CategoryRow); /* Documents.AreaVisible = */ GetAreas(query.Get(), Area); //, AreaRow); } 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(CoreTreeNode node) { _folderid = node != null ? node.ID : Guid.Empty; LoadDocuments(_folderid); } private void LoadDocuments(Guid folderid) { List folders = new List(); this.Folders.Nodes.GetChildren(folders, folderid); Documents.FolderIDs = folders.ToArray(); Documents.Refresh(); } private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelSettings e) { LoadDocuments(e.View == DynamicSplitPanelView.Detail ? Guid.Empty : _folderid); } private void Preview_OnSizeChanged(object sender, SizeChangedEventArgs e) { //throw new NotImplementedException(); } private void Documents_OnMileStoneSelected(JobDocumentSetMileStoneBlock block) { tasks.JobID = ParentID; tasks.MileStoneID = block?.ID ?? Guid.Empty; tasks.Refresh(false, true); 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.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(), r.ToObject() ) ).ToList(); } else preview.ItemsSource = new List>(); } private void Tag_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { Documents.DisciplineID = (Guid)(Discipline.SelectedValue ?? Guid.Empty); Documents.TypeID = (Guid)(Type.SelectedValue ?? Guid.Empty); Documents.CategoryID = (Guid)(Category.SelectedValue ?? Guid.Empty); Documents.AreaID = (Guid)(Area.SelectedValue ?? Guid.Empty); Documents.Refresh(); } private void PDFDoubleClick(object sender, MouseButtonEventArgs e) { var image = (sender as ListViewItem).Content as Tuple; if (image != null) { var viewer = new DocumentEditor(new JobDocumentSetMileStoneFile[] { image.Item4 }); viewer.ButtonsVisible = false; viewer.ShowDialog(); } } private void Search_OnKeyUp(object sender, KeyEventArgs e) { if ((e.Key == Key.Enter) || (e.Key == Key.Return) || (e.Key == Key.Tab) || (e.Key == Key.OemBackTab)) { Documents.SearchText = Search.Text; Documents.Refresh(); } } private void EditDocumentTags(JobDocumentSetTagType tagtype) { var editor = new JobDocumentSetTagEditor() { TagType = tagtype, JobID = ParentID }; editor.Refresh(true, true); var window = new DynamicContentDialog(editor, false); window.Title = $"{tagtype.ToString()} Document Tags"; window.ShowDialog(); LoadDocumentTags(); } private void DisciplineButton_OnClick(object sender, RoutedEventArgs e) { EditDocumentTags(JobDocumentSetTagType.Discipline); } private void TypeButton_OnClick(object sender, RoutedEventArgs e) { EditDocumentTags(JobDocumentSetTagType.Type); } private void CategoryButton_OnClick(object sender, RoutedEventArgs e) { EditDocumentTags(JobDocumentSetTagType.Category); } private void ShowPreview_OnClick(object sender, RoutedEventArgs e) { PreviewColumn.Width = new GridLength(260, GridUnitType.Pixel); ShowPreview.Visibility = Visibility.Collapsed; } private void HidePreview_OnClick(object sender, RoutedEventArgs e) { PreviewColumn.Width = new GridLength(0, GridUnitType.Pixel); ShowPreview.Visibility = Visibility.Visible; } private void Tasks_OnOnChanged(IDynamicGrid sender) { Documents.Refresh(); } private JobPanelSettings Tasks_OnGetJobPanelSettings() { return Settings; } } }