343 lines
11 KiB
C#
343 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Forms;
|
|
|
|
/**
|
|
* TODO:
|
|
* * ADD API SUPPORT
|
|
*/
|
|
|
|
namespace PWAPPv2
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for MainWindow.xaml
|
|
/// </summary>
|
|
public partial class MainWindow : Window
|
|
{
|
|
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;
|
|
|
|
List<Source.DataObjects.PWImage> images;
|
|
|
|
|
|
//string ConfigPath = "C:\\PWAPP\\Config\\Config.xml";
|
|
|
|
string ConfigPath;
|
|
|
|
public MainWindow()
|
|
{
|
|
try
|
|
{
|
|
args = App.Args;
|
|
}
|
|
catch (Exception)
|
|
{ }
|
|
|
|
try
|
|
{
|
|
//ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
//ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\");
|
|
|
|
ConfigPath = "C:\\PWAPP\\Config\\";
|
|
|
|
practiceConfig = new Source.Config.Configuration(ConfigPath + "PracticeConfig.xml");
|
|
universalConfig = new Source.Config.Configuration(ConfigPath + "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!");
|
|
Process p = new Process();
|
|
p.StartInfo.FileName = "C:\\PWAPP\\Updater\\PWAppUpdaterForm.exe";
|
|
p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
|
|
p.StartInfo.UseShellExecute = false;
|
|
p.StartInfo.RedirectStandardOutput = true;
|
|
p.StartInfo.RedirectStandardError = true;
|
|
p.StartInfo.Arguments = args[0];
|
|
if(System.Environment.OSVersion.Version.Major >= 6)
|
|
{
|
|
p.StartInfo.Verb = "runas";
|
|
}
|
|
p.Start();
|
|
Environment.Exit(0);
|
|
}
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
System.Windows.MessageBox.Show("An error has occured while checking for updates");
|
|
}
|
|
|
|
try
|
|
{
|
|
images = new List<Source.DataObjects.PWImage>();
|
|
|
|
|
|
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(universalConfig.Get("PWBaseURI"), apiCreds);
|
|
|
|
InitializeComponent();
|
|
|
|
PopulateComboBoxes();
|
|
|
|
patient = new Source.Patient();
|
|
|
|
patient.BuildFromDatabase(dbcon, args[0]);
|
|
|
|
this.DataContext = new Source.PatientGUIAdapter(patient);
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
System.Windows.MessageBox.Show(e.Message);
|
|
}
|
|
}
|
|
|
|
private void PopulateComboBoxes()
|
|
{
|
|
PopulateReferTypesBox();
|
|
PopulateReferToBox();
|
|
PopulateReferFromBox();
|
|
}
|
|
|
|
private void PopulateReferTypesBox()
|
|
{
|
|
//string ReferTypeString = apiConnection.SendPostRequestAsync("api/PWReferralTypes");
|
|
string ReferTypeString = pwapiConnection.GetReferalTypes();
|
|
TypeBox = new Source.DataObjects.ReferralTypeBox(boxReferType, ReferTypeString);
|
|
|
|
}
|
|
|
|
private void PopulateReferToBox()
|
|
{
|
|
string ReferToString = pwapiConnection.GetReferTo(); //apiConnection.SendPostRequestAsync("api/PWReferTo");
|
|
ToBox = new Source.DataObjects.ReferToBox(boxReferTo, ReferToString);
|
|
}
|
|
|
|
private void PopulateReferFromBox()
|
|
{
|
|
string ReferFromString = pwapiConnection.GetReferFrom(); //apiConnection.SendPostRequestAsync("api/PWReferFrom");
|
|
FromBox = new Source.DataObjects.ReferFromBox(boxReferFrom, ReferFromString);
|
|
}
|
|
|
|
private void RichTextBox_TextChanged(object sender, TextChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void DataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void CheckBox_Checked(object sender, RoutedEventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void boxReferType_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
TypeBox.GetSelectedID();
|
|
}
|
|
catch (Source.DataObjects.ReferralTypeDefaultException)
|
|
{
|
|
|
|
}
|
|
catch (Source.DataObjects.InvalidReferralTypeException)
|
|
{
|
|
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
//Cancel button
|
|
private void Button_Click(object sender, RoutedEventArgs e)
|
|
{
|
|
this.Close();
|
|
}
|
|
|
|
//OK Button
|
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
|
{
|
|
Source.DataObjects.Referral referral;
|
|
if (images.Count == 0)
|
|
{
|
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
|
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
|
(Source.DataObjects.ReferToBox)ToBox,
|
|
(Source.DataObjects.ReferFromBox)FromBox,
|
|
fieldRemakrs, contact, false);
|
|
}
|
|
else
|
|
{
|
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
|
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
|
(Source.DataObjects.ReferToBox)ToBox,
|
|
(Source.DataObjects.ReferFromBox)FromBox,
|
|
fieldRemakrs, contact, true);
|
|
}
|
|
|
|
try
|
|
{
|
|
string referralString = referral.ToJsonString();
|
|
string result = pwapiConnection.SendReferral(referralString); //apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString);
|
|
if (images.Count > 0)
|
|
{
|
|
foreach (Source.DataObjects.PWImage im in images)
|
|
{
|
|
Source.DataObjects.Attachment att = new Source.DataObjects.Attachment(apiCreds, im, result);
|
|
string json = att.ToJsonString();
|
|
apiConnection.SendPostRequestAsync("api/PWAttachment", json);
|
|
}
|
|
}
|
|
|
|
System.Windows.MessageBox.Show("Referral added successfully!");
|
|
|
|
this.Close();
|
|
}
|
|
catch (Source.DataObjects.Referral.InvalidReferalDataException)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
//AddImage Button
|
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
|
{
|
|
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() == System.Windows.Forms.DialogResult.OK)
|
|
{
|
|
foreach (string filename in openFileDialog.FileNames)
|
|
{
|
|
try
|
|
{
|
|
images.Add(new Source.DataObjects.PWImage(filename));
|
|
}
|
|
catch (NullReferenceException)
|
|
{
|
|
images = new List<Source.DataObjects.PWImage>();
|
|
images.Add(new Source.DataObjects.PWImage(filename));
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
try
|
|
{
|
|
ImageList.Items.Clear();
|
|
foreach (Source.DataObjects.PWImage image in images)
|
|
{
|
|
ImageList.Items.Add(CreateImageGridItem(image));
|
|
}
|
|
}
|
|
catch (NullReferenceException)
|
|
{ }
|
|
|
|
}
|
|
|
|
private void Button_Click_3(object sender, RoutedEventArgs e)
|
|
{
|
|
int index = ImageList.SelectedIndex;
|
|
if (index == -1)
|
|
{
|
|
return;
|
|
}
|
|
images.RemoveAt(index);
|
|
try
|
|
{
|
|
ImageList.Items.Clear();
|
|
foreach (Source.DataObjects.PWImage image in images)
|
|
{
|
|
ImageList.Items.Add(CreateImageGridItem(image));
|
|
}
|
|
}
|
|
catch (NullReferenceException)
|
|
{ }
|
|
}
|
|
|
|
public Grid CreateImageGridItem(Source.DataObjects.PWImage image)
|
|
{
|
|
Grid imageGrid = new Grid();
|
|
imageGrid.Width = 477;
|
|
imageGrid.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
|
|
imageGrid.VerticalAlignment = VerticalAlignment.Top;
|
|
imageGrid.ShowGridLines = true;
|
|
|
|
ColumnDefinition imageColumn = new ColumnDefinition();
|
|
imageColumn.Width = new GridLength(50);
|
|
ColumnDefinition textColumn = new ColumnDefinition();
|
|
textColumn.Width = new GridLength(427);
|
|
|
|
imageGrid.ColumnDefinitions.Add(imageColumn);
|
|
imageGrid.ColumnDefinitions.Add(textColumn);
|
|
|
|
Image addedImage = new Image();
|
|
addedImage.Source = image.GetBitmapImage();
|
|
|
|
TextBlock text = new TextBlock();
|
|
text.Text = image.GetPath();
|
|
text.FontSize = 12;
|
|
|
|
|
|
Grid.SetColumn(addedImage, 0);
|
|
Grid.SetColumn(text, 1);
|
|
|
|
imageGrid.Children.Add(addedImage);
|
|
imageGrid.Children.Add(text);
|
|
return imageGrid;
|
|
|
|
}
|
|
}
|
|
}
|