Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ public class InputWizardDevice : DataModelBase
#region [ Members ]

// Fields
private int m_id;
private string m_acronym;
private string m_name;
private string m_configAcronym;
private string m_configName;
private string m_linkAcronym;
private decimal m_longitude;
private decimal m_latitude;
private int? m_vendorDeviceId;
Expand All @@ -56,24 +58,43 @@ public class InputWizardDevice : DataModelBase
private int m_analogCount;
private bool m_addDigitals;
private bool m_addAnalogs;
private bool m_existing;
private bool m_hasConflict;
private string m_statusColor;
private ObservableCollection<InputWizardDevicePhasor> m_phasorList;
private bool m_useConfigLabels;

#endregion

#region [ Properties ]

/// <summary>
/// Gets or sets existing device ID, if any.
/// Gets or sets ID of the existing database record, if any.
/// </summary>
public int ID { get; set; }
public int ID
{
get => m_id;
set
{
m_id = value;
UpdateStatusColor();
}
}

/// <summary>
/// Gets or sets and provided unique ID for the device.
/// </summary>
public Guid? UniqueID { get; set; }

/// <summary>
/// Gets or sets and provided global ID for the device's configuration cell.
/// </summary>
public Guid? GlobalID3 { get; set; }

/// <summary>
/// Gets or sets the acronym of the existing device record.
/// </summary>
public string OldAcronym { get; set; }

/// <summary>
/// Gets or sets acronym of the <see cref="InputWizardDevice"/>.
/// </summary>
Expand All @@ -91,7 +112,15 @@ public string Acronym
m_acronym = m_acronym.Substring(0, 200);

OnPropertyChanged(nameof(Acronym));
Existing = Device.GetDevice(null, $"WHERE Acronym = '{m_acronym.ToUpper()}'") is not null;

HasConflict =
m_acronym != OldAcronym &&
Device.GetDevice(null, $"WHERE Acronym = '{m_acronym.ToUpper()}'") is not null;

if (UseConfigLabels)
ConfigFrameAcronym = value;
else
DatabaseAcronym = value;
}
}

Expand All @@ -106,6 +135,11 @@ public string Name
{
m_name = value is null || value.Length <= 200 ? value : value.Substring(0, 200);
OnPropertyChanged(nameof(Name));

if (UseConfigLabels)
ConfigFrameName = value;
else
DatabaseName = value;
}
}

Expand Down Expand Up @@ -135,6 +169,19 @@ public string ConfigName
}
}

/// <summary>
/// Gets or sets tooltip info describing the device acronym from the database.
/// </summary>
public string LinkAcronym
{
get => m_linkAcronym;
set
{
m_linkAcronym = value;
OnPropertyChanged(nameof(LinkAcronym));
}
}

/// <summary>
/// Gets or sets <see cref="InputWizardDevice"/> Longitude.
/// </summary>
Expand Down Expand Up @@ -268,14 +315,14 @@ public bool AddAnalogs
/// <summary>
/// Gets or sets <see cref="InputWizardDevice"/> existing flag.
/// </summary>
public bool Existing
public bool HasConflict
{
get => m_existing;
get => m_hasConflict;
set
{
m_existing = value;
OnPropertyChanged(nameof(Existing));
StatusColor = m_existing ? "green" : "transparent";
m_hasConflict = value;
OnPropertyChanged(nameof(HasConflict));
UpdateStatusColor();
}
}

Expand All @@ -289,9 +336,16 @@ public string StatusColor
{
m_statusColor = value;
OnPropertyChanged(nameof(StatusColor));
OnPropertyChanged(nameof(IsHighlighted));
}
}

/// <summary>
/// Gets flag to indicate whether the device is highlighted via <see cref="StatusColor"/>.
/// </summary>
public bool IsHighlighted =>
StatusColor != "transparent";

/// <summary>
/// Gets or sets <see cref="InputWizardDevice"/> phasor list.
/// </summary>
Expand Down Expand Up @@ -380,10 +434,63 @@ public string DigitalLabelsPreview
/// </summary>
public string AnalogLabelsPreview => AnalogLabels is not null ? string.Join(Environment.NewLine, AnalogLabels.Select((label, index) => $"Analog {index}: {label}")) : string.Empty;

