Refactor to api connections. Update Checker.

This commit is contained in:
Matthew Burke
2023-08-24 12:45:56 -04:00
parent 4a4bcc81e0
commit 87a73ff24b
14 changed files with 355 additions and 45 deletions
+51 -13
View File
@@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
using System.Windows.Media;
/**
@@ -17,16 +18,22 @@ namespace PWAPPv2
/// </summary>
public partial class MainWindow : Window
{
static Source.APIConfig apiconfig = new Source.APIConfig();
static Source.APIConfig apiconfig;// = new Source.APIConfig();
static Source.Database.DatabaseConfig DataConfig;
static Source.API.APIConnection apiConnection;
Source.DataObjects.APICredentials apiCreds;
Source.API.PWApiConnection pwapiConnection;
Source.DataObjects.ComboBoxData TypeBox;
Source.DataObjects.ComboBoxData ToBox;
Source.DataObjects.ComboBoxData FromBox;
Source.Config.Configuration practiceConfig;
Source.Config.Configuration universalConfig;
string[] args;
Source.Patient patient;
@@ -43,18 +50,49 @@ namespace PWAPPv2
}
catch (Exception)
{ }
try
{
practiceConfig = new Source.Config.Configuration(".\\Config\\PracticeConfig.xml");
universalConfig = new Source.Config.Configuration(".\\Config\\UniversalConfig.xml");
}
catch
(Exception)
{
System.Windows.MessageBox.Show("An error has occured in the configurations files.");
}
pwapiConnection = new Source.API.PWApiConnection(practiceConfig, universalConfig);
try
{
if(pwapiConnection.CheckForUpdate() == true)
{
string message = "An update is available! Would you like to install it?";
string title = "Update available!";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result = System.Windows.Forms.MessageBox.Show(message, title, buttons);
if(result == System.Windows.Forms.DialogResult.Yes)
{
System.Windows.MessageBox.Show("HAHA NO UPDATE FOR YOU!");
}
}
}
catch (Exception)
{
System.Windows.MessageBox.Show("An error has occured while checking for updates");
}
try
{
images = new List<Source.DataObjects.PWImage>();
apiconfig.LoadConfig(ConfigPath);
DataConfig = new Source.Database.DatabaseConfig(ConfigPath);
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig);
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(practiceConfig);
apiconfig = new Source.APIConfig(practiceConfig, universalConfig);
apiCreds = new Source.DataObjects.APICredentials(apiconfig);
apiConnection = new Source.API.APIConnection("http://apipatientweb.azurewebsites.net/",
apiCreds);
apiConnection = new Source.API.APIConnection(universalConfig.Get("PWBaseURI"), apiCreds);
InitializeComponent();
@@ -72,7 +110,7 @@ namespace PWAPPv2
}
catch(Exception e)
{
MessageBox.Show(e.Message);
System.Windows.MessageBox.Show(e.Message);
}
}
@@ -176,11 +214,11 @@ namespace PWAPPv2
string json = att.ToJsonString();
apiConnection.SendPostRequestAsync("api/PWAttachment", json);
}
MessageBox.Show("Referral added successfully!");
System.Windows.MessageBox.Show("Referral added successfully!");
}
else
{
MessageBox.Show(result);
System.Windows.MessageBox.Show(result);
}
this.Close();
}
@@ -193,12 +231,12 @@ namespace PWAPPv2
//AddImage Button
private void Button_Click_2(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
openFileDialog.Multiselect = true;
openFileDialog.Filter = "Image files (*.jpg,*.jpeg)|*.jpg;*.jpeg";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == true)
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (string filename in openFileDialog.FileNames)
{
@@ -252,7 +290,7 @@ namespace PWAPPv2
{
Grid imageGrid = new Grid();
imageGrid.Width = 477;
imageGrid.HorizontalAlignment = HorizontalAlignment.Left;
imageGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
imageGrid.VerticalAlignment = VerticalAlignment.Top;
imageGrid.ShowGridLines = true;