WIP - DB-Clls failing on Locations (Add, Update)

This commit is contained in:
Francesco 2020-07-26 14:28:12 +02:00
parent 08a53739ee
commit b8549bb60a
15 changed files with 177 additions and 255 deletions

View File

@ -1,15 +1,11 @@
<Window x:Class="LoggingClient.MainWindow" <Window x:Class="LoggingClient.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:views="clr-namespace:LoggingClient.Views" xmlns:views="clr-namespace:LoggingClient.Views"
xmlns:local="clr-namespace:LoggingClient.ViewModel" xmlns:local="clr-namespace:LoggingClient.ViewModel"
Title="MainWindow" Height="450" Width="800" ResizeMode="NoResize"> Title="MainWindow" Height="470" Width="800" ResizeMode="NoResize">
<!--<Grid>
<views:LogView x:Name = "LogView"/>
</Grid>-->
<Window.Resources> <Window.Resources>
<DataTemplate DataType="{x:Type local:LogViewModel}"> <DataTemplate DataType="{x:Type local:LogViewModel}">
<views:LogView/> <views:LogView/>
</DataTemplate> </DataTemplate>
@ -20,7 +16,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
</Window.Resources> </Window.Resources>
<DockPanel LastChildFill="True"> <DockPanel LastChildFill="True">
<Grid x:Name="Navigation" DockPanel.Dock="Top"> <Grid x:Name="Navigation" DockPanel.Dock="Top">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition> <ColumnDefinition Width="Auto"></ColumnDefinition>
@ -30,12 +25,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Button Grid.Row="0" Width="400" Content="Locations" Command="{Binding LocationsCommand}" Margin="394,0,-393,0"/> <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"/> <Button HorizontalAlignment="Right" Width="400" Content="Log Reader" Command="{Binding LogsCommand}" Margin="0,0,2,0"/>
</Grid> </Grid>
<ContentControl x:Name="Pages" DockPanel.Dock="Right" Content="{Binding SelectedViewModel}"/> <ContentControl x:Name="Pages" DockPanel.Dock="Right" Content="{Binding SelectedViewModel}"/>
</DockPanel> </DockPanel>
</Window> </Window>

20
LoggingClient/LoggingClient/MainWindow.xaml.cs Normal file → Executable file
View File

@ -1,20 +1,5 @@
using System; using System.Windows;
using System.Collections.Generic; using WpfControlNugget.ViewModel;
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;
namespace LoggingClient namespace LoggingClient
{ {
@ -26,6 +11,7 @@ namespace LoggingClient
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
this.DataContext = new NavigationViewModel();
} }
} }
} }

View File

@ -1,7 +1,10 @@
namespace LoggingClient.Model using System;
namespace LoggingClient.Model
{ {
public class Location : Model<Location> public class Location : Model<Location>
{ {
public new int Id { get; set; }
public int ParentId { get; set; } public int ParentId { get; set; }
public int AddressId { get; set; } public int AddressId { get; set; }
public string Designation { get; set; } public string Designation { get; set; }
@ -10,9 +13,8 @@
public Location() public Location()
{ {
// Emty Constructor
}
}
public Location(int id, int parentId, int addressId, string designation, int buildingNr, int roomNr) public Location(int id, int parentId, int addressId, string designation, int buildingNr, int roomNr)
{ {
this.Id = id; this.Id = id;
@ -22,5 +24,56 @@
this.BuildingNr = buildingNr; this.BuildingNr = buildingNr;
this.RoomNr = roomNr; 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;
}
} }
} }

View File

@ -1,17 +1,23 @@
using System; using System;
using DuplicateCheckerLib;
namespace LoggingClient.Model namespace LoggingClient.Model
{ {
public class Logging : Model<Logging> public class Logging : IEntity
{ {
public int Id { get; set; }
public string Pod { get; set; } public string Pod { get; set; }
public string Location { get; set; } public string Location { get; set; }
public string Hostname { get; set; } public string Hostname { get; set; }
public int Severity { get; set; } public string Severity { get; set; }
public DateTime Timestamp { get; set; } public DateTime Timestamp { get; set; }
public string Message { get; set; } public string Message { get; set; }
public Logging(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.Id = id;
this.Pod = pod; this.Pod = pod;
@ -37,12 +43,12 @@ namespace LoggingClient.Model
unchecked unchecked
{ {
// Choose large primes to avoid hashing collisions // Choose large primes to avoid hashing collisions
const int HashingBase = (int)2166136261; const int hashingBase = (int)2166136261;
const int HashingMultiplier = 16777619; const int hashingMultiplier = 16777619;
int hash = HashingBase; int hash = hashingBase;
hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Message) ? Message.GetHashCode() : 0); hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, Message) ? Message.GetHashCode() : 0);
hash = (hash * HashingMultiplier) ^ (!Object.ReferenceEquals(null, Severity) ? Severity.GetHashCode() : 0); hash = (hash * hashingMultiplier) ^ (!Object.ReferenceEquals(null, Severity) ? Severity.GetHashCode() : 0);
return hash; return hash;
} }
} }

