Fixed issue with attachment tokens. Changed how attachments are handled to be more modular. Added support for PNG files.
This commit is contained in:
parent
40f9db3ea4
commit
f31302438d
@ -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.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@ -40,13 +44,23 @@ namespace PWAPPv2
|
|||||||
|
|
||||||
List<Source.DataObjects.Attachment> attachments;
|
List<Source.DataObjects.Attachment> attachments;
|
||||||
|
|
||||||
|
List<string> SupportedImageTypes = new List<string>();
|
||||||
|
|
||||||
|
|
||||||
//string ConfigPath = "C:\\PWAPP\\Config\\Config.xml";
|
//string ConfigPath = "C:\\PWAPP\\Config\\Config.xml";
|
||||||
|
|
||||||
string ConfigPath;
|
string ConfigPath;
|
||||||
|
|
||||||
|
FileHandler fileHandler;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
|
SupportedImageTypes.Clear();
|
||||||
|
SupportedImageTypes.Add(".jpeg");
|
||||||
|
SupportedImageTypes.Add(".jpg");
|
||||||
|
SupportedImageTypes.Add(".png");
|
||||||
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
args = App.Args;
|
args = App.Args;
|
||||||
@ -56,11 +70,6 @@ namespace PWAPPv2
|
|||||||
ConfigPath = "C:\\PWAPP\\Config\\";
|
ConfigPath = "C:\\PWAPP\\Config\\";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//ConfigPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
|
|
||||||
//ConfigPath = Path.Combine(ConfigPath, "PWAPP\\Config\\");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
practiceConfig = new Source.Config.Configuration("C:\\PWAPP\\Config\\PracticeConfig.xml");
|
practiceConfig = new Source.Config.Configuration("C:\\PWAPP\\Config\\PracticeConfig.xml");
|
||||||
universalConfig = new Source.Config.Configuration("C:\\PWAPP\\App\\Config\\UniversalConfig.xml");
|
universalConfig = new Source.Config.Configuration("C:\\PWAPP\\App\\Config\\UniversalConfig.xml");
|
||||||
}
|
}
|
||||||
@ -74,7 +83,7 @@ namespace PWAPPv2
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (pwapiConnection.CheckForUpdate() == true)
|
/*if (pwapiConnection.CheckForUpdate() == true)
|
||||||
{
|
{
|
||||||
string message = "An update is available! Would you like to install it?";
|
string message = "An update is available! Would you like to install it?";
|
||||||
string title = "Update available!";
|
string title = "Update available!";
|
||||||
@ -101,7 +110,9 @@ namespace PWAPPv2
|
|||||||
p.Start();
|
p.Start();
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
pwapiConnection.Update(args);
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception)
|
||||||
{
|
{
|
||||||
@ -118,23 +129,33 @@ namespace PWAPPv2
|
|||||||
apiCreds = new Source.DataObjects.APICredentials(apiconfig);
|
apiCreds = new Source.DataObjects.APICredentials(apiconfig);
|
||||||
apiConnection = new Source.API.APIConnection(universalConfig.Get("PWBaseURI"), apiCreds);
|
apiConnection = new Source.API.APIConnection(universalConfig.Get("PWBaseURI"), apiCreds);
|
||||||
|
|
||||||
|
fileHandler = new FileHandler(apiCreds);
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
PopulateComboBoxes();
|
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);
|
this.DataContext = new Source.PatientGUIAdapter(patient);
|
||||||
}
|
}
|
||||||
catch (NullReferenceException)
|
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)
|
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;
|
Source.DataObjects.Referral referral;
|
||||||
|
|
||||||
if (attachments.Count == 0)
|
if (fileHandler.Attachments.Count == 0)
|
||||||
{
|
{
|
||||||
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
||||||
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
||||||
@ -234,16 +255,7 @@ namespace PWAPPv2
|
|||||||
string referralString = referral.ToJsonString();
|
string referralString = referral.ToJsonString();
|
||||||
string result = pwapiConnection.SendReferral(referralString);
|
string result = pwapiConnection.SendReferral(referralString);
|
||||||
|
|
||||||
|
fileHandler.SendFilesAsAttachments(apiConnection, result);
|
||||||
if (attachments.Count > 0)
|
|
||||||
{
|
|
||||||
foreach (Source.DataObjects.Attachment attachment in attachments)
|
|
||||||
{
|
|
||||||
attachment.Token = result;
|
|
||||||
string json = attachment.ToJsonString();
|
|
||||||
apiConnection.SendPostWithCredsInHeader("api/PWAttachment", json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
System.Windows.MessageBox.Show("Referral added successfully!");
|
System.Windows.MessageBox.Show("Referral added successfully!");
|
||||||
|
|
||||||
@ -258,57 +270,60 @@ namespace PWAPPv2
|
|||||||
//AddImage Button
|
//AddImage Button
|
||||||
private void Button_Click_2(object sender, RoutedEventArgs e)
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
/*//System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
|
||||||
openFileDialog.Multiselect = true;
|
//openFileDialog.Multiselect = true;
|
||||||
openFileDialog.Filter = "Attachment files (*.jpg,*.jpeg,*.pdf)|*.jpg;*.jpeg;*.pdf";
|
//openFileDialog.Filter = "Attachment files (*.jpg,*.jpeg,*.pdf,*.png)|*.jpg;*.jpeg;*.pdf;*.png;";
|
||||||
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
//openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
||||||
|
|
||||||
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
//if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
|
||||||
{
|
//{
|
||||||
foreach (string filename in openFileDialog.FileNames)
|
// foreach (string filename in openFileDialog.FileNames)
|
||||||
{
|
// {
|
||||||
if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".jpeg")
|
// //if (Path.GetExtension(filename) == ".jpg" || Path.GetExtension(filename) == ".jpeg")
|
||||||
{
|
// if(SupportedImageTypes.Contains(Path.GetExtension(filename)))
|
||||||
try
|
// {
|
||||||
{
|
// try
|
||||||
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename)));
|
// {
|
||||||
}
|
// attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename)));
|
||||||
catch (NullReferenceException)
|
// }
|
||||||
{
|
// catch (NullReferenceException)
|
||||||
|
// {
|
||||||
|
|
||||||
attachments = new List<Source.DataObjects.Attachment>
|
// attachments = new List<Source.DataObjects.Attachment>
|
||||||
{
|
// {
|
||||||
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename))
|
// new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWImage(filename))
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (Path.GetExtension(filename) == ".pdf")
|
// if (Path.GetExtension(filename) == ".pdf")
|
||||||
{
|
// {
|
||||||
try
|
// try
|
||||||
{
|
// {
|
||||||
attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename)));
|
// attachments.Add(new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename)));
|
||||||
}
|
// }
|
||||||
catch (NullReferenceException)
|
// catch (NullReferenceException)
|
||||||
{
|
// {
|
||||||
attachments = new List<Source.DataObjects.Attachment>()
|
// attachments = new List<Source.DataObjects.Attachment>()
|
||||||
{
|
// {
|
||||||
new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename))
|
// new Source.DataObjects.Attachment(apiCreds, new Source.DataObjects.PWPdf(filename))
|
||||||
};
|
// };
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
//}*/
|
||||||
|
|
||||||
|
fileHandler.AddFile();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
ImageList.Items.Clear();
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -334,11 +349,11 @@ namespace PWAPPv2
|
|||||||
{
|
{
|
||||||
ImageList.Items.Clear();
|
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
|
else
|
||||||
{
|
{
|
||||||
@ -374,6 +389,39 @@ namespace PWAPPv2
|
|||||||
text.FontSize = 12;
|
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(addedImage, 0);
|
||||||
Grid.SetColumn(text, 1);
|
Grid.SetColumn(text, 1);
|
||||||
|
|
||||||
|
@ -227,6 +227,9 @@
|
|||||||
<Compile Include="Source\API\APIConnection.cs" />
|
<Compile Include="Source\API\APIConnection.cs" />
|
||||||
<Compile Include="Source\API\APIRequestBuilder.cs" />
|
<Compile Include="Source\API\APIRequestBuilder.cs" />
|
||||||
<Compile Include="Source\API\PWApiConnection.cs" />
|
<Compile Include="Source\API\PWApiConnection.cs" />
|
||||||
|
<Compile Include="Source\Attachments\AttachmentFactory.cs" />
|
||||||
|
<Compile Include="Source\Attachments\FileHandler.cs" />
|
||||||
|
<Compile Include="Source\Attachments\PWAttachment.cs" />
|
||||||
<Compile Include="Source\Config\Configuration.cs" />
|
<Compile Include="Source\Config\Configuration.cs" />
|
||||||
<Compile Include="Source\Database\DatabaseConfig.cs" />
|
<Compile Include="Source\Database\DatabaseConfig.cs" />
|
||||||
<Compile Include="Source\Database\DatabaseConnection.cs" />
|
<Compile Include="Source\Database\DatabaseConnection.cs" />
|
||||||
@ -242,8 +245,8 @@
|
|||||||
<Compile Include="Source\DataObjects\Referral.cs" />
|
<Compile Include="Source\DataObjects\Referral.cs" />
|
||||||
<Compile Include="Source\DataObjects\ReferralTypeBox.cs" />
|
<Compile Include="Source\DataObjects\ReferralTypeBox.cs" />
|
||||||
<Compile Include="Source\DataObjects\ReferToBox.cs" />
|
<Compile Include="Source\DataObjects\ReferToBox.cs" />
|
||||||
<Compile Include="Source\Patient.cs" />
|
<Compile Include="Source\DataObjects\Patient.cs" />
|
||||||
<Compile Include="Source\PatientGUIAdapter.cs" />
|
<Compile Include="Source\DataObjects\PatientGUIAdapter.cs" />
|
||||||
<Page Include="MainWindow.xaml">
|
<Page Include="MainWindow.xaml">
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
using PWAPPv2.Source.DataObjects;
|
using PWAPPv2.Source.DataObjects;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
namespace PWAPPv2.Source.API
|
namespace PWAPPv2.Source.API
|
||||||
{
|
{
|
||||||
@ -57,6 +59,45 @@ namespace PWAPPv2.Source.API
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Update(string[] args)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (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;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
p.StartInfo.Arguments = args[0];
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
if (System.Environment.OSVersion.Version.Major >= 6)
|
||||||
|
{
|
||||||
|
p.StartInfo.Verb = "runas";
|
||||||
|
}
|
||||||
|
p.Start();
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw new UpdateException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public string GetReferalTypes()
|
public string GetReferalTypes()
|
||||||
{
|
{
|
||||||
return ReferTypesConnection.SendPostWithCredsInHeader("", "");
|
return ReferTypesConnection.SendPostWithCredsInHeader("", "");
|
||||||
@ -78,4 +119,6 @@ namespace PWAPPv2.Source.API
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class UpdateException : Exception { }
|
||||||
}
|
}
|
||||||
|
53
PWAPPv2/Source/Attachments/AttachmentFactory.cs
Normal file
53
PWAPPv2/Source/Attachments/AttachmentFactory.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
using PWAPPv2.Source.DataObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PWAPPv2.Source.Attachments
|
||||||
|
{
|
||||||
|
public class AttachmentFactory
|
||||||
|
{
|
||||||
|
public static PWAttachment BuildAttachment(APICredentials credentials, string token, PWImage image)
|
||||||
|
{
|
||||||
|
PWAttachment attachment = new PWAttachment();
|
||||||
|
attachment.UserID = credentials.UserID;
|
||||||
|
attachment.Password = credentials.Password;
|
||||||
|
attachment.PracticeId = credentials.PracticeId;
|
||||||
|
attachment.APIid = credentials.APIid;
|
||||||
|
attachment.UserNum = "API";
|
||||||
|
attachment.AttToken = token.Replace("\"", "");
|
||||||
|
attachment.ThumbExists = "1";
|
||||||
|
attachment.ZoomExists = "1";
|
||||||
|
attachment.FileDate = "";
|
||||||
|
attachment.FileName = image.ShortFileName();
|
||||||
|
attachment.FileType = image.FileType;
|
||||||
|
attachment.Base64FileContents = image.GetBase64String();
|
||||||
|
attachment.Base64ThumbContents = image.GetBase64ThumbString();
|
||||||
|
attachment.Base64ZoomContents = image.GetBase64ZoomString();
|
||||||
|
return attachment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static PWAttachment BuildAttachment(APICredentials credentials, string token, PWPdf pdf)
|
||||||
|
{
|
||||||
|
PWAttachment attachment = new PWAttachment();
|
||||||
|
attachment.UserID = credentials.UserID;
|
||||||
|
attachment.Password = credentials.Password;
|
||||||
|
attachment.PracticeId = credentials.PracticeId;
|
||||||
|
attachment.APIid = credentials.APIid;
|
||||||
|
attachment.UserNum = "API";
|
||||||
|
attachment.AttToken = token.Replace("\"", "");
|
||||||
|
attachment.ThumbExists = "0";
|
||||||
|
attachment.ZoomExists = "0";
|
||||||
|
attachment.FileDate = "";
|
||||||
|
attachment.FileName = pdf.ShortFileName();
|
||||||
|
attachment.FileType = "application/pdf";
|
||||||
|
attachment.Base64FileContents = pdf.GetBase64String();
|
||||||
|
attachment.Base64ThumbContents = "";
|
||||||
|
attachment.Base64ZoomContents = "";
|
||||||
|
return attachment;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
134
PWAPPv2/Source/Attachments/FileHandler.cs
Normal file
134
PWAPPv2/Source/Attachments/FileHandler.cs
Normal file
@ -0,0 +1,134 @@
|
|||||||
|
using PWAPPv2.Source.API;
|
||||||
|
using PWAPPv2.Source.DataObjects;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace PWAPPv2.Source.Attachments
|
||||||
|
{
|
||||||
|
public class FileHandler
|
||||||
|
{
|
||||||
|
|
||||||
|
public List<string> SupportedImageTypes;
|
||||||
|
public List<string> SupportedVideoTypes;
|
||||||
|
public List<string> SupportedDocumentTypes;
|
||||||
|
|
||||||
|
public List<Source.DataObjects.Attachment> Attachments;
|
||||||
|
|
||||||
|
private APICredentials credentials;
|
||||||
|
|
||||||
|
private string filterString;
|
||||||
|
|
||||||
|
public FileHandler(APICredentials apiCredentials)
|
||||||
|
{
|
||||||
|
credentials = apiCredentials;
|
||||||
|
SupportedImageTypes = new List<string>();
|
||||||
|
SupportedVideoTypes = new List<string>();
|
||||||
|
SupportedDocumentTypes = new List<string>();
|
||||||
|
|
||||||
|
SupportedImageTypes.Clear();
|
||||||
|
SupportedImageTypes.Add(".jpeg");
|
||||||
|
SupportedImageTypes.Add(".jpg");
|
||||||
|
SupportedImageTypes.Add(".png");
|
||||||
|
//SupportedImageTypes.Add(".tiff");
|
||||||
|
|
||||||
|
SupportedDocumentTypes.Clear();
|
||||||
|
SupportedDocumentTypes.Add(".pdf");
|
||||||
|
|
||||||
|
Attachments = new List<Source.DataObjects.Attachment>();
|
||||||
|
|
||||||
|
filterString = "Attachment files (";
|
||||||
|
string filter = "|";
|
||||||
|
foreach (string imageType in SupportedImageTypes)
|
||||||
|
{
|
||||||
|
filterString += "*" + imageType + ",";
|
||||||
|
filter += "*" + imageType + ";";
|
||||||
|
}
|
||||||
|
foreach (string videoType in SupportedVideoTypes)
|
||||||
|
{
|
||||||
|
filterString += "*" + videoType + ",";
|
||||||
|
filter += "*" + videoType + ";";
|
||||||
|
}
|
||||||
|
foreach (string documentType in SupportedDocumentTypes)
|
||||||
|
{
|
||||||
|
filterString += "*" + documentType + ",";
|
||||||
|
filter += "*" + documentType + ";";
|
||||||
|
}
|
||||||
|
filterString = filterString.Remove(filterString.Length - 1, 1);
|
||||||
|
filterString += ")" + filter;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddFile()
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.Multiselect = true;
|
||||||
|
|
||||||
|
|
||||||
|
openFileDialog.Filter = filterString;
|
||||||
|
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
||||||
|
|
||||||
|
if (openFileDialog.ShowDialog() == DialogResult.OK)
|
||||||
|
{
|
||||||
|
foreach (string filename in openFileDialog.FileNames)
|
||||||
|
{
|
||||||
|
if(SupportedImageTypes.Contains(Path.GetExtension(filename)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Attachments.Add(new DataObjects.Attachment(credentials, new DataObjects.PWImage(filename)));
|
||||||
|
}
|
||||||
|
catch (NullReferenceException)
|
||||||
|
{ }
|
||||||
|
}
|
||||||
|
if(SupportedDocumentTypes.Contains(Path.GetExtension(filename)))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Attachments.Add(new Source.DataObjects.Attachment(credentials, new Source.DataObjects.PWPdf(filename)));
|
||||||
|
}
|
||||||
|
catch(NullReferenceException) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SendFilesAsAttachments(APIConnection connection, string token)
|
||||||
|
{
|
||||||
|
if(Attachments.Count <= 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
foreach(DataObjects.Attachment attachment in Attachments)
|
||||||
|
{
|
||||||
|
PWAttachment att = null;
|
||||||
|
if (attachment.image != null)
|
||||||
|
{
|
||||||
|
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.image);
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (attachment.pdf != null)
|
||||||
|
{
|
||||||
|
att = AttachmentFactory.BuildAttachment(credentials, token, attachment.pdf);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (att == null)
|
||||||
|
{
|
||||||
|
throw new AttachmentTypeNotYetSupportedException();
|
||||||
|
}
|
||||||
|
string json = JsonSerializer.Serialize(att);
|
||||||
|
connection.SendPostWithCredsInHeader("api/PWAttachment", json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AttachmentTypeNotYetSupportedException : Exception { }
|
||||||
|
}
|
28
PWAPPv2/Source/Attachments/PWAttachment.cs
Normal file
28
PWAPPv2/Source/Attachments/PWAttachment.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PWAPPv2.Source.Attachments
|
||||||
|
{
|
||||||
|
public class PWAttachment
|
||||||
|
{
|
||||||
|
public string UserID { get; set; }
|
||||||
|
public string Password { get; set; }
|
||||||
|
public string PracticeId { get; set; }
|
||||||
|
public string APIid { get; set; }
|
||||||
|
public string UserNum { get; set; }
|
||||||
|
public string AttToken { get; set; }
|
||||||
|
public string FileName { get; set; }
|
||||||
|
public string ThumbExists { get; set; }
|
||||||
|
public string ZoomExists { get; set; }
|
||||||
|
public string FileDate { get; set; }
|
||||||
|
public string FileType { get; set; }
|
||||||
|
public string Base64FileContents { get; set; }
|
||||||
|
public string Base64ThumbContents { get; set; }
|
||||||
|
public string Base64ZoomContents { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
namespace PWAPPv2.Source.DataObjects
|
namespace PWAPPv2.Source.DataObjects
|
||||||
{
|
{
|
||||||
class Attachment
|
public class Attachment
|
||||||
{
|
{
|
||||||
APICredentials Credentials;
|
APICredentials Credentials;
|
||||||
public PWImage image { get; set; }
|
public PWImage image { get; set; }
|
||||||
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
public string ToJsonString()
|
public string ToJsonString()
|
||||||
{
|
{
|
||||||
if (fileType == "image/jpeg")
|
if (image != null)
|
||||||
{
|
{
|
||||||
return "\"{" + Credentials.BuildJsonBodyContents() +
|
return "\"{" + Credentials.BuildJsonBodyContents() +
|
||||||
",'UserNum':'API'," +
|
",'UserNum':'API'," +
|
||||||
@ -37,10 +37,8 @@
|
|||||||
"'ThumbExists':'1'," +
|
"'ThumbExists':'1'," +
|
||||||
"'ZoomExists':'1'," +
|
"'ZoomExists':'1'," +
|
||||||
"'FileDate':''," +
|
"'FileDate':''," +
|
||||||
"'FileType':'" + fileType + "'," +
|
"'FileType':'" + image.FileType + "'," +
|
||||||
"'Base64FileContents':'" + image.GetBase64String() + "',\n" +
|
image.GetJsonContents() + "}\"";
|
||||||
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
|
|
||||||
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,8 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
|
|
||||||
private BitmapImage bitmap;
|
private BitmapImage bitmap;
|
||||||
|
|
||||||
|
public string FileType { get; }
|
||||||
|
|
||||||
|
|
||||||
//private Bitmap bmp;
|
//private Bitmap bmp;
|
||||||
//private Bitmap thumb;
|
//private Bitmap thumb;
|
||||||
@ -26,6 +28,17 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
bitmap.DecodePixelWidth = 100;
|
bitmap.DecodePixelWidth = 100;
|
||||||
bitmap.EndInit();
|
bitmap.EndInit();
|
||||||
|
|
||||||
|
string extension = Path.GetExtension(path).ToLower();
|
||||||
|
|
||||||
|
if(extension == ".jpeg" || extension == ".jpg")
|
||||||
|
{
|
||||||
|
FileType = "image/jpeg";
|
||||||
|
}
|
||||||
|
else if(extension == ".png")
|
||||||
|
{
|
||||||
|
FileType = "image/png";
|
||||||
|
}
|
||||||
|
|
||||||
//bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
|
//bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
|
||||||
//thumb = resize(bmp, 50, 50);
|
//thumb = resize(bmp, 50, 50);
|
||||||
//zoom = resize(bmp, bmp.Width, bmp.Height);
|
//zoom = resize(bmp, bmp.Width, bmp.Height);
|
||||||
@ -96,5 +109,14 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
return ImagePath.Substring(ImagePath.LastIndexOf("\\") + 1);
|
return ImagePath.Substring(ImagePath.LastIndexOf("\\") + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string GetJsonContents()
|
||||||
|
{
|
||||||
|
string str = "'Base64FileContents':'" + GetBase64String() + "',\n" +
|
||||||
|
"'Base64ThumbContents':'" + GetBase64ThumbString() + "',\n" +
|
||||||
|
"'Base64ZoomContents':'" + GetBase64ZoomString() + "'\n";
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,13 @@ namespace PWAPPv2.Source
|
|||||||
public string Email;
|
public string Email;
|
||||||
|
|
||||||
|
|
||||||
|
public static Patient GetPatient(Database.DatabaseConnection connection, string patNum)
|
||||||
|
{
|
||||||
|
Patient patient = new Patient();
|
||||||
|
patient.BuildFromDatabase(connection, patNum);
|
||||||
|
return patient;
|
||||||
|
}
|
||||||
|
|
||||||
public void BuildFromDatabase(Database.DatabaseConnection databaseConnection, string patNum)
|
public void BuildFromDatabase(Database.DatabaseConnection databaseConnection, string patNum)
|
||||||
{
|
{
|
||||||
List<string> result = databaseConnection.QueryDatabase("SELECT PatNum, LName, FName, MiddleI, Gender, Birthdate," +
|
List<string> result = databaseConnection.QueryDatabase("SELECT PatNum, LName, FName, MiddleI, Gender, Birthdate," +
|
Loading…
x
Reference in New Issue
Block a user