V6ElevationSelection.xaml.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Windows;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using InABox.DynamicGrid;
  8. using InABox.Integration.V6;
  9. using PRSDesktop.Integrations.V6;
  10. using PRSDesktop.Integrations.Common;
  11. using PRSDesktop.Integrations.Logikal;
  12. namespace PRSDesktop.Integrations.V6;
  13. public partial class V6ElevationSelection : Window
  14. {
  15. private V6Client _client;
  16. private V6Project? _project;
  17. private string _variation;
  18. private Func<V6Project,V6Elevation[], bool> _callback;
  19. private Func<V6Elevation, bool>? _filter;
  20. public V6ElevationSelection(V6Client client, V6Project? project, Func<V6Elevation,bool>? filter, bool multiselect, Func<V6Project, V6Elevation[],bool> callback)
  21. {
  22. _client = client;
  23. _callback = callback;
  24. _project = project;
  25. _filter = filter;
  26. InitializeComponent();
  27. Projects.Refresh(true,false);
  28. Variations.Refresh(true,false);
  29. Elevations.Options.MultiSelect = multiselect;
  30. Elevations.Refresh(true, false);
  31. }
  32. private void V6ElevationSelection_OnLoaded(object sender, RoutedEventArgs e)
  33. {
  34. if (_client.IsConnected)
  35. {
  36. if (_project != null)
  37. {
  38. ProjectsRow.Height = new GridLength(0);
  39. SplitterRow.Height = new GridLength(0);
  40. Variations.Items = _client.GetVariations(_project);
  41. Variations.Refresh(false,true);
  42. }
  43. else
  44. {
  45. ProjectsRow.Height = new GridLength(2, GridUnitType.Star);
  46. SplitterRow.Height = new GridLength(1, GridUnitType.Auto);
  47. Projects.Items = _client.GetProjects().ToList();
  48. Projects.Refresh(false,true);
  49. }
  50. }
  51. }
  52. private void OK_Click(object sender, RoutedEventArgs e)
  53. {
  54. if (_project == null)
  55. return;
  56. var selected = Elevations.SelectedRows.Select(x => x.Index).ToArray();
  57. var result = _callback.Invoke(_project,selected.Select(x=>Elevations.Items[x]).ToArray());
  58. DialogResult = result;
  59. }
  60. private void Cancel_Click(object sender, RoutedEventArgs e)
  61. {
  62. DialogResult = false;
  63. }
  64. private void Elevations_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  65. {
  66. OK.IsEnabled = Elevations.SelectedRows.Any();
  67. }
  68. private void Projects_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  69. {
  70. var row = e.Rows?.FirstOrDefault();
  71. if (row == null)
  72. return;
  73. _project = Projects.Items[row.Index];
  74. Variations.Items = _client.GetVariations(_project);
  75. Variations.Items.Insert(0, new V6Variation() { ID = "", Description = "Main project"});
  76. }
  77. private void Variations_OnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  78. {
  79. if (_project == null)
  80. return;
  81. var row = e.Rows?.FirstOrDefault();
  82. if (row == null)
  83. return;
  84. _variation = Variations.Items[row.Index].ID;
  85. Elevations.Items = _client.GetElevations(_project, _variation).Where(x=>x.Drawings > 0).ToList();
  86. Elevations.Refresh(false,true);
  87. }
  88. }