View File

@ -6,11 +6,11 @@ using System.Windows;
namespace LoggingClient.Repository namespace LoggingClient.Repository
{ {
class LocationRepository : RepositoryBase<Location> public class LocationRepository : RepositoryBase<Location>
{ {
public override string TableName => "Location"; public override string TableName => "Location";
public override string ColumnsForSelect => "location_id, parent_location, address_fk, designation, building, room"; public override string ColumnsForSelect => "location_id, parentId, address_fk, designation, building, room";
public override string ColumnsForAdd => "parent_location, address_fk, designation, building, room"; public override string ColumnsForAdd => "parentId, address_fk, designation, building, room";
public override string PrimaryKeyFromTable => "location_id"; public override string PrimaryKeyFromTable => "location_id";
public List<Location> Locations { get; set; } public List<Location> Locations { get; set; }
@ -86,7 +86,7 @@ namespace LoggingClient.Repository
Locations.Add(new Location( Locations.Add(new Location(
reader.GetInt32("location_id"), reader.GetInt32("location_id"),
reader.GetInt32("parent_location"), reader.GetInt32("parentId"),
reader.GetInt32("address_fk"), reader.GetInt32("address_fk"),
reader.GetValue(reader.GetOrdinal("designation")) as string, reader.GetValue(reader.GetOrdinal("designation")) as string,
reader.GetInt32("building"), reader.GetInt32("building"),
@ -119,7 +119,7 @@ namespace LoggingClient.Repository
Locations.Add(new Location( Locations.Add(new Location(
reader.GetInt32("location_id"), reader.GetInt32("location_id"),
reader.GetInt32("parent_location"), reader.GetInt32("parentId"),
reader.GetInt32("address_fk"), reader.GetInt32("address_fk"),
reader.GetValue(reader.GetOrdinal("designation")) as string, reader.GetValue(reader.GetOrdinal("designation")) as string,
reader.GetInt32("building"), reader.GetInt32("building"),
@ -157,7 +157,7 @@ namespace LoggingClient.Repository
_Locations = (new Location( _Locations = (new Location(
reader.GetInt32("location_id"), reader.GetInt32("location_id"),
reader.GetInt32("parent_location"), reader.GetInt32("parentId"),
reader.GetInt32("address_fk"), reader.GetInt32("address_fk"),
reader.GetValue(reader.GetOrdinal("designation")) as string, reader.GetValue(reader.GetOrdinal("designation")) as string,
reader.GetInt32("building"), reader.GetInt32("building"),

View File

@ -45,7 +45,7 @@ namespace LoggingClient.Repository
reader.GetValue(reader.GetOrdinal("pod")) as string, reader.GetValue(reader.GetOrdinal("pod")) as string,
reader.GetValue(reader.GetOrdinal("location")) as string, reader.GetValue(reader.GetOrdinal("location")) as string,
reader.GetValue(reader.GetOrdinal("hostname")) as string, reader.GetValue(reader.GetOrdinal("hostname")) as string,
reader.GetInt32("severity"), reader.GetString("severity"),
reader.GetDateTime("timestamp"), reader.GetDateTime("timestamp"),
reader.GetValue(reader.GetOrdinal("message")) as string reader.GetValue(reader.GetOrdinal("message")) as string
)); ));
@ -59,7 +59,7 @@ namespace LoggingClient.Repository
} }
return _Logs; return _Logs;
} }
public override void Add(Logging newLogging) public override void Add(Logging newLogModelEntry)
{ {
try try
{ {
@ -71,10 +71,10 @@ namespace LoggingClient.Repository
cmd.CommandText = "LogMessageAdd"; cmd.CommandText = "LogMessageAdd";
cmd.CommandType = CommandType.StoredProcedure; cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = newLogging.Pod; cmd.Parameters.Add("@i_pod", MySqlDbType.String).Value = newLogModelEntry.Pod;
cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = newLogging.Hostname; cmd.Parameters.Add("@i_hostname", MySqlDbType.String).Value = newLogModelEntry.Hostname;
cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = newLogging.Severity; cmd.Parameters.Add("@i_severity", MySqlDbType.Int32).Value = newLogModelEntry.Severity;
cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = newLogging.Message; cmd.Parameters.Add("@i_message", MySqlDbType.String).Value = newLogModelEntry.Message;
cmd.ExecuteNonQuery(); cmd.ExecuteNonQuery();
} }
@ -120,7 +120,7 @@ namespace LoggingClient.Repository
reader.GetValue(reader.GetOrdinal("pod")) as string, reader.GetValue(reader.GetOrdinal("pod")) as string,
reader.GetValue(reader.GetOrdinal("location")) as string, reader.GetValue(reader.GetOrdinal("location")) as string,
reader.GetValue(reader.GetOrdinal("hostname")) as string, reader.GetValue(reader.GetOrdinal("hostname")) as string,
reader.GetInt32("severity"), reader.GetString("severity"),
reader.GetDateTime("timestamp"), reader.GetDateTime("timestamp"),
reader.GetValue(reader.GetOrdinal("message")) as string reader.GetValue(reader.GetOrdinal("message")) as string
)); ));
@ -153,7 +153,7 @@ namespace LoggingClient.Repository
reader.GetValue(reader.GetOrdinal("pod")) as string, reader.GetValue(reader.GetOrdinal("pod")) as string,
reader.GetValue(reader.GetOrdinal("location")) as string, reader.GetValue(reader.GetOrdinal("location")) as string,
reader.GetValue(reader.GetOrdinal("hostname")) as string, reader.GetValue(reader.GetOrdinal("hostname")) as string,
reader.GetInt32("severity"), reader.GetString("severity"),
reader.GetDateTime("timestamp"), reader.GetDateTime("timestamp"),
reader.GetValue(reader.GetOrdinal("message")) as string reader.GetValue(reader.GetOrdinal("message")) as string
)); ));

View File

@ -10,21 +10,9 @@ namespace LoggingClient.Validators
{ {
public class IntRangeValidationRule : ValidationRule public class IntRangeValidationRule : ValidationRule
{ {
private int Min = 1; public int MinimumLength { get; set; }
private int Max = 3; public int MaximumLength { get; set; }
public string ErrorMessage { get; set; }
public int MinimumLength
{
get { return Min; }
set { Min = value; }
}
public int MaximumLength
{
get { return Max; }
set { Max = value; }
}
public override ValidationResult Validate(object value, public override ValidationResult Validate(object value,
CultureInfo cultureInfo) CultureInfo cultureInfo)
{ {
@ -43,11 +31,11 @@ namespace LoggingClient.Validators
+ e.Message); + e.Message);
} }
if ((parameter < this.Min) || (parameter > this.Max)) if ((parameter < this.MinimumLength) || (parameter > this.MaximumLength))
{ {
return new ValidationResult(false, return new ValidationResult(false,
"Severity must be a number between " "Input must be a number between "
+ this.Min + " - " + this.Max + "."); + this.MinimumLength + " - " + this.MaximumLength + ".");
} }
return new ValidationResult(true, null); return new ValidationResult(true, null);
} }

View File

@ -10,20 +10,8 @@ namespace LoggingClient.Validators
{ {
public class StringRangeValidationRule : ValidationRule public class StringRangeValidationRule : ValidationRule
{ {
private int _minimumLength = 3; public int MinimumLength { get; set; }
private int _maximumLength = 255; public int MaximumLength { get; set; }
public int MinimumLength
{
get { return _minimumLength; }
set { _minimumLength = value; }
}
public int MaximumLength
{
get { return _maximumLength; }
set { _maximumLength = value; }
}
public string ErrorMessage { get; set; } public string ErrorMessage { get; set; }

View File

@ -40,8 +40,8 @@ namespace LoggingClient.ViewModel.Commands
public event EventHandler CanExecuteChanged public event EventHandler CanExecuteChanged
{ {
add { CommandManager.RequerySuggested += value; } add => CommandManager.RequerySuggested += value;
remove { CommandManager.RequerySuggested -= value; } remove => CommandManager.RequerySuggested -= value;
} }
} }
@ -93,12 +93,5 @@ namespace LoggingClient.ViewModel.Commands
} }
private event EventHandler CanExecuteChangedInternal; private event EventHandler CanExecuteChangedInternal;
public void RaiseCanExecuteChanged()
{
//CanExecuteChangedInternal.Raise(this);
} }
}
} }

