Images working
This commit is contained in:
parent
1b65e9bb83
commit
09d86b86c2
@ -94,9 +94,10 @@
|
|||||||
<ColumnDefinition Width="80*"/>
|
<ColumnDefinition Width="80*"/>
|
||||||
<ColumnDefinition Width="77*"/>
|
<ColumnDefinition Width="77*"/>
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<Button Content="Add Image" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Height="20"/>
|
<Button x:Name="AddImageButton" Content="Add Image" Grid.Column="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Height="20" Click="Button_Click_2"/>
|
||||||
<Button Content="Remove" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Height="20"/>
|
<Button Content="Remove" Grid.Column="1" Margin="0,0,5,1" HorizontalAlignment="Right" Width="75" Click="Button_Click_3"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
<ListBox x:Name="ImageList" HorizontalAlignment="Left" Height="234" Grid.Row="1" VerticalAlignment="Top" Width="447"/>
|
||||||
</Grid>
|
</Grid>
|
||||||
</GroupBox>
|
</GroupBox>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
@ -12,6 +12,8 @@ using System.Windows.Media;
|
|||||||
using System.Windows.Media.Imaging;
|
using System.Windows.Media.Imaging;
|
||||||
using System.Windows.Navigation;
|
using System.Windows.Navigation;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
using System.IO;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO:
|
* TODO:
|
||||||
@ -39,6 +41,8 @@ namespace PWAPPv2
|
|||||||
|
|
||||||
Source.Patient patient;
|
Source.Patient patient;
|
||||||
|
|
||||||
|
List<Source.DataObjects.PWImage> images;
|
||||||
|
|
||||||
public MainWindow()
|
public MainWindow()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@ -48,6 +52,8 @@ namespace PWAPPv2
|
|||||||
catch(Exception)
|
catch(Exception)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
images = new List<Source.DataObjects.PWImage>();
|
||||||
|
|
||||||
apiconfig.LoadConfig("./Config/Config.xml");
|
apiconfig.LoadConfig("./Config/Config.xml");
|
||||||
DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml");
|
DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml");
|
||||||
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig);
|
Source.Database.DatabaseConnection dbcon = new Source.Database.DatabaseConnection(DataConfig);
|
||||||
@ -130,23 +136,51 @@ namespace PWAPPv2
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Cancel button
|
||||||
private void Button_Click(object sender, RoutedEventArgs e)
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//OK Button
|
||||||
private void Button_Click_1(object sender, RoutedEventArgs e)
|
private void Button_Click_1(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
Source.DataObjects.Referral referral = new Source.DataObjects.Referral(apiCreds, patient,
|
Source.DataObjects.Referral referral;
|
||||||
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
if(images.Count == 0)
|
||||||
(Source.DataObjects.ReferToBox)ToBox,
|
{
|
||||||
(Source.DataObjects.ReferFromBox)FromBox,
|
referral = new Source.DataObjects.Referral(apiCreds, patient,
|
||||||
fieldRemakrs, contact);
|
(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
|
try
|
||||||
{
|
{
|
||||||
string referralString = referral.ToJsonString();
|
string referralString = referral.ToJsonString();
|
||||||
string result = apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString);
|
string result = apiConnection.SendPostRequestAsync("api/PWMakeReferral", referralString);
|
||||||
MessageBox.Show(result);
|
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);
|
||||||
|
}
|
||||||
|
MessageBox.Show("Referral added successfully!");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
MessageBox.Show(result);
|
||||||
|
}
|
||||||
this.Close();
|
this.Close();
|
||||||
}
|
}
|
||||||
catch(Source.DataObjects.Referral.InvalidReferalDataException)
|
catch(Source.DataObjects.Referral.InvalidReferalDataException)
|
||||||
@ -154,5 +188,97 @@ namespace PWAPPv2
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//AddImage Button
|
||||||
|
private void Button_Click_2(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
OpenFileDialog openFileDialog = new OpenFileDialog();
|
||||||
|
openFileDialog.Multiselect = true;
|
||||||
|
openFileDialog.Filter = "Image files (*.jpg,*.jpeg)|*.jpg;*.jpeg";
|
||||||
|
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
|
||||||
|
|
||||||
|
if(openFileDialog.ShowDialog() == true)
|
||||||
|
{
|
||||||
|
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 = HorizontalAlignment.Left;
|
||||||
|
imageGrid.VerticalAlignment = VerticalAlignment.Top;
|
||||||
|
imageGrid.ShowGridLines = true;
|
||||||
|
imageGrid.Background = new SolidColorBrush(Colors.LightSteelBlue);
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,14 +210,17 @@
|
|||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
</ApplicationDefinition>
|
</ApplicationDefinition>
|
||||||
|
<Compile Include="PwImage.cs" />
|
||||||
<Compile Include="Source\API\APIConfig.cs" />
|
<Compile Include="Source\API\APIConfig.cs" />
|
||||||
<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\Database\DatabaseConfig.cs" />
|
<Compile Include="Source\Database\DatabaseConfig.cs" />
|
||||||
<Compile Include="Source\Database\DatabaseConnection.cs" />
|
<Compile Include="Source\Database\DatabaseConnection.cs" />
|
||||||
<Compile Include="Source\DataObjects\APICredentials.cs" />
|
<Compile Include="Source\DataObjects\APICredentials.cs" />
|
||||||
|
<Compile Include="Source\DataObjects\Attachment.cs" />
|
||||||
<Compile Include="Source\DataObjects\ComboBoxData.cs" />
|
<Compile Include="Source\DataObjects\ComboBoxData.cs" />
|
||||||
<Compile Include="Source\DataObjects\Exceptions.cs" />
|
<Compile Include="Source\DataObjects\Exceptions.cs" />
|
||||||
|
<Compile Include="Source\DataObjects\PWImage.cs" />
|
||||||
<Compile Include="Source\DataObjects\NumValList.cs" />
|
<Compile Include="Source\DataObjects\NumValList.cs" />
|
||||||
<Compile Include="Source\DataObjects\NumValPair.cs" />
|
<Compile Include="Source\DataObjects\NumValPair.cs" />
|
||||||
<Compile Include="Source\DataObjects\ReferFromBox.cs" />
|
<Compile Include="Source\DataObjects\ReferFromBox.cs" />
|
||||||
|
6
PWAPPv2/PwImage.cs
Normal file
6
PWAPPv2/PwImage.cs
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
namespace PWAPPv2
|
||||||
|
{
|
||||||
|
internal class PwImage
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
40
PWAPPv2/Source/DataObjects/Attachment.cs
Normal file
40
PWAPPv2/Source/DataObjects/Attachment.cs
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PWAPPv2.Source.DataObjects
|
||||||
|
{
|
||||||
|
class Attachment
|
||||||
|
{
|
||||||
|
APICredentials Credentials;
|
||||||
|
PWImage image;
|
||||||
|
|
||||||
|
string Token;
|
||||||
|
|
||||||
|
|
||||||
|
public Attachment(APICredentials credentials, PWImage pwImage, string token)
|
||||||
|
{
|
||||||
|
Credentials = credentials;
|
||||||
|
image = pwImage;
|
||||||
|
Token = token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ToJsonString()
|
||||||
|
{
|
||||||
|
return "\"{" + Credentials.BuildJsonBodyContents() +
|
||||||
|
",'UserNum':'API'," +
|
||||||
|
"'AttToken':'" + Token.Replace("\"", "") + "'," +
|
||||||
|
"'FileName':'" + image.ShortFileName() + "'," +
|
||||||
|
"'ContentType':'_1'," +
|
||||||
|
"'ThumbExists':'1'," +
|
||||||
|
"'ZoomExists':'1'," +
|
||||||
|
"'FileDate':''," +
|
||||||
|
"'Base64FileContents':'" + image.GetBase64String() + "',\n" +
|
||||||
|
"'Base64ThumbContents':'" + image.GetBase64ThumbString() + "',\n" +
|
||||||
|
"'Base64ZoomContents':'" + image.GetBase64ZoomString() + "'}\"";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
105
PWAPPv2/Source/DataObjects/PWImage.cs
Normal file
105
PWAPPv2/Source/DataObjects/PWImage.cs
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Media.Imaging;
|
||||||
|
using System.Windows.Media;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
|
namespace PWAPPv2.Source.DataObjects
|
||||||
|
{
|
||||||
|
public class PWImage
|
||||||
|
{
|
||||||
|
|
||||||
|
private string ImagePath;
|
||||||
|
|
||||||
|
private BitmapImage bitmap;
|
||||||
|
|
||||||
|
|
||||||
|
//private Bitmap bmp;
|
||||||
|
//private Bitmap thumb;
|
||||||
|
//private Bitmap zoom;
|
||||||
|
public PWImage(string path)
|
||||||
|
{
|
||||||
|
ImagePath = path;
|
||||||
|
bitmap = new BitmapImage();
|
||||||
|
|
||||||
|
bitmap.BeginInit();
|
||||||
|
bitmap.UriSource = new Uri(@ImagePath);
|
||||||
|
bitmap.DecodePixelWidth = 100;
|
||||||
|
bitmap.EndInit();
|
||||||
|
|
||||||
|
//bmp = (Bitmap)System.Drawing.Image.FromFile(ImagePath);
|
||||||
|
//thumb = resize(bmp, 50, 50);
|
||||||
|
//zoom = resize(bmp, bmp.Width, bmp.Height);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetPath()
|
||||||
|
{
|
||||||
|
return ImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BitmapImage GetBitmapImage()
|
||||||
|
{
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetBase64String()
|
||||||
|
{
|
||||||
|
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
|
||||||
|
{
|
||||||
|
using (MemoryStream m = new MemoryStream())
|
||||||
|
{
|
||||||
|
image.Save(m, image.RawFormat);
|
||||||
|
byte[] imageBytes = m.ToArray();
|
||||||
|
|
||||||
|
return Convert.ToBase64String(imageBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetBase64ThumbString()
|
||||||
|
{
|
||||||
|
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
|
||||||
|
{
|
||||||
|
Image thumb = resize(image, new Size(50, 50));
|
||||||
|
using (MemoryStream m = new MemoryStream())
|
||||||
|
{
|
||||||
|
thumb.Save(m, image.RawFormat);
|
||||||
|
byte[] imageBytes = m.ToArray();
|
||||||
|
|
||||||
|
return Convert.ToBase64String(imageBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetBase64ZoomString()
|
||||||
|
{
|
||||||
|
using (System.Drawing.Image image = System.Drawing.Image.FromFile(ImagePath))
|
||||||
|
{
|
||||||
|
Image zoom = resize(image, new Size(image.Width + 800, image.Height + 800));
|
||||||
|
using (MemoryStream m = new MemoryStream())
|
||||||
|
{
|
||||||
|
zoom.Save(m, image.RawFormat);
|
||||||
|
byte[] imageBytes = m.ToArray();
|
||||||
|
|
||||||
|
return Convert.ToBase64String(imageBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Image resize(Image toResize, Size size)
|
||||||
|
{
|
||||||
|
return new Bitmap(toResize, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
public string ShortFileName()
|
||||||
|
{
|
||||||
|
return ImagePath.Substring(ImagePath.LastIndexOf("\\") + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,9 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
RichTextBox RemarksBox;
|
RichTextBox RemarksBox;
|
||||||
CheckBox ContactBox;
|
CheckBox ContactBox;
|
||||||
|
|
||||||
public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox)
|
bool Attachments;
|
||||||
|
|
||||||
|
public Referral(APICredentials apiCredentials, Patient patient, ReferralTypeBox referralType, ReferToBox referTo, ReferFromBox referFrom, RichTextBox remarksBox, CheckBox contactBox, bool attachments)
|
||||||
{
|
{
|
||||||
ApiCredentials = apiCredentials;
|
ApiCredentials = apiCredentials;
|
||||||
PatientData = patient;
|
PatientData = patient;
|
||||||
@ -29,6 +31,7 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
ReferFrom = referFrom;
|
ReferFrom = referFrom;
|
||||||
RemarksBox = remarksBox;
|
RemarksBox = remarksBox;
|
||||||
ContactBox = contactBox;
|
ContactBox = contactBox;
|
||||||
|
Attachments = attachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToJsonString()
|
public string ToJsonString()
|
||||||
@ -41,7 +44,11 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
{
|
{
|
||||||
contact = 1;
|
contact = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string attachmentsText = "False";
|
||||||
|
if (Attachments)
|
||||||
|
attachmentsText = "True";
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return "\"{" + ApiCredentials.BuildJsonBodyContents() + "," +
|
return "\"{" + ApiCredentials.BuildJsonBodyContents() + "," +
|
||||||
@ -61,7 +68,7 @@ namespace PWAPPv2.Source.DataObjects
|
|||||||
"'SubmittedBy':'" + ReferFrom.GetSelectedID() + "'," +
|
"'SubmittedBy':'" + ReferFrom.GetSelectedID() + "'," +
|
||||||
"'ToPracticeId':'" + ReferTo.GetSelectedPracticeID() + "'," +
|
"'ToPracticeId':'" + ReferTo.GetSelectedPracticeID() + "'," +
|
||||||
"'ToDoctorID':'" + ReferTo.GetSelectedDoctorID() + "'," +
|
"'ToDoctorID':'" + ReferTo.GetSelectedDoctorID() + "'," +
|
||||||
"'Attachments':'False'," +
|
"'Attachments':'" + attachmentsText + "'," +
|
||||||
"'Remarks':'" + RemarksText + "'," +
|
"'Remarks':'" + RemarksText + "'," +
|
||||||
"'Contact':'" + contact + "'}\"";
|
"'Contact':'" + contact + "'}\"";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user