Merge branch 'master' of s434739/DINO_SCRUM into master

This commit is contained in:
s1202077 2019-01-27 18:16:05 +00:00 committed by Gogs
commit 3c332a07ea
2 changed files with 56 additions and 28 deletions

View File

@ -17,8 +17,13 @@
mc:Ignorable="d"
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"/>
<Grid.RowDefinitions>
<RowDefinition Height="435*"/>
<RowDefinition Height="0*"/>
<RowDefinition Height="34*"/>
</Grid.RowDefinitions>
<ListBox MouseDoubleClick="fruitListMouseDoubleClick" x:Name="fruitList" Margin="10,51,10,55"/>
<Button Name="sum" Content="Wartość magazynu" Margin="0,0,10,10" VerticalAlignment="Bottom" Height="35" Click="Value_Click" HorizontalAlignment="Right" Width="163" Grid.RowSpan="3"/>
<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"/>
@ -27,9 +32,11 @@
<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"/>
<TextBlock x:Name="pageBlock" FontSize="16" Margin="274,0,273,59" TextWrapping="Wrap" Text="NaN" Height="19" VerticalAlignment="Bottom"/>
<Button x:Name="prevButton" Content="Poprzednia" HorizontalAlignment="Left" Margin="10,0,0,18" VerticalAlignment="Bottom" Width="105" Click="prevButton_Click"/>
<Button x:Name="nextButton" Content="Następna" HorizontalAlignment="Right" Margin="0,0,10,18" VerticalAlignment="Bottom" Width="105" Click="nextButton_Click"/>
<TextBlock x:Name="pageBlock" FontSize="16" Margin="274,0,273,25" TextWrapping="Wrap" Text="NaN" Height="19" VerticalAlignment="Bottom"/>
<Label Content="Status:" HorizontalAlignment="Left" Margin="4,0,0,14" VerticalAlignment="Bottom" Grid.RowSpan="3"/>
<TextBlock Name="netStatus" HorizontalAlignment="Left" Margin="50,0,0,19" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Bottom" Grid.RowSpan="3"/>
</Grid>

View File

@ -21,6 +21,7 @@ using Newtonsoft.Json.Linq;
using System.Net;
using Magazyn.Windows;
using Magazyn.Tools;
using System.Net.NetworkInformation;
namespace Magazyn
{
@ -32,6 +33,7 @@ namespace Magazyn
bool firstPage;
bool lastPage;
bool netConn;
HttpClient client;
@ -42,6 +44,11 @@ namespace Magazyn
InitializeComponent();
client = new HttpClient();
this.Loaded += MainWindowLoaded;
netConn = checkInternetConnection();
if (netConn)
netStatus.Text = "Połączony";
else
netStatus.Text = "Rozłączony";
}
private void MainWindowLoaded(object sender, EventArgs e)
@ -85,33 +92,36 @@ namespace Magazyn
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) ;
if (response.Result.StatusCode != HttpStatusCode.OK)
if (netConn)
{
ErrorWindow window = new ErrorWindow("Nastąpił błąd połączenia z serwerem.");
window.Owner = this;
window.ShowDialog();
pageBlock.Text = page.ToString();
page = 0;
size = 0;
Task<HttpResponseMessage> response = client.GetAsync("https://sysmag.herokuapp.com/api/get-all?page=" + page.ToString() + "&size=" + size.ToString());
while (response.IsCompleted != true) ;
return;
if (response.Result.StatusCode != HttpStatusCode.OK)
{
ErrorWindow window = new ErrorWindow("Nastąpił błąd połączenia z serwerem.");
window.Owner = this;
window.ShowDialog();
page = 0;
size = 0;
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);
}
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);
}
private void UpdateListOfFruits(Fruit[] list)
@ -178,6 +188,17 @@ namespace Magazyn
window.ShowDialog();
}
}
private Boolean checkInternetConnection()
{
try
{
return new Ping().Send("www.google.com").Status == IPStatus.Success;
} catch
{
return false;
}
}
}
}