Merge branch 'master' of s442333/DINO_SCRUM into master

This commit is contained in:
s1202077 2019-01-24 00:36:10 +00:00 committed by Gogs
commit 9240057242
14 changed files with 395 additions and 256 deletions

View File

@ -11,10 +11,10 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Debug|Any CPU.Build.0 = Release|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Release|Any CPU.Build.0 = Release|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Release|Any CPU.ActiveCfg = Debug|Any CPU
{C50EC6F3-86E6-405C-991F-1B4157C04B34}.Release|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -6,11 +6,11 @@
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Cyan.xaml" />
</ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml" />
<ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Cyan.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>

View File

@ -5,6 +5,7 @@ using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
namespace Magazyn
{
@ -13,39 +14,7 @@ namespace Magazyn
/// </summary>
public partial class App : Application
{
public void ChangeTheme(int index)
{
Resources.MergedDictionaries.Clear();
Uri[] uris = new Uri[4];
uris[1] = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml");
switch (index % 3) {
case 0:
uris[0] = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml");
uris[2] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Blue.xaml");
uris[3] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Cyan.xaml");
break;
case 1:
uris[0] = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Light.xaml");
uris[2] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.Lime.xaml");
uris[3] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Green.xaml");
break;
case 2:
uris[0] = new Uri("pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Dark.xaml");
uris[2] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/MaterialDesignColor.DeepOrange.xaml");
uris[3] = new Uri("pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/MaterialDesignColor.Orange.xaml");
break;
}
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = uris[0] });
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = uris[1] });
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = uris[2] });
Resources.MergedDictionaries.Add(new ResourceDictionary() { Source = uris[3] });
}
}
}

View File

@ -1,8 +1,11 @@
using System;
using Magazyn.Tools;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Media.Imaging;
namespace Magazyn.DataModels
{
@ -11,10 +14,14 @@ namespace Magazyn.DataModels
int id;
string name;
int quantity;
float price;
int quantityMax;
float price;
string imageLink;
public int Id
BitmapImage imageSource;
public int Id
{
get
{
@ -38,7 +45,16 @@ namespace Magazyn.DataModels
}
}
public float Price
public int QuantityMax
{
get
{
return quantityMax;
}
}
public float Price
{
get
{
@ -54,13 +70,26 @@ namespace Magazyn.DataModels
}
}
public Fruit(int id, string name, int quantity, float price, string imageLink)
public BitmapImage ImageSource
{
get
{
return imageSource;
}
}
public Fruit(int id, string name, int quantity, int quantityMax, float price, string imageLink)
{
this.id = id;
this.name = name;
this.quantity = quantity;
this.price = price;
this.quantityMax = quantityMax;
this.price = price;
this.imageLink = imageLink;
}
}
imageSource = CacheImage.GetImageSource(new Uri(imageLink));
}
}
}

View File

@ -67,6 +67,7 @@
</ApplicationDefinition>
<Compile Include="DataModels\Fruit.cs" />
<Compile Include="DataModels\WarehousePrice.cs" />
<Compile Include="Tools\CacheImage.cs" />
<Compile Include="Views\FruitView.xaml.cs">
<DependentUpon>FruitView.xaml</DependentUpon>
</Compile>
@ -76,6 +77,9 @@
<Compile Include="Windows\ErrorWindow.xaml.cs">
<DependentUpon>ErrorWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\InfoWindow.xaml.cs">
<DependentUpon>InfoWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ValueWindow.xaml.cs">
<DependentUpon>ValueWindow.xaml</DependentUpon>
</Compile>
@ -103,6 +107,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\InfoWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\ValueWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>

View File

