JobDocumentSetPanel.xaml.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using System.Windows.Controls;
  6. using System.Windows.Media;
  7. using System.Windows.Media.Imaging;
  8. using Comal.Classes;
  9. using InABox.Clients;
  10. using InABox.Core;
  11. using InABox.DynamicGrid;
  12. using InABox.WPF;
  13. using Color = System.Drawing.Color;
  14. namespace PRSDesktop
  15. {
  16. public partial class JobDocumentSetPanel : UserControl, IJobControl, IDataModelSource, IPanel<Job>
  17. {
  18. public Guid JobID { get; set; }
  19. public JobDocumentSetPanel()
  20. {
  21. InitializeComponent();
  22. // Dictionary<String, BitmapImage> images = new Dictionary<string, BitmapImage>()
  23. // {
  24. // { "Sample", PRSDesktop.Resources.localfile.AsBitmapImage() },
  25. // { "Another File", PRSDesktop.Resources.tick.AsBitmapImage() }
  26. // };
  27. // preview.ItemsSource = images;
  28. }
  29. public string SectionName => "Job Document Set";
  30. public DataModel DataModel(Selection selection)
  31. {
  32. var ids = Documents.Data != null ? Documents.Data.ExtractValues<JobDocumentSet, Guid>(x => x.ID).ToArray() : new Guid[] { };
  33. return new AutoDataModel<JobDocumentSet>(new Filter<JobDocumentSet>(x => x.ID).InList(ids));
  34. }
  35. public event DataModelUpdateEvent OnUpdateDataModel;
  36. public void Setup()
  37. {
  38. }
  39. public void Shutdown()
  40. {
  41. }
  42. public void Refresh()
  43. {
  44. Folders.JobID = this.JobID;
  45. Documents.JobID = this.JobID;
  46. Folders.Refresh();
  47. Documents.Refresh();
  48. }
  49. public bool IsReady { get; set; }
  50. public void CreateToolbarButtons(IPanelHost host)
  51. {
  52. // Check In
  53. // Check Out
  54. // Issue
  55. }
  56. public Dictionary<string, object[]> Selected()
  57. {
  58. return new Dictionary<string, object[]>();
  59. }
  60. public void Heartbeat(TimeSpan time)
  61. {
  62. }
  63. private Guid _folderid = Guid.Empty;
  64. private void Folders_OnOnSelectItem(DynamicTreeNode node)
  65. {
  66. _folderid = node != null ? node.ID : Guid.Empty;
  67. Documents.FolderID = _folderid;
  68. Documents.Refresh();
  69. }
  70. private void DynamicSplitPanel_OnOnChanged(object sender, DynamicSplitPanelChangedArgs e)
  71. {
  72. if (e.View == DynamicSplitPanelView.Detail)
  73. Documents.FolderID = Guid.Empty;
  74. else
  75. Documents.FolderID = _folderid;
  76. Documents.Refresh();
  77. }
  78. private void Preview_OnSizeChanged(object sender, SizeChangedEventArgs e)
  79. {
  80. //throw new NotImplementedException();
  81. }
  82. private void Documents_OnMileStoneSelected(JobDocumentSetMileStoneBlock block)
  83. {
  84. if (block != null && block.Attachments > 0)
  85. {
  86. var id = block.ID;
  87. var files = new Client<JobDocumentSetMileStoneFile>().Query(
  88. new Filter<JobDocumentSetMileStoneFile>(x => x.EntityLink.ID).IsEqualTo(block.ID),
  89. new Columns<JobDocumentSetMileStoneFile>(x => x.ID)
  90. .Add(x => x.DocumentLink.FileName)
  91. .Add(x => x.Thumbnail),
  92. new SortOrder<JobDocumentSetMileStoneFile>(x => x.DocumentLink.FileName)
  93. );
  94. preview.ItemsSource = files.Rows
  95. .Select(r =>
  96. new Tuple<Guid, String, BitmapImage>(
  97. r.Get<JobDocumentSetMileStoneFile, Guid>(c => c.ID),
  98. r.Get<JobDocumentSetMileStoneFile, String>(c => c.DocumentLink.FileName),
  99. r.Get<JobDocumentSetMileStoneFile,byte[]>(c=>c.Thumbnail) != null
  100. ? String.IsNullOrWhiteSpace(block.Watermark)
  101. ? ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
  102. : ImageUtils.LoadImage(r.Get<JobDocumentSetMileStoneFile, byte[]>(c => c.Thumbnail))
  103. .AsBitmap().WatermarkImage(block.Watermark,Color.LightSalmon)
  104. .AsBitmapImage()
  105. : ImageUtils.BitmapFromColor(Color.White,256, 192, Color.Transparent)
  106. .WatermarkImage("No Preview\nAvailable", Color.LightGray).AsBitmapImage()
  107. )
  108. ).ToList();
  109. }
  110. else
  111. preview.ItemsSource = new List<Tuple<Guid, String, BitmapImage>>();
  112. }
  113. }
  114. }