Files
DP44/DataPRO/Modules/Hardware/AddEditHardware/.svn/pristine/d0/d05ceee2052f26ae8c472f448a1fbf6994877003.svn-base

236 lines
8.3 KiB
Plaintext
Raw Normal View History

2026-04-17 14:55:32 -04:00
using DTS.Common;
using DTS.Common.Converters;
using DTS.Common.Enums.Hardware;
using DTS.Common.Interface.Hardware.AddEditHardware;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
// ReSharper disable CheckNamespace
namespace AddEditHardware
{
/// <inheritdoc cref="IAddEditHardwareView" />
/// <summary>
/// Interaction logic for AddEditHardwareView.xaml
/// </summary>
public partial class AddEditHardwareView : IAddEditHardwareView, INotifyPropertyChanged
{
#region IPropertyNotified
public event PropertyChangedEventHandler PropertyChanged;
protected bool SetProperty<T>(ref T storage, T value, string propertyName = null)
{
if (Equals(storage, value)) return false;
storage = value;
OnPropertyChanged(propertyName);
return true;
}
protected void OnPropertyChanged(string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion #PropertyNotified
/// <summary>
/// whether the SLICE6TreeView should be shown or not
/// </summary>
public bool AllowStandin
{
get
{
if (null == DataContext) { return true; }
if (!(DataContext is IAddEditHardwareViewModel vm)) { return true; }
return vm.AllowStandin;
}
}
private static List<HardwareTypes> _allDASTypes = new List<HardwareTypes>();
private static HardwareTypes[] AvailableDASType(int ConnectionDbVersion)
{
lock (_allDASTypes)
{
if (!_allDASTypes.Any())
{
PopulateDASTypes(ConnectionDbVersion);
}
}
return _allDASTypes.ToArray();
}
private static void PopulateDASTypes(int ConnectionDbVersion)
{
lock (_allDASTypes)
{
_allDASTypes.AddRange(new[]
{
HardwareTypes.TDAS_Pro_Rack,
HardwareTypes.TDAS_LabRack,
HardwareTypes.G5INDUMMY,
HardwareTypes.G5VDS,
HardwareTypes.SLICE_NANO_Base,
HardwareTypes.SLICE_Micro_Base,
HardwareTypes.SLICE_Distributor,
HardwareTypes.SLICE_EthernetController,
HardwareTypes.SLICE_Mini_Distributor,
HardwareTypes.SLICE_LabEthernet,
HardwareTypes.SLICE1_5_Nano_Base,
HardwareTypes.SLICE1_5_Micro_Base,
HardwareTypes.SLICE2_SIM,
HardwareTypes.SLICE2_DIM,
HardwareTypes.SLICE2_TOM,
HardwareTypes.SLICE2_SLS,
HardwareTypes.SLICE2_SLD,
HardwareTypes.SLICE2_SLT,
HardwareTypes.SLICE6DB,
HardwareTypes.SLICE6DB3,
HardwareTypes.SLICE_Pro_Distributor,
HardwareTypes.SLICE6DB_InDummy,
HardwareTypes.SLICE6_Base,
HardwareTypes.SLICE6_AIR,
HardwareTypes.PowerPro,
HardwareTypes.TSR_AIR_RevB,
HardwareTypes.SLICE1_G5Stack,
HardwareTypes.S6A_EthernetRecorder
});
if (ConnectionDbVersion >= Constants.SLICE6AIR_BR_DB_VERSION)
{
_allDASTypes.Add(HardwareTypes.SLICE6_AIR_BR);
}
if (ConnectionDbVersion >= Constants.SLICE_TC_DB_VERSION)
{
_allDASTypes.Add(HardwareTypes.SLICE6_AIR_TC);
}
if (ConnectionDbVersion >= Constants.SLICE_PRO_CAN_FD_DB_VERSION)
{
_allDASTypes.Add(HardwareTypes.SLICE_PRO_CAN_FD);
}
_allDASTypes.Sort((a, b) =>
{
return EnumDescriptionTypeConverter.GetEnumDescription(a)
.CompareTo(EnumDescriptionTypeConverter.GetEnumDescription(b));
});
}
}
private static SLICEPROSIMConfigurations[] _availableSliceProSimConfigurations = new[]
{
SLICEPROSIMConfigurations.MEGA,
SLICEPROSIMConfigurations.EIGHT_HUNDRED,
SLICEPROSIMConfigurations.SEVEN_HUNDRED,
SLICEPROSIMConfigurations.SIX_HUNDRED
};
private static SLICETCConfigurations[] _availableSliceTCConfigurations = new[]
{
SLICETCConfigurations.EIGHT,
SLICETCConfigurations.SIXTEEN,
SLICETCConfigurations.TWENTYFOUR
};
private static RackSizes[] _availableRackSizes = new[]
{
RackSizes.FOUR,
RackSizes.EIGHT
};
public AddEditHardwareView()
{
InitializeComponent();
cbHardwareTypes.ItemsSource = AvailableDASType(ViewDbVersion);
cbSliceProSimConfigurations.ItemsSource = _availableSliceProSimConfigurations;
cbSliceTCConfigurations.ItemsSource = _availableSliceTCConfigurations;
cbRackSize.ItemsSource = _availableRackSizes;
}
private void btnRemoveModule_Click(object sender, RoutedEventArgs e)
{
if (!(sender is Control control))
{
return;
}
if (!(control.DataContext is IAddEditHardwareDASModule dasModule))
{
return;
}
dasModule.OwningHardware.RemoveModule(dasModule);
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
private void btnAdd_Click(object sender, RoutedEventArgs e)
{
if (!(sender is Control control))
{
return;
}
if (!(control.DataContext is IAddEditHardwareHardware hardware))
{
return;
}
hardware.AddModule();
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
private void cb_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
private void cb_Checked(object sender, RoutedEventArgs e)
{
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
private void cb_Unchecked(object sender, RoutedEventArgs e)
{
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
private void tb_TextChanged(object sender, TextChangedEventArgs e)
{
if (!(ctrlView.DataContext is AddEditHardwareViewModel vm)) { return; }
vm.NotifyModified();
}
/// <summary>
/// handle any initialization that should occur when view is activated
/// </summary>
public void Activated()
{
OnPropertyChanged("AllowStandin");
if (!(DataContext is IAddEditHardwareViewModel vm)) { return; }
if (null != vm.SLICE6TreeView)
{
SLICE6TreeView.Content = vm.SLICE6TreeView;
}
}
private int _DbVersion = DTS.Common.Storage.DbOperations.MINIMUM_LTS_DB_VERSION;
public int ViewDbVersion
{
get => _DbVersion;
set
{
SetProperty(ref _DbVersion, value, "ViewDbVersion");
lock (_allDASTypes)
{
_allDASTypes.Clear();
}
cbHardwareTypes.ItemsSource = AvailableDASType(ViewDbVersion);
}
}
}
}