@ -15,24 +15,23 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn"
mc:Ignorable="d"
Title="Magazyn Owoców" Height="500" MaxWidth="590" MinWidth="590" Width="590" SizeChanged="Window_SizeChanged">
<Grid>
<ListBox x:Name="fruitList" Margin="10,51,10,89"/>
Title="Magazyn Owoców" MinHeight="259" Height="500" MaxWidth="590" MinWidth="590" Width="590" >
<Grid>
<ListBox MouseDoubleClick="fruitListMouseDoubleClick" x:Name="fruitList" Margin="10,51,10,89"/>
<Button Name="sum" Content="Wartość magazynu" Margin="0,0,10,10" VerticalAlignment="Bottom" Height="35" Click="Value_Click" HorizontalAlignment="Right" Width="163"/>
<Label Content="Lista owoców:" FontWeight="Bold" HorizontalAlignment="Left" Margin="10,4,0,0" VerticalAlignment="Top" Width="100"/>
<Label Content="Nazwa owocu:" FontWeight="Bold" HorizontalAlignment="Left" Margin="91,25,0,0" VerticalAlignment="Top" Width="100"/>
<Button Name="sum" Content="Wartość magazynu" Margin="0,0,10,10" VerticalAlignment="Bottom" Height="35" Click="Value_Click" HorizontalAlignment="Right" Width="163"/>
<Label Content="Lista owoców:" FontWeight="Bold" HorizontalAlignment="Left" Margin="10,4,0,0" VerticalAlignment="Top" Width="100"/>
<Label Content="Nazwa owocu:" FontWeight="Bold" HorizontalAlignment="Left" Margin="91,25,0,0" VerticalAlignment="Top" Width="100"/>
<Label Content="Ilość:" FontWeight="Bold" HorizontalAlignment="Left" Margin="283,25,0,0" VerticalAlignment="Top" Width="46"/>
<Label Content="Ilość:" FontWeight="Bold" HorizontalAlignment="Left" Margin="283,25,0,0" VerticalAlignment="Top" Width="46"/>
<Label Content="Cena 1szt:" FontWeight="Bold" HorizontalAlignment="Left" Margin="360,25,0,0" VerticalAlignment="Top" Width="73"/>
<Label Content="Wartość:" FontWeight="Bold" HorizontalAlignment="Left" Margin="438,25,0,0" VerticalAlignment="Top" Width="65"/>
<Label Content="Cena 1szt:" FontWeight="Bold" HorizontalAlignment="Left" Margin="360,25,0,0" VerticalAlignment="Top" Width="73"/>
<Label Content="Wartość:" FontWeight="Bold" HorizontalAlignment="Left" Margin="438,25,0,0" VerticalAlignment="Top" Width="65"/>
<Button x:Name="prevButton" Content="Poprzednia" HorizontalAlignment="Left" Margin="10,0,0,52" VerticalAlignment="Bottom" Width="105" Click="prevButton_Click"/>
<Button x:Name="nextButton" Content="Następna" HorizontalAlignment="Right" Margin="0,0,10,52" VerticalAlignment="Bottom" Width="105" Click="nextButton_Click"/>
<ComboBox SelectionChanged="themeCombo_SelectionChanged" x:Name="themeCombo" HorizontalAlignment="Left" Margin="10,0,0,10" VerticalAlignment="Bottom" Width="162"/>
<Button x:Name="prevButton" Content="Poprzednia" HorizontalAlignment="Left" Margin="10,0,0,52" VerticalAlignment="Bottom" Width="105" Click="prevButton_Click"/>
<Button x:Name="nextButton" Content="Następna" HorizontalAlignment="Right" Margin="0,0,10,52" VerticalAlignment="Bottom" Width="105" Click="nextButton_Click"/>
<TextBlock x:Name="pageBlock" FontSize="16" Margin="274,0,273,59" TextWrapping="Wrap" Text="NaN" Height="19" VerticalAlignment="Bottom"/>
</Grid>
</Grid>
</Window>

View File

