Push Changes from Techcrafters Repo
This commit is contained in:
@@ -1,127 +1,176 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace InfineonHMI.Common
|
||||
namespace InfineonHMI.Common;
|
||||
|
||||
public static class L4ItXmlSerializer
|
||||
{
|
||||
public static class L4ItXmlSerializer
|
||||
/// <summary>
|
||||
/// Serializes an object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="serializableObject"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="encrypt"></param>
|
||||
/// <param name="rootElementName"></param>
|
||||
|
||||
public static void SerializeObject<T>(T serializableObject, string fileName, bool encrypt = false, string rootElementName = null)
|
||||
{
|
||||
/// <summary>
|
||||
/// Serializes an object.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="serializableObject"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="encrypt"></param>
|
||||
/// <param name="rootElementName"></param>
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
return;
|
||||
|
||||
public static void SerializeObject<T>(T serializableObject, string fileName, bool encrypt = false, string rootElementName = null)
|
||||
if (serializableObject == null)
|
||||
return;
|
||||
|
||||
XmlSerializer serializer;
|
||||
if (rootElementName != null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName))
|
||||
return;
|
||||
var xmlRoot = new XmlRootAttribute(rootElementName);
|
||||
serializer = new XmlSerializer(serializableObject.GetType(), xmlRoot);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer = new XmlSerializer(serializableObject.GetType());
|
||||
}
|
||||
|
||||
if (serializableObject == null)
|
||||
try
|
||||
{
|
||||
var dir = new FileInfo(fileName).DirectoryName;
|
||||
if (dir != null && !Directory.Exists(dir)) // Überprüfen Sie, ob dir nicht null ist, bevor Sie es verwenden
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
var xmlDocument = new XmlDocument();
|
||||
using var stream = new MemoryStream();
|
||||
serializer.Serialize(stream, serializableObject);
|
||||
stream.Position = 0;
|
||||
xmlDocument.Load(stream);
|
||||
if (encrypt && false)
|
||||
{
|
||||
//FileEncryption.SaveEncryptedToFile(fileName, xmlDocument.OuterXml);
|
||||
return;
|
||||
}
|
||||
xmlDocument.Save(fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Write(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes an xml file into an object list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="decrypt"></param>
|
||||
/// <param name="rootElementName"></param>
|
||||
/// <returns></returns>
|
||||
///
|
||||
///
|
||||
public static T DeSerializeObject<T>(string fileName, bool decrypt = false, string rootElementName = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) return default!;
|
||||
|
||||
T objectOut;
|
||||
|
||||
try
|
||||
{
|
||||
string xmlString;
|
||||
if (decrypt && false)
|
||||
{
|
||||
//xmlString = FileEncryption.ReadDecryptedFromFile(fileName)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var xmlDocument = new XmlDocument();
|
||||
xmlDocument.Load(fileName);
|
||||
xmlString = xmlDocument.OuterXml;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(xmlString))
|
||||
{
|
||||
// Handle empty xmlString if necessary
|
||||
return default!;
|
||||
}
|
||||
|
||||
using var read = new StringReader(xmlString);
|
||||
var outType = typeof(T);
|
||||
|
||||
XmlSerializer serializer;
|
||||
if (rootElementName != null)
|
||||
{
|
||||
var xmlRoot = new XmlRootAttribute(rootElementName);
|
||||
serializer = new XmlSerializer(serializableObject.GetType(), xmlRoot);
|
||||
var root = new XmlRootAttribute(rootElementName);
|
||||
serializer = new XmlSerializer(outType, root);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer = new XmlSerializer(serializableObject.GetType());
|
||||
serializer = new XmlSerializer(outType);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var dir = new FileInfo(fileName).DirectoryName;
|
||||
if (dir != null && !Directory.Exists(dir)) // Überprüfen Sie, ob dir nicht null ist, bevor Sie es verwenden
|
||||
Directory.CreateDirectory(dir);
|
||||
|
||||
var xmlDocument = new XmlDocument();
|
||||
using var stream = new MemoryStream();
|
||||
serializer.Serialize(stream, serializableObject);
|
||||
stream.Position = 0;
|
||||
xmlDocument.Load(stream);
|
||||
if (encrypt && false)
|
||||
{
|
||||
//FileEncryption.SaveEncryptedToFile(fileName, xmlDocument.OuterXml);
|
||||
return;
|
||||
}
|
||||
xmlDocument.Save(fileName);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Write(ex);
|
||||
}
|
||||
using XmlReader reader = new XmlTextReader(read);
|
||||
objectOut = (T)serializer.Deserialize(reader)!;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Deserializes an xml file into an object list
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="decrypt"></param>
|
||||
/// <param name="rootElementName"></param>
|
||||
/// <returns></returns>
|
||||
///
|
||||
///
|
||||
public static T DeSerializeObject<T>(string fileName, bool decrypt = false, string rootElementName = null)
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (string.IsNullOrEmpty(fileName) || !File.Exists(fileName)) return default!;
|
||||
|
||||
T objectOut;
|
||||
|
||||
try
|
||||
{
|
||||
string xmlString;
|
||||
if (decrypt && false)
|
||||
{
|
||||
//xmlString = FileEncryption.ReadDecryptedFromFile(fileName)!;
|
||||
}
|
||||
else
|
||||
{
|
||||
var xmlDocument = new XmlDocument();
|
||||
xmlDocument.Load(fileName);
|
||||
xmlString = xmlDocument.OuterXml;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(xmlString))
|
||||
{
|
||||
// Handle empty xmlString if necessary
|
||||
return default!;
|
||||
}
|
||||
|
||||
using var read = new StringReader(xmlString);
|
||||
var outType = typeof(T);
|
||||
|
||||
XmlSerializer serializer;
|
||||
if (rootElementName != null)
|
||||
{
|
||||
var root = new XmlRootAttribute(rootElementName);
|
||||
serializer = new XmlSerializer(outType, root);
|
||||
}
|
||||
else
|
||||
{
|
||||
serializer = new XmlSerializer(outType);
|
||||
}
|
||||
|
||||
using XmlReader reader = new XmlTextReader(read);
|
||||
objectOut = (T)serializer.Deserialize(reader)!;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.Write(ex);
|
||||
return default!;
|
||||
}
|
||||
|
||||
return objectOut;
|
||||
Console.Write(ex);
|
||||
return default!;
|
||||
}
|
||||
|
||||
return objectOut;
|
||||
}
|
||||
}
|
||||
|
||||
public static string Encrypt(string encryptString)
|
||||
{
|
||||
string EncryptionKey = "0ram@1234xxxxxxxxxxtttttuuuuuiiiiio"; //we can change the code converstion key as per our requirement
|
||||
byte[] clearBytes = Encoding.Unicode.GetBytes(encryptString);
|
||||
using (Aes encryptor = Aes.Create())
|
||||
{
|
||||
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] {
|
||||
0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76
|
||||
});
|
||||
encryptor.Key = pdb.GetBytes(32);
|
||||
encryptor.IV = pdb.GetBytes(16);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(clearBytes, 0, clearBytes.Length);
|
||||
cs.Close();
|
||||
}
|
||||
encryptString = Convert.ToBase64String(ms.ToArray());
|
||||
}
|
||||
}
|
||||
return encryptString;
|
||||
}
|
||||
|
||||
public static string Decrypt(string cipherText)
|
||||
{
|
||||
string EncryptionKey = "0ram@1234xxxxxxxxxxtttttuuuuuiiiiio"; //we can change the code converstion key as per our requirement, but the decryption key should be same as encryption key
|
||||
cipherText = cipherText.Replace(" ", "+");
|
||||
byte[] cipherBytes = Convert.FromBase64String(cipherText);
|
||||
using (Aes encryptor = Aes.Create())
|
||||
{
|
||||
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] {
|
||||
0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76
|
||||
});
|
||||
encryptor.Key = pdb.GetBytes(32);
|
||||
encryptor.IV = pdb.GetBytes(16);
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
|
||||
{
|
||||
cs.Write(cipherBytes, 0, cipherBytes.Length);
|
||||
cs.Close();
|
||||
}
|
||||
cipherText = Encoding.Unicode.GetString(ms.ToArray());
|
||||
}
|
||||
}
|
||||
return cipherText;
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,9 @@
|
||||
xmlns:common="clr-namespace:Common"
|
||||
xmlns:HMIToolkit="clr-namespace:HMIToolkit"
|
||||
d:DataContext="{d:DesignInstance Type=common:MediaContainerVm, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
MinWidth="200">
|
||||
<UserControl.Resources>
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Resources>
|
||||
<HMIToolkit:FeedbackToColorConverter x:Key="feedbackConverter" />
|
||||
</UserControl.Resources>
|
||||
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
|
||||
@@ -19,65 +17,85 @@
|
||||
<Style TargetType="UserControl">
|
||||
<!-- Property="Background" Value="White" /> -->
|
||||
<Setter Property="Height" Value="300" />
|
||||
<Setter Property="Width" Value="100" />
|
||||
</Style>
|
||||
</d:DesignerProperties.DesignStyle>
|
||||
|
||||
<Grid Height="Auto">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition/>
|
||||
<ColumnDefinition Width="25*"/>
|
||||
<ColumnDefinition Width="25*"/>
|
||||
<ColumnDefinition Width="50*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="10*"/>
|
||||
<RowDefinition Height="30*"/>
|
||||
<RowDefinition Height="30*"/>
|
||||
<RowDefinition Height="30*"/>
|
||||
<RowDefinition Height="70"/>
|
||||
<RowDefinition Height="100"/>
|
||||
<RowDefinition Height="100"/>
|
||||
<RowDefinition Height="180"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="2"/>
|
||||
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="3" BorderBrush="White" BorderThickness="2"/>
|
||||
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
|
||||
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding SName, Mode=OneWay }" HorizontalAlignment="Center" FontSize="24"/>
|
||||
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3" HorizontalContentAlignment="Center" Content="{Binding SName, Mode=OneWay }" FontSize="35"/>
|
||||
|
||||
<Grid Grid.Row="1">
|
||||
<Grid Grid.Row="1" Grid.Column="2">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
|
||||
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Übervoll" HorizontalAlignment="Center" FontSize="16"/>
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Übervoll" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Width="200" FontSize="30"/>
|
||||
<RadioButton Margin="5" Grid.Row="1" IsChecked="{Binding Overload}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid Grid.Column="0" Grid.Row="2">
|
||||
|
||||
<Grid Grid.Column="1" Grid.Row="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
|
||||
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Voll" HorizontalAlignment="Center" FontSize="16"/>
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Voll" HorizontalAlignment="Center" FontSize="30"/>
|
||||
<RadioButton Grid.Row="1" Margin="5" IsChecked="{Binding Full}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
<Grid Grid.Row="3">
|
||||
|
||||
<Grid Grid.Row="1" Grid.Column="0">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Row="0" BorderBrush="White" BorderThickness="1" />
|
||||
<Border Grid.Row="1" BorderBrush="White" BorderThickness="1" />
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Leer" HorizontalAlignment="Center" FontSize="16"/>
|
||||
<Label Grid.Row="0" VerticalAlignment="Center" Content="Leer" HorizontalAlignment="Center" FontSize="30"/>
|
||||
<RadioButton Grid.Row="1" Margin="5" IsChecked="{Binding Empty}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
|
||||
</Grid>
|
||||
|
||||
<Border Grid.Column="1" Grid.Row="1" Grid.RowSpan="3" BorderBrush="White" BorderThickness="1"></Border>
|
||||
<Grid Grid.Column="1" Grid.Row="1" Grid.RowSpan="3">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition/>
|
||||
<RowDefinition/>
|
||||
</Grid.RowDefinitions>
|
||||
<Button x:Name="btnFill" DataContext="{Binding FillButton}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" Grid.Row="0" Grid.Column="0" Content="Füllen" Margin="5" />
|
||||
<Button x:Name="btnOpen" DataContext="{Binding EmptyButton}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" Grid.Row="1" Grid.Column="0" Content="Leeren" Margin="5" />
|
||||
</Grid>
|
||||
<Border Grid.Column="1" Grid.Row="1" BorderBrush="White" BorderThickness="1"/>
|
||||
|
||||
</Grid>
|
||||
<Grid Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button x:Name="btnOpen"
|
||||
Grid.Column="0"
|
||||
DataContext="{Binding EmptyButton}"
|
||||
Command="{Binding ButtonClickedCommand}"
|
||||
IsEnabled="{Binding XRelease}"
|
||||
Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}"
|
||||
Content="Leeren"
|
||||
Height="100"
|
||||
FontSize="30"/>
|
||||
|
||||
<Button x:Name="btnFill"
|
||||
Grid.Column="1"
|
||||
DataContext="{Binding FillButton}"
|
||||
Command="{Binding ButtonClickedCommand}"
|
||||
IsEnabled="{Binding XRelease}"
|
||||
Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}"
|
||||
Content="Füllen"
|
||||
Height="100"
|
||||
FontSize="30"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Common
|
||||
namespace Common;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class MediaContainer : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class MediaContainer : UserControl
|
||||
{
|
||||
public bool IsReadonly { get; set; }
|
||||
public bool IsReadonly { get; set; }
|
||||
|
||||
public MediaContainer()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
public MediaContainer()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
68
uniper_hmi/UniperHMI/Common/PackMLControl.xaml
Normal file
68
uniper_hmi/UniperHMI/Common/PackMLControl.xaml
Normal file
@@ -0,0 +1,68 @@
|
||||
<UserControl x:Class="Common.PackMLControl"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:common="clr-namespace:Common"
|
||||
xmlns:HMIToolkit="clr-namespace:HMIToolkit"
|
||||
d:DataContext="{d:DesignInstance Type=common:PackMLControlVM, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
Width="Auto"
|
||||
Height="Auto"
|
||||
MinHeight="800"
|
||||
MinWidth="500">
|
||||
<UserControl.Resources>
|
||||
<HMIToolkit:FeedbackToColorConverter x:Key="feedbackConverter"/>
|
||||
</UserControl.Resources>
|
||||
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
|
||||
<!-- Style to see things in the designer-->
|
||||
<d:DesignerProperties.DesignStyle>
|
||||
<Style TargetType="UserControl">
|
||||
<!--<Setter Property="Background" Value="Transparent" />-->
|
||||
<Setter Property="Height" Value="300" />
|
||||
<Setter Property="Width" Value="250" />
|
||||
</Style>
|
||||
</d:DesignerProperties.DesignStyle>
|
||||
|
||||
<Grid Height="Auto">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="250"/>
|
||||
<ColumnDefinition Width="250"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="8*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="1*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
<RowDefinition Height="15*"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Border Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="2"/>
|
||||
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
|
||||
<Label Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Content="{Binding STitle}" HorizontalAlignment="Center" FontSize="44"/>
|
||||
|
||||
<Label Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" Content="{Binding SCurrentState}" FontSize="32"/>
|
||||
<Border Grid.Row="1" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="1,1,1,0"></Border>
|
||||
<Label Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" Margin="10" Content="{Binding SCurrentMode}" FontSize="32"/>
|
||||
<Border Grid.Row="2" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="1,0,1,1"></Border>
|
||||
|
||||
|
||||
<Border Grid.Row="0" Grid.Column="0" Grid.RowSpan="9" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="1"></Border>
|
||||
<Border Grid.Row="4" Grid.Column="0" Grid.RowSpan="1" Grid.ColumnSpan="2" BorderBrush="White" BorderThickness="2"></Border>
|
||||
|
||||
<Button Visibility="Visible" Grid.Row="3" Grid.Column="0" Content="Produktion" Margin="5" DataContext="{Binding ProdModeButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="3" Grid.Column="1" Content="Manuell" Margin="5" DataContext="{Binding ManualModeButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="5" Grid.Column="0" Content="Clear" Margin="5" DataContext="{Binding ClearButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="5" Grid.Column="1" Content="Reset" Margin="5" DataContext="{Binding ResetButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="6" Grid.Column="0" Content="Abbruch" Margin="5" DataContext="{Binding AbortButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="6" Grid.Column="1" Content="Hold" Margin="5" DataContext="{Binding HoldButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="7" Grid.Column="0" Content="Stop" Margin="5" DataContext="{Binding StopButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="7" Grid.Column="1" Content="Suspend" Margin="5" DataContext="{Binding SuspendButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="8" Grid.Column="0" Content="Unhold" Margin="5" DataContext="{Binding UnholdButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
<Button Visibility="Visible" Grid.Row="8" Grid.Column="1" Content="Unsuspend" Margin="5" DataContext="{Binding UnsuspendButtonVm}" Command="{Binding ButtonClickedCommand}" IsEnabled="{Binding XRelease}" Background="{Binding IFeedback, Converter={StaticResource feedbackConverter}}" FontSize="32" />
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
27
uniper_hmi/UniperHMI/Common/PackMLControl.xaml.cs
Normal file
27
uniper_hmi/UniperHMI/Common/PackMLControl.xaml.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Common;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für WorkingModeSelectionControl.xaml
|
||||
/// </summary>
|
||||
public partial class PackMLControl : UserControl
|
||||
{
|
||||
public PackMLControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
201
uniper_hmi/UniperHMI/Common/PackMLControlVm.cs
Normal file
201
uniper_hmi/UniperHMI/Common/PackMLControlVm.cs
Normal file
@@ -0,0 +1,201 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using TwinCAT.TypeSystem;
|
||||
using Heisig.HMI.AdsManager;
|
||||
using HMIToolkit;
|
||||
using InfineonHMI.Common;
|
||||
|
||||
namespace Common;
|
||||
|
||||
public sealed partial class PackMLControlVM : ObservableValidator, IDisposable
|
||||
{
|
||||
|
||||
private IAdsManager _adsManager;
|
||||
private readonly string _variableName;
|
||||
|
||||
[ObservableProperty] private string? sTitle;
|
||||
|
||||
[ObservableProperty] private string? sCurrentMode;
|
||||
|
||||
[ObservableProperty] private string? sCurrentState;
|
||||
|
||||
[ObservableProperty] private HMIControlButtonVM? prodModeButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? manualModeButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? clearButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? resetButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? startButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? abortButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? holdButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? stopButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? suspendButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? unholdButtonVm;
|
||||
[ObservableProperty] private HMIControlButtonVM? unsuspendButtonVm;
|
||||
|
||||
[ObservableProperty] private bool canUserInteract;
|
||||
|
||||
public PackMLControlVM()
|
||||
{
|
||||
SCurrentMode = "Modus: ";
|
||||
SCurrentState = "Aktueller Zustand: ";
|
||||
STitle = "Betriebsart";
|
||||
ProdModeButtonVm = new();
|
||||
ManualModeButtonVm = new();
|
||||
ClearButtonVm= new();
|
||||
ResetButtonVm= new();
|
||||
StartButtonVm = new();
|
||||
AbortButtonVm = new();
|
||||
HoldButtonVm = new();
|
||||
StopButtonVm = new();
|
||||
SuspendButtonVm = new();
|
||||
UnholdButtonVm = new();
|
||||
UnsuspendButtonVm = new();
|
||||
|
||||
var currentUser = Users.getCurrentUser();
|
||||
canUserInteract = currentUser.UserLevel > 50;
|
||||
}
|
||||
|
||||
public PackMLControlVM(IAdsManager adsManager, string variableName)
|
||||
{
|
||||
|
||||
_adsManager = adsManager;
|
||||
_variableName = variableName;
|
||||
STitle = "Betriebsart";
|
||||
|
||||
SCurrentMode = "Modus: ";
|
||||
SCurrentState = "Aktueller Zustand: ";
|
||||
|
||||
ProdModeButtonVm = new(_adsManager, _variableName + ".stBtnProdMode");
|
||||
ManualModeButtonVm = new(_adsManager, _variableName + ".stBtnManualMode");
|
||||
ClearButtonVm = new(_adsManager, _variableName + ".stBtnClear");
|
||||
ResetButtonVm = new(_adsManager, _variableName + ".stBtnReset");
|
||||
StartButtonVm = new(_adsManager, _variableName + ".stBtnStart");
|
||||
AbortButtonVm = new(_adsManager, _variableName + ".stBtnAbort");
|
||||
HoldButtonVm = new(_adsManager, _variableName + ".stBtnHold");
|
||||
StopButtonVm = new(_adsManager, _variableName + ".stBtnStop");
|
||||
SuspendButtonVm = new(_adsManager, _variableName + ".stBtnSuspend");
|
||||
UnholdButtonVm = new(_adsManager, _variableName + ".stBtnUnhold");
|
||||
UnsuspendButtonVm = new(_adsManager, _variableName + ".stBtnUnsuspend");
|
||||
|
||||
_adsManager.Register(_variableName + ".eCurrentState", StateChanged);
|
||||
_adsManager.Register(_variableName + ".eCurrentMode", ModeChanged);
|
||||
|
||||
var currentUser = Users.getCurrentUser();
|
||||
canUserInteract = currentUser.UserLevel > 50;
|
||||
}
|
||||
|
||||
private void StateChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
var state = (int)e.Value;
|
||||
var curState = "Aktueller Status: ";
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
curState += "Undefined";
|
||||
break;
|
||||
case 1:
|
||||
curState += "Clearing";
|
||||
break;
|
||||
case 2:
|
||||
curState += "Stopped";
|
||||
break;
|
||||
case 3:
|
||||
curState += "Starting";
|
||||
break;
|
||||
case 4:
|
||||
curState += "Idle";
|
||||
break;
|
||||
case 5:
|
||||
curState += "Suspended";
|
||||
break;
|
||||
case 6:
|
||||
curState += "Execute";
|
||||
break;
|
||||
case 7:
|
||||
curState += "Stopping";
|
||||
break;
|
||||
case 8:
|
||||
curState += "Aborting";
|
||||
break;
|
||||
case 9:
|
||||
curState += "Aborted";
|
||||
break;
|
||||
case 10:
|
||||
curState += "Holding";
|
||||
break;
|
||||
case 11:
|
||||
curState += "Held";
|
||||
break;
|
||||
case 12:
|
||||
curState += "Unholding";
|
||||
break;
|
||||
case 13:
|
||||
curState += "Suspending";
|
||||
break;
|
||||
case 14:
|
||||
curState += "Unsuspending";
|
||||
break;
|
||||
case 15:
|
||||
curState += "Resetting";
|
||||
break;
|
||||
case 16:
|
||||
curState += "Completing";
|
||||
break;
|
||||
case 17:
|
||||
curState += "Completed";
|
||||
break;
|
||||
default:
|
||||
curState += "Undefined";
|
||||
break;
|
||||
}
|
||||
SCurrentState = curState;
|
||||
}
|
||||
|
||||
private void ModeChanged(object? sender, ValueChangedEventArgs e)
|
||||
{
|
||||
var curMode = "Aktueller Modus: ";
|
||||
var mode = (int)e.Value;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case 0:
|
||||
curMode += "Invalid";
|
||||
break;
|
||||
case 1:
|
||||
curMode += "Production";
|
||||
break;
|
||||
case 2:
|
||||
curMode += "Maintenance";
|
||||
break;
|
||||
case 3:
|
||||
curMode += "Manual";
|
||||
break;
|
||||
case 4:
|
||||
curMode += "change_over";
|
||||
break;
|
||||
case 5:
|
||||
curMode += "clean";
|
||||
break;
|
||||
case 6:
|
||||
curMode += "set up";
|
||||
break;
|
||||
case 7:
|
||||
curMode += "empty out";
|
||||
break;
|
||||
default:
|
||||
curMode += "Invalid";
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
SCurrentMode = curMode;
|
||||
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -6,27 +6,20 @@
|
||||
xmlns:local="clr-namespace:Common"
|
||||
d:DataContext="{d:DesignInstance Type=local:ParamControlFloatVm, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="600"
|
||||
d:DesignHeight="120"
|
||||
Width="Auto"
|
||||
Height="Auto">
|
||||
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
|
||||
<!-- Style to see things in the designer-->
|
||||
<d:DesignerProperties.DesignStyle>
|
||||
<Style TargetType="UserControl">
|
||||
<!-- Property="Background" Value="White" /> -->
|
||||
<Setter Property="Height" Value="40" />
|
||||
<Setter Property="Width" Value="280" />
|
||||
</Style>
|
||||
</d:DesignerProperties.DesignStyle>
|
||||
<Grid Height="Auto">
|
||||
<Grid Height="70">
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- <ColumnDefinition Width="Auto" /> -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="400" />
|
||||
<ColumnDefinition Width="200" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
|
||||
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" Width="200"/>
|
||||
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay, StringFormat=N2}" Grid.Column="1" MaxLines="1" Width="80" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
|
||||
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" FontSize="30" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay, StringFormat=N2}" Margin="10" Width="Auto" FontSize="30" Grid.Column="1" MaxLines="1" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
|
||||
|
||||
|
||||
</Grid>
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Common
|
||||
namespace Common;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class ParamControlFloat : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class ParamControlFloat : UserControl
|
||||
{
|
||||
public bool IsReadonly { get; set; }
|
||||
public bool IsReadonly { get; set; }
|
||||
|
||||
public ParamControlFloat()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
public ParamControlFloat()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
@@ -6,28 +6,21 @@
|
||||
xmlns:common="clr-namespace:Common"
|
||||
d:DataContext="{d:DesignInstance Type=common:ParamControlIntVm, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
d:DesignWidth="600"
|
||||
d:DesignHeight="120"
|
||||
Width="Auto"
|
||||
Height="Auto">
|
||||
<!-- :DataContext="{d:DesignInstance Type=local:AnalogValueVM, IsDesignTimeCreatable=True}" -->
|
||||
<!-- Style to see things in the designer-->
|
||||
<d:DesignerProperties.DesignStyle>
|
||||
<Style TargetType="UserControl">
|
||||
<!-- Property="Background" Value="White" /> -->
|
||||
<Setter Property="Height" Value="40" />
|
||||
<Setter Property="Width" Value="280" />
|
||||
</Style>
|
||||
</d:DesignerProperties.DesignStyle>
|
||||
<Grid Height="Auto">
|
||||
<Grid Height="70">
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- <ColumnDefinition Width="Auto" /> -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<ColumnDefinition Width="400" />
|
||||
<ColumnDefinition Width="200" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<!-- <Label Grid.Column="0" Content="{Binding SName}" VerticalAlignment="Center" HorizontalAlignment="Left"/> -->
|
||||
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" Width="200"/>
|
||||
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay}" Grid.Column="1" MaxLines="1" Width="80" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
|
||||
|
||||
<Label x:Name="tbName" Grid.Column="0" Content="{Binding SName, Mode=OneWay }" FontSize="30" VerticalAlignment="Center"/>
|
||||
<TextBox x:Name="tbValue" Text="{Binding Value, Mode=TwoWay}" Margin="10" Width="Auto" FontSize="30" Grid.Column="1" MaxLines="1" HorizontalContentAlignment="Right" VerticalContentAlignment="Center" IsReadOnly="{Binding Readonly}" />
|
||||
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace Common
|
||||
namespace Common;
|
||||
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class ParamControlInt : UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaktionslogik für AnalogValue.xaml
|
||||
/// </summary>
|
||||
public partial class ParamControlInt : UserControl
|
||||
{
|
||||
public bool IsReadonly { get; set; }
|
||||
public bool IsReadonly { get; set; }
|
||||
|
||||
public ParamControlInt()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
public ParamControlInt()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Unloaded += OnUnloaded;
|
||||
}
|
||||
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
private void OnUnloaded(object? sender, EventArgs e)
|
||||
{
|
||||
var disposable = DataContext as IDisposable;
|
||||
disposable?.Dispose();
|
||||
}
|
||||
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
private void NumberValidation(object sender, TextCompositionEventArgs e)
|
||||
{
|
||||
Regex regex = new("^[-+]?[0-9]*,?[0-9]+$");
|
||||
e.Handled = regex.IsMatch(e.Text);
|
||||
}
|
||||
}
|
||||
57
uniper_hmi/UniperHMI/Common/User.cs
Normal file
57
uniper_hmi/UniperHMI/Common/User.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace InfineonHMI.Common;
|
||||
|
||||
public static class Users
|
||||
{
|
||||
|
||||
private static User CurrentUser { get; set; }
|
||||
public static ObservableCollection<User> UsersCollection { get; set; }
|
||||
|
||||
public static void setCurrentUser(User u)
|
||||
{
|
||||
CurrentUser = new User(u);
|
||||
}
|
||||
|
||||
public static User getCurrentUser()
|
||||
{
|
||||
if (CurrentUser == null)
|
||||
CurrentUser = new User("undefined", "undef", 0);
|
||||
|
||||
return CurrentUser;
|
||||
}
|
||||
}
|
||||
public class User
|
||||
{
|
||||
public string? UserName { get; set; }
|
||||
|
||||
public string PasswordHash { get; set; }
|
||||
|
||||
public int UserLevel { get; set; }
|
||||
|
||||
|
||||
public User()
|
||||
{
|
||||
}
|
||||
|
||||
public User(User u)
|
||||
{
|
||||
UserName = u.UserName;
|
||||
PasswordHash = u.PasswordHash;
|
||||
UserLevel = u.UserLevel;
|
||||
}
|
||||
|
||||
public User(string name, string hash, int level)
|
||||
{
|
||||
UserName = name;
|
||||
PasswordHash = hash;
|
||||
UserLevel = level;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
52
uniper_hmi/UniperHMI/Common/UserManagementWindow.xaml
Normal file
52
uniper_hmi/UniperHMI/Common/UserManagementWindow.xaml
Normal file
@@ -0,0 +1,52 @@
|
||||
<Window x:Class="InfineonHMI.Common.UserManagementWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:common="clr-namespace:Common"
|
||||
d:DesignHeight="800" d:DesignWidth="1500"
|
||||
d:DataContext="{d:DesignInstance Type=common:UserManagementWindowVm, IsDesignTimeCreatable=True}"
|
||||
mc:Ignorable="d"
|
||||
Title="Benutzer anmelden"
|
||||
Icon="../Resources/user.png"
|
||||
Height="800"
|
||||
Width="1500"
|
||||
Background="Black">
|
||||
<Grid Margin="20">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
<RowDefinition Height="*"/>
|
||||
<RowDefinition Height="Auto"/>
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="550"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="400"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Label Grid.Row="0" Grid.Column="0" Content="Benutzername:" FontSize="50" Margin="20"/>
|
||||
<ComboBox Grid.Row="0"
|
||||
Grid.Column="1"
|
||||
FontSize="40"
|
||||
Margin="20"
|
||||
ItemsSource="{Binding SavedUsers}" SelectedItem="{Binding SelectedUsername}"/>
|
||||
<Button Grid.Row="0" Grid.Column="2"
|
||||
Margin="20" Content="Löschen" FontSize="40" Command="{Binding DeleteUserCommand}"/>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="1" Content="Neuer Benutzer: " FontSize="50" Margin="20" />
|
||||
<TextBox Grid.Column="1" Grid.Row="1" Margin="20" Text="{Binding NewUser}"/>
|
||||
<Button Grid.Row="1" Grid.Column="2" Margin="20" Content="Anmelden" FontSize="40" Command="{Binding LoginCommand}"/>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="2" Content="Passwort: " FontSize="50" Margin="20" />
|
||||
<TextBox Grid.Column="1" Grid.Row="2" FontSize="50" Margin="20" Text="{Binding SelectedUserPassword, UpdateSourceTrigger=PropertyChanged}" Foreground="Transparent" Background="Transparent" />
|
||||
<Button Grid.Row="2" Grid.Column="2" Margin="20" Content="Erstellen" FontSize="40" Command="{Binding CreateUserCommand}" IsEnabled="{Binding IsCreateCommandEnabled}"/>
|
||||
|
||||
<Label Grid.Column="0" Grid.Row="3" Content="Passwort wiederholen: " FontSize="50" Margin="20" />
|
||||
<TextBox Grid.Column="1" Grid.Row="3" FontSize="50" Margin="20" Text="{Binding SelectedUserPasswordWdh, UpdateSourceTrigger=PropertyChanged}" Foreground="Transparent" Background="Transparent"/>
|
||||
|
||||
<Button Grid.Row="5" Grid.Column="2" Height="80" Margin="20" Content="Abmelden" FontSize="40" Command="{Binding LogoffCommand}"/>
|
||||
</Grid>
|
||||
</Window>
|
||||
17
uniper_hmi/UniperHMI/Common/UserManagementWindow.xaml.cs
Normal file
17
uniper_hmi/UniperHMI/Common/UserManagementWindow.xaml.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Windows;
|
||||
|
||||
namespace InfineonHMI.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Login or change user dialog.
|
||||
/// </summary>
|
||||
public partial class UserManagementWindow
|
||||
{
|
||||
public UserManagementWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
// Center dialog to MainWindow
|
||||
Owner = Application.Current.MainWindow;
|
||||
WindowStartupLocation = WindowStartupLocation.CenterOwner;
|
||||
}
|
||||
}
|
||||
213
uniper_hmi/UniperHMI/Common/UserManagementWindowVm.cs
Normal file
213
uniper_hmi/UniperHMI/Common/UserManagementWindowVm.cs
Normal file
@@ -0,0 +1,213 @@
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using Heisig.HMI.AdsManager;
|
||||
using HMIToolkit;
|
||||
using InfineonHMI.Common;
|
||||
using MahApps.Metro.Controls;
|
||||
using Microsoft.Win32;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Drawing.Text;
|
||||
using System.Security;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using TwinCAT.TypeSystem;
|
||||
|
||||
namespace Common;
|
||||
|
||||
public sealed partial class UserManagementWindowVm : ObservableValidator
|
||||
{
|
||||
|
||||
private IAdsManager _adsManager;
|
||||
private readonly string _variableName;
|
||||
|
||||
[ObservableProperty] private string? selectedUsername;
|
||||
|
||||
[ObservableProperty] private string newUser;
|
||||
|
||||
[ObservableProperty] private ObservableCollection<string>? savedUsers;
|
||||
|
||||
private ObservableCollection<User> users;
|
||||
|
||||
private UserManagementWindow dlg = new UserManagementWindow();
|
||||
|
||||
private string selectedUserPassword;
|
||||
|
||||
private string filePath = "C:\\ProgramData\\InfineonHMI_UserData\\Userdata.xml";
|
||||
|
||||
private string selectedUserPasswordWdh;
|
||||
public User CurrentUser { get; set; }
|
||||
public string SelectedUserPassword
|
||||
{
|
||||
get { return selectedUserPassword; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref selectedUserPassword, value);
|
||||
IsCreateCommandEnabled = SelectedUserPasswordWdh.Equals(value) && !string.IsNullOrEmpty(value)&& CurrentUser.UserLevel>0;
|
||||
}
|
||||
}
|
||||
|
||||
public string? SelectedUserPasswordWdh
|
||||
{
|
||||
get { return selectedUserPasswordWdh; }
|
||||
set
|
||||
{
|
||||
SetProperty(ref selectedUserPasswordWdh, value);
|
||||
IsCreateCommandEnabled = SelectedUserPassword.Equals(value) && !string.IsNullOrEmpty(value) && CurrentUser.UserLevel > 0;
|
||||
}
|
||||
}
|
||||
|
||||
[ObservableProperty] private bool isCreateCommandEnabled;
|
||||
|
||||
|
||||
public UserManagementWindowVm()
|
||||
{
|
||||
IsCreateCommandEnabled = false;
|
||||
CurrentUser = new("default", "default", 0);
|
||||
users = L4ItXmlSerializer.DeSerializeObject<ObservableCollection<User>>(filePath);
|
||||
savedUsers = new ObservableCollection<string>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (user.UserName != null)
|
||||
savedUsers.Add(user.UserName);
|
||||
}
|
||||
|
||||
selectedUserPassword = "";
|
||||
selectedUserPasswordWdh = "";
|
||||
selectedUsername = "";
|
||||
SelectedUserPasswordWdh = "";
|
||||
SelectedUserPassword = "";
|
||||
SelectedUsername = "";
|
||||
}
|
||||
|
||||
public UserManagementWindowVm(User curUser)
|
||||
{
|
||||
IsCreateCommandEnabled = true;
|
||||
if (curUser != null)
|
||||
{
|
||||
CurrentUser = curUser;
|
||||
}
|
||||
else
|
||||
{
|
||||
CurrentUser = new User("unknown", "default", 100);
|
||||
}
|
||||
users = L4ItXmlSerializer.DeSerializeObject<ObservableCollection<User>>(filePath);
|
||||
savedUsers = new ObservableCollection<string>();
|
||||
if (users == null)
|
||||
{
|
||||
users = new ObservableCollection<User>();
|
||||
users.Add(new User("default", "ssW+1nwLrdWTKi1tkE/pfQ==", 100));
|
||||
}
|
||||
|
||||
|
||||
foreach (var user in users)
|
||||
{
|
||||
if(user.UserName != null)
|
||||
savedUsers.Add(user.UserName);
|
||||
}
|
||||
|
||||
selectedUserPassword = "";
|
||||
selectedUserPasswordWdh = "";
|
||||
selectedUsername = "";
|
||||
SelectedUserPasswordWdh = "";
|
||||
SelectedUserPassword = "";
|
||||
SelectedUsername = "";
|
||||
|
||||
}
|
||||
|
||||
public User GetCurrentUserLevel()
|
||||
{
|
||||
dlg.DataContext = this;
|
||||
|
||||
dlg.ShowDialog();
|
||||
|
||||
return CurrentUser;
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Login()
|
||||
{
|
||||
|
||||
User userInFile = new User("default", "default", 0);
|
||||
bool userFound = false;
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (user.UserName.Equals(SelectedUsername))
|
||||
{
|
||||
userInFile = user;
|
||||
userFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (userFound && CheckPassword(userInFile))
|
||||
{
|
||||
CurrentUser = userInFile;
|
||||
}
|
||||
|
||||
dlg.Close();
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void Logoff()
|
||||
{
|
||||
CurrentUser = new User("default", "default", 0);
|
||||
dlg.Close();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CreateUser()
|
||||
{
|
||||
if(!SelectedUserPassword.Equals(SelectedUserPasswordWdh))
|
||||
return;
|
||||
|
||||
if (users == null)
|
||||
users = new ();
|
||||
var u = new User
|
||||
{
|
||||
UserName = NewUser,
|
||||
PasswordHash = L4ItXmlSerializer.Encrypt(SelectedUserPassword),
|
||||
UserLevel = 100,
|
||||
};
|
||||
|
||||
users.Add(new User(u));
|
||||
SavedUsers.Add(NewUser);
|
||||
|
||||
SelectedUserPassword = "";
|
||||
SelectedUserPasswordWdh = "";
|
||||
|
||||
L4ItXmlSerializer.SerializeObject(users, filePath);
|
||||
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void DeleteUser()
|
||||
{
|
||||
if (SelectedUsername.Equals("default"))
|
||||
return;
|
||||
|
||||
users.Remove(users.First(user => user.UserName.Equals(SelectedUsername)));
|
||||
|
||||
SavedUsers = new ObservableCollection<string>();
|
||||
foreach (var user in users)
|
||||
{
|
||||
SavedUsers.Add(user.UserName);
|
||||
}
|
||||
|
||||
L4ItXmlSerializer.SerializeObject(users, filePath);
|
||||
|
||||
}
|
||||
|
||||
private bool CheckPassword(User user)
|
||||
{
|
||||
var hashcode = L4ItXmlSerializer.Decrypt(user.PasswordHash);
|
||||
if (hashcode.Equals(SelectedUserPassword))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
34
uniper_hmi/UniperHMI/Common/WorkingmodeToColorConverter.cs
Normal file
34
uniper_hmi/UniperHMI/Common/WorkingmodeToColorConverter.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
|
||||
namespace Common;
|
||||
|
||||
class WorkingmodeToColorConverter : IValueConverter
|
||||
{
|
||||
public Object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
|
||||
{
|
||||
|
||||
if (targetType != typeof(System.Windows.Media.Brush))
|
||||
throw new InvalidOperationException("The target must be a brush");
|
||||
|
||||
|
||||
#pragma warning disable CS8604 // Mögliches Nullverweisargument.
|
||||
var selected = (bool)value;
|
||||
#pragma warning restore CS8604 // Mögliches Nullverweisargument.
|
||||
|
||||
if (selected)
|
||||
{
|
||||
return System.Windows.Media.Brushes.LightSeaGreen;
|
||||
}
|
||||
else
|
||||
{ return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return DependencyProperty.UnsetValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user