diff --git a/.vs/HospitalServerManager/v15/.suo b/.vs/HospitalServerManager/v15/.suo index 64b0009..ba53633 100644 Binary files a/.vs/HospitalServerManager/v15/.suo and b/.vs/HospitalServerManager/v15/.suo differ diff --git a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide index fa929e3..63436ee 100644 Binary files a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide and b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide differ diff --git a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-shm b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-shm index a21d0eb..b2d9721 100644 Binary files a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-shm and b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-shm differ diff --git a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-wal b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-wal index 68065ae..5f33c40 100644 Binary files a/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-wal and b/.vs/HospitalServerManager/v15/Server/sqlite3/storage.ide-wal differ diff --git a/HospitalServerManager.csproj b/HospitalServerManager.csproj index 79d3bfd..2e62842 100644 --- a/HospitalServerManager.csproj +++ b/HospitalServerManager.csproj @@ -99,6 +99,8 @@ + + @@ -110,18 +112,25 @@ + + + + DoctorsPage.xaml MainFrameView.xaml + + NewRecordDialog.xaml + PatientsPage.xaml @@ -161,6 +170,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -178,6 +191,9 @@ 6.1.9 + + 12.0.1 + 14.0 diff --git a/InterfacesAndEnums/Enums.cs b/InterfacesAndEnums/Enums.cs index e3b2a28..13a8e39 100644 --- a/InterfacesAndEnums/Enums.cs +++ b/InterfacesAndEnums/Enums.cs @@ -61,7 +61,7 @@ namespace HospitalServerManager.InterfacesAndEnums Stable, [Description("ZAGROŻONY")] Endangered, - [Description("NULL")] + [Description("null")] None, } diff --git a/InterfacesAndEnums/Interfaces.cs b/InterfacesAndEnums/Interfaces.cs index 23d9cae..64429ec 100644 --- a/InterfacesAndEnums/Interfaces.cs +++ b/InterfacesAndEnums/Interfaces.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using Windows.UI.Xaml.Controls; namespace HospitalServerManager.InterfacesAndEnums { @@ -15,4 +16,37 @@ namespace HospitalServerManager.InterfacesAndEnums string GetPrimaryKey(); string GetPrimaryKeyName(); } + public interface INavigator + { + bool IsParameterSet { get; } + void SetParameter(object parameter); + void RemoveParameters(); + IPageNavigateable ChangeFrame(Type typeOfPage, Frame navigationFrame); + } + public interface IPageNavigateable + { + void UnloadPage(); + } + public interface IValidateIfInterfaceIsImplemented + { + /// + /// Validates if type implement interface. TypeProvider have to be initialized before use this overloaded method. + /// + /// + /// + /// + bool ValidateIfTypeImplementInterface(string typeName, string interfaceNameToCheck); + bool ValidateIfTypeImplementInterface(Type typeToCheck, string interfaceNameToCheck); + bool ValidateIfTypeImplementInterface(Type typeToCheck, Type interfaceToCheck); + } + public interface IProvideType + { + void RegisterType(Type typeToRegister); + Type GetTypeFromString(string typeName); + } + public interface IProvideDBInfo + { + IEnumerable GetColumnNames(string tableName); + IDictionary GetColumnTypesNames(string tableName); + } } diff --git a/Model/Basic/Doctor.cs b/Model/Basic/Doctor.cs index b9f1672..34ad2f4 100644 --- a/Model/Basic/Doctor.cs +++ b/Model/Basic/Doctor.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using HospitalServerManager.InterfacesAndEnums; +using Newtonsoft.Json; namespace HospitalServerManager.Model.Basic { @@ -19,23 +20,35 @@ namespace HospitalServerManager.Model.Basic protected Doctor() : base() { } - public Doctor(int primaryKey, string name, string surname, AcademicDegrees academicDegree, - MedicalSpecializations medicalSpecialization, DateTime dateOfEmployment, JobPositions jobPosition) - : base(primaryKey.ToString(), "Id_Lekarza", new List { }) + public Doctor(int doctorID, string name, string surname, AcademicDegrees academicDegree, + MedicalSpecializations specialization, DateTime dateOfEmployment, JobPositions jobPosition) + : base(doctorID.ToString(), "Id_Lekarza", new List { }) { Name = name; Surname = surname; _AcademicDegree = academicDegree; - _MedicalSpecialization = medicalSpecialization; + _MedicalSpecialization = specialization; DateOfEmployment = dateOfEmployment; _JobPosition = jobPosition; } - /// - /// List have to be in right order (doctor id, name, surname, academic degree, medical specialization, - /// date of employment, jobposition). - /// - /// - public Doctor(List listOfValues) : base(listOfValues[0], "Id_Lekarza", new List { }) + [JsonConstructor] + protected Doctor(int doctorID, string name, string surname, string academicDegree, + string specialization, DateTime dateOfEmployment, string jobPosition) + : base(doctorID.ToString(), "Id_Lekarza", new List { }) + { + Name = name; + Surname = surname; + _AcademicDegree = academicDegree.GetEnumFromDescription(); + _MedicalSpecialization = specialization.GetEnumFromDescription(); + DateOfEmployment = dateOfEmployment; + _JobPosition = jobPosition.GetEnumFromDescription(); + } + /// + /// List have to be in right order (doctor id, name, surname, academic degree, medical specialization, + /// date of employment, jobposition). + /// + /// + public Doctor(List listOfValues) : base(listOfValues[0], "Id_Lekarza", new List { }) { Name = listOfValues[1]; Surname = listOfValues[2]; diff --git a/Model/Basic/Patient.cs b/Model/Basic/Patient.cs index a0cad4a..c27d4ff 100644 --- a/Model/Basic/Patient.cs +++ b/Model/Basic/Patient.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using HospitalServerManager.InterfacesAndEnums; +using Newtonsoft.Json; namespace HospitalServerManager.Model.Basic { @@ -18,23 +19,35 @@ namespace HospitalServerManager.Model.Basic protected Patient() : base() { } - public Patient(string primaryKey, string surname, string name, DateTime birthDate, PatientState patientState, - Sex patientSex) : base(primaryKey, "PESEL", new List()) + [JsonConstructor] + protected Patient(string pesel, string name, string surname, DateTime birthDate, string patientState, + string patientSex) : base(pesel, "PESEL", new List()) { - if (primaryKey.Length < 11 || primaryKey.Length > 11) + if (pesel.Length < 11 || pesel.Length > 11) throw new FormatException("PESEL musi mieć 11 cyfr"); - PrimaryKey = primaryKey; + //PrimaryKey = pesel; Surname = surname; Name = name; BirthDate = birthDate; - PatientState = patientState; - PatientSex = patientSex; + PatientState = patientState.GetEnumFromDescription(); + PatientSex = patientSex.GetEnumFromDescription(); } - /// - /// List have to be in right order (pesel, surname, name, birth date, patient state, patient sex). - /// - /// - public Patient(List listOfValues) : base(listOfValues[0], "PESEL", new List()) + public Patient(string pesel, string name, string surname, DateTime birthDate, PatientState patientState, + Sex patientSex) : base(pesel, "PESEL", new List()) + { + if (pesel.Length < 11 || pesel.Length > 11) + throw new FormatException("PESEL musi mieć 11 cyfr"); + //PrimaryKey = pesel; + Surname = surname; + Name = name; + BirthDate = birthDate; + PatientState = patientState; + PatientSex = patientSex; + }/// + /// List have to be in right order (pesel, surname, name, birth date, patient state, patient sex). + /// + /// + public Patient(List listOfValues) : base(listOfValues[0], "PESEL", new List()) { // TODO: Dodać zabezpieczenia dla pozostałych wartosci // TODO: VALIDATOR! Lista kolumn nazw; diff --git a/Model/Basic/SqlTable.cs b/Model/Basic/SqlTable.cs index 721ad03..3971461 100644 --- a/Model/Basic/SqlTable.cs +++ b/Model/Basic/SqlTable.cs @@ -4,13 +4,14 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using HospitalServerManager.InterfacesAndEnums; +using HospitalServerManager.Model.Controllers; namespace HospitalServerManager.Model.Basic { internal abstract class SqlTable : ISqlTableModelable { - // TODO: Dodac table do klas modelu - public string PrimaryKey { get; protected set; } + // TODO: Dodac table do klas modelu + public string PrimaryKey { get; protected set; } protected string PrimaryKeyName { get; set; } protected List ColumnNames { get; set; } protected SqlTable() diff --git a/Model/Controllers/ApiCommandProvider.cs b/Model/Controllers/ApiCommandProvider.cs new file mode 100644 index 0000000..4667446 --- /dev/null +++ b/Model/Controllers/ApiCommandProvider.cs @@ -0,0 +1,37 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HospitalServerManager.Model.Controllers +{ + internal static class ApiCommandProvider + { + public static string GetRecordHttpRequest(string tableName) + { + return @"/getfromdb/" + tableName; + } + public static string GetColumnNamesHttpRequest(string tableName) + { + return @"/getcolumnnames/" + tableName; + } + public static string GetColumnTypesHttpRequest(string tableName) + { + return @"/getcolumntypes/" + tableName; + } + public static string CreateNewRecordAsync(string tableName, List valuesList) + { + string createRequest = "/insertrec/" + tableName + "/nr/" + valuesList.Count() + "/pk/" + valuesList[0]; + for(int i = 1; i<8; i++) + { + var maxIndex = valuesList.Count(); + if (i < maxIndex) + createRequest += "/" + valuesList[i]; + else + createRequest += "/_"; + } + return createRequest; + } + } +} diff --git a/Model/Controllers/WebService.cs b/Model/Controllers/WebService.cs new file mode 100644 index 0000000..4c35129 --- /dev/null +++ b/Model/Controllers/WebService.cs @@ -0,0 +1,113 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using HospitalServerManager.InterfacesAndEnums; +using Newtonsoft.Json; +using System.IO; + +namespace HospitalServerManager.Model.Controllers +{ + class WebService + { + private HttpClient httpClient; + private IProvideDBInfo databaseInfoProvider { get; } + + public WebService(HttpClient httpClient) + { + this.httpClient = httpClient; + InitializeHttpClient(new Uri("http://localhost:1433/")); + } + public WebService(Uri baseAdress) + { + httpClient = new HttpClient(new HttpClientHandler(), false); + InitializeHttpClient(baseAdress); + } + + private void InitializeHttpClient(Uri baseAdress) + { + httpClient.BaseAddress = baseAdress; + httpClient.DefaultRequestHeaders.Clear(); + //httpClient.DefaultRequestHeaders.Add("JSON", new MediaTypeWithQualityHeaderValue("application/json")); + } + + public async Task> GetRecordAsync(string tableName) + { + // TODO: SPRAWDZIC CZY IMPLEMENTUJE INTERFACE!! + List modelsList = new List(); + //using (var client = httpClient) + using (var message = new HttpRequestMessage(HttpMethod.Get, ApiCommandProvider.GetRecordHttpRequest(tableName))) + using (var response = await httpClient.SendAsync(message)) + { + response.EnsureSuccessStatusCode(); + var stream = await response.Content.ReadAsStreamAsync(); + return DeserializeJsonFromStream>(stream); + //return JsonConvert.DeserializeObject>(content); + } + } + public async Task> GetColumnNamesAsync(string tableName) + { + using (var message = new HttpRequestMessage(HttpMethod.Get, ApiCommandProvider.GetColumnNamesHttpRequest(tableName))) + using (var response = await httpClient.SendAsync(message)) + { + response.EnsureSuccessStatusCode(); + var columns = await response.Content.ReadAsStringAsync(); + var columnNames = columns.Split("."); + var x = columnNames.ToList(); + x.RemoveAt(x.Count - 1); + return x; + } + } + public async Task> GetColumnTypesAsync(string tableName) + { + using (var message = new HttpRequestMessage(HttpMethod.Get, ApiCommandProvider.GetColumnTypesHttpRequest(tableName))) + using (var response = await httpClient.SendAsync(message)) + { + response.EnsureSuccessStatusCode(); + var columns = await response.Content.ReadAsStringAsync(); + var columnTypes = columns.Split("."); + var x = columnTypes.ToList(); + x.RemoveAt(x.Count - 1); + var dictionary = new Dictionary(); + for(int i = 0; i CreateNewRecordAsync(string tableName, IEnumerable valuesList) + { + using (var message = new HttpRequestMessage(HttpMethod.Get, ApiCommandProvider.CreateNewRecordAsync(tableName, valuesList.ToList()))) + using (var response = await httpClient.SendAsync(message)) + { + response.EnsureSuccessStatusCode(); + return true; + } + } + + private static T DeserializeJsonFromStream(Stream stream) + { + if (stream == null || stream.CanRead == false) + return default(T); + + using (var sr = new StreamReader(stream)) + using (var textReader = new JsonTextReader(sr)) + { + var js = new JsonSerializer(); + var searchResult = js.Deserialize(textReader); + return searchResult; + } + } + + + private string GetRecordHttpRequest(string tableName) + { + return @"/getfromdb/" + tableName; + } + } +} diff --git a/Model/ModelRoster.cs b/Model/ModelRoster.cs index 050c787..843c657 100644 --- a/Model/ModelRoster.cs +++ b/Model/ModelRoster.cs @@ -1,24 +1,78 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; using System.Threading.Tasks; using HospitalServerManager.InterfacesAndEnums; using HospitalServerManager.Model.Basic; +using HospitalServerManager.Model.Controllers; namespace HospitalServerManager.Model { class ModelRoster { private List _modelsList = new List(); - public IEnumerable ModelsEnumerable { get => _modelsList; } + private WebService webService = new WebService(new Uri("http://localhost:8080/")); + public string ActualTableName { get; private set; } + public IEnumerable ColumnNames { get; private set; } + public IDictionary ColumnTypes { get; private set; } + public Dictionary EnumTypes { get; protected set; } + public IEnumerable ModelsEnumerable { get => _modelsList; } //private Controllers.DatabaseReader DatabaseReader = new Controllers.DatabaseReader(); public ModelRoster() { - + ActualTableName = string.Empty; + ColumnNames = new List(); + EnumTypes = CreateEnumTypesDictionary(); } - public void AddRange(IEnumerable modelsList) + public async Task ReadModels(string tableName) + { + _modelsList.Clear(); + if(ColumnNames.Any()) + ColumnNames.ToList().Clear(); + /*MethodInfo method = typeof(WebService).GetMethod("GetRecordAsync"); + method = method.MakeGenericMethod(type); + var resp = method.Invoke(webService, new[] { "Pacjenci" });*/ + ActualTableName = tableName; + ColumnNames = await GetColumnNames(); + ColumnTypes = await GetColumnTypes(); + IEnumerable response = new List(); + if(tableName == "Pacjenci") response = await webService.GetRecordAsync(tableName); + else if(tableName == "Lekarze") response = await webService.GetRecordAsync(tableName); + _modelsList.AddRange(response); + + //ColumnNames = await GetColumnNames(); + } + public async Task> GetColumnNames() + { + if (ActualTableName == string.Empty) + throw new Exception(); + return await webService.GetColumnNamesAsync(ActualTableName); + } + public async Task> GetColumnTypes() + { + if (ActualTableName == string.Empty) + throw new Exception(); + return await webService.GetColumnTypesAsync(ActualTableName); + } + public async void CreateRecord(string tableName, IEnumerable valueList) + { + await webService.CreateNewRecordAsync(tableName, valueList); + } + private Dictionary CreateEnumTypesDictionary() + { + // TODO: Uzupełniać w miare dodawania tabel! + Dictionary newDictionary = new Dictionary(); + newDictionary.Add("Plec", typeof(Sex)); + newDictionary.Add("Stan", typeof(PatientState)); + newDictionary.Add("Stopien_naukowy", typeof(AcademicDegrees)); + newDictionary.Add("Specjalizacja", typeof(MedicalSpecializations)); + newDictionary.Add("Stanowisko", typeof(JobPositions)); + return newDictionary; + } + public void AddRange(IEnumerable modelsList) { _modelsList.Clear(); _modelsList.AddRange(modelsList); diff --git a/View/DoctorsPage.xaml b/View/DoctorsPage.xaml index cba096e..a518b17 100644 --- a/View/DoctorsPage.xaml +++ b/View/DoctorsPage.xaml @@ -7,7 +7,7 @@ xmlns:viewmodel="using:HospitalServerManager.ViewModel" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" - Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> + Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Loaded="Page_Loaded"> @@ -28,7 +28,7 @@ -