@ -20,149 +20,164 @@ using Newtonsoft.Json.Linq;
using System.Net;
using Magazyn.Windows;
using Magazyn.Tools;
namespace Magazyn
{
public partial class MainWindow : Window
{
public partial class MainWindow : Window
{
public int size = 4;
public int page = 0;
public int size = 4;
public int page = 0;
bool firstPage;
bool lastPage;
bool firstPage;
bool lastPage;
HttpClient client;
HttpClient client;
public MainWindow()
{
InitializeComponent();
this.Initialized += MainWindow_Initialized;
themeCombo.Items.Add("Jasno/Niebieski");
themeCombo.Items.Add("Jasno/Zielony");
themeCombo.Items.Add("Ciemno/Pomarańczowy");
themeCombo.SelectedIndex = 0;
Size windowSize;
client = new HttpClient();
}
public MainWindow()
{
InitializeComponent();
client = new HttpClient();
this.Loaded += MainWindowLoaded;
}
private void MainWindow_Initialized(object sender, EventArgs e)
{
RefreshListOfFruits();
}
private void MainWindowLoaded(object sender, EventArgs e)
{
RefreshListOfFruits();
windowSize = new Size(this.Width, this.Height);
this.SizeChanged += Window_SizeChanged;
}
private void FruitViewSaveChangingAmountOfFruits(int amountChanged, Fruit fruit)
{
string json = "{\"id\": " + fruit.Id.ToString() + ", \"change\": " + amountChanged.ToString() + " }";
private void FruitViewSaveChangingAmountOfFruits(int amountChanged, Fruit fruit)
{
string json = "{\"id\": " + fruit.Id.ToString() + ", \"change\": " + amountChanged.ToString() + " }";
Task<HttpResponseMessage> response = client.PostAsync("https://sysmag.herokuapp.com/api/product/change-quantity", new StringContent(json, Encoding.UTF8, "application/json"));
while (response.IsCompleted != true) ;
Task<HttpResponseMessage> response = client.PostAsync("https://sysmag.herokuapp.com/api/product/change-quantity", new StringContent(json, Encoding.UTF8, "application/json"));
while (response.IsCompleted != true) ;
if (response.Result.StatusCode == HttpStatusCode.BadRequest)
{
JObject data = JObject.Parse(response.Result.Content.ReadAsStringAsync().Result.ToString());
if (response.Result.StatusCode == HttpStatusCode.BadRequest)
{
JObject data = JObject.Parse(response.Result.Content.ReadAsStringAsync().Result.ToString());
ErrorWindow window;
ErrorWindow window;
if (data["message"].ToString().Contains("Too low"))
{
window = new ErrorWindow("Wystąpił błąd niedomiaru. Próbujesz usunąć więcej owoców niż masz w magazynie.");
}
else if (data["message"].ToString().Contains("Over max"))
{
window = new ErrorWindow("Wystąpił błąd nadmiaru. Próbujesz dodać więcej owoców niż pomieści magazyn.");
}
else
{
window = new ErrorWindow("Nieznany błąd.");
}
window.Owner = this;
window.ShowDialog();
}
if (data["message"].ToString().Contains("Too low"))
{
window = new ErrorWindow("Wystąpił błąd niedomiaru. Próbujesz usunąć więcej owoców niż masz w magazynie.");
}
else if (data["message"].ToString().Contains("Over max"))
{
window = new ErrorWindow("Wystąpił błąd nadmiaru. Próbujesz dodać więcej owoców niż pomieści magazyn.");
}
else
{
window = new ErrorWindow("Nieznany błąd.");
}
window.Owner = this;
window.ShowDialog();
}
RefreshListOfFruits();
}
RefreshListOfFruits();
}
private void RefreshListOfFruits()
{
private void RefreshListOfFruits()
{
pageBlock.Text = page.ToString();
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all?page=" + page.ToString() + "&size=" + size.ToString());
while (response.IsCompleted != true) ;
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all?page=" + page.ToString() + "&size=" + size.ToString());
while (response.IsCompleted != true) ;
if (response.Result.StatusCode != HttpStatusCode.OK)
{
ErrorWindow window = new ErrorWindow("Nastąpił błąd połączenia z serwerem.");
window.Owner = this;
window.ShowDialog();
return;
}
if (response.Result.StatusCode != HttpStatusCode.OK)
{
ErrorWindow window = new ErrorWindow("Nastąpił błąd połączenia z serwerem.");
window.Owner = this;
window.ShowDialog();
string responseString = response.Result.Content.ReadAsStringAsync().Result;
page = 0;
size = 0;
JObject replay = JObject.Parse(responseString);
return;
}
firstPage = bool.Parse(replay["first"].ToString());
lastPage = bool.Parse(replay["last"].ToString());
string responseString = response.Result.Content.ReadAsStringAsync().Result;
Fruit[] fruits = JsonConvert.DeserializeObject<Fruit[]>(replay["content"].ToString());
JObject replay = JObject.Parse(responseString);
UpdateListOfFruits(fruits);
}
firstPage = bool.Parse(replay["first"].ToString());
lastPage = bool.Parse(replay["last"].ToString());
private void UpdateListOfFruits(Fruit[] list)
{
fruitList.Items.Clear();
Fruit[] fruits = JsonConvert.DeserializeObject<Fruit[]>(replay["content"].ToString());
foreach (Fruit item in list)
{
FruitView fruitView = new FruitView(item);
fruitView.SaveChangingAmountOfFruits += FruitViewSaveChangingAmountOfFruits;
fruitList.Items.Add(fruitView);
}
}
UpdateListOfFruits(fruits);
}
private WarehousePrice GetWarehousePrice()
{
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-price-of-all");
while (response.IsCompleted != true) ;
private void UpdateListOfFruits(Fruit[] list)
{
fruitList.Items.Clear();
WarehousePrice price = JsonConvert.DeserializeObject<WarehousePrice>(response.Result.Content.ReadAsStringAsync().Result.ToString());
foreach (Fruit item in list)
{
FruitView fruitView = new FruitView(item);
fruitView.SaveChangingAmountOfFruits += FruitViewSaveChangingAmountOfFruits;
fruitList.Items.Add(fruitView);
}
}
return price;
}
private WarehousePrice GetWarehousePrice()
{
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-price-of-all");
while (response.IsCompleted != true) ;
private void Value_Click(object sender, RoutedEventArgs e)
{
ValueWindow window = new ValueWindow(GetWarehousePrice().Price);
window.Owner = this;
window.ShowDialog();
}
WarehousePrice price = JsonConvert.DeserializeObject<WarehousePrice>(response.Result.Content.ReadAsStringAsync().Result.ToString());
private void prevButton_Click(object sender, RoutedEventArgs e)
{
if (firstPage != true) page--;
RefreshListOfFruits();
}
return price;
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
if (lastPage != true) page++;
RefreshListOfFruits();
}
private void Value_Click(object sender, RoutedEventArgs e)
{
ValueWindow window = new ValueWindow(GetWarehousePrice().Price);
window.Owner = this;
window.ShowDialog();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
Size size = e.NewSize;
double height = size.Height - 124;
this.size = (int)(height / 90);
RefreshListOfFruits();
}
private void prevButton_Click(object sender, RoutedEventArgs e)
{
if (firstPage != true) page--;
RefreshListOfFruits();
}
private void themeCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var app = App.Current as App;
app.ChangeTheme(themeCombo.SelectedIndex);
}
}
private void nextButton_Click(object sender, RoutedEventArgs e)
{
if (lastPage != true) page++;
RefreshListOfFruits();
}
private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
{
Size size = e.NewSize;
if( Math.Abs(windowSize.Height - size.Height) >= 40 )
{
//size -> number of elementy by page
this.size = (int)((size.Height - 124) / 80);
page = 0;
windowSize = size;
RefreshListOfFruits();
}
}
private void fruitListMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
if (fruitList.SelectedItem != null)
{
InfoWindow window = new InfoWindow((fruitList.SelectedItem as FruitView).fruit);
window.Owner = this;
window.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace Magazyn.Tools
{
class CacheImage
{
static Dictionary<Uri, BitmapImage> dic = new Dictionary<Uri, BitmapImage>();
static public BitmapImage GetImageSource( Uri url )
{
if (dic.Keys.Contains<Uri>(url)) return dic[url];
else
{
BitmapImage imageSource = new BitmapImage();
imageSource.BeginInit();
imageSource.UriSource = url;
imageSource.CacheOption = BitmapCacheOption.OnLoad;
imageSource.EndInit();
dic.Add(url, imageSource);
return imageSource;
}
}
}
}

View File

@ -24,7 +24,7 @@ namespace Magazyn.Views
/// </summary>
public partial class FruitView : UserControl
{
Fruit fruit;
public Fruit fruit;
public delegate void ChangingAmountOfFruits(int amountChanged, Fruit fruit);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
@ -42,18 +42,18 @@ namespace Magazyn.Views
try
{
fruitImage.Source = new BitmapImage(new Uri(fruit.ImageLink));
}
fruitImage.Source = fruit.ImageSource;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
private void subaddButton_Click(object sender, RoutedEventArgs e)
private void subaddButton_Click(object sender, RoutedEventArgs e)
{
AmountWindow window = new AmountWindow(fruit, ((sender as Image).Name == "minusImage")?-1:1, fruit.Quantity);
AmountWindow window = new AmountWindow(fruit, ((sender as Image).Name == "minusImage")?-1:1, fruit.Quantity);
window.SaveChangingAmountOfFruits += WindowSaveChangingAmountOfFruits;
window.Owner = Application.Current.MainWindow;
window.ShowDialog();

View File

@ -15,14 +15,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn.Windows"
mc:Ignorable="d"
Title="Magazyn" WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize" Keyboard.KeyDown="Window_KeyDown">
<Grid>
<TextBlock x:Name="fruitName" HorizontalAlignment="Left" Margin="10,82,0,0" TextWrapping="Wrap" Text="fruitName" Width="64" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="messageBox" HorizontalAlignment="Left" Margin="80,10,0,0" TextWrapping="Wrap" Text="messageBox" VerticalAlignment="Top" Width="125" Height="64"/>
<TextBox x:Name="amountToChange" Margin="0,71,9,0" TextWrapping="Wrap" Text="0" RenderTransformOrigin="1.456,0.316" Height="32" VerticalAlignment="Top" HorizontalAlignment="Right" Width="64"/>
<Button x:Name="saveButton" Content="Zastosuj" Margin="105,122,0,0" VerticalAlignment="Top" Click="saveButton_Click" Width="90" HorizontalAlignment="Left"/>
<Button x:Name="cancelButton" Content="Anuluj" Margin="10,122,0,0" VerticalAlignment="Top" Click="cancelButton_Click" Width="90" HorizontalAlignment="Left" />
Title="" WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize" Keyboard.KeyDown="Window_KeyDown">
<Grid>
<TextBlock x:Name="fruitName" HorizontalAlignment="Left" Margin="10,82,0,0" TextWrapping="Wrap" Text="fruitName" Width="64" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="messageBox" HorizontalAlignment="Left" Margin="80,10,0,0" TextWrapping="Wrap" Text="messageBox" VerticalAlignment="Top" Width="125" Height="64"/>
<TextBox x:Name="amountToChange" Margin="0,71,9,0" TextWrapping="Wrap" Text="" RenderTransformOrigin="1.456,0.316" Height="32" VerticalAlignment="Top" HorizontalAlignment="Right" Width="64"/>
<Button x:Name="saveButton" Content="Zastosuj" Margin="0,0,9,10" VerticalAlignment="Bottom" Click="saveButton_Click" Width="90" HorizontalAlignment="Right"/>
<Button x:Name="cancelButton" Content="Anuluj" Margin="10,0,0,10" VerticalAlignment="Bottom" Click="cancelButton_Click" Width="90" HorizontalAlignment="Left" />
<Image x:Name="fruitImage" HorizontalAlignment="Left" Height="64" Margin="10,10,0,0" VerticalAlignment="Top" Width="64"/>
</Grid>

View File

@ -15,85 +15,94 @@ using System.Windows.Shapes;
namespace Magazyn.Windows
{
/// <summary>
/// Interaction logic for AmountWindow.xaml
/// </summary>
///
/// <summary>
/// Interaction logic for AmountWindow.xaml
/// </summary>
///
public partial class AmountWindow : Window
{
Fruit fruit;
int type;
int quantity;
public partial class AmountWindow : Window
{
Fruit fruit;
int type;
int quantity;
public delegate void ChangingAmountOfFruits(int amountChanged);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
public delegate void ChangingAmountOfFruits(int amountChanged);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
public AmountWindow(Fruit fruit, int type, int quantity)
{
InitializeComponent();
this.fruit = fruit;
this.type = type;
bool focusLock = false;
this.quantity = quantity;
public AmountWindow(Fruit fruit, int type, int quantity)
{
InitializeComponent();
this.fruit = fruit;
this.type = type;
if (type == -1)
this.Title = "Zmniejsz ilość: " + fruit.Name;
else
this.Title = "Zwiększ ilość: " + fruit.Name;
this.quantity = quantity;
fruitName.Text = fruit.Name;
if (type == -1)
this.Title = "Zmniejsz ilość: " + fruit.Name;
else
this.Title = "Zwiększ ilość: " + fruit.Name;
messageBox.Text = String.Format("Jaką ilość produktu chcesz {0} do magazynu?", (type > 0) ? "dodać" : "odjąć");
fruitName.Text = fruit.Name;
try
{
fruitImage.Source = new BitmapImage(new Uri(fruit.ImageLink));
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
messageBox.Text = String.Format("Jaką ilość produktu chcesz {0} do magazynu?", (type > 0) ? "dodać" : "odjąć");
}
try
{
fruitImage.Source = fruit.ImageSource;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
private void SendNewQuantity()
{
int amount = int.Parse(amountToChange.Text);
try
{
if (amount < 0)
{
ErrorWindow window = new ErrorWindow("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią.");
window.Owner = Application.Current.MainWindow;
window.ShowDialog();
amountToChange.Text = "0";
return;
}
this.Loaded += AmountWindowLoaded;
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
}
SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
this.Close();
}
private void AmountWindowLoaded(object sender, RoutedEventArgs e)
{
amountToChange.Focus();
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
SendNewQuantity();
}
private void SendNewQuantity()
{
int amount = int.Parse(amountToChange.Text);
try
{
if (amount < 0)
{
ErrorWindow window = new ErrorWindow("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią.");
window.Owner = Application.Current.MainWindow;
window.ShowDialog();
amountToChange.Text = "0";
return;
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) SendNewQuantity();
}
}
SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
this.Close();
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
SendNewQuantity();
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void Window_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Return) SendNewQuantity();
}
}
}

View File

@ -15,7 +15,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn.Windows"
mc:Ignorable="d"
Title="Błąd" WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize">
Title="Błąd" WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize">
<Grid>
<Button x:Name="okButton" Content="Ok" HorizontalAlignment="Right" Margin="0,0,10,10" VerticalAlignment="Bottom" Width="75" Click="okButton_Click"/>
<TextBlock x:Name="messageBlock" FontSize="16" Margin="10,10,10,0" TextWrapping="Wrap" Text="messageBlock" VerticalAlignment="Top"/>

View File

@ -0,0 +1,28 @@
<Window x:Class="Magazyn.Windows.InfoWindow"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
TextElement.Foreground="{DynamicResource MaterialDesignBody}"
TextElement.FontWeight="Regular"
TextElement.FontSize="13"
TextOptions.TextFormattingMode="Ideal"
TextOptions.TextRenderingMode="Auto"
Background="{DynamicResource MaterialDesignPaper}"
FontFamily="{DynamicResource MaterialDesignFont}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn.Windows"
mc:Ignorable="d"
Title="Informacje o: " WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize">
<Grid>
<TextBlock x:Name="fruitName" Margin="79,10,9,0" TextWrapping="Wrap" Text="fruitName" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="fruitPrice" Margin="79,31,10,0" TextWrapping="Wrap" Text="fruitPrice" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="fruitQuantity" Margin="79,52,10,0" TextWrapping="Wrap" Text="fruitQuantity" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="fruitQuantityMax" Margin="79,73,10,0" TextWrapping="Wrap" Text="fruitQuantityMax" Height="16" VerticalAlignment="Top"/>
<TextBlock x:Name="fruitValue" Margin="79,94,10,0" TextWrapping="Wrap" Text="fruitValue" Height="16" VerticalAlignment="Top"/>
<Button x:Name="okButton" Content="Ok" Margin="0,0,9,10" VerticalAlignment="Bottom" Click="okButton_Click" Width="75" HorizontalAlignment="Right"/>
<Image x:Name="fruitImage" HorizontalAlignment="Left" Height="64" Margin="10,10,0,0" VerticalAlignment="Top" Width="64"/>
</Grid>
</Window>

View File

@ -0,0 +1,53 @@
using Magazyn.DataModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
namespace Magazyn.Windows
{
/// <summary>
/// Interaction logic for InfoWindow.xaml
/// </summary>
public partial class InfoWindow : Window
{
Fruit fruit;
public InfoWindow(Fruit fruit)
{
InitializeComponent();
this.fruit = fruit;
fruitName.Text = "Owoc: " + fruit.Name;
this.Title = this.Title + fruit.Name;
fruitPrice.Text = "Cena: " + fruit.Price.ToString() + "zł";
fruitQuantity.Text = "Ilość: " + fruit.Quantity.ToString();
fruitQuantityMax.Text = "Ilość maks: " + fruit.QuantityMax.ToString();
fruitValue.Text = "Wartość: " + (fruit.Price * fruit.Quantity).ToString() + "zł";
try
{
fruitImage.Source = fruit.ImageSource;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}