1
0
forked from s442333/DINO_SCRUM

Error window, error when quantityMax is touched, pagination, small bugfixs

This commit is contained in:
Konrad Pierzyński 2019-01-22 21:02:49 +01:00
parent e2a0994fd2
commit 3fbea7ec0d
11 changed files with 242 additions and 77 deletions

View File

@ -73,6 +73,12 @@
<Compile Include="Windows\AmountWindow.xaml.cs"> <Compile Include="Windows\AmountWindow.xaml.cs">
<DependentUpon>AmountWindow.xaml</DependentUpon> <DependentUpon>AmountWindow.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Windows\ErrorWindow.xaml.cs">
<DependentUpon>ErrorWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Windows\ValueWindow.xaml.cs">
<DependentUpon>ValueWindow.xaml</DependentUpon>
</Compile>
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
@ -93,6 +99,14 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Windows\ErrorWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Windows\ValueWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs"> <Compile Include="Properties\AssemblyInfo.cs">

View File

@ -15,12 +15,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn" xmlns:local="clr-namespace:Magazyn"
mc:Ignorable="d" mc:Ignorable="d"
Title="Magazyn Owoców" Height="400" MaxWidth="590" MinWidth="590" Width="590"> Title="Magazyn Owoców" Height="500" MaxWidth="590" MinWidth="590" Width="590" SizeChanged="Window_SizeChanged">
<Grid> <Grid>
<ListBox x:Name="fruitList" Margin="10,35,10,50"/> <ListBox x:Name="fruitList" Margin="10,35,10,89"/>
<Button Name="sum" Content="Wartość magazynu" Margin="0,0,10,10" VerticalAlignment="Bottom" Height="35" Click="Button_Click_1" HorizontalAlignment="Right" Width="163"/> <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="Lista owoców:" FontWeight="Bold" HorizontalAlignment="Left" Margin="10,4,0,0" VerticalAlignment="Top" Width="100"/>
<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"/>
</Grid> </Grid>

View File

@ -18,22 +18,30 @@ using System.Windows.Shapes;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using System.Net;
using Magazyn.Windows;
namespace Magazyn namespace Magazyn
{ {
public partial class MainWindow : Window public partial class MainWindow : Window
{ {
public int size = 4;
public int page = 0;
bool firstPage;
bool lastPage;
HttpClient client; HttpClient client;
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
client = new HttpClient(); this.Initialized += MainWindow_Initialized; ;
RefreshListOfFruits();
}
private void Button_Click(object sender, RoutedEventArgs e) client = new HttpClient();
}
private void MainWindow_Initialized(object sender, EventArgs e)
{ {
RefreshListOfFruits(); RefreshListOfFruits();
} }
@ -43,27 +51,58 @@ namespace Magazyn
string json = "{\"id\": " + fruit.Id.ToString() + ", \"change\": " + amountChanged.ToString() + " }"; 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")); Task<HttpResponseMessage> response = client.PostAsync("https://sysmag.herokuapp.com/api/product/change-quantity", new StringContent(json, Encoding.UTF8, "application/json"));
while (response.IsCompleted != true) while (response.IsCompleted != true) ;
{
RefreshListOfFruits();
}
if (response.Result.StatusCode == HttpStatusCode.BadRequest)
{
JObject data = JObject.Parse(response.Result.Content.ReadAsStringAsync().Result.ToString());
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();
}
RefreshListOfFruits();
} }
private void RefreshListOfFruits() private void RefreshListOfFruits()
{ {
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all"); Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all?page=" + page.ToString() + "&size=" + size.ToString());
while (response.IsCompleted != true) ; 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;
}
string responseString = response.Result.Content.ReadAsStringAsync().Result; string responseString = response.Result.Content.ReadAsStringAsync().Result;
JObject replay = JObject.Parse(responseString); JObject replay = JObject.Parse(responseString);
firstPage = bool.Parse(replay["first"].ToString());
lastPage = bool.Parse(replay["last"].ToString());
Fruit[] fruits = JsonConvert.DeserializeObject<Fruit[]>(replay["content"].ToString()); Fruit[] fruits = JsonConvert.DeserializeObject<Fruit[]>(replay["content"].ToString());
UpdateListOfFruits(fruits); UpdateListOfFruits(fruits);
} }
private void UpdateListOfFruits(Fruit[] list) private void UpdateListOfFruits(Fruit[] list)
{ {
@ -87,16 +126,32 @@ namespace Magazyn
return price; return price;
} }
private void Button_Click_1(object sender, RoutedEventArgs e) private void Value_Click(object sender, RoutedEventArgs e)
{ {
ValueWindow window = new ValueWindow(GetWarehousePrice().Price);
window.Owner = this;
window.ShowDialog();
MessageBox.Show("Wartość magazynu to: " + GetWarehousePrice().Price.ToString() + "zł", "Wartość magazynu" );
} }
private void prevButton_Click(object sender, RoutedEventArgs e)
{
if (firstPage != true) page--;
RefreshListOfFruits();
}
} 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;
double height = size.Height - 124;
this.size = (int)(height / 90);
RefreshListOfFruits();
}
}
} }

