diff --git a/Magazyn_Client/Magazyn/MainWindow.xaml b/Magazyn_Client/Magazyn/MainWindow.xaml
index 6df635d..5c211dd 100644
--- a/Magazyn_Client/Magazyn/MainWindow.xaml
+++ b/Magazyn_Client/Magazyn/MainWindow.xaml
@@ -17,8 +17,13 @@
mc:Ignorable="d"
Title="Magazyn Owoców" MinHeight="259" Height="500" MaxWidth="590" MinWidth="590" Width="590" >
-
-
+
+
+
+
+
+
+
@@ -27,9 +32,11 @@
-
-
-
+
+
+
+
+
diff --git a/Magazyn_Client/Magazyn/MainWindow.xaml.cs b/Magazyn_Client/Magazyn/MainWindow.xaml.cs
index 7d09588..da90eb7 100644
--- a/Magazyn_Client/Magazyn/MainWindow.xaml.cs
+++ b/Magazyn_Client/Magazyn/MainWindow.xaml.cs
@@ -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 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 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(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(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;
+ }
+ }
}
}