Skip to content

Commit

Permalink
Optimize ControlPanel ConfigurationDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager committed Feb 28, 2022
1 parent 4b52a30 commit c76e14d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
<DropShadowEffect BlurRadius="12" Direction="-90" RenderingBias="Quality" ShadowDepth="1"/>
</Grid.Effect>
<Button Content="Connect" HorizontalAlignment="Center" Margin="0,392,0,0" VerticalAlignment="Top" Click="ButtonConnect_Click" Width="500" RenderTransformOrigin="0.525,2.063" FontSize="16" Background="White" Height="39"/>
<ComboBox x:Name="ComboBoxLanguage" HorizontalAlignment="Left" Margin="214,279,0,0" VerticalAlignment="Top" Width="177" FontSize="16"/>
<TextBox x:Name="TextBoxIpAddress" HorizontalAlignment="Left" Text="192.168.100.20" TextWrapping="Wrap" VerticalAlignment="Top" Width="122" Margin="214,245,0,0" Height="24" FontSize="16" KeyDown="TextBoxIpAddress_KeyDown" GotFocus="TextBoxIpAddress_GotFocus"/>
<Label Content="IpAddress:" HorizontalAlignment="Left" Margin="125,242,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<Label Content="Language:" HorizontalAlignment="Left" Margin="126,277,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<ComboBox x:Name="ComboBoxEncoding" HorizontalAlignment="Left" Margin="214,315,0,0" VerticalAlignment="Top" Width="177" FontSize="16" />
<Label Content="Encoding:" HorizontalAlignment="Left" Margin="130,313,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<ComboBox x:Name="ComboBoxLanguage" HorizontalAlignment="Left" Margin="214,308,0,0" VerticalAlignment="Top" Width="177" FontSize="16"/>
<TextBox x:Name="TextBoxIpAddress" HorizontalAlignment="Left" Text="192.168.100.20" TextWrapping="Wrap" VerticalAlignment="Top" Width="122" Margin="214,212,0,0" Height="24" FontSize="16" KeyDown="TextBoxIpAddress_KeyDown" GotFocus="TextBoxIpAddress_GotFocus"/>
<Label Content="IpAddress" HorizontalAlignment="Left" Margin="125,208,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<Label Content="Language" HorizontalAlignment="Left" Margin="126,306,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<ComboBox x:Name="ComboBoxEncoding" HorizontalAlignment="Left" Margin="214,341,0,0" VerticalAlignment="Top" Width="177" FontSize="16"/>
<Label Content="Encoding" HorizontalAlignment="Left" Margin="130,339,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<Image HorizontalAlignment="Left" Height="220" VerticalAlignment="Top" Width="500" Source="SplashScreen.png"/>

<TextBox x:Name="TextBoxPort" HorizontalAlignment="Left" Text="20007" TextWrapping="Wrap" VerticalAlignment="Top" Width="51" Margin="214,245,0,0" Height="24" FontSize="16" TextAlignment="Right"/>
<Label Content="Port" HorizontalAlignment="Left" Margin="166,241,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
<CheckBox x:Name="CheckBoxTcpKeepalive" Content="" HorizontalAlignment="Left" Margin="214,283,0,0" VerticalAlignment="Top"/>
<Label Content="TCP Keepalive" HorizontalAlignment="Left" Margin="97,273,0,0" VerticalAlignment="Top" FontSize="16" Foreground="White"/>
</Grid>
</Window>
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@ public DeviceConfigurationDialog()

private void CloseDialog()
{
if (!int.TryParse(this.TextBoxPort.Text, out var port))
{
MessageBox.Show("Cannot parse port", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
return;
}

this.DeviceConfiguration.IpAddress = this.TextBoxIpAddress.Text.Trim();
this.DeviceConfiguration.Port = port;
this.DeviceConfiguration.Language = (Language)this.ComboBoxLanguage.SelectedItem;
this.DeviceConfiguration.Encoding = (ZvtEncoding)this.ComboBoxEncoding.SelectedItem;
this.DeviceConfiguration.TcpKeepalive = (bool)this.CheckBoxTcpKeepalive.IsChecked;

this.DialogResult = true;
this.Close();
Expand Down
7 changes: 6 additions & 1 deletion src/Portalum.Zvt.ControlPanel/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ private async Task<bool> ConnectAsync()
var loggerCommunication = this._loggerFactory.CreateLogger<TcpNetworkDeviceCommunication>();
var loggerZvtClient = this._loggerFactory.CreateLogger<ZvtClient>();

this._deviceCommunication = new TcpNetworkDeviceCommunication(this._deviceConfiguration.IpAddress, logger: loggerCommunication);
this._deviceCommunication = new TcpNetworkDeviceCommunication(
ipAddress: this._deviceConfiguration.IpAddress,
port:this._deviceConfiguration.Port,
enableKeepAlive: this._deviceConfiguration.TcpKeepalive,
logger: loggerCommunication);

this._deviceCommunication.ConnectionStateChanged += this.ConnectionStateChanged;

this.CommunicationUserControl.SetDeviceCommunication(this._deviceCommunication);
Expand Down
2 changes: 2 additions & 0 deletions src/Portalum.Zvt.ControlPanel/Models/DeviceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
public class DeviceConfiguration
{
public string IpAddress { get; set; }
public int Port { get; set; }
public ZvtEncoding Encoding { get; set; }
public Language Language { get; set; }
public bool TcpKeepalive { get; set; }
}
}

0 comments on commit c76e14d

Please sign in to comment.