View File

@ -9,7 +9,7 @@ using LoggingClient.ViewModel.Commands;
namespace LoggingClient.ViewModel namespace LoggingClient.ViewModel
{ {
class LocationViewModel : INotifyPropertyChanged public class LocationViewModel : INotifyPropertyChanged
{ {
private string _txtConnectionString; private string _txtConnectionString;
@ -34,12 +34,12 @@ namespace LoggingClient.ViewModel
public LocationViewModel() public LocationViewModel()
{ {
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; TxtConnectionString = "Server=localhost;Database=;Uid=root;Pwd=;";
Locations = new List<Location>(); Locations = new List<Location>();
NewLocationModelEntry = new Location(); NewLocationModelEntry = new Location();
} }
public Logging MySelectedItem { get; set; } public Location MySelectedItem { get; set; }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
public string TxtConnectionString public string TxtConnectionString
{ {

View File

@ -9,24 +9,22 @@ using LoggingClient.Model;
using LoggingClient.ViewModel.Commands; using LoggingClient.ViewModel.Commands;
using DuplicateCheckerLib; using DuplicateCheckerLib;
using System.Linq; using System.Linq;
using System.Collections.Generic;
using LoggingClient.Repository;
namespace LoggingClient.ViewModel namespace LoggingClient.ViewModel
{ {
public class LogViewModel : INotifyPropertyChanged public class LogViewModel : INotifyPropertyChanged
{ {
private string _txtConnectionString; private string _txtConnectionString;
private string _enterPod; private readonly DuplicateChecker _dupChecker;
private string _enterHostname;
private int _enterSeverity;
private string _enterMessage;
private readonly DuplicateChecker _duplicateChecker;
private ICommand _btnLoadDataClick; private ICommand _btnLoadDataClick;
private ICommand _btnConfirmdataClick; private ICommand _btnConfirmDataClick;
private ICommand _btnAdddataClick; private ICommand _btnAddDataClick;
private ICommand _btnFindDuplicateClick; private ICommand _btnFindDuplicatesClick;
public ObservableCollection<Logging> Logs public List<Logging> Logs
{ {
get => _logs; get => _logs;
set set
@ -35,21 +33,22 @@ namespace LoggingClient.ViewModel
OnPropertyChanged("Logs"); OnPropertyChanged("Logs");
} }
} }
private ObservableCollection<Logging> _logs; private List<Logging> _logs;
public Logging NewLogModelEntry { get; set; }
public ObservableCollection<SeverityComboBoxItem> SeverityComboBox { get; set; } public ObservableCollection<SeverityComboBoxItem> SeverityComboBox { get; set; }
public LogViewModel() public LogViewModel()
{ {
TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; TxtConnectionString = "Server=localhost;Database=;Uid=root;Pwd=;";
_enterSeverity = 1;
Logs = new ObservableCollection<Logging>(); Logs = new List<Logging>();
NewLogModelEntry = new Logging();
SeverityComboBox = new ObservableCollection<SeverityComboBoxItem>(){ SeverityComboBox = new ObservableCollection<SeverityComboBoxItem>(){
new SeverityComboBoxItem(){Id=1, Severity= 1}, new SeverityComboBoxItem(){Id=1, Severity= 1},
new SeverityComboBoxItem(){Id=2, Severity= 2}, new SeverityComboBoxItem(){Id=2, Severity= 2},
new SeverityComboBoxItem(){Id=3, Severity= 3} new SeverityComboBoxItem(){Id=3, Severity= 3}
}; };
_duplicateChecker = new DuplicateChecker(); _dupChecker = new DuplicateChecker();
} }
public Logging MySelectedItem { get; set; } public Logging MySelectedItem { get; set; }
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
@ -64,44 +63,17 @@ namespace LoggingClient.ViewModel
OnPropertyChanged(nameof(TxtConnectionString)); OnPropertyChanged(nameof(TxtConnectionString));
} }
} }
public string EnterPod public ICommand BtnFindDuplicatesClick
{ {
get => _enterPod; get
set
{ {
_enterPod = value; return _btnFindDuplicatesClick ?? (_btnFindDuplicatesClick = new RelayCommand(
OnPropertyChanged(nameof(EnterPod)); 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 public ICommand BtnLoadDataClick
{ {
get get
@ -117,36 +89,33 @@ namespace LoggingClient.ViewModel
{ {
get get
{ {
return _btnAdddataClick ?? (_btnAdddataClick = new RelayCommand( return _btnAddDataClick ?? (_btnAddDataClick = new RelayCommand(
x => x =>
{ {
BtnAdd_Click(); BtnAdd_Click();
})); }));
} }
} }
public ICommand BtnFindDuplicateClick
{
get
{
return _btnFindDuplicateClick ?? (_btnFindDuplicateClick = new RelayCommand(
x =>
{
BtnFindDuplicate_Click();
}));
}
}
public ICommand BtnConfirmDataClick public ICommand BtnConfirmDataClick
{ {
get get
{ {
return _btnConfirmdataClick ?? (_btnConfirmdataClick = new RelayCommand( return _btnConfirmDataClick ?? (_btnConfirmDataClick = new RelayCommand(
x => x =>
{ {
BtnLogClear_Click(); 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() public void BtnLoadData_Click()
{ {
try try
@ -162,28 +131,8 @@ namespace LoggingClient.ViewModel
{ {
try try
{ {
Logs.Clear(); var logModelRepository = new LoggingRepository(TxtConnectionString);
using (var conn = new MySqlConnection(TxtConnectionString)) this.Logs = logModelRepository.GetAll();
{
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())
{
Logs.Add(new Logging(
reader.GetInt32(reader.GetOrdinal("id")),
reader.GetValue(reader.GetOrdinal("pod")) as string,
reader.GetValue(reader.GetOrdinal("location")) as string,
reader.GetValue(reader.GetOrdinal("hostname")) as string,
reader.GetInt32(reader.GetOrdinal("severity")),
reader.GetDateTime(reader.GetOrdinal("timestamp")),
reader.GetValue(reader.GetOrdinal("message")) as string
)) ;
}
}
conn.Close();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -191,24 +140,14 @@ namespace LoggingClient.ViewModel
} }
} }
private void BtnLogClear_Click() private void BtnLogClear_Click()
{ {
if (MySelectedItem == null) return; if (MySelectedItem == null) return;
try try
{ {
using (var conn = new MySqlConnection(TxtConnectionString)) var logModelRepository = new LoggingRepository(TxtConnectionString);
{ logModelRepository.CallStoredProcedure(MySelectedItem);
conn.Open(); this.Logs = logModelRepository.GetAll();
using (var cmd = conn.CreateCommand())
{
cmd.CommandText = "LogClear";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("_logentries_id", MySelectedItem.Id);
cmd.ExecuteNonQuery();
}
}
LoadData();
} }
catch (MySqlException ex) catch (MySqlException ex)
{ {
@ -219,37 +158,15 @@ namespace LoggingClient.ViewModel
{ {
try try
{ {
using (var conn = new MySqlConnection(TxtConnectionString)) var logModelRepository = new LoggingRepository(TxtConnectionString);
{ logModelRepository.Add(this.NewLogModelEntry);
using (MySqlCommand cmd = new MySqlCommand("LogMessageAdd", conn)) this.Logs = logModelRepository.GetAll();
{
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();
}
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show("Error occurred: " + ex.Message); MessageBox.Show("Error occurred: " + ex.Message);
} }
} }
public ObservableCollection<Logging> BtnFindDuplicate_Click()
{
LoadData();
var duplicateList = _duplicateChecker.FindDuplicates(Logs);
Logs = new ObservableCollection<Logging>(duplicateList.Cast<Logging>());
return Logs;
}
private void OnPropertyChanged(string propertyName) private void OnPropertyChanged(string propertyName)
{ {
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

View File

@ -59,30 +59,30 @@
<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="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" > <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 Path="NewLocationModelEntry.AddressId" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:IntRangeValidationRule <validators:IntRangeValidationRule
MinimumLength="1" MaximumLength="10000"/> MinimumLength="1" MaximumLength="10000"/>
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="95,366,0,0" TextWrapping="Wrap" Name="EnterParentId" VerticalAlignment="Top" Width="80"> <TextBox HorizontalAlignment="Left" Height="25" Margin="95,366,0,0" TextWrapping="Wrap" Name="EnterParentId" VerticalAlignment="Top" Width="80">
<TextBox.Text> <TextBox.Text>
<Binding Path="NewLocationModelEntry.ParentId" UpdateSourceTrigger="PropertyChanged"> <Binding Path="NewLocationModelEntry.ParentId" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:IntRangeValidationRule <validators:IntRangeValidationRule
validators:MinimumLength="1" validators:MaximumLength="10000"/> validators:MinimumLength="1" validators:MaximumLength="10000"/>
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="180,366,0,0" TextWrapping="Wrap" Name="EnterDesignation" VerticalAlignment="Top" Width="80"> <TextBox HorizontalAlignment="Left" Height="25" Margin="180,366,0,0" TextWrapping="Wrap" Name="EnterDesignation" VerticalAlignment="Top" Width="80">
<TextBox.Text> <TextBox.Text>
<Binding Path="NewLocationModelEntry.Designation" UpdateSourceTrigger="PropertyChanged"> <Binding Path="NewLocationModelEntry.Designation" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:StringRangeValidationRule <validators:StringRangeValidationRule
validators:MinimumLength="1" validators:MaximumLength="45" validators:MinimumLength="1" validators:MaximumLength="45"
ErrorMessage="Designation must contain at least 1 characters up to 45" /> ErrorMessage="Designation must contain at least 1 characters up to 45" />
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
@ -90,20 +90,20 @@
<TextBox HorizontalAlignment="Left" Height="25" Margin="265,366,0,0" TextWrapping="Wrap" Name="EnterBuildingNr" VerticalAlignment="Top" Width="80"> <TextBox HorizontalAlignment="Left" Height="25" Margin="265,366,0,0" TextWrapping="Wrap" Name="EnterBuildingNr" VerticalAlignment="Top" Width="80">
<TextBox.Text> <TextBox.Text>
<Binding Path="NewLocationModelEntry.BuildingNr" UpdateSourceTrigger="PropertyChanged"> <Binding Path="NewLocationModelEntry.BuildingNr" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:IntRangeValidationRule <validators:IntRangeValidationRule
validators:MinimumLength="1" validators:MaximumLength="10000"/> validators:MinimumLength="1" validators:MaximumLength="10000"/>
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="350,366,0,0" TextWrapping="Wrap" Name="EnterRoomNr" VerticalAlignment="Top" Width="80" > <TextBox HorizontalAlignment="Left" Height="25" Margin="350,366,0,0" TextWrapping="Wrap" Name="EnterRoomNr" VerticalAlignment="Top" Width="80" >
<TextBox.Text> <TextBox.Text>
<Binding Path="NewLocationModelEntry.RoomNr" UpdateSourceTrigger="PropertyChanged"> <Binding Path="NewLocationModelEntry.RoomNr" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:IntRangeValidationRule <validators:IntRangeValidationRule
validators:MinimumLength="1" validators:MaximumLength="10000"/> validators:MinimumLength="1" validators:MaximumLength="10000"/>
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>

View File

@ -55,39 +55,39 @@ CanUserResizeRows="False">
<TextBox HorizontalAlignment="Left" Height="25" Margin="10,350,0,0" TextWrapping="Wrap" Name="EnterPod" VerticalAlignment="Top" Width="110"> <TextBox HorizontalAlignment="Left" Height="25" Margin="10,350,0,0" TextWrapping="Wrap" Name="EnterPod" VerticalAlignment="Top" Width="110">
<TextBox.Text> <TextBox.Text>
<Binding Path="EnterPod" UpdateSourceTrigger="PropertyChanged"> <Binding Path="EnterPod" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:StringRangeValidationRule <validators:StringRangeValidationRule
ErrorMessage="Pod must contain atleast 3 characters up to 255" /> ErrorMessage="Pod must contain atleast 3 characters up to 255" />
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="125,350,0,0" TextWrapping="Wrap" Name="EnterHostname" VerticalAlignment="Top" Width="110"> <TextBox HorizontalAlignment="Left" Height="25" Margin="125,350,0,0" TextWrapping="Wrap" Name="EnterHostname" VerticalAlignment="Top" Width="110">
<TextBox.Text> <TextBox.Text>
<Binding Path="EnterHostname" UpdateSourceTrigger="PropertyChanged"> <Binding Path="EnterHostname" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:StringRangeValidationRule <validators:StringRangeValidationRule
ErrorMessage="Hostname must contain atleast 3 characters up to 255" /> ErrorMessage="Hostname must contain atleast 3 characters up to 255" />
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="240,350,0,0" TextWrapping="Wrap" Name="EnterSeverity" VerticalAlignment="Top" Width="110" > <TextBox HorizontalAlignment="Left" Height="25" Margin="240,350,0,0" TextWrapping="Wrap" Name="EnterSeverity" VerticalAlignment="Top" Width="110" >
<TextBox.Text> <TextBox.Text>
<Binding Path="EnterSeverity" UpdateSourceTrigger="PropertyChanged"> <Binding Path="EnterSeverity" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:IntRangeValidationRule/> <validators:IntRangeValidationRule/>
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>
<TextBox HorizontalAlignment="Left" Height="25" Margin="355,350,0,0" TextWrapping="Wrap" Name="EnterMessage" VerticalAlignment="Top" Width="418" RenderTransformOrigin="0.5,0.5"> <TextBox HorizontalAlignment="Left" Height="25" Margin="355,350,0,0" TextWrapping="Wrap" Name="EnterMessage" VerticalAlignment="Top" Width="418" RenderTransformOrigin="0.5,0.5">
<TextBox.Text> <TextBox.Text>
<Binding Path="EnterMessage" UpdateSourceTrigger="PropertyChanged"> <Binding Path="EnterMessage" UpdateSourceTrigger="PropertyChanged">
<Binding.ValidationRules> <!--<Binding.ValidationRules>
<validators:StringRangeValidationRule <validators:StringRangeValidationRule
ErrorMessage="Message must contain atleast 3 characters up to 255" /> ErrorMessage="Message must contain atleast 3 characters up to 255" />
</Binding.ValidationRules> </Binding.ValidationRules>-->
</Binding> </Binding>
</TextBox.Text> </TextBox.Text>
</TextBox> </TextBox>