Images working
This commit is contained in:
+133
-7
@@ -12,6 +12,8 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.Windows.Navigation;
|
||||
using System.Windows.Shapes;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
|
||||
/**
|
||||
* TODO:
|
||||
@@ -39,6 +41,8 @@ namespace PWAPPv2
|
||||
|
||||
Source.Patient patient;
|
||||
|
||||
List<Source.DataObjects.PWImage> images;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
try
|
||||
@@ -48,6 +52,8 @@ namespace PWAPPv2
|
||||
catch(Exception)
|
||||
{ }
|
||||
|
||||
images = new List<Source.DataObjects.PWImage>();
|
||||
|
||||
apiconfig.LoadConfig("./Config/Config.xml");
|
||||
DataConfig = new Source.Database.DatabaseConfig("./Config/Config.xml");
|
||||
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)
|
||||
{
|
||||
this.Close();
|
||||
}
|
||||
|
||||
|
||||
//OK Button
|
||||
private void Button_Click_1(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Source.DataObjects.Referral referral = new Source.DataObjects.Referral(apiCreds, patient,
|
||||
(Source.DataObjects.ReferralTypeBox)TypeBox,
|
||||
(Source.DataObjects.ReferToBox)ToBox,
|
||||
(Source.DataObjects.ReferFromBox)FromBox,
|
||||
fieldRemakrs, contact);
|
||||
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 = 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();
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user