internal string DatabaseAcronym { get; set; }
internal string ConfigFrameAcronym { get; set; }
internal string DatabaseName { get; set; }
internal string ConfigFrameName { get; set; }

internal bool UseConfigLabels
{
get => m_useConfigLabels;
set
{
if (m_useConfigLabels == value) return;
m_useConfigLabels = value;
Acronym = m_useConfigLabels ? ConfigFrameAcronym : DatabaseAcronym;
Name = m_useConfigLabels ? ConfigFrameName : DatabaseName;

foreach (InputWizardDevicePhasor phasor in PhasorList)
phasor.UseConfigLabels = value;
}
}

#endregion

#region [ Methods ]

/// <summary>
/// Detaches the input wizard device from the database record it was mapped to.
/// </summary>
public void Unlink()
{
ID = 0;
UniqueID = GlobalID3;
OldAcronym = null;
VendorDeviceID = null;
DatabaseAcronym = ConfigFrameAcronym;
DatabaseName = ConfigFrameName;

if (!UseConfigLabels)
{
Acronym = ConfigFrameAcronym;
Name = ConfigFrameName;
}

foreach (InputWizardDevicePhasor phasor in m_phasorList)
{
phasor.DatabaseLabel = phasor.ConfigFrameLabel;
phasor.DatabaseType = phasor.ConfigFrameType;
phasor.DatabasePhase = phasor.ConfigFramePhase;

if (!phasor.UseConfigLabels)
{
phasor.Label = phasor.ConfigFrameLabel;
phasor.Type = phasor.ConfigFrameType;
phasor.Phase = phasor.ConfigFramePhase;
}
}
}

/// <summary>
/// Retrieves <see cref="ObservableCollection{T}"/> type collection of <see cref="InputWizardDevice"/>.
/// </summary>
Expand Down Expand Up @@ -419,6 +526,22 @@ public static Dictionary<int, string> GetLookupList(AdoDataConnection database,
public static string Delete(AdoDataConnection database, int deviceID) =>
string.Empty;

private void UpdateStatusColor()
{
string statusColor;
if (m_acronym == OldAcronym)
statusColor = "green";
else if (HasConflict)
statusColor = "red";
else if (m_id != 0)
statusColor = "yellow";
else
statusColor = "transparent";

if (statusColor != StatusColor)
StatusColor = statusColor;
}

#endregion
}

Expand All @@ -438,11 +561,14 @@ public class InputWizardDevicePhasor : DataModelBase
private string m_baseKVInput;
//private string m_destinationLabel;
private bool m_include;
private bool m_useConfigLabels;

internal string DatabaseLabel;
internal string ConfigFrameLabel;
internal string DatabaseType;
internal string ConfigFrameType;
internal string DatabasePhase;
internal string ConfigFramePhase;

#endregion

Expand All @@ -460,6 +586,11 @@ public string Label
{
m_label = value is null || value.Length <= 200 ? value : value.Substring(0, 200);
OnPropertyChanged("Label");

if (UseConfigLabels)
ConfigFrameLabel = value;
else
DatabaseLabel = value;
}
}

Expand All @@ -475,6 +606,11 @@ public string Type
{
m_type = value;
OnPropertyChanged("Type");

if (UseConfigLabels)
ConfigFrameType = value;
else
DatabaseType = value;
}
}

Expand Down Expand Up @@ -579,6 +715,18 @@ public bool Include
/// </summary>
public float AngleAdder { get; set; }

internal bool UseConfigLabels
{
get => m_useConfigLabels;
set
{
m_useConfigLabels = value;
Label = m_useConfigLabels ? ConfigFrameLabel : DatabaseLabel;
Type = m_useConfigLabels ? ConfigFrameType : DatabaseType;
Phase = m_useConfigLabels ? ConfigFramePhase : DatabasePhase;
}
}

#endregion
}
}
2 changes: 2 additions & 0 deletions Source/Libraries/GSF.PhasorProtocols/UI/DataModels/Phasor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ public static string SaveAndReorder(AdoDataConnection database, Phasor phasor, i

if (phasor.SourceIndex == 0)
phasor.SourceIndex = database.ExecuteScalar<int>("SELECT MAX(SourceIndex) FROM Phasor WHERE DeviceID = {0}", phasor.DeviceID) + 1;
else if (phasor.SourceIndex != oldSourceIndex)
database.ExecuteNonQuery("UPDATE Phasor SET SourceIndex = -SourceIndex WHERE DeviceID = {0} AND SourceIndex = {1}", phasor.DeviceID, phasor.SourceIndex);

// Since phasors could be reordered in the source device, this test could inadvertently throw an exception when it should not - so the validation has been removed
//if (database.ExecuteScalar<int>("SELECT COUNT(*) FROM Phasor WHERE ID <> {0} AND DeviceID = {1} AND SourceIndex = {2}", phasor.ID, phasor.DeviceID, phasor.SourceIndex) > 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,12 @@
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Step 3: Select Devices to Configure" Margin="0,0,50,0" />
<CheckBox IsChecked="{tsfBinding:Column Path=DataContext.UseConfigLabels, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}}" Content="Use Config Phasor Labels" Margin="0,0,150,0" Visibility="{Binding ElementName=ExpanderStep3, Path=IsExpanded, Converter={StaticResource ObjectToVisibilityConverter}}" />
<CheckBox IsChecked="{tsfBinding:Column Path=DataContext.UseConfigLabels, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=2}}" Content="Use Config Frame Labels" Margin="0,0,150,0" Visibility="{Binding ElementName=ExpanderStep3, Path=IsExpanded, Converter={StaticResource ObjectToVisibilityConverter}}" />
<StackPanel Orientation="Horizontal" Visibility="{Binding ElementName=ExpanderStep3, Path=IsExpanded, Converter={StaticResource ObjectToVisibilityConverter}}">
<TextBlock Background="#FF2EB30D" Foreground="White" Text="*" FontWeight="Bold" TextAlignment="Center" Width="20"/>
<TextBlock Foreground="Red" Text=" Device acronym already exists in the database." />
<TextBlock Foreground="Red" Text="Mouse over to see description: " />
<TextBlock Margin="2 0" Background="#FF2EB30D" Foreground="White" Text="*" FontWeight="Bold" TextAlignment="Center" Width="20" Cursor="Hand" ToolTip="Acronym will not be changed."/>
<TextBlock Margin="2 0" Background="#FFE8E831" Foreground="White" Text="*" FontWeight="Bold" TextAlignment="Center" Width="20" Cursor="Hand" ToolTip="Acronym will be updated."/>
<TextBlock Margin="2 0" Background="#FFFC0808" Foreground="White" Text="*" FontWeight="Bold" TextAlignment="Center" Width="20" Cursor="Hand" ToolTip="Acronym conflicts with another database record. Wizard will fail!"/>
</StackPanel>
</StackPanel>
</DataTemplate>
Expand All @@ -276,13 +278,28 @@
</sdk:DataGridTemplateColumn.HeaderTemplate>
</sdk:DataGridTemplateColumn>

<sdk:DataGridTemplateColumn Width="*">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="{Binding Path=DataContext.UnlinkCommand, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=StackPanel, AncestorLevel=1}}"
CommandParameter="{Binding}" ToolTip="{Binding Path=LinkAcronym}" Width="Auto">
<Button.Template>
<ControlTemplate>
<Image Source="/GSF.TimeSeries.UI;component/images/Unlink.png" Height="24" Width="24" />
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>

<sdk:DataGridTemplateColumn Header="Acronym" Width="4*">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Background="{tsfBinding:Column Path=StatusColor, Converter={StaticResource StringToStatusColorConverter}}">
<TextBox Text="{tsfBinding:Column Path=Acronym}" ToolTip="{Binding Path=ConfigAcronym}" Margin="25,0,0,0" Width="{StaticResource ItemSize}" MaxLength="200"/>
<TextBlock Text="*" Foreground="White" FontWeight="Bold" Margin="2"
Visibility="{tsfBinding:Column Path=Existing, Converter={StaticResource ObjectToVisibilityConverter}}"/>
Visibility="{Binding Path=IsHighlighted, Converter={StaticResource ObjectToVisibilityConverter}}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
Expand Down
Loading
Loading