diff --git a/Magazyn_Client/Magazyn/Magazyn.csproj b/Magazyn_Client/Magazyn/Magazyn.csproj
index f088802..5c4a801 100644
--- a/Magazyn_Client/Magazyn/Magazyn.csproj
+++ b/Magazyn_Client/Magazyn/Magazyn.csproj
@@ -73,6 +73,12 @@
AmountWindow.xaml
+
+ ErrorWindow.xaml
+
+
+ ValueWindow.xaml
+
MSBuild:Compile
Designer
@@ -93,6 +99,14 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
+
+ Designer
+ MSBuild:Compile
+
diff --git a/Magazyn_Client/Magazyn/MainWindow.xaml b/Magazyn_Client/Magazyn/MainWindow.xaml
index e7d530a..aa7ac06 100644
--- a/Magazyn_Client/Magazyn/MainWindow.xaml
+++ b/Magazyn_Client/Magazyn/MainWindow.xaml
@@ -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">
-
+
-
+
+
+
diff --git a/Magazyn_Client/Magazyn/MainWindow.xaml.cs b/Magazyn_Client/Magazyn/MainWindow.xaml.cs
index aae5b5d..fda40b9 100644
--- a/Magazyn_Client/Magazyn/MainWindow.xaml.cs
+++ b/Magazyn_Client/Magazyn/MainWindow.xaml.cs
@@ -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();
- client = new HttpClient();
- RefreshListOfFruits();
- }
+ this.Initialized += MainWindow_Initialized; ;
+
+ client = new HttpClient();
+ }
- private void Button_Click(object sender, RoutedEventArgs e)
+ private void MainWindow_Initialized(object sender, EventArgs e)
{
RefreshListOfFruits();
}
@@ -43,27 +51,58 @@ namespace Magazyn
string json = "{\"id\": " + fruit.Id.ToString() + ", \"change\": " + amountChanged.ToString() + " }";
Task response = client.PostAsync("https://sysmag.herokuapp.com/api/product/change-quantity", new StringContent(json, Encoding.UTF8, "application/json"));
- while (response.IsCompleted != true)
- {
- RefreshListOfFruits();
- }
+ while (response.IsCompleted != true) ;
+ 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()
{
- Task response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all");
+ Task 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(replay["content"].ToString());
UpdateListOfFruits(fruits);
- }
+ }
private void UpdateListOfFruits(Fruit[] list)
{
@@ -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();
+ }
+ }
}
diff --git a/Magazyn_Client/Magazyn/Views/FruitView.xaml b/Magazyn_Client/Magazyn/Views/FruitView.xaml
index a9401d9..a6abfc0 100644
--- a/Magazyn_Client/Magazyn/Views/FruitView.xaml
+++ b/Magazyn_Client/Magazyn/Views/FruitView.xaml
@@ -11,12 +11,12 @@
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/Magazyn_Client/Magazyn/Views/FruitView.xaml.cs b/Magazyn_Client/Magazyn/Views/FruitView.xaml.cs
index 47098aa..c5759c2 100644
--- a/Magazyn_Client/Magazyn/Views/FruitView.xaml.cs
+++ b/Magazyn_Client/Magazyn/Views/FruitView.xaml.cs
@@ -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();
diff --git a/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml b/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml
index dcdd3b1..3615522 100644
--- a/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml
+++ b/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml
@@ -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">
diff --git a/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml.cs b/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml.cs
index a2428d7..041a8a0 100644
--- a/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml.cs
+++ b/Magazyn_Client/Magazyn/Windows/AmountWindow.xaml.cs
@@ -18,13 +18,13 @@ namespace Magazyn.Windows
///
/// Interaction logic for AmountWindow.xaml
///
- ///
-
+ ///
+
public partial class AmountWindow : Window
{
Fruit fruit;
int type;
- int quantity;
+ int quantity;
public delegate void ChangingAmountOfFruits(int amountChanged);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
@@ -35,16 +35,16 @@ namespace Magazyn.Windows
this.fruit = fruit;
this.type = type;
- this.quantity = quantity;
- if (type == -1)
- this.Title = "Zmniejsz ilość " + fruit.Name;
- else
- this.Title = "Zwiększ ilość " + fruit.Name;
- fruitName.Text = fruit.Name;
+ this.quantity = quantity;
+
+ if (type == -1)
+ this.Title = "Zmniejsz ilość: " + fruit.Name;
+ else
+ 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,46 +52,33 @@ namespace Magazyn.Windows
}
catch (Exception ex)
{
-
+ MessageBox.Show(ex.Message);
}
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
- 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);
- amountToChange.Text = "0";
- return;
- }
-
- } catch (Exception ex) {
+ 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;
+ }
+
+ }
+ 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();
- }
-
+ SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
+ this.Close();
}
private void cancelButton_Click(object sender, RoutedEventArgs e)
diff --git a/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml b/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml
new file mode 100644
index 0000000..ef49a77
--- /dev/null
+++ b/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml
@@ -0,0 +1,23 @@
+
+
+
+
+
+
diff --git a/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml.cs b/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml.cs
new file mode 100644
index 0000000..fc75bc0
--- /dev/null
+++ b/Magazyn_Client/Magazyn/Windows/ErrorWindow.xaml.cs
@@ -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
+{
+ ///
+ /// Interaction logic for ErrorWindow.xaml
+ ///
+ public partial class ErrorWindow : Window
+ {
+ public ErrorWindow(string text)
+ {
+ InitializeComponent();
+ messageBlock.Text = text;
+ }
+
+ private void okButton_Click(object sender, RoutedEventArgs e)
+ {
+ this.Close();
+ }
+ }
+}
diff --git a/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml b/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml
new file mode 100644
index 0000000..cd8524e
--- /dev/null
+++ b/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml
@@ -0,0 +1,25 @@
+
+
+
+
+
+
+
+
diff --git a/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml.cs b/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml.cs
new file mode 100644
index 0000000..79c8666
--- /dev/null
+++ b/Magazyn_Client/Magazyn/Windows/ValueWindow.xaml.cs
@@ -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
+{
+ ///
+ /// Interaction logic for ValueWindow.xaml
+ ///
+ 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();
+ }
+ }
+}