Check requestResult.Data null, Set lblStatusSign.BackColor Status

This commit is contained in:
DucDangAnh 2020-06-20 19:35:41 +07:00
parent 2aa346ec64
commit 241162c5ee

View File

@ -9,6 +9,7 @@ using System.Threading.Tasks;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Drawing; using System.Drawing;
using System.Net.Http; using System.Net.Http;
using System.Threading;
namespace BITable namespace BITable
{ {
@ -136,6 +137,8 @@ namespace BITable
} }
private void ShowImageOnUI(RequestResult requestResult) private void ShowImageOnUI(RequestResult requestResult)
{
if (requestResult != null && requestResult.Data != null)
{ {
foreach (var item in requestResult.Data) foreach (var item in requestResult.Data)
{ {
@ -190,6 +193,7 @@ namespace BITable
break; break;
} }
} }
}
private void DoRequest(int option, bool isClearFaceImage, bool isClearIDCard) private void DoRequest(int option, bool isClearFaceImage, bool isClearIDCard)
{ {
@ -247,7 +251,6 @@ namespace BITable
{ {
if (!string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl)) if (!string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
{ {
DoRequestAPI(1, true, true); DoRequestAPI(1, true, true);
} }
else else
@ -415,6 +418,7 @@ namespace BITable
{ {
lblStatus.Text = "ĐANG XỬ LÝ"; lblStatus.Text = "ĐANG XỬ LÝ";
})); }));
if (isClearIDCard) if (isClearIDCard)
{ {
pictureBoxIDCard.Invoke(new Action(() => pictureBoxIDCard.Invoke(new Action(() =>
@ -476,13 +480,15 @@ namespace BITable
{ {
lblStatusSign.Invoke(new Action(() => lblStatusSign.Invoke(new Action(() =>
{ {
lblStatusSign.BackColor = Color.Blue; lblStatusSign.BackColor = Color.Green;
})); }));
} }
} }
else else
{ {
using (var client = new HttpClient { BaseAddress = new Uri("http://api.bitableconnect.beetai.com/"), Timeout = TimeSpan.FromMilliseconds(10000) }) using (var client = new HttpClient { BaseAddress = new Uri("http://api.bitableconnect.beetai.com/"), Timeout = TimeSpan.FromMilliseconds(20000) })
{
try
{ {
string deviceName = string.Empty; string deviceName = string.Empty;
txtDeviceName.Invoke(new Action(() => txtDeviceName.Invoke(new Action(() =>
@ -503,6 +509,27 @@ namespace BITable
{ {
txtIPAddress.Text = deviceUrl.Substring(7, deviceUrl.Length - 28); txtIPAddress.Text = deviceUrl.Substring(7, deviceUrl.Length - 28);
})); }));
if (!Util.IsPingable(txtIPAddress.Text, out long pingTime))
{
lblStatusSign.Invoke(new Action(() =>
{
lblStatusSign.BackColor = Color.Red;
}));
MessageBox.Show("Không thể ping tới thiết bị!");
}
else
{
lblStatusSign.Invoke(new Action(() =>
{
lblStatusSign.BackColor = Color.Green;
}));
}
}
catch (Exception)
{
MessageBox.Show("Kết nối tới server api gặp sự cố!");
}
} }
} }
} }