1
0
forked from s434786/DINO_SCRUM

Usuniece konfliktu

This commit is contained in:
Krystian Kabat 2019-01-27 19:31:58 +01:00
commit 9e5a1bde5b
2 changed files with 56 additions and 27 deletions

View File

@ -17,8 +17,13 @@
mc:Ignorable="d" mc:Ignorable="d"
Title="Magazyn Owoców" MinHeight="259" Height="500" MaxWidth="590" MinWidth="590" Width="590" > Title="Magazyn Owoców" MinHeight="259" Height="500" MaxWidth="590" MinWidth="590" Width="590" >
<Grid> <Grid>
<ListBox MouseDoubleClick="fruitListMouseDoubleClick" x:Name="fruitList" Margin="10,51,10,89"/> <Grid.RowDefinitions>
<Button Name="sum" Content="Wartość magazynu" Margin="0,0,10,10" VerticalAlignment="Bottom" Height="35" Click="Value_Click" HorizontalAlignment="Right" Width="163"/> <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="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"/> <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="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"/> <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="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,52" VerticalAlignment="Bottom" Width="105" Click="nextButton_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,59" TextWrapping="Wrap" Text="NaN" Height="19" VerticalAlignment="Bottom"/> <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> </Grid>

View File

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