0
0
forked from s434786/DINO_SCRUM

Merge branch 'master' of s442333/DINO_SCRUM into master

This commit is contained in:
s1202077 2019-01-22 20:42:51 +00:00 committed by Gogs
commit 231ee392da
11 changed files with 273 additions and 98 deletions

View File

@ -73,6 +73,12 @@
<Compile Include="Windows\AmountWindow.xaml.cs">
<DependentUpon>AmountWindow.xaml</DependentUpon>
</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">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -93,6 +99,14 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</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>
<Compile Include="Properties\AssemblyInfo.cs">

View File

@ -15,12 +15,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn"
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>
<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"/>
<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>

View File

@ -18,22 +18,30 @@ using System.Windows.Shapes;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Net;
using Magazyn.Windows;
namespace Magazyn
{
public partial class MainWindow : Window
{
public int size = 4;
public int page = 0;
bool firstPage;
bool lastPage;
HttpClient client;
public MainWindow()
{
InitializeComponent();
this.Initialized += MainWindow_Initialized; ;
client = new HttpClient();
RefreshListOfFruits();
}
private void Button_Click(object sender, RoutedEventArgs e)
private void MainWindow_Initialized(object sender, EventArgs e)
{
RefreshListOfFruits();
}
@ -43,23 +51,54 @@ namespace Magazyn
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)
while (response.IsCompleted != true) ;
if (response.Result.StatusCode == HttpStatusCode.BadRequest)
{
RefreshListOfFruits();
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()
{
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) ;
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;
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());
UpdateListOfFruits(fruits);
@ -87,16 +126,32 @@ namespace Magazyn
return price;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
private void Value_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show("Wartość magazynu to: " + GetWarehousePrice().Price.ToString() + "zł", "Wartość magazynu" );
ValueWindow window = new ValueWindow(GetWarehousePrice().Price);
window.Owner = this;
window.ShowDialog();
}
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}">
<Grid>
<Image 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"/>
<Image Name="minusImage" HorizontalAlignment="Left" Height="24" Margin="240,25,0,0" VerticalAlignment="Top" Width="24" Source="/Images/minus.png" MouseDown="subButton_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"/>
<TextBlock 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"/>
<Image x:Name="fruitImage" HorizontalAlignment="Left" Margin="10,10,0,7" Width="50"/>
<TextBlock x:Name="fruitName" HorizontalAlignment="Left" Margin="80,26,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Width="116"/>
<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 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 x:Name="fruitAmount" HorizontalAlignment="Left" Margin="267,29,0,19" Width="34" TextAlignment="Center" RenderTransformOrigin="0.489,-0.623"/>
<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"/>
</Grid>

View File

@ -46,21 +46,14 @@ namespace Magazyn.Views
}
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);
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);
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,7 +15,7 @@
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">
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"/>

View File

@ -36,15 +36,15 @@ namespace Magazyn.Windows
this.type = type;
this.quantity = quantity;
if (type == -1)
this.Title = "Zmniejsz ilość " + fruit.Name;
this.Title = "Zmniejsz ilość: " + fruit.Name;
else
this.Title = "Zwiększ ilość " + fruit.Name;
fruitName.Text = fruit.Name;
this.Title = "Zwiększ ilość: " + 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
{
@ -52,51 +52,48 @@ namespace Magazyn.Windows
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void saveButton_Click(object sender, RoutedEventArgs e)
private void SendNewQuantity()
{
int amount = 0;
int maxAmount = 2500;
int amount = int.Parse(amountToChange.Text);
try
{
amount = int.Parse(amountToChange.Text);
if (amount < 0)
{
MessageBox.Show("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią", "Nieprawidłowa wartość", MessageBoxButton.OK, MessageBoxImage.Error);
ErrorWindow window = new ErrorWindow("Podana wartość jest nieprawidłowa, proszę podać wartość dodatnią.");
window.Owner = Application.Current.MainWindow;
window.ShowDialog();
amountToChange.Text = "0";
return;
}
} catch (Exception ex) {
}
catch (Exception ex)
{
throw new NotImplementedException(ex.Message);
}
if ((quantity + amount > maxAmount) && amount >= 0 && type == 1)
{
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 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

@ -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();
}
}
}