diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index ef12a5e..aad4d26 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -78,7 +78,13 @@ MSBuild:Compile Designer + + + + + + @@ -93,7 +99,7 @@ App.xaml Code - + MainWindow.xaml diff --git a/LoggingClient/LoggingClient/Model/Location.cs b/LoggingClient/LoggingClient/Model/Location.cs new file mode 100755 index 0000000..5012d62 --- /dev/null +++ b/LoggingClient/LoggingClient/Model/Location.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoggingClient.Model +{ + class Location : Model + { + } +} diff --git a/LoggingClient/LoggingClient/Model/LogModel.cs b/LoggingClient/LoggingClient/Model/Logging.cs old mode 100644 new mode 100755 similarity index 84% rename from LoggingClient/LoggingClient/Model/LogModel.cs rename to LoggingClient/LoggingClient/Model/Logging.cs index 59b0489..170146d --- a/LoggingClient/LoggingClient/Model/LogModel.cs +++ b/LoggingClient/LoggingClient/Model/Logging.cs @@ -1,9 +1,8 @@ using System; -using DuplicateCheckerLib; namespace LoggingClient.Model { - public class LogModel : IEntity + public class Logging : Model { public int Id { get; set; } public string Pod { get; set; } @@ -13,7 +12,7 @@ namespace LoggingClient.Model 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(int id, string pod, string location, string hostname, int severity, DateTime timestamp, string message) { this.Id = id; this.Pod = pod; @@ -23,7 +22,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,7 +31,7 @@ namespace LoggingClient.Model } public override bool Equals(object value) { - return Equals(value as LogModel); + return Equals(value as Logging); } public override int GetHashCode() { diff --git a/LoggingClient/LoggingClient/Model/Model.cs b/LoggingClient/LoggingClient/Model/Model.cs new file mode 100755 index 0000000..46e3758 --- /dev/null +++ b/LoggingClient/LoggingClient/Model/Model.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using DuplicateCheckerLib; + +namespace LoggingClient.Model +{ + public class Model : IEntity + { + } +} diff --git a/LoggingClient/LoggingClient/Repository/IRepositoryBase.cs b/LoggingClient/LoggingClient/Repository/IRepositoryBase.cs new file mode 100755 index 0000000..d7170a0 --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/IRepositoryBase.cs @@ -0,0 +1,76 @@ +using System.Collections.Generic; + +namespace LoggingClient.Repository +{ + public interface IRepositoryBase + { + /// + /// Liefert ein einzelnes Model-Objekt vom Typ M zurück, + /// welches anhand dem übergebenen PrimaryKey geladen wird. + /// + /// Type des PrimaryKey + /// Wert des PrimaryKey + /// gefundenes Model-Objekt, ansonsten null + M GetSingle

(P pkValue); + + ///

+ /// Fügt das Model-Objekt zur Datenbank hinzu (Insert) + /// + /// zu speicherndes Model-Object + void Add(M entity); + + /// + /// Löscht das Model-Objekt aus der Datenbank (Delete) + /// + /// zu löschendes Model-Object + void Delete(M entity); + + /// + /// Aktualisiert das Model-Objekt in der Datenbank hinzu (Update) + /// + /// zu aktualisierendes Model-Object + void Update(M entity); + + /// + /// 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) + /// + /// WhereBedingung als string + /// z.B. "NetPrice > @netPrice and Active = @active and Description like @desc + /// Parameter-Werte für die Wherebedingung + /// bspw: {{"netPrice", 10.5}, {"active", true}, {"desc", "Wolle%"}} + /// + List GetAll(string whereCondition, Dictionary parameterValues); + + /// + /// Gibt eine Liste aller in der DB vorhandenen Model-Objekte vom Typ M zurück + /// + /// + List GetAll(); + + /// + /// Zählt in der Datenbank die Anzahl Model-Objekte vom Typ M, die der + /// Where-Bedingung entsprechen + /// + /// WhereBedingung als string + /// z.B. "NetPrice > @netPrice and Active = @active and Description like @desc + /// Parameter-Werte für die Wherebedingung + /// bspw: {{"netPrice", 10.5}, {"active", true}, {"desc", "Wolle%"}} + /// + long Count(string whereCondition, Dictionary parameterValues); + + /// + /// Zählt alle Model-Objekte vom Typ M + /// + /// + long Count(); + + /// + /// Gibt den Tabellennamen zurück, auf die sich das Repository bezieht + /// + string TableName { get; } + } +} \ No newline at end of file diff --git a/LoggingClient/LoggingClient/Repository/LocationRepository.cs b/LoggingClient/LoggingClient/Repository/LocationRepository.cs new file mode 100755 index 0000000..f13ec8e --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/LocationRepository.cs @@ -0,0 +1,50 @@ +using LoggingClient.Model; +using System.Collections.Generic; + +namespace LoggingClient.Repository +{ + class LocationRepository : RepositoryBase + { + public override string TableName => throw new System.NotImplementedException(); + + public override void Add(Location entity) + { + throw new System.NotImplementedException(); + } + + public override long Count(string whereCondition, Dictionary parameterValues) + { + throw new System.NotImplementedException(); + } + + public override long Count() + { + throw new System.NotImplementedException(); + } + + public override void Delete(Location entity) + { + throw new System.NotImplementedException(); + } + + public override List GetAll(string whereCondition, Dictionary parameterValues) + { + throw new System.NotImplementedException(); + } + + public override List GetAll() + { + throw new System.NotImplementedException(); + } + + public override Location GetSingle

(P pkValue) + { + throw new System.NotImplementedException(); + } + + public override void Update(Location entity) + { + throw new System.NotImplementedException(); + } + } +} diff --git a/LoggingClient/LoggingClient/Repository/LoggingRepository.cs b/LoggingClient/LoggingClient/Repository/LoggingRepository.cs new file mode 100755 index 0000000..36bf3d4 --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/LoggingRepository.cs @@ -0,0 +1,54 @@ +using LoggingClient.Model; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoggingClient.Repository +{ + class LoggingRepository : RepositoryBase + { + public override string TableName => throw new NotImplementedException(); + + public override void Add(Logging entity) + { + throw new NotImplementedException(); + } + + public override long Count(string whereCondition, Dictionary parameterValues) + { + throw new NotImplementedException(); + } + + public override long Count() + { + throw new NotImplementedException(); + } + + public override void Delete(Logging entity) + { + throw new NotImplementedException(); + } + + public override List GetAll(string whereCondition, Dictionary parameterValues) + { + throw new NotImplementedException(); + } + + public override List GetAll() + { + throw new NotImplementedException(); + } + + public override Logging GetSingle

(P pkValue) + { + throw new NotImplementedException(); + } + + public override void Update(Logging entity) + { + throw new NotImplementedException(); + } + } +} diff --git a/LoggingClient/LoggingClient/Repository/RepositoryBase.cs b/LoggingClient/LoggingClient/Repository/RepositoryBase.cs new file mode 100755 index 0000000..b2000f2 --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/RepositoryBase.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoggingClient.Repository +{ + public abstract class RepositoryBase : IRepositoryBase + { + public abstract string TableName { get; } + + public abstract void Add(M entity); + public abstract long Count(string whereCondition, Dictionary parameterValues); + public abstract long Count(); + public abstract void Delete(M entity); + public abstract List GetAll(string whereCondition, Dictionary parameterValues); + public abstract List GetAll(); + public abstract M GetSingle

(P pkValue); + public abstract void Update(M entity); + } +} \ No newline at end of file diff --git a/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs b/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs old mode 100644 new mode 100755 index f84825a..b128820 --- a/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/LogViewModel.cs @@ -26,7 +26,7 @@ namespace LoggingClient.ViewModel private ICommand _btnAdddataClick; private ICommand _btnFindDuplicateClick; - public ObservableCollection Logs + public ObservableCollection Logs { get => _logs; set @@ -35,15 +35,15 @@ namespace LoggingClient.ViewModel OnPropertyChanged("Logs"); } } - private ObservableCollection _logs; + private ObservableCollection _logs; public ObservableCollection SeverityComboBox { get; set; } public LogViewModel() { - TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=foekicoe9i4kpos;"; + TxtConnectionString = "Server=localhost;Database=inventarisierungsloesung;Uid=root;Pwd=MySQLPassword1234!;"; _enterSeverity = 1; - Logs = new ObservableCollection(); + Logs = new ObservableCollection(); SeverityComboBox = new ObservableCollection(){ new SeverityComboBoxItem(){Id=1, Severity= 1}, new SeverityComboBoxItem(){Id=2, Severity= 2}, @@ -51,7 +51,7 @@ namespace LoggingClient.ViewModel }; _duplicateChecker = new DuplicateChecker(); } - public LogModel MySelectedItem { get; set; } + public Logging MySelectedItem { get; set; } public event PropertyChangedEventHandler PropertyChanged; public SeverityComboBoxItem SetSeverity { get; set; } @@ -177,7 +177,7 @@ namespace LoggingClient.ViewModel { location = reader.GetString("location"); } - Logs.Add(new LogModel( + Logs.Add(new Logging( reader.GetInt32("id"), reader.GetString("pod"), location, @@ -247,12 +247,12 @@ namespace LoggingClient.ViewModel MessageBox.Show("Error occurred: " + ex.Message); } } - public ObservableCollection BtnFindDuplicate_Click() + public ObservableCollection BtnFindDuplicate_Click() { LoadData(); var duplicateList = _duplicateChecker.FindDuplicates(Logs); - Logs = new ObservableCollection(duplicateList.Cast()); + Logs = new ObservableCollection(duplicateList.Cast()); return Logs; }