View File

@ -11,12 +11,12 @@
<materialDesign:Card Background="{DynamicResource SecondaryAccentBrush}"> <materialDesign:Card Background="{DynamicResource SecondaryAccentBrush}">
<Grid> <Grid>
<Image Name="fruitImage" HorizontalAlignment="Left" Margin="10,10,0,7" Width="50"/> <Image x:Name="fruitImage" HorizontalAlignment="Left" Margin="10,10,0,7" Width="50"/>
<TextBlock Name="fruitName" HorizontalAlignment="Left" Margin="80,26,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="116"/> <TextBlock x:Name="fruitName" HorizontalAlignment="Left" Margin="80,26,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="116"/>
<Image Name="minusImage" HorizontalAlignment="Left" Height="24" Margin="240,25,0,0" VerticalAlignment="Top" Width="24" Source="/Images/minus.png" MouseDown="subButton_Click" /> <Image x:Name="minusImage" HorizontalAlignment="Left" Height="24" Margin="240,25,0,0" VerticalAlignment="Top" Width="24" Source="/Images/minus.png" MouseDown="subaddButton_Click" />
<Image Name="plusImage" HorizontalAlignment="Left" Height="24" Margin="304,25,0,0" VerticalAlignment="Top" Width="24" Source="/Magazyn;component/Images/plus.png" RenderTransformOrigin="0.208,0.521" MouseDown="addButton_Click"/> <Image x:Name="plusImage" HorizontalAlignment="Left" Height="24" Margin="304,25,0,0" VerticalAlignment="Top" Width="24" Source="/Magazyn;component/Images/plus.png" RenderTransformOrigin="0.208,0.521" MouseDown="subaddButton_Click"/>
<TextBlock Name="fruitAmount" HorizontalAlignment="Left" Margin="267,29,0,19" Width="34" TextAlignment="Center" RenderTransformOrigin="0.489,-0.623"/> <TextBlock x:Name="fruitAmount" HorizontalAlignment="Left" Margin="267,29,0,19" Width="34" TextAlignment="Center" RenderTransformOrigin="0.489,-0.623"/>
<TextBlock Name="fruitPrice" Margin="362,26,106,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" IsEnabled="False"/> <TextBlock x:Name="fruitPrice" Margin="362,26,106,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" IsEnabled="False"/>
<TextBlock x:Name="allPrice" Margin="425,26,43,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/> <TextBlock x:Name="allPrice" Margin="425,26,43,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
</Grid> </Grid>

View File

@ -46,21 +46,14 @@ namespace Magazyn.Views
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message);
} }
} }
private void subButton_Click(object sender, RoutedEventArgs e) private void subaddButton_Click(object sender, RoutedEventArgs e)
{ {
AmountWindow window = new AmountWindow(fruit, -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();
}
private void addButton_Click(object sender, RoutedEventArgs e)
{
AmountWindow window = new AmountWindow(fruit, 1, fruit.Quantity);
window.SaveChangingAmountOfFruits += WindowSaveChangingAmountOfFruits; window.SaveChangingAmountOfFruits += WindowSaveChangingAmountOfFruits;
window.Owner = Application.Current.MainWindow; window.Owner = Application.Current.MainWindow;
window.ShowDialog(); window.ShowDialog();

View File

@ -15,7 +15,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn.Windows" xmlns:local="clr-namespace:Magazyn.Windows"
mc:Ignorable="d" mc:Ignorable="d"
Title="Magazyn" WindowStartupLocation="CenterOwner" Height="205" Width="220"> Title="Magazyn" WindowStartupLocation="CenterOwner" Height="205" Width="220" ResizeMode="NoResize">
<Grid> <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="fruitName" HorizontalAlignment="Left" Margin="10,82,0,0" TextWrapping="Wrap" Text="fruitName" Width="64" Height="16" VerticalAlignment="Top"/>

View File

@ -18,13 +18,13 @@ namespace Magazyn.Windows
/// <summary> /// <summary>
/// Interaction logic for AmountWindow.xaml /// Interaction logic for AmountWindow.xaml
/// </summary> /// </summary>
/// ///
public partial class AmountWindow : Window public partial class AmountWindow : Window
{ {
Fruit fruit; Fruit fruit;
int type; int type;
int quantity; int quantity;
public delegate void ChangingAmountOfFruits(int amountChanged); public delegate void ChangingAmountOfFruits(int amountChanged);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits; public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
@ -35,16 +35,16 @@ namespace Magazyn.Windows
this.fruit = fruit; this.fruit = fruit;
this.type = type; this.type = type;
this.quantity = quantity; this.quantity = quantity;
if (type == -1)
this.Title = "Zmniejsz ilość " + fruit.Name; if (type == -1)
else this.Title = "Zmniejsz ilość: " + fruit.Name;
this.Title = "Zwiększ ilość " + fruit.Name; else
fruitName.Text = fruit.Name; this.Title = "Zwiększ ilość: " + fruit.Name;
fruitName.Text = fruit.Name; fruitName.Text = fruit.Name;
messageBox.Text = String.Format("Jaką ilość produktu chcesz {0} do magazynu?", (type > 0) ? "dodać":"odjąć"); messageBox.Text = String.Format("Jaką ilość produktu chcesz {0} do magazynu?", (type > 0) ? "dodać" : "odjąć");
try try
{ {
@ -52,46 +52,33 @@ namespace Magazyn.Windows
} }
catch (Exception ex) catch (Exception ex)
{ {
MessageBox.Show(ex.Message);
} }
} }
private void saveButton_Click(object sender, RoutedEventArgs e) private void saveButton_Click(object sender, RoutedEventArgs e)
{ {
int amount = 0; int amount = int.Parse(amountToChange.Text);
int maxAmount = 2500;
try try
{ {
amount = int.Parse(amountToChange.Text); if (amount < 0)
if (amount < 0) {
{ ErrorWindow window = new ErrorWindow("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią.");
MessageBox.Show("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią", "Nieprawidłowa wartość", MessageBoxButton.OK, MessageBoxImage.Error); window.Owner = Application.Current.MainWindow;
amountToChange.Text = "0"; window.ShowDialog();
return; amountToChange.Text = "0";
} return;
}
} catch (Exception ex) { }
catch (Exception ex)
{
throw new NotImplementedException(ex.Message); throw new NotImplementedException(ex.Message);
} }
if ((quantity + amount > maxAmount) && amount >= 0 && type == 1) SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
{ this.Close();
MessageBox.Show("Przepełnienie magazynu", "Przepełnienie, maksymalnie 2500 sztuk", MessageBoxButton.OK, MessageBoxImage.Error);
amountToChange.Text = "0";
return;
} else if ((quantity - amount < 0) && amount >= 0 && type == -1)
{
MessageBox.Show("Niedobór magazynu", "Ilość przedmiotów nie możę być mniejsza niz 0", MessageBoxButton.OK, MessageBoxImage.Error);
amountToChange.Text = "0";
return;
} else
{
SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
this.Close();
}
} }
private void cancelButton_Click(object sender, RoutedEventArgs e) private void cancelButton_Click(object sender, RoutedEventArgs e)

View File

@ -0,0 +1,23 @@
<Window x:Class="Magazyn.Windows.ErrorWindow"
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="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"/>
</Grid>
</Window>

View File

@ -0,0 +1,33 @@
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 ErrorWindow.xaml
/// </summary>
public partial class ErrorWindow : Window
{
public ErrorWindow(string text)
{
InitializeComponent();
messageBlock.Text = text;
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}

View File

@ -0,0 +1,25 @@
<Window x:Class="Magazyn.Windows.ValueWindow"
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="Wartość magazynu" 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 FontSize="16" Margin="10,10,10,0" TextWrapping="Wrap" Text="Wartość magazynu to:" VerticalAlignment="Top"/>
<TextBlock x:Name="valueBlock" FontSize="16" HorizontalAlignment="Left" Margin="10,34,0,0" TextWrapping="Wrap" Text="NaN zł" VerticalAlignment="Top"/>
</Grid>
</Window>

View File

@ -0,0 +1,33 @@
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 ValueWindow.xaml
/// </summary>
public partial class ValueWindow : Window
{
public ValueWindow(float value)
{
InitializeComponent();
valueBlock.Text = value.ToString() + " zł";
}
private void okButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
}