V6ElevationSelection.xaml.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 Func<V6Project,V6Elevation[], bool> _callback;
  18. private Func<V6Elevation, bool>? _filter;
  19. public V6ElevationSelection(V6Client client, V6Project? project, Func<V6Elevation,bool>? filter, bool multiselect, Func<V6Project, V6Elevation[],bool> callback)
  20. {
  21. _client = client;
  22. _callback = callback;
  23. _project = project;
  24. _filter = filter;
  25. InitializeComponent();
  26. Projects.Refresh(true,false);
  27. Elevations.Options.MultiSelect = multiselect;
  28. Elevations.Refresh(true, false);
  29. }
  30. private void V6ElevationSelection_OnLoaded(object sender, RoutedEventArgs e)
  31. {
  32. if (_client.IsConnected)
  33. {
  34. if (_project != null)
  35. {
  36. ProjectsColumn.Width = new GridLength(0);
  37. SplitterColumn.Width = new GridLength(0);
  38. Elevations.Items = _client.GetElevations(_project).Where(x=> _filter == null || _filter(x)).ToList();
  39. Elevations.Refresh(false,true);
  40. }
  41. else
  42. {
  43. ProjectsColumn.Width = new GridLength(500);
  44. SplitterColumn.Width = new GridLength(1, GridUnitType.Auto);
  45. Projects.Items = _client.GetProjects().ToList();
  46. Projects.Refresh(false,true);
  47. }
  48. }
  49. }
  50. private void OK_Click(object sender, RoutedEventArgs e)
  51. {
  52. if (_project == null)
  53. return;
  54. var selected = Elevations.SelectedRows.Select(x => x.Index).ToArray();
  55. var result = _callback.Invoke(_project,selected.Select(x=>Elevations.Items[x]).ToArray());
  56. DialogResult = result;
  57. }
  58. private void Cancel_Click(object sender, RoutedEventArgs e)
  59. {
  60. DialogResult = false;
  61. }
  62. private void Elevations_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  63. {
  64. OK.IsEnabled = Elevations.SelectedRows.Any();
  65. }
  66. private void Projects_OnOnSelectItem(object sender, DynamicGridSelectionEventArgs e)
  67. {
  68. var row = e.Rows?.FirstOrDefault();
  69. if (row == null)
  70. return;
  71. _project = Projects.Items[row.Index];
  72. Elevations.Items = _client.GetElevations(_project);
  73. Elevations.Refresh(false,true);
  74. }
  75. }