Fixed issue with attachment tokens. Changed how attachments are handled to be more modular. Added support for PNG files.

This commit is contained in:
2024-02-09 19:02:09 -05:00
parent 40f9db3ea4
commit f31302438d
10 changed files with 410 additions and 74 deletions
+114 -66
View File
@@ -1,7 +1,11 @@
using System;
using PWAPPv2.Source;
using PWAPPv2.Source.Attachments;
using PWAPPv2.Source.Database;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text.Json;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Forms;
@@ -40,13 +44,23 @@ namespace PWAPPv2
List<Source.DataObjects.Attachment> attachments;
List<string> SupportedImageTypes = new List<string>();
//string ConfigPath = "C:\\PWAPP\\Config\\Config.xml";
string ConfigPath;
FileHandler fileHandler;
public MainWindow()
{
SupportedImageTypes.Clear();
SupportedImageTypes.Add(".jpeg");
SupportedImageTypes.Add(".jpg");
SupportedImageTypes.Add(".png");
try
{
args = App.Args;
@@ -56,11 +70,6 @@ namespace PWAPPv2
ConfigPath = "C:\\PWAPP\\Config\\";
try
{
//ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
//ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\");
practiceConfig = new Source.Config.Configuration("C:\\PWAPP\\Config\\PracticeConfig.xml");
universalConfig = new Source.Config.Configuration("C:\\PWAPP\\App\\Config\\UniversalConfig.xml");
}
@@ -74,7 +83,7 @@ namespace PWAPPv2
try
{
if (pwapiConnection.CheckForUpdate() == true)
/*if (pwapiConnection.CheckForUpdate() == true)
{
string message = "An update is available! Would you like to install it?";
string title = "Update available!";
@@ -101,7 +110,9 @@ namespace PWAPPv2
p.Start();
Environment.Exit(0);
}
}
}*/
pwapiConnection.Update(args);
}
catch (Exception)
{
@@ -118,23 +129,33 @@ namespace PWAPPv2
apiCreds = new Source.DataObjects.APICredentials(apiconfig);
apiConnection = new Source.API.APIConnection(universalConfig.Get("PWBaseURI"), apiCreds);
fileHandler = new FileHandler(apiCreds);
InitializeComponent();
PopulateComboBoxes();
patient = new Source.Patient();
//patient = new Source.Patient();
patient.BuildFromDatabase(dbcon, args[0]);
//patient.BuildFromDatabase(dbcon, args[0]);
patient = Patient.GetPatient(dbcon, args[0]);
this.DataContext = new Source.PatientGUIAdapter(patient);
}
catch (NullReferenceException)
{
}
catch (CouldNotOpenConnectionException)
{
System.Windows.MessageBox.Show("An problem occurred trying to connect to the OpenDental database.\nThe program will now exit.");
Environment.Exit(-1);
}
catch (Exception e)
{
System.Windows.MessageBox.Show(e.Message);
System.Windows.MessageBox.Show("An unknow error has occurred.\n" + e.Message);
System.Environment.Exit(-1);
}
}
@@ -211,7 +232,7 @@ namespace PWAPPv2
{
Source.DataObjects.Referral referral;
if (attachments.Count == 0)
if (fileHandler.Attachments.Count == 0)
{
referral = new Source.DataObjects.Referral(apiCreds, patient,
(Source.DataObjects.ReferralTypeBox)TypeBox,
@@ -234,16 +255,7 @@ namespace PWAPPv2
string referralString = referral.ToJsonString();
string result = pwapiConnection.SendReferral(referralString);
if (attachments.Count > 0)
{
foreach (Source.DataObjects.Attachment attachment in attachments)
{
attachment.Token = result;
string json = attachment.ToJsonString();
apiConnection.SendPostWithCredsInHeader("api/PWAttachment", json);
}
}
fileHandler.SendFilesAsAttachments(apiConnection, result);
System.Windows.MessageBox.Show("Referral added successfully!");
@@ -258,57 +270,60 @@ namespace PWAPPv2
//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 = "Attachment files (*.jpg,*.jpeg,*.pdf)|*.jpg;*.jpeg;*.pdf";
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
/*//System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
//openFileDialog.Multiselect = true;
//openFileDialog.Filter = "Attachment files (*.jpg,*.jpeg,*.pdf,*.png)|*.jpg;*.jpeg;*.pdf;*.png;";
//openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (string filename in openFileDialog.FileNames)
{
if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".jpeg")
{
try
{
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename)));
}
catch (NullReferenceException)
{
//if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
//{
// foreach (string filename in openFileDialog.FileNames)
// {
// //if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".jpeg")
// if(SupportedImageTypes.Contains(Path.GetExtension(filename)))
// {
// try
// {
// attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename)));
// }
// catch (NullReferenceException)
// {
attachments = new List<Source.DataObjects.Attachment>
{
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename))
};
}
}
if (Path.GetExtension(filename) == ".pdf")
{
try
{
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename)));
}
catch (NullReferenceException)
{
attachments = new List<Source.DataObjects.Attachment>()
{
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename))
};
}
}
}
// attachments = new List<Source.DataObjects.Attachment>
// {
// new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename))
// };
// }
// }
// if (Path.GetExtension(filename) == ".pdf")
// {
// try
// {
// attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename)));
// }
// catch (NullReferenceException)
// {
// attachments = new List<Source.DataObjects.Attachment>()
// {
// new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename))
// };
// }
// }
// }
}
//}*/
fileHandler.AddFile();
try
{
ImageList.Items.Clear();
foreach (var attachment in attachments)
foreach (var attachment in fileHandler.Attachments)
{
if (attachment.image == null)
if (attachment.pdf != null)
{
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg")));
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg"), attachment.pdf.path));
}
else
{
@@ -334,11 +349,11 @@ namespace PWAPPv2
{
ImageList.Items.Clear();
foreach (var attachment in attachments)
foreach (var attachment in fileHandler.Attachments)
{
if (attachment.image == null)
if (attachment.pdf != null)
{
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg")));
ImageList.Items.Add(CreateImageGridItem(new Source.DataObjects.PWImage("C:\\PWAPP\\App\\App\\pdf.jpg"), attachment.pdf.path));
}
else
{
@@ -374,6 +389,39 @@ namespace PWAPPv2
text.FontSize = 12;
Grid.SetColumn(addedImage, 0);
Grid.SetColumn(text, 1);
imageGrid.Children.Add(addedImage);
imageGrid.Children.Add(text);
return imageGrid;
}
public Grid CreateImageGridItem(Source.DataObjects.PWImage image, string path)
{
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 = path;
text.FontSize = 12;
Grid.SetColumn(addedImage, 0);
Grid.SetColumn(text, 1);