Implementation Logging and Location with Generics
This commit is contained in:
commit
96b1dc8193
@ -78,10 +78,24 @@
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
<SubType>Designer</SubType>
|
||||
</ApplicationDefinition>
|
||||
<Compile Include="Model\Model.cs" />
|
||||
<Compile Include="Model\Location.cs" />
|
||||
<Compile Include="Model\Node.cs" />
|
||||
<Compile Include="Model\SeverityComboBoxItem.cs" />
|
||||
<Compile Include="Repository\IRepositoryBase.cs" />
|
||||
<Compile Include="Repository\LocationRepository.cs" />
|
||||
<Compile Include="Repository\LoggingRepository.cs" />
|
||||
<Compile Include="Repository\RepositoryBase.cs" />
|
||||
<Compile Include="Validators\IntRangeValidationRule.cs" />
|
||||
<Compile Include="ViewModel\Commands\BaseCommand.cs" />
|
||||
<Compile Include="ViewModel\Commands\RelayCommand.cs" />
|
||||
<Compile Include="Validators\StringRangeValidationRule.cs" />
|
||||
<Compile Include="ViewModel\LocationTreeBuilder.cs" />
|
||||
<Compile Include="ViewModel\LocationViewModel.cs" />
|
||||
<Compile Include="ViewModel\NavigationViewModel.cs" />
|
||||
<Compile Include="Views\LocationView.xaml.cs">
|
||||
<DependentUpon>LocationView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Views\LogView.xaml.cs">
|
||||
<DependentUpon>LogView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@ -93,12 +107,16 @@
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Model\LogModel.cs" />
|
||||
<Compile Include="Model\Logging.cs" />
|
||||
<Compile Include="ViewModel\LogViewModel.cs" />
|
||||
<Compile Include="MainWindow.xaml.cs">
|
||||
<DependentUpon>MainWindow.xaml</DependentUpon>
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Page Include="Views\LocationView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Views\LogView.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
|
35
LoggingClient/LoggingClient/MainWindow.xaml
Normal file → Executable file
35
LoggingClient/LoggingClient/MainWindow.xaml
Normal file → Executable file
@ -1,9 +1,32 @@
|
||||
<Window x:Class="LoggingClient.MainWindow"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:views="clr-namespace:LoggingClient.Views"
|
||||
Title="MainWindow" Height="450" Width="800" ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<views:LogView x:Name = "LogView"/>
|
||||
</Grid>
|
||||
xmlns:local="clr-namespace:LoggingClient.ViewModel"
|
||||
Title="MainWindow" Height="470" Width="800" ResizeMode="NoResize">
|
||||
|
||||
<Window.Resources>
|
||||
<DataTemplate DataType="{x:Type local:LogViewModel}">
|
||||
<views:LogView/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type local:LocationViewModel}">
|
||||
<views:LocationView/>
|
||||
</DataTemplate>
|
||||
</Window.Resources>
|
||||
|
||||
<DockPanel LastChildFill="True">
|
||||
<Grid x:Name="Navigation" DockPanel.Dock="Top">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*"></RowDefinition>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<Button Grid.Row="0" Width="400" Content="Locations" Command="{Binding LocationsCommand}" Margin="394,0,-393,0"/>
|
||||
<Button HorizontalAlignment="Right" Width="400" Content="Log Reader" Command="{Binding LogsCommand}" Margin="0,0,2,0"/>
|
||||
</Grid>
|
||||
<ContentControl x:Name="Pages" DockPanel.Dock="Right" Content="{Binding SelectedViewModel}"/>
|
||||
</DockPanel>
|
||||
</Window>
|
20
LoggingClient/LoggingClient/MainWindow.xaml.cs
Normal file → Executable file
20
LoggingClient/LoggingClient/MainWindow.xaml.cs
Normal file → Executable file
@ -1,20 +1,5 @@
|
||||
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;
|
||||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System.Configuration;
|
||||
using System.Windows;
|
||||
using WpfControlNugget.ViewModel;
|
||||
|
||||
namespace LoggingClient
|
||||
{
|
||||
@ -26,6 +11,7 @@ namespace LoggingClient
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
this.DataContext = new NavigationViewModel();
|
||||
}
|
||||
}
|
||||
}
|
79
LoggingClient/LoggingClient/Model/Location.cs
Executable file
79
LoggingClient/LoggingClient/Model/Location.cs
Executable file
@ -0,0 +1,79 @@
|
||||
using System;
|
||||
|
||||
namespace LoggingClient.Model
|
||||
{
|
||||
public class Location : Model<Location>
|
||||
{
|
||||
public new int Id { get; set; }
|
||||
public int ParentId { get; set; }
|
||||
public int AddressId { get; set; }
|
||||
public string Designation { get; set; }
|
||||
public int BuildingNr { get; set; }
|
||||
public int RoomNr { get; set; }
|
||||
|
||||
public Location()
|
||||
{
|
||||
|
||||
}
|
||||
public Location(int id, int parentId, int addressId, string designation, int buildingNr, int roomNr)
|
||||
{
|
||||
this.Id = id;
|
||||
this.ParentId = parentId;
|
||||
this.AddressId = addressId;
|
||||
this.Designation = designation;
|
||||
this.BuildingNr = buildingNr;
|
||||
this.RoomNr = roomNr;
|
||||
}
|
||||
public bool Equals(Location location)
|
||||
{
|
||||
if (Object.ReferenceEquals(null, location)) return false;
|
||||
if (Object.ReferenceEquals(this, location)) return true;
|
||||
|
||||
return String.Equals(Designation, location.Designation) && String.Equals(BuildingNr, location.BuildingNr) && String.Equals(RoomNr, location.RoomNr);
|
||||
}
|
||||
public override bool Equals(object value)
|
||||
{
|
||||
return Equals(value as Location);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// Choose large primes to avoid hashing collisions
|
||||
const int hashingBase = (int)2166136261;
|
||||
const int hashingMultiplier = 16777619;
|
||||
|
||||
int hash = hashingBase;
|
||||
hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, Designation) ? Designation.GetHashCode() : 0);
|
||||
hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, BuildingNr) ? BuildingNr.GetHashCode() : 0);
|
||||
hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, RoomNr) ? RoomNr.GetHashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
public static bool operator ==(Location locA, Location locB)
|
||||
{
|
||||
if (Object.ReferenceEquals(locA, locB))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
//Ensure that A isnt Null
|
||||
if (Object.ReferenceEquals(null, locA))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (locA.Equals(locB));
|
||||
}
|
||||
|
||||
public static bool operator !=(Location locA, Location locB)
|
||||
{
|
||||
return !(locA == locB);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Designation;
|
||||
}
|
||||
}
|
||||
}
|
@ -3,17 +3,21 @@ using DuplicateCheckerLib;
|
||||
|
||||
namespace LoggingClient.Model
|
||||
{
|
||||
public class LogModel : IEntity
|
||||
public class Logging : IEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Pod { get; set; }
|
||||
public string Location { get; set; }
|
||||
public string Hostname { get; set; }
|
||||
public int Severity { get; set; }
|
||||
public string Severity { get; set; }
|
||||
public DateTime Timestamp { get; set; }
|
||||
public string Message { get; set; }
|
||||
|
||||
public LogModel(int id, string pod, string location, string hostname, int severity, DateTime timestamp, string message)
|
||||
public Logging()
|
||||
{
|
||||
this.Severity = "1";
|
||||
}
|
||||
public Logging(int id, string pod, string location, string hostname, string severity, DateTime timestamp, string message)
|
||||
{
|
||||
this.Id = id;
|
||||
this.Pod = pod;
|
||||
@ -23,7 +27,7 @@ namespace LoggingClient.Model
|
||||
this.Timestamp = timestamp;
|
||||
this.Message = message;
|
||||
}
|
||||
public bool Equals(LogModel secondLogModel)
|
||||
public bool Equals(Logging secondLogModel)
|
||||
{
|
||||
if (Object.ReferenceEquals(null, secondLogModel)) return false;
|
||||
if (Object.ReferenceEquals(this, secondLogModel)) return true;
|
||||
@ -32,19 +36,19 @@ namespace LoggingClient.Model
|
||||
}
|
||||
public override bool Equals(object value)
|
||||
{
|
||||
return Equals(value as LogModel);
|
||||
return Equals(value as Logging);
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
unchecked
|
||||
{
|
||||
// Choose large primes to avoid hashing collisions
|
||||
const int HashingBase = (int)2166136261;
|
||||
const int HashingMultiplier = 16777619;
|
||||
const int hashingBase = (int)2166136261;
|
||||
const int hashingMultiplier = 16777619;
|
||||
|
||||
int hash = HashingBase;
|
||||
hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Message) ? Message.GetHashCode() : 0);
|
||||
hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Severity) ? Severity.GetHashCode() : 0);
|
||||
int hash = hashingBase;
|
||||
hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, Message) ? Message.GetHashCode() : 0);
|
||||
hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, Severity) ? Severity.GetHashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
}
|
9
LoggingClient/LoggingClient/Model/Model.cs
Executable file
9
LoggingClient/LoggingClient/Model/Model.cs
Executable file
@ -0,0 +1,9 @@
|
||||
using DuplicateCheckerLib;
|
||||
|
||||
namespace LoggingClient.Model
|
||||
{
|
||||
public abstract class Model<M> : IEntity
|
||||
{
|
||||
public int Id { get; set; }
|
||||
}
|
||||
}
|
47
LoggingClient/LoggingClient/Model/Node.cs
Executable file
47
LoggingClient/LoggingClient/Model/Node.cs
Executable file
@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace LoggingClient.Model
|
||||
{
|
||||
public class Node<M>
|
||||
{
|
||||
public M ValueObject { get; set; }
|
||||
public Node<M> ParentNode { get; set; }
|
||||
public List<Node<M>> ChildNodesList { get; set; }
|
||||
|
||||
public Node()
|
||||
{
|
||||
this.ChildNodesList = new List<Node<M>>();
|
||||
}
|
||||
public Node(M valueObject)
|
||||
{
|
||||
this.ValueObject = valueObject;
|
||||
this.ParentNode = default;
|
||||
this.ChildNodesList = new List<Node<M>>();
|
||||
}
|
||||
|
||||
public Node(Node<M> parentNode, M valueObject)
|
||||
{
|
||||
this.ValueObject = valueObject;
|
||||
this.ParentNode = parentNode;
|
||||
this.ChildNodesList = new List<Node<M>>();
|
||||
}
|
||||
|
||||
public void AddChildNode(Node<M> childNode)
|
||||
{
|
||||
this.ChildNodesList.Add(childNode);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
if (ValueObject != null)
|
||||
{
|
||||
return ValueObject.ToString();
|
||||
}
|
||||
return "-1";
|
||||
}
|
||||
}
|
||||
}
|
1
LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs
Normal file → Executable file
1
LoggingClient/LoggingClient/Model/SeverityComboBoxItem.cs
Normal file → Executable file
@ -13,5 +13,4 @@ namespace LoggingClient.Model
|
||||
public int Id { get; set; }
|
||||
public int Severity { get; set; }
|
||||
}
|
||||
|
||||
}
|
||||
|
76
LoggingClient/LoggingClient/Repository/IRepositoryBase.cs
Executable file
76
LoggingClient/LoggingClient/Repository/IRepositoryBase.cs
Executable file
@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace LoggingClient.Repository
|
||||
{
|
||||
public interface IRepositoryBase<M>
|
||||
{
|
||||
/// <summary>
|
||||
/// Liefert ein einzelnes Model-Objekt vom Typ M zurück,
|
||||
/// welches anhand dem übergebenen PrimaryKey geladen wird.
|
||||
/// </summary>
|
||||
/// <typeparam name="P">Type des PrimaryKey</typeparam>
|
||||
/// <param name="pkValue">Wert des PrimaryKey</param>
|
||||
/// <returns>gefundenes Model-Objekt, ansonsten null</returns>
|
||||
M GetSingle<P>(P pkValue);
|
||||
|
||||
/// <summary>
|
||||
/// Fügt das Model-Objekt zur Datenbank hinzu (Insert)
|
||||
/// </summary>
|
||||
/// <param name="entity">zu speicherndes Model-Object</param>
|
||||
void Add(M entity);
|
||||
|
||||
/// <summary>
|
||||
/// Löscht das Model-Objekt aus der Datenbank (Delete)
|
||||
/// </summary>
|
||||
/// <param name="entity">zu löschendes Model-Object</param>
|
||||
void Delete(M entity);
|
||||
|
||||
/// <summary>
|
||||
/// Aktualisiert das Model-Objekt in der Datenbank hinzu (Update)
|
||||
/// </summary>
|
||||
/// <param name="entity">zu aktualisierendes Model-Object</param>
|
||||
void Update(M entity);
|
||||
|
||||
/// <summary>
|
||||
/// Gibt eine Liste von Model-Objekten vom Typ M zurück,
|
||||
/// die gemäss der WhereBedingung geladen wurden. Die Werte der
|
||||
/// Where-Bedingung können als separat übergeben werden,
|
||||
/// damit diese für PreparedStatements verwendet werden können.
|
||||
/// (Verhinderung von SQL-Injection)
|
||||
/// </summary>
|
||||
/// <param name="whereCondition">WhereBedingung als string
|
||||
/// z.B. "NetPrice > @netPrice and Active = @active and Description like @desc</param>
|
||||
/// <param name="parameterValues">Parameter-Werte für die Wherebedingung
|
||||
/// bspw: {{"netPrice", 10.5}, {"active", true}, {"desc", "Wolle%"}}</param>
|
||||
/// <returns></returns>
|
||||
List<M> GetAll(string whereCondition, Dictionary<string, object> parameterValues);
|
||||
|
||||
/// <summary>
|
||||
/// Gibt eine Liste aller in der DB vorhandenen Model-Objekte vom Typ M zurück
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
List<M> GetAll();
|
||||
|
||||
/// <summary>
|
||||
/// Zählt in der Datenbank die Anzahl Model-Objekte vom Typ M, die der
|
||||
/// Where-Bedingung entsprechen
|
||||
/// </summary>
|
||||
/// <param name="whereCondition">WhereBedingung als string
|
||||
/// z.B. "NetPrice > @netPrice and Active = @active and Description like @desc</param>
|
||||
/// <param name="parameterValues">Parameter-Werte für die Wherebedingung
|
||||
/// bspw: {{"netPrice", 10.5}, {"active", true}, {"desc", "Wolle%"}}</param>
|
||||
/// <returns></returns>
|
||||
long Count(string whereCondition, Dictionary<string, object> parameterValues);
|
||||
|
||||
/// <summary>
|
||||
/// Zählt alle Model-Objekte vom Typ M
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
long Count();
|
||||
|
||||
/// <summary>
|
||||
/// Gibt den Tabellennamen zurück, auf die sich das Repository bezieht
|
||||
/// </summary>
|
||||
string TableName { get; }
|
||||
}
|
||||
}
|
199
LoggingClient/LoggingClient/Repository/LocationRepository.cs
Executable file
199
LoggingClient/LoggingClient/Repository/LocationRepository.cs
Executable file
@ -0,0 +1,199 @@
|
||||
using LoggingClient.Model;
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
|
||||
namespace LoggingClient.Repository
|
||||
{
|
||||
public class LocationRepository : RepositoryBase<Location>
|
||||
{
|
||||
public override string TableName => "Location";
|
||||
public override string ColumnsForSelect => "location_id, parentId, address_fk, designation, building, room";
|
||||
public override string ColumnsForAdd => "parentId, address_fk, designation, building, room";
|
||||
public override string PrimaryKeyFromTable => "location_id";
|
||||
|
||||
public List<Location> Locations { get; set; }
|
||||
public Location _Locations { get; set; }
|
||||
public LocationRepository(string connectionString) : base(connectionString)
|
||||
{
|
||||
Locations = new List<Location>();
|
||||
}
|
||||
public override void Add(Location location)
|
||||
{
|
||||
try
|
||||
{
|
||||
location.AddressId = 2;
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText =
|
||||
$"INSERT INTO {TableName} ({ColumnsForAdd}) " +
|
||||
$"VALUES " +
|
||||
$"(parentId = {location.ParentId}, address_fk = {location.AddressId} , designation = '{location.Designation}', building = {location.BuildingNr} , room = {location.RoomNr} )";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Delete(Location location)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"DELETE FROM {TableName} WHERE location_id = {location.Id}";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public override List<Location> GetAll(string whereCondition, Dictionary<string, object> parameterValues)
|
||||
{
|
||||
var whereCon = whereCondition;
|
||||
if (parameterValues.Count > 0 && whereCondition != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> p in parameterValues)
|
||||
{
|
||||
whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {whereCon}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Locations.Add(new Location(
|
||||
|
||||
reader.GetInt32("location_id"),
|
||||
reader.GetInt32("parentId"),
|
||||
reader.GetInt32("address_fk"),
|
||||
reader.GetValue(reader.GetOrdinal("designation")) as string,
|
||||
reader.GetInt32("building"),
|
||||
reader.GetInt32("room")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return Locations;
|
||||
}
|
||||
|
||||
public override List<Location> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Locations.Add(new Location(
|
||||
|
||||
reader.GetInt32("location_id"),
|
||||
reader.GetInt32("parentId"),
|
||||
reader.GetInt32("address_fk"),
|
||||
reader.GetValue(reader.GetOrdinal("designation")) as string,
|
||||
reader.GetInt32("building"),
|
||||
reader.GetInt32("room")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return Locations;
|
||||
}
|
||||
|
||||
public override void CallStoredProcedure(Location entity)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
|
||||
public override Location GetSingle<P>(P pkValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {PrimaryKeyFromTable} = {pkValue}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
_Locations = (new Location(
|
||||
|
||||
reader.GetInt32("location_id"),
|
||||
reader.GetInt32("parentId"),
|
||||
reader.GetInt32("address_fk"),
|
||||
reader.GetValue(reader.GetOrdinal("designation")) as string,
|
||||
reader.GetInt32("building"),
|
||||
reader.GetInt32("room")
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return _Locations;
|
||||
}
|
||||
|
||||
public override void Update(Location location)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText =
|
||||
$"UPDATE {TableName} SET address_fk = {location.Id} , designation = '{location.Designation}', building = {location.BuildingNr} , room = {location.RoomNr} WHERE location_id = {location.Id}";
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
192
LoggingClient/LoggingClient/Repository/LoggingRepository.cs
Executable file
192
LoggingClient/LoggingClient/Repository/LoggingRepository.cs
Executable file
@ -0,0 +1,192 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using MySql.Data.MySqlClient;
|
||||
using LoggingClient.Model;
|
||||
|
||||
namespace LoggingClient.Repository
|
||||
{
|
||||
class LoggingRepository : RepositoryBase<Logging>
|
||||
{
|
||||
public override string TableName => "v_logentries";
|
||||
public override string ColumnsForSelect => "id, pod, location, hostname, severity, timestamp, message";
|
||||
public override string ColumnsForAdd { get; }
|
||||
public override string PrimaryKeyFromTable => "id";
|
||||
|
||||
public List<Logging> Logs { get; set; }
|
||||
public Logging _Logs { get; set; }
|
||||
|
||||
public LoggingRepository(string connectionString) : base(connectionString)
|
||||
{
|
||||
Logs = new List<Logging>();
|
||||
}
|
||||
|
||||
public override Logging GetSingle<P>(P pkValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {PrimaryKeyFromTable} = {pkValue}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
_Logs = (new Logging(
|
||||
|
||||
reader.GetInt32("id"),
|
||||
reader.GetValue(reader.GetOrdinal("pod")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("location")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("hostname")) as string,
|
||||
reader.GetString("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetValue(reader.GetOrdinal("message")) as string
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return _Logs;
|
||||
}
|
||||
public override void Add(Logging newLogModelEntry)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "LogMessageAdd";
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = newLogModelEntry.Pod;
|
||||
cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = newLogModelEntry.Hostname;
|
||||
cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = newLogModelEntry.Severity;
|
||||
cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = newLogModelEntry.Message;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
public override void Delete(Logging entity)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
public override void Update(Logging entity)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
public override List<Logging> GetAll(string whereCondition, Dictionary<string, object> parameterValues)
|
||||
{
|
||||
var whereCon = whereCondition;
|
||||
if (parameterValues.Count > 0 && whereCondition != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> p in parameterValues)
|
||||
{
|
||||
whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName} WHERE {whereCon}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Logs.Add(new Logging(
|
||||
|
||||
reader.GetInt32("id"),
|
||||
reader.GetValue(reader.GetOrdinal("pod")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("location")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("hostname")) as string,
|
||||
reader.GetString("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetValue(reader.GetOrdinal("message")) as string
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return Logs;
|
||||
}
|
||||
public override List<Logging> GetAll()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (MySqlCommand cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = $"SELECT {ColumnsForSelect} FROM {TableName}";
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
Logs.Add(new Logging(
|
||||
|
||||
reader.GetInt32("id"),
|
||||
reader.GetValue(reader.GetOrdinal("pod")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("location")) as string,
|
||||
reader.GetValue(reader.GetOrdinal("hostname")) as string,
|
||||
reader.GetString("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetValue(reader.GetOrdinal("message")) as string
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
return Logs;
|
||||
}
|
||||
public override void CallStoredProcedure(Logging logModelEntry)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(ConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "LogClear";
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.AddWithValue("_logentries_id", logModelEntry.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
86
LoggingClient/LoggingClient/Repository/RepositoryBase.cs
Executable file
86
LoggingClient/LoggingClient/Repository/RepositoryBase.cs
Executable file
@ -0,0 +1,86 @@
|
||||
using MySql.Data.MySqlClient;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
|
||||
namespace LoggingClient.Repository
|
||||
{
|
||||
public abstract class RepositoryBase<M> : IRepositoryBase<M>
|
||||
{
|
||||
protected RepositoryBase(string connectionString)
|
||||
{
|
||||
this.ConnectionString = connectionString;
|
||||
}
|
||||
protected string ConnectionString { get; }
|
||||
public abstract M GetSingle<P>(P pkValue);
|
||||
|
||||
public abstract void Add(M entity);
|
||||
|
||||
public abstract void Delete(M entity);
|
||||
|
||||
public abstract void Update(M entity);
|
||||
public abstract List<M> GetAll(string whereCondition, Dictionary<string, object> parameterValues);
|
||||
|
||||
public abstract List<M> GetAll();
|
||||
|
||||
public abstract void CallStoredProcedure(M entity);
|
||||
|
||||
public IQueryable<M> Query(string whereCondition, Dictionary<string, object> parameterValues)
|
||||
{
|
||||
throw new System.NotSupportedException();
|
||||
}
|
||||
public long Count(string whereCondition, Dictionary<string, object> parameterValues)
|
||||
{
|
||||
var whereCon = whereCondition;
|
||||
if (parameterValues.Count > 0 && whereCondition != null)
|
||||
{
|
||||
foreach (KeyValuePair<string, object> p in parameterValues)
|
||||
{
|
||||
whereCon = whereCon.Replace($"@{p.Key}", p.Value.ToString());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(this.ConnectionString))
|
||||
{
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
conn.Open();
|
||||
cmd.CommandText = $"select count(*) from {this.TableName} where {whereCon}";
|
||||
return (long)cmd.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public long Count()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(this.ConnectionString))
|
||||
{
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
conn.Open();
|
||||
cmd.CommandText = $"select count(*) from {this.TableName}";
|
||||
return (long)cmd.ExecuteScalar();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
public abstract string TableName { get; }
|
||||
public abstract string ColumnsForSelect { get; }
|
||||
public abstract string ColumnsForAdd { get; }
|
||||
public abstract string PrimaryKeyFromTable { get; }
|
||||
}
|
||||
}
|
24
LoggingClient/LoggingClient/Validators/IntRangeValidationRule.cs
Normal file → Executable file
24
LoggingClient/LoggingClient/Validators/IntRangeValidationRule.cs
Normal file → Executable file
@ -10,21 +10,9 @@ namespace LoggingClient.Validators
|
||||
{
|
||||
public class IntRangeValidationRule : ValidationRule
|
||||
{
|
||||
private int Min = 1;
|
||||
private int Max = 3;
|
||||
|
||||
public int MinimumLength
|
||||
{
|
||||
get { return Min; }
|
||||
set { Min = value; }
|
||||
}
|
||||
|
||||
public int MaximumLength
|
||||
{
|
||||
get { return Max; }
|
||||
set { Max = value; }
|
||||
}
|
||||
|
||||
public int MinimumLength { get; set; }
|
||||
public int MaximumLength { get; set; }
|
||||
public string ErrorMessage { get; set; }
|
||||
public override ValidationResult Validate(object value,
|
||||
CultureInfo cultureInfo)
|
||||
{
|
||||
@ -43,11 +31,11 @@ namespace LoggingClient.Validators
|
||||
+ e.Message);
|
||||
}
|
||||
|
||||
if ((parameter < this.Min) || (parameter > this.Max))
|
||||
if ((parameter < this.MinimumLength) || (parameter > this.MaximumLength))
|
||||
{
|
||||
return new ValidationResult(false,
|
||||
"Severity must be a number between "
|
||||
+ this.Min + " - " + this.Max + ".");
|
||||
"Input must be a number between "
|
||||
+ this.MinimumLength + " - " + this.MaximumLength + ".");
|
||||
}
|
||||
return new ValidationResult(true, null);
|
||||
}
|
||||
|
16
LoggingClient/LoggingClient/Validators/StringRangeValidationRule.cs
Normal file → Executable file
16
LoggingClient/LoggingClient/Validators/StringRangeValidationRule.cs
Normal file → Executable file
@ -10,20 +10,8 @@ namespace LoggingClient.Validators
|
||||
{
|
||||
public class StringRangeValidationRule : ValidationRule
|
||||
{
|
||||
private int _minimumLength = 3;
|
||||
private int _maximumLength = 255;
|
||||
|
||||
public int MinimumLength
|
||||
{
|
||||
get { return _minimumLength; }
|
||||
set { _minimumLength = value; }
|
||||
}
|
||||
|
||||
public int MaximumLength
|
||||
{
|
||||
get { return _maximumLength; }
|
||||
set { _maximumLength = value; }
|
||||
}
|
||||
public int MinimumLength { get; set; }
|
||||
public int MaximumLength { get; set; }
|
||||
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
|
30
LoggingClient/LoggingClient/ViewModel/Commands/BaseCommand.cs
Executable file
30
LoggingClient/LoggingClient/ViewModel/Commands/BaseCommand.cs
Executable file
@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace WpfControlNugget.ViewModel.Commands
|
||||
{
|
||||
public class BaseCommand : ICommand
|
||||
{
|
||||
private Action<object> _method;
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
public BaseCommand(Action<object> method)
|
||||
{
|
||||
_method = method;
|
||||
}
|
||||
|
||||
public bool CanExecute(object parameter)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Execute(object parameter)
|
||||
{
|
||||
_method.Invoke(parameter);
|
||||
}
|
||||
}
|
||||
}
|
11
LoggingClient/LoggingClient/ViewModel/Commands/RelayCommand.cs
Normal file → Executable file
11
LoggingClient/LoggingClient/ViewModel/Commands/RelayCommand.cs
Normal file → Executable file
@ -40,8 +40,8 @@ namespace LoggingClient.ViewModel.Commands
|
||||
|
||||
public event EventHandler CanExecuteChanged
|
||||
{
|
||||
add { CommandManager.RequerySuggested += value; }
|
||||
remove { CommandManager.RequerySuggested -= value; }
|
||||
add => CommandManager.RequerySuggested += value;
|
||||
remove => CommandManager.RequerySuggested -= value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,12 +93,5 @@ namespace LoggingClient.ViewModel.Commands
|
||||
}
|
||||
|
||||
private event EventHandler CanExecuteChangedInternal;
|
||||
|
||||
public void RaiseCanExecuteChanged()
|
||||
{
|
||||
//CanExecuteChangedInternal.Raise(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
54
LoggingClient/LoggingClient/ViewModel/LocationTreeBuilder.cs
Executable file
54
LoggingClient/LoggingClient/ViewModel/LocationTreeBuilder.cs
Executable file
@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LoggingClient.Model;
|
||||
|
||||
namespace LoggingClient.ViewModel
|
||||
{
|
||||
public class LocationTreeBuilder
|
||||
{
|
||||
public Node<Location> BuildTree(List<Location> locations)
|
||||
{
|
||||
if (locations == null) return new Node<Location>();
|
||||
var nodeList = locations.ToList();
|
||||
var tree = FindTreeRoot(nodeList);
|
||||
BuildTree(tree, nodeList);
|
||||
return tree;
|
||||
}
|
||||
|
||||
private void BuildTree(Node<Location> locationNode, List<Location> descendants)
|
||||
{
|
||||
var children = descendants.Where(node => node.ParentId == locationNode.ValueObject.Id).ToArray();
|
||||
foreach (var child in children)
|
||||
{
|
||||
var branch = Map(child, locationNode);
|
||||
locationNode.AddChildNode(branch);
|
||||
descendants.Remove(child);
|
||||
}
|
||||
foreach (var branch in locationNode.ChildNodesList)
|
||||
{
|
||||
BuildTree(branch, descendants);
|
||||
}
|
||||
}
|
||||
|
||||
private Node<Location> FindTreeRoot(List<Location> nodes)
|
||||
{
|
||||
var rootNodes = nodes.Where(node => node.ParentId == 0);
|
||||
if (rootNodes.Count() != 1) return new Node<Location>();
|
||||
var rootNode = rootNodes.Single();
|
||||
nodes.Remove(rootNode);
|
||||
return Map(rootNode, null);
|
||||
}
|
||||
|
||||
private Node<Location> Map(Location loc, Node<Location> parentNode)
|
||||
{
|
||||
return new Node<Location>
|
||||
{
|
||||
ValueObject = loc,
|
||||
ParentNode = parentNode
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
191
LoggingClient/LoggingClient/ViewModel/LocationViewModel.cs
Executable file
191
LoggingClient/LoggingClient/ViewModel/LocationViewModel.cs
Executable file
@ -0,0 +1,191 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using LoggingClient.Model;
|
||||
using LoggingClient.Repository;
|
||||
using LoggingClient.ViewModel.Commands;
|
||||
|
||||
namespace LoggingClient.ViewModel
|
||||
{
|
||||
public class LocationViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _txtConnectionString;
|
||||
|
||||
private ICommand _btnLoadDataClick;
|
||||
private ICommand _btnAddDataClick;
|
||||
private ICommand _btnDeleteDataClick;
|
||||
private ICommand _btnUpdateDataClick;
|
||||
private ICommand _btnBuildTreeClick;
|
||||
|
||||
public List<Location> Locations
|
||||
{
|
||||
get => _locations;
|
||||
set
|
||||
{
|
||||
_locations = value;
|
||||
OnPropertyChanged("Locations");
|
||||
}
|
||||
}
|
||||
private List<Location> _locations;
|
||||
public Location NewLocationModelEntry { get; set; }
|
||||
public List<Node<Location>> LocationTree { get; set; }
|
||||
|
||||
public LocationViewModel()
|
||||
{
|
||||
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;";
|
||||
Locations = new List<Location>();
|
||||
NewLocationModelEntry = new Location();
|
||||
|
||||
}
|
||||
public Location MySelectedItem { get; set; }
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public string TxtConnectionString
|
||||
{
|
||||
get => _txtConnectionString;
|
||||
set
|
||||
{
|
||||
_txtConnectionString = value;
|
||||
OnPropertyChanged(nameof(TxtConnectionString));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand BtnLoadDataClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnLoadDataClick ?? (_btnLoadDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
LoadData();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public ICommand BtnAddDataClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnAddDataClick ?? (_btnAddDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
AddData();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public ICommand BtnDeleteDataClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnDeleteDataClick ?? (_btnDeleteDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
DeleteData();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public ICommand BtnUpdateDataClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnUpdateDataClick ?? (_btnUpdateDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
UpdateData();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public ICommand BtnBuildTreeClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnBuildTreeClick ?? (_btnBuildTreeClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
LoadTreeData();
|
||||
}));
|
||||
}
|
||||
}
|
||||
private void LoadData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var locationModelRepository = new LocationRepository(TxtConnectionString);
|
||||
this.Locations = locationModelRepository.GetAll();
|
||||
this.LocationTree = new List<Node<Location>>();
|
||||
GenerateLocationTreeFromList(Locations);
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocationTree"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void AddData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var locationModelRepository = new LocationRepository(TxtConnectionString);
|
||||
locationModelRepository.Add(this.NewLocationModelEntry);
|
||||
this.Locations = locationModelRepository.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void DeleteData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var locationModelRepository = new LocationRepository(TxtConnectionString);
|
||||
locationModelRepository.Delete(this.NewLocationModelEntry);
|
||||
this.Locations = locationModelRepository.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void UpdateData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var locationModelRepository = new LocationRepository(TxtConnectionString);
|
||||
locationModelRepository.Update(this.NewLocationModelEntry);
|
||||
this.Locations = locationModelRepository.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void LoadTreeData()
|
||||
{
|
||||
try
|
||||
{
|
||||
var locationModelRepository = new LocationRepository(TxtConnectionString);
|
||||
this.Locations = locationModelRepository.GetAll();
|
||||
this.LocationTree = new List<Node<Location>>();
|
||||
GenerateLocationTreeFromList(Locations);
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs("LocationTree"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
public void GenerateLocationTreeFromList(List<Location> locationList)
|
||||
{
|
||||
var treeBuilder = new LocationTreeBuilder();
|
||||
var locationNode = treeBuilder.BuildTree(locationList);
|
||||
this.LocationTree.Add(locationNode);
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
@ -9,24 +9,22 @@ using LoggingClient.Model;
|
||||
using LoggingClient.ViewModel.Commands;
|
||||
using DuplicateCheckerLib;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using LoggingClient.Repository;
|
||||
|
||||
namespace LoggingClient.ViewModel
|
||||
{
|
||||
public class LogViewModel : INotifyPropertyChanged
|
||||
{
|
||||
private string _txtConnectionString;
|
||||
private string _enterPod;
|
||||
private string _enterHostname;
|
||||
private int _enterSeverity;
|
||||
private string _enterMessage;
|
||||
private readonly DuplicateChecker _duplicateChecker;
|
||||
private readonly DuplicateChecker _dupChecker;
|
||||
|
||||
private ICommand _btnLoadDataClick;
|
||||
private ICommand _btnConfirmdataClick;
|
||||
private ICommand _btnAdddataClick;
|
||||
private ICommand _btnFindDuplicateClick;
|
||||
private ICommand _btnConfirmDataClick;
|
||||
private ICommand _btnAddDataClick;
|
||||
private ICommand _btnFindDuplicatesClick;
|
||||
|
||||
public ObservableCollection<LogModel> Logs
|
||||
public List<Logging> Logs
|
||||
{
|
||||
get => _logs;
|
||||
set
|
||||
@ -35,23 +33,24 @@ namespace LoggingClient.ViewModel
|
||||
OnPropertyChanged("Logs");
|
||||
}
|
||||
}
|
||||
private ObservableCollection<LogModel> _logs;
|
||||
private List<Logging> _logs;
|
||||
public Logging NewLogModelEntry { get; set; }
|
||||
public ObservableCollection<SeverityComboBoxItem> SeverityComboBox { get; set; }
|
||||
|
||||
public LogViewModel()
|
||||
{
|
||||
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=foekicoe9i4kpos;";
|
||||
_enterSeverity = 1;
|
||||
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;";
|
||||
|
||||
Logs = new ObservableCollection<LogModel>();
|
||||
Logs = new List<Logging>();
|
||||
NewLogModelEntry = new Logging();
|
||||
SeverityComboBox = new ObservableCollection<SeverityComboBoxItem>(){
|
||||
new SeverityComboBoxItem(){Id=1, Severity= 1},
|
||||
new SeverityComboBoxItem(){Id=2, Severity= 2},
|
||||
new SeverityComboBoxItem(){Id=3, Severity= 3}
|
||||
};
|
||||
_duplicateChecker = new DuplicateChecker();
|
||||
_dupChecker = new DuplicateChecker();
|
||||
}
|
||||
public LogModel MySelectedItem { get; set; }
|
||||
public Logging MySelectedItem { get; set; }
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public SeverityComboBoxItem SetSeverity { get; set; }
|
||||
|
||||
@ -64,44 +63,17 @@ namespace LoggingClient.ViewModel
|
||||
OnPropertyChanged(nameof(TxtConnectionString));
|
||||
}
|
||||
}
|
||||
public string EnterPod
|
||||
public ICommand BtnFindDuplicatesClick
|
||||
{
|
||||
get => _enterPod;
|
||||
set
|
||||
get
|
||||
{
|
||||
_enterPod = value;
|
||||
OnPropertyChanged(nameof(EnterPod));
|
||||
return _btnFindDuplicatesClick ?? (_btnFindDuplicatesClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
BtnFindDuplicates_Click();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public string EnterHostname
|
||||
{
|
||||
get => _enterHostname;
|
||||
set
|
||||
{
|
||||
_enterHostname = value;
|
||||
OnPropertyChanged(nameof(EnterHostname));
|
||||
}
|
||||
}
|
||||
public int EnterSeverity
|
||||
{
|
||||
get => _enterSeverity;
|
||||
set
|
||||
{
|
||||
_enterSeverity = value;
|
||||
OnPropertyChanged(nameof(EnterSeverity));
|
||||
}
|
||||
}
|
||||
public string EnterMessage
|
||||
{
|
||||
get => _enterMessage;
|
||||
set
|
||||
{
|
||||
_enterMessage = value;
|
||||
OnPropertyChanged(nameof(EnterMessage));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand BtnLoadDataClick
|
||||
{
|
||||
get
|
||||
@ -117,36 +89,33 @@ namespace LoggingClient.ViewModel
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnAdddataClick ?? (_btnAdddataClick = new RelayCommand(
|
||||
return _btnAddDataClick ?? (_btnAddDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
BtnAdd_Click();
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public ICommand BtnFindDuplicateClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnFindDuplicateClick ?? (_btnFindDuplicateClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
BtnFindDuplicate_Click();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public ICommand BtnConfirmDataClick
|
||||
{
|
||||
get
|
||||
{
|
||||
return _btnConfirmdataClick ?? (_btnConfirmdataClick = new RelayCommand(
|
||||
return _btnConfirmDataClick ?? (_btnConfirmDataClick = new RelayCommand(
|
||||
x =>
|
||||
{
|
||||
BtnLogClear_Click();
|
||||
}));
|
||||
}
|
||||
}
|
||||
public List<Logging> BtnFindDuplicates_Click()
|
||||
{
|
||||
var logModelRepository = new LoggingRepository(TxtConnectionString);
|
||||
this.Logs = logModelRepository.GetAll();
|
||||
var dupList = _dupChecker.FindDuplicates(Logs);
|
||||
Logs = new List<Logging>(dupList.Cast<Logging>());
|
||||
|
||||
return Logs;
|
||||
}
|
||||
public void BtnLoadData_Click()
|
||||
{
|
||||
try
|
||||
@ -162,34 +131,8 @@ namespace LoggingClient.ViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
Logs.Clear();
|
||||
using (var conn = new MySqlConnection(TxtConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (var cmd = new MySqlCommand("SELECT id, pod, location, hostname, severity, timestamp, message FROM v_logentries ORDER BY timestamp", conn))
|
||||
{
|
||||
var reader = cmd.ExecuteReader();
|
||||
while (reader.Read())
|
||||
{
|
||||
// ISDBNull Check because location can be NULL in Database
|
||||
var location = "";
|
||||
if (!reader.IsDBNull(reader.GetOrdinal("location")))
|
||||
{
|
||||
location = reader.GetString("location");
|
||||
}
|
||||
Logs.Add(new LogModel(
|
||||
reader.GetInt32("id"),
|
||||
reader.GetString("pod"),
|
||||
location,
|
||||
reader.GetString("hostname"),
|
||||
reader.GetInt32("severity"),
|
||||
reader.GetDateTime("timestamp"),
|
||||
reader.GetString("message")
|
||||
));
|
||||
}
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
var logModelRepository = new LoggingRepository(TxtConnectionString);
|
||||
this.Logs = logModelRepository.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@ -197,24 +140,14 @@ namespace LoggingClient.ViewModel
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void BtnLogClear_Click()
|
||||
{
|
||||
if (MySelectedItem == null) return;
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(TxtConnectionString))
|
||||
{
|
||||
conn.Open();
|
||||
using (var cmd = conn.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "LogClear";
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.Id);
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
LoadData();
|
||||
var logModelRepository = new LoggingRepository(TxtConnectionString);
|
||||
logModelRepository.CallStoredProcedure(MySelectedItem);
|
||||
this.Logs = logModelRepository.GetAll();
|
||||
}
|
||||
catch (MySqlException ex)
|
||||
{
|
||||
@ -225,37 +158,15 @@ namespace LoggingClient.ViewModel
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var conn = new MySqlConnection(TxtConnectionString))
|
||||
{
|
||||
using (MySqlCommand cmd = new MySqlCommand("LogMessageAdd", conn))
|
||||
{
|
||||
conn.Open();
|
||||
cmd.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = EnterPod;
|
||||
cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = EnterHostname;
|
||||
cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = EnterSeverity;
|
||||
cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = EnterMessage;
|
||||
|
||||
cmd.ExecuteNonQuery();
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
var logModelRepository = new LoggingRepository(TxtConnectionString);
|
||||
logModelRepository.Add(this.NewLogModelEntry);
|
||||
this.Logs = logModelRepository.GetAll();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Error occurred: " + ex.Message);
|
||||
}
|
||||
}
|
||||
public ObservableCollection<LogModel> BtnFindDuplicate_Click()
|
||||
{
|
||||
LoadData();
|
||||
|
||||
var duplicateList = _duplicateChecker.FindDuplicates(Logs);
|
||||
Logs = new ObservableCollection<LogModel>(duplicateList.Cast<LogModel>());
|
||||
|
||||
return Logs;
|
||||
}
|
||||
private void OnPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
|
46
LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs
Executable file
46
LoggingClient/LoggingClient/ViewModel/NavigationViewModel.cs
Executable file
@ -0,0 +1,46 @@
|
||||
using LoggingClient.ViewModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows.Input;
|
||||
using WpfControlNugget.ViewModel.Commands;
|
||||
|
||||
namespace WpfControlNugget.ViewModel
|
||||
{
|
||||
class NavigationViewModel : INotifyPropertyChanged
|
||||
{
|
||||
public ICommand LogsCommand { get; set; }
|
||||
public ICommand LocationsCommand { get; set; }
|
||||
|
||||
private object _selectedViewModel;
|
||||
public object SelectedViewModel
|
||||
{
|
||||
get => _selectedViewModel;
|
||||
set { _selectedViewModel = value; OnPropertyChanged("SelectedViewModel"); }
|
||||
}
|
||||
|
||||
public NavigationViewModel()
|
||||
{
|
||||
LogsCommand = new BaseCommand(OpenLogs);
|
||||
LocationsCommand = new BaseCommand(OpenLocations);
|
||||
}
|
||||
|
||||
private void OpenLogs(object obj)
|
||||
{
|
||||
SelectedViewModel = new LogViewModel();
|
||||
}
|
||||
|
||||
private void OpenLocations(object obj)
|
||||
{
|
||||
SelectedViewModel = new LocationViewModel();
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private void OnPropertyChanged(string propName)
|
||||
{
|
||||
if (PropertyChanged != null)
|
||||
{
|
||||
PropertyChanged(this, new PropertyChangedEventArgs(propName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
120
LoggingClient/LoggingClient/Views/LocationView.xaml
Executable file
120
LoggingClient/LoggingClient/Views/LocationView.xaml
Executable file
@ -0,0 +1,120 @@
|
||||
<UserControl x:Class="LoggingClient.Views.LocationView"
|
||||
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:local="clr-namespace:LoggingClient.Views"
|
||||
xmlns:validators="clr-namespace:LoggingClient.Validators"
|
||||
xmlns:viewModel="clr-namespace:LoggingClient.ViewModel"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<Control.DataContext>
|
||||
<viewModel:LocationViewModel/>
|
||||
</Control.DataContext>
|
||||
|
||||
<Grid Height="450" Width="800" Background="#FF89A9B2" >
|
||||
<TextBlock Height="32" HorizontalAlignment="Left" Margin="10,18,0,0" Name="TextBlockHeading" Text="Locations" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch="Normal"/>
|
||||
<Grid HorizontalAlignment="Left" Height="416" VerticalAlignment="Top" Width="773">
|
||||
<DataGrid Validation.ErrorTemplate="{x:Null}" CanUserAddRows="False" AutoGenerateColumns="False" HorizontalAlignment="Left" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" Margin="10,196,0,76" Name="DataGridLocations" Width="763" ItemsSource="{Binding Path=Locations}" CanUserResizeRows="False">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Path=Id}" Header="id" Width="1*" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=ParentId}" Header="ParentId" Width="1*" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=AddressId}" Header="AddressId" Width="1*" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Designation}" Header="Designation" Width="1*" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=BuildingNr}" Header="BuildingNr" Width="1*" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=RoomNr}" Header="RoomNr" Width="1*" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<TreeView Grid.Row="0" Margin="10,51,0,225" ItemsSource="{Binding LocationTree, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=true, Mode=TwoWay}">
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding ChildNodesList, UpdateSourceTrigger=PropertyChanged, NotifyOnSourceUpdated=true, Mode=TwoWay}">
|
||||
<TreeViewItem Header="{Binding}"/>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
|
||||
<!--<Button Content="Add" Height="25" HorizontalAlignment="Left" Margin="478,366,0,0" Name="BtnAdd" VerticalAlignment="Top" Width="70" Command="{Binding BtnAddDataClick}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterDesignation, UpdateSourceTrigger=PropertyChanged}" Value="0">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterBuildingNr, UpdateSourceTrigger=PropertyChanged}" Value="0">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
<DataTrigger Binding="{Binding Text.Length, ElementName=EnterRoomNr, UpdateSourceTrigger=PropertyChanged}" Value="0">
|
||||
<Setter Property="IsEnabled" Value="False"/>
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
<Button Content="Update" Height="25" HorizontalAlignment="Left" Margin="553,366,0,0" Name="BtnUpdateDataClick" VerticalAlignment="Top" Width="70" Command="{Binding BtnUpdateDataClick}" />-->
|
||||
<Button Content="Load Data" Height="25" HorizontalAlignment="Left" Margin="628,366,0,0" Name="BtnLoadDataClick" VerticalAlignment="Top" Width="70" Command="{Binding BtnLoadDataClick}" />
|
||||
<!--<Button Content="Delete" Height="25" HorizontalAlignment="Left" Margin="703,366,0,0" Name="BtnDeleteDataClick" VerticalAlignment="Top" Width="70" Command="{Binding BtnDeleteDataClick}"/>
|
||||
|
||||
<TextBox HorizontalAlignment="Left" Height="23" Margin="248,22,0,0" TextWrapping="Wrap" Text="{Binding TxtConnectionString}" Name="TxtConnectionString" VerticalAlignment="Top" Width="525" />
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,366,0,0" TextWrapping="Wrap" x:Name="LocationId" VerticalAlignment="Top" Width="80" >
|
||||
<Binding Path="NewLocationModelEntry.AddressId" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule
|
||||
MinimumLength="1" MaximumLength="10000"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="95,366,0,0" TextWrapping="Wrap" Name="EnterParentId" VerticalAlignment="Top" Width="80">
|
||||
<TextBox.Text>
|
||||
<Binding Path="NewLocationModelEntry.ParentId" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule
|
||||
validators:MinimumLength="1" validators:MaximumLength="10000"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="180,366,0,0" TextWrapping="Wrap" Name="EnterDesignation" VerticalAlignment="Top" Width="80">
|
||||
<TextBox.Text>
|
||||
<Binding Path="NewLocationModelEntry.Designation" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
validators:MinimumLength="1" validators:MaximumLength="45"
|
||||
ErrorMessage="Designation must contain at least 1 characters up to 45" />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="265,366,0,0" TextWrapping="Wrap" Name="EnterBuildingNr" VerticalAlignment="Top" Width="80">
|
||||
<TextBox.Text>
|
||||
<Binding Path="NewLocationModelEntry.BuildingNr" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule
|
||||
validators:MinimumLength="1" validators:MaximumLength="10000"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="350,366,0,0" TextWrapping="Wrap" Name="EnterRoomNr" VerticalAlignment="Top" Width="80" >
|
||||
<TextBox.Text>
|
||||
<Binding Path="NewLocationModelEntry.RoomNr" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule
|
||||
validators:MinimumLength="1" validators:MaximumLength="10000"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>-->
|
||||
|
||||
<!--<ComboBox x:Name="SeverityCombobox" DisplayMemberPath="Severity" SelectedValuePath="id" ItemsSource="{Binding SeverityComboBox}" SelectedValue="{Binding Path=Severity , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="240,359,470,66" Width="90" Height="25"/>-->
|
||||
|
||||
<Label Content="Database Connection" HorizontalAlignment="Left" Margin="118,22,0,0" VerticalAlignment="Top" Height="23" Width="125" Background="{x:Null}" RenderTransformOrigin="0.366,0.725"/>
|
||||
<!--<Label Content="LocationId" HorizontalAlignment="Left" Margin="10,340,0,0" VerticalAlignment="Top" Width="80" FontSize="12"/>
|
||||
<Label Content="ParentId" HorizontalAlignment="Left" Margin="95,340,0,0" VerticalAlignment="Top" Width="80" FontSize="12"/>
|
||||
<Label Content="Designation" HorizontalAlignment="Left" Margin="180,340,0,0" VerticalAlignment="Top" Width="80" FontSize="12"/>
|
||||
<Label Content="BuildingNr" HorizontalAlignment="Left" Margin="265,340,0,0" VerticalAlignment="Top" Width="80" FontSize="12"/>
|
||||
<Label Content="RoomNr" HorizontalAlignment="Left" Margin="350,340,0,0" VerticalAlignment="Top" Width="80" FontSize="12"/>-->
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
15
LoggingClient/LoggingClient/Views/LocationView.xaml.cs
Executable file
15
LoggingClient/LoggingClient/Views/LocationView.xaml.cs
Executable file
@ -0,0 +1,15 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace LoggingClient.Views
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for LocationView.xaml
|
||||
/// </summary>
|
||||
public partial class LocationView : UserControl
|
||||
{
|
||||
public LocationView()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,34 +5,30 @@
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:LoggingClient.Views"
|
||||
xmlns:validators="clr-namespace:LoggingClient.Validators"
|
||||
xmlns:viewModel="clr-namespace:LoggingClient.ViewModel"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
|
||||
<Control.DataContext>
|
||||
<viewModel:LogViewModel/>
|
||||
</Control.DataContext>
|
||||
|
||||
<Grid Height="450" Width="800" Background="#FF89A9B2" >
|
||||
|
||||
<TextBlock Height="32" HorizontalAlignment="Left" Margin="10,18,0,0" Name="TextBlockHeading"
|
||||
Text="LogReader" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch="Normal"/>
|
||||
<TextBlock Height="32" HorizontalAlignment="Left" Margin="10,18,0,0" Name="TextBlockHeading" Text="Log Reader" VerticalAlignment="Top" Width="310" FontSize="20" FontStretch="Normal"/>
|
||||
<Grid HorizontalAlignment="Left" Height="416" VerticalAlignment="Top" Width="773">
|
||||
<DataGrid AutoGenerateColumns="False" HorizontalAlignment="Left" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" Margin="10,55,0,97" Name="DataGridCustomers" Width="780" ItemsSource="{Binding Path=Logs}"
|
||||
CanUserResizeRows="False">
|
||||
<DataGrid CanUserAddRows="False" AutoGenerateColumns="False" HorizontalAlignment="Left" SelectedItem="{Binding MySelectedItem, Mode=TwoWay}" Margin="10,55,0,97" Name="DataGridLogs" Width="780" ItemsSource="{Binding Path=Logs}" CanUserResizeRows="False">
|
||||
<DataGrid.Columns>
|
||||
<DataGridTextColumn Binding="{Binding Path=Id}" Header="ID" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Pod}" Header="POD" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Location}" Header="Location" Width="111" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Hostname}" Header="Hostname" Width="111" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Severity}" Header="Severity" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Timestamp}" Header="Timestamp" Width="130" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Message}" Header="Message" Width="215" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Id}" Header="id" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Pod}" Header="pod" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Location}" Header="location" Width="111" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Hostname}" Header="hostname" Width="111" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Severity}" Header="severity" Width="70" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Timestamp}" Header="timestamp" Width="130" IsReadOnly="True" />
|
||||
<DataGridTextColumn Binding="{Binding Path=Message}" Header="message" Width="215" IsReadOnly="True" />
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<Label Content="Database Connection" HorizontalAlignment="Left" Margin="118,22,0,0" VerticalAlignment="Top" Height="23" Width="125" Background="{x:Null}" RenderTransformOrigin="0.366,0.725"/>
|
||||
<TextBox HorizontalAlignment="Left" Height="23" Margin="248,22,0,0" TextWrapping="Wrap" Text="{Binding TxtConnectionString}" Name="TxtConnectionString" VerticalAlignment="Top" Width="525" />
|
||||
|
||||
<Button Content="Find duplicate" Height="25" HorizontalAlignment="Left" Margin="545,355,0,0" x:Name="BtnFindDuplicate" VerticalAlignment="Top" Width="78" Command="{Binding BtnFindDuplicateClick}" />
|
||||
<Button Content="Load Data" Height="25" HorizontalAlignment="Left" Margin="628,355,0,0" Name="Btnloaddata" VerticalAlignment="Top" Width="70" Command="{Binding BtnLoadDataClick}" />
|
||||
<Button Content="Confirm" Height="25" HorizontalAlignment="Left" Margin="703,355,0,0" Name="BtnConfirm" VerticalAlignment="Top" Width="70" Command="{Binding BtnConfirmDataClick}"/>
|
||||
<Button Content="Add" Height="25" HorizontalAlignment="Left" Margin="470,355,0,0" Name="BtnAdd" VerticalAlignment="Top" Width="70" Command="{Binding BtnAddDataClick}">
|
||||
<Button Content="Add" Height="25" HorizontalAlignment="Left" Margin="418,375,0,0" Name="BtnAdd" VerticalAlignment="Top" Width="85" Command="{Binding BtnAddDataClick}">
|
||||
<Button.Style>
|
||||
<Style TargetType="{x:Type Button}">
|
||||
<Style.Triggers>
|
||||
@ -52,50 +48,62 @@ CanUserResizeRows="False">
|
||||
</Style>
|
||||
</Button.Style>
|
||||
</Button>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,355,0,0" TextWrapping="Wrap" Name="EnterPod" VerticalAlignment="Top" Width="110">
|
||||
<Button Content="Find Duplicates" Height="25" HorizontalAlignment="Left" Margin="508,375,0,0" Name="BtnFindDuplicates" VerticalAlignment="Top" Width="85" Command="{Binding BtnFindDuplicatesClick}" />
|
||||
<Button Content="Load Data" Height="25" HorizontalAlignment="Left" Margin="598,375,0,0" Name="BtnLoadData" VerticalAlignment="Top" Width="85" Command="{Binding BtnLoadDataClick}" />
|
||||
<Button Content="Confirm" Height="25" HorizontalAlignment="Left" Margin="688,375,0,0" Name="BtnConfirm" VerticalAlignment="Top" Width="85" Command="{Binding BtnConfirmDataClick}"/>
|
||||
|
||||
<TextBox HorizontalAlignment="Left" Height="23" Margin="248,22,0,0" TextWrapping="Wrap" Text="{Binding TxtConnectionString}" Name="TxtConnectionString" VerticalAlignment="Top" Width="525" />
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,345,0,0" TextWrapping="Wrap" Name="EnterPod" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding Path="EnterPod" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="NewLogModelEntry.Pod" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
ErrorMessage="Pod must contain atleast 3 characters up to 255" />
|
||||
validators:MinimumLength="3" validators:MaximumLength="255"
|
||||
ErrorMessage="Pod must contain at least 3 characters up to 255" />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="125,355,0,0" TextWrapping="Wrap" Name="EnterHostname" VerticalAlignment="Top" Width="110">
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="110,345,0,0" TextWrapping="Wrap" Name="EnterHostname" VerticalAlignment="Top" Width="95">
|
||||
<TextBox.Text>
|
||||
<Binding Path="EnterHostname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="NewLogModelEntry.Hostname" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
ErrorMessage="Hostname must contain atleast 3 characters up to 255" />
|
||||
validators:MinimumLength="3" validators:MaximumLength="255"
|
||||
ErrorMessage="Hostname must contain at least 3 characters up to 255" />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="240,355,0,0" TextWrapping="Wrap" Name="EnterSeverity" VerticalAlignment="Top" Width="110" >
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="210,345,0,0" TextWrapping="Wrap" Name="EnterSeverity" VerticalAlignment="Top" Width="95" >
|
||||
<TextBox.Text>
|
||||
<Binding Path="EnterSeverity" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="NewLogModelEntry.Severity" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:IntRangeValidationRule/>
|
||||
<validators:IntRangeValidationRule
|
||||
validators:MinimumLength="1" validators:MaximumLength="3"/>
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<TextBox HorizontalAlignment="Left" Height="50" Margin="355,355,0,0" TextWrapping="Wrap" Name="EnterMessage" VerticalAlignment="Top" Width="110">
|
||||
<TextBox HorizontalAlignment="Left" Height="25" Margin="310,345,0,0" TextWrapping="Wrap" Name="EnterMessage" VerticalAlignment="Top" Width="463">
|
||||
<TextBox.Text>
|
||||
<Binding Path="EnterMessage" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding Path="NewLogModelEntry.Message" UpdateSourceTrigger="PropertyChanged">
|
||||
<Binding.ValidationRules>
|
||||
<validators:StringRangeValidationRule
|
||||
ErrorMessage="Message must contain atleast 3 characters up to 255" />
|
||||
validators:MinimumLength="3" validators:MaximumLength="255"
|
||||
ErrorMessage="Message must contain at least 3 characters up to 255" />
|
||||
</Binding.ValidationRules>
|
||||
</Binding>
|
||||
</TextBox.Text>
|
||||
</TextBox>
|
||||
<Label Content="Enter Pod" HorizontalAlignment="Left" Margin="10,324,0,0" VerticalAlignment="Top" Width="110"/>
|
||||
<Label Content="Enter Hostname" HorizontalAlignment="Left" Margin="125,324,0,0" VerticalAlignment="Top" Width="110"/>
|
||||
<Label Content="Enter Severity" HorizontalAlignment="Left" Margin="240,324,0,0" VerticalAlignment="Top" Width="110"/>
|
||||
<Label Content="Enter Message" HorizontalAlignment="Left" Margin="355,324,0,0" VerticalAlignment="Top" Width="110"/>
|
||||
|
||||
<!--<ComboBox x:Name="SeverityCombobox" DisplayMemberPath="Severity" SelectedValuePath="id" ItemsSource="{Binding SeverityComboBox}" SelectedValue="{Binding Path=Severity , Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="240,359,470,66" Width="90" Height="25"/>-->
|
||||
|
||||
<Label Content="Database Connection" HorizontalAlignment="Left" Margin="118,22,0,0" VerticalAlignment="Top" Height="23" Width="125" Background="{x:Null}" RenderTransformOrigin="0.366,0.725"/>
|
||||
<Label Content="Pod" HorizontalAlignment="Left" Margin="10,319,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<Label Content="Hostname" HorizontalAlignment="Left" Margin="110,319,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<Label Content="Severity" HorizontalAlignment="Left" Margin="210,319,0,0" VerticalAlignment="Top" Width="95"/>
|
||||
<Label Content="Message" HorizontalAlignment="Left" Margin="310,319,0,0" VerticalAlignment="Top" Width="110"/>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
||||
</UserControl>
|
@ -8,7 +8,6 @@ namespace LoggingClient.Views
|
||||
public LogView()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new LogViewModel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user