Niedomiar, nadmiar, zmiana na polski, ustalenie max dla kazdego projektu na 2500 szt

This commit is contained in:
Mati 2019-01-21 14:43:04 +01:00
parent a6e7cd50f3
commit 701ed8a173
5 changed files with 45 additions and 19 deletions

View File

@ -7,13 +7,14 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn"
mc:Ignorable="d"
Title="Fruit Warehouse" Height="400" Width="520">
Title="Magazyn Owoców
" Height="400" Width="520">
<Grid>
<ListBox x:Name="fruitList" Margin="10,35,10,0" Height="239" VerticalAlignment="Top"/>
<Button Name="sum" Content="Suma" HorizontalAlignment="Left" Margin="414,0,0,46" VerticalAlignment="Bottom" Width="74" Height="35" Background="Teal" Click="Button_Click_1"/>
<TextBlock Name="payment" HorizontalAlignment="Left" Margin="404,322,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="84"/>
<ProgressBar Name="loadingContent" HorizontalAlignment="Left" Height="10" Margin="304,294,0,0" VerticalAlignment="Top" Width="100"/>
<Button Name="sum" Content="Wartość magazynu
" HorizontalAlignment="Left" Margin="325,0,0,46" VerticalAlignment="Bottom" Width="163" Height="35" Background="Teal" Click="Button_Click_1"/>
<ProgressBar Name="loadingContent" HorizontalAlignment="Left" Height="10" Margin="213,295,0,0" VerticalAlignment="Top" Width="100"/>
<Label Content="Lista owoców:" FontWeight="Bold" HorizontalAlignment="Left" Margin="10,4,0,0" VerticalAlignment="Top" Width="100"/>

View File

@ -43,9 +43,10 @@ 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) ;
RefreshListOfFruits();
while (response.IsCompleted != true)
{
RefreshListOfFruits();
}
}
@ -89,8 +90,7 @@ namespace Magazyn
private void Button_Click_1(object sender, RoutedEventArgs e)
{
payment.Text = GetWarehousePrice().Price.ToString();
//MessageBox.Show("Value of warehouse: " + GetWarehousePrice().Price.ToString() );
MessageBox.Show("Wartość magazynu: " + GetWarehousePrice().Price.ToString() );
}

View File

@ -52,14 +52,14 @@ namespace Magazyn.Views
private void subButton_Click(object sender, RoutedEventArgs e)
{
AmountWindow window = new AmountWindow(fruit, -1);
AmountWindow window = new AmountWindow(fruit, -1, fruit.Quantity);
window.SaveChangingAmountOfFruits += WindowSaveChangingAmountOfFruits;
window.Show();
}
private void addButton_Click(object sender, RoutedEventArgs e)
{
AmountWindow window = new AmountWindow(fruit, 1);
AmountWindow window = new AmountWindow(fruit, 1, fruit.Quantity);
window.SaveChangingAmountOfFruits += WindowSaveChangingAmountOfFruits;
window.Show();
}

View File

@ -5,11 +5,11 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:Magazyn.Windows"
mc:Ignorable="d"
Title="Change Quantity" Height="100" Width="280">
Title="Magazyn" Height="100" Width="280">
<Grid>
<TextBlock x:Name="fruitName" HorizontalAlignment="Left" Margin="10,36,0,0" TextWrapping="Wrap" Text="fruitName" VerticalAlignment="Top" Width="64"/>
<TextBox x:Name="amountToChange" HorizontalAlignment="Left" Margin="74,0,0,10" TextWrapping="Wrap" Text="0" Width="64" Height="32" VerticalAlignment="Bottom" RenderTransformOrigin="1.456,0.316"/>
<Button x:Name="saveButton" Content="Save" Margin="175,0,10,10" VerticalAlignment="Bottom" Click="saveButton_Click" />
<TextBox x:Name="amountToChange" HorizontalAlignment="Left" Margin="85,0,0,10" TextWrapping="Wrap" Text="0" Width="64" Height="32" VerticalAlignment="Bottom" RenderTransformOrigin="1.456,0.316"/>
<Button x:Name="saveButton" Content="Zapisz" Margin="175,0,10,10" VerticalAlignment="Bottom" Click="saveButton_Click" />
</Grid>
</Window>

View File

@ -18,35 +18,60 @@ namespace Magazyn.Windows
/// <summary>
/// Interaction logic for AmountWindow.xaml
/// </summary>
///
public partial class AmountWindow : Window
{
Fruit fruit;
int type;
int quantity;
public delegate void ChangingAmountOfFruits(int amountChanged);
public event ChangingAmountOfFruits SaveChangingAmountOfFruits;
public AmountWindow(Fruit fruit, int type)
public AmountWindow(Fruit fruit, int type, int quantity)
{
InitializeComponent();
this.fruit = fruit;
this.type = type;
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;
}
private void saveButton_Click(object sender, RoutedEventArgs e)
{
int amount = 0;
int maxAmount = 2500;
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) {
throw new NotImplementedException(ex.Message);
}
SaveChangingAmountOfFruits.Invoke((type>0)?amount:-amount);
if ((quantity + amount > maxAmount) && amount >= 0 && type == 1)
{
MessageBox.Show("Przepełnienie magazynu", "Przepełnienie, maxymalnie 2500 sztuk", MessageBoxButton.OK, MessageBoxImage.Error);
} 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);
} else
{
SaveChangingAmountOfFruits.Invoke((type > 0) ? amount : -amount);
}
this.Close();
}
}