Use API
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
</startup>
|
||||
<runtime>
|
||||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
|
||||
<bindingRedirect oldVersion="0.0.0.0-12.0.0.0" newVersion="12.0.0.0" />
|
||||
</dependentAssembly>
|
||||
</assemblyBinding>
|
||||
</runtime>
|
||||
</configuration>
|
||||
@@ -50,6 +50,9 @@
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Net.Http.Formatting, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Net.Sockets, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\System.Net.Sockets.4.3.0\lib\net46\System.Net.Sockets.dll</HintPath>
|
||||
</Reference>
|
||||
@@ -81,6 +84,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Util.cs" />
|
||||
<EmbeddedResource Include="BiTable.resx">
|
||||
<DependentUpon>BiTable.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
|
||||
140
BITable/BiTable.Designer.cs
generated
140
BITable/BiTable.Designer.cs
generated
@@ -41,6 +41,13 @@
|
||||
this.BluetoothDeviceName = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||
this.lblConnectedDevice = new System.Windows.Forms.Label();
|
||||
this.lblStatus = new System.Windows.Forms.Label();
|
||||
this.txtDeviceName = new System.Windows.Forms.TextBox();
|
||||
this.txtTimeout = new System.Windows.Forms.TextBox();
|
||||
this.btnConnectIP = new System.Windows.Forms.Button();
|
||||
this.radioButtonBluetooth = new System.Windows.Forms.RadioButton();
|
||||
this.radioButtonIpApi = new System.Windows.Forms.RadioButton();
|
||||
this.lblStatusSign = new System.Windows.Forms.Label();
|
||||
this.txtIPAddress = new System.Windows.Forms.TextBox();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxFaceImage)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxIDCard)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvBluetoothDevices)).BeginInit();
|
||||
@@ -48,9 +55,9 @@
|
||||
//
|
||||
// pictureBoxFaceImage
|
||||
//
|
||||
this.pictureBoxFaceImage.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
|
||||
this.pictureBoxFaceImage.BackColor = System.Drawing.SystemColors.ButtonShadow;
|
||||
this.pictureBoxFaceImage.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.pictureBoxFaceImage.Location = new System.Drawing.Point(12, 12);
|
||||
this.pictureBoxFaceImage.Location = new System.Drawing.Point(12, 60);
|
||||
this.pictureBoxFaceImage.Name = "pictureBoxFaceImage";
|
||||
this.pictureBoxFaceImage.Size = new System.Drawing.Size(350, 350);
|
||||
this.pictureBoxFaceImage.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
@@ -59,82 +66,82 @@
|
||||
//
|
||||
// pictureBoxIDCard
|
||||
//
|
||||
this.pictureBoxIDCard.BackColor = System.Drawing.SystemColors.GradientInactiveCaption;
|
||||
this.pictureBoxIDCard.BackColor = System.Drawing.SystemColors.ButtonShadow;
|
||||
this.pictureBoxIDCard.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.pictureBoxIDCard.Location = new System.Drawing.Point(12, 368);
|
||||
this.pictureBoxIDCard.Location = new System.Drawing.Point(385, 60);
|
||||
this.pictureBoxIDCard.Name = "pictureBoxIDCard";
|
||||
this.pictureBoxIDCard.Size = new System.Drawing.Size(350, 237);
|
||||
this.pictureBoxIDCard.Size = new System.Drawing.Size(495, 350);
|
||||
this.pictureBoxIDCard.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
|
||||
this.pictureBoxIDCard.TabIndex = 0;
|
||||
this.pictureBoxIDCard.TabStop = false;
|
||||
//
|
||||
// btnScanBluetoothDevices
|
||||
//
|
||||
this.btnScanBluetoothDevices.Location = new System.Drawing.Point(395, 212);
|
||||
this.btnScanBluetoothDevices.Location = new System.Drawing.Point(951, 455);
|
||||
this.btnScanBluetoothDevices.Name = "btnScanBluetoothDevices";
|
||||
this.btnScanBluetoothDevices.Size = new System.Drawing.Size(388, 38);
|
||||
this.btnScanBluetoothDevices.TabIndex = 4;
|
||||
this.btnScanBluetoothDevices.Text = "Quét thiết bị";
|
||||
this.btnScanBluetoothDevices.Text = "Scan Bluetooth";
|
||||
this.btnScanBluetoothDevices.UseVisualStyleBackColor = true;
|
||||
this.btnScanBluetoothDevices.Click += new System.EventHandler(this.btnScanBluetoothDevices_Click);
|
||||
//
|
||||
// btnFaceAndPaper
|
||||
//
|
||||
this.btnFaceAndPaper.Location = new System.Drawing.Point(396, 368);
|
||||
this.btnFaceAndPaper.Location = new System.Drawing.Point(12, 450);
|
||||
this.btnFaceAndPaper.Name = "btnFaceAndPaper";
|
||||
this.btnFaceAndPaper.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnFaceAndPaper.TabIndex = 5;
|
||||
this.btnFaceAndPaper.Text = "Mặt + Giấy tờ";
|
||||
this.btnFaceAndPaper.Text = "CD vs CMT";
|
||||
this.btnFaceAndPaper.UseVisualStyleBackColor = true;
|
||||
this.btnFaceAndPaper.Click += new System.EventHandler(this.btnFaceAndPaper_Click);
|
||||
//
|
||||
// btnFace
|
||||
//
|
||||
this.btnFace.Location = new System.Drawing.Point(660, 368);
|
||||
this.btnFace.Location = new System.Drawing.Point(150, 450);
|
||||
this.btnFace.Name = "btnFace";
|
||||
this.btnFace.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnFace.TabIndex = 5;
|
||||
this.btnFace.Text = "Mặt";
|
||||
this.btnFace.Text = "CD";
|
||||
this.btnFace.UseVisualStyleBackColor = true;
|
||||
this.btnFace.Click += new System.EventHandler(this.btnFace_Click);
|
||||
//
|
||||
// btnFontPaper
|
||||
//
|
||||
this.btnFontPaper.Location = new System.Drawing.Point(396, 441);
|
||||
this.btnFontPaper.Location = new System.Drawing.Point(293, 450);
|
||||
this.btnFontPaper.Name = "btnFontPaper";
|
||||
this.btnFontPaper.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnFontPaper.TabIndex = 5;
|
||||
this.btnFontPaper.Text = "Giấy tờ trước";
|
||||
this.btnFontPaper.Text = "CMT MT";
|
||||
this.btnFontPaper.UseVisualStyleBackColor = true;
|
||||
this.btnFontPaper.Click += new System.EventHandler(this.btnFontPaper_Click);
|
||||
//
|
||||
// btnBehindPaper
|
||||
//
|
||||
this.btnBehindPaper.Location = new System.Drawing.Point(660, 441);
|
||||
this.btnBehindPaper.Location = new System.Drawing.Point(451, 450);
|
||||
this.btnBehindPaper.Name = "btnBehindPaper";
|
||||
this.btnBehindPaper.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnBehindPaper.TabIndex = 5;
|
||||
this.btnBehindPaper.Text = "Giấy tờ sau";
|
||||
this.btnBehindPaper.Text = "CMT MS";
|
||||
this.btnBehindPaper.UseVisualStyleBackColor = true;
|
||||
this.btnBehindPaper.Click += new System.EventHandler(this.btnBehindPaper_Click);
|
||||
//
|
||||
// btnFaceCamera
|
||||
//
|
||||
this.btnFaceCamera.Location = new System.Drawing.Point(396, 513);
|
||||
this.btnFaceCamera.Location = new System.Drawing.Point(608, 450);
|
||||
this.btnFaceCamera.Name = "btnFaceCamera";
|
||||
this.btnFaceCamera.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnFaceCamera.TabIndex = 5;
|
||||
this.btnFaceCamera.Text = "Cam khuôn mặt";
|
||||
this.btnFaceCamera.Text = "CD PREVIEW";
|
||||
this.btnFaceCamera.UseVisualStyleBackColor = true;
|
||||
this.btnFaceCamera.Click += new System.EventHandler(this.btnFaceCamera_Click);
|
||||
//
|
||||
// btnPaperCamera
|
||||
//
|
||||
this.btnPaperCamera.Location = new System.Drawing.Point(660, 513);
|
||||
this.btnPaperCamera.Location = new System.Drawing.Point(757, 450);
|
||||
this.btnPaperCamera.Name = "btnPaperCamera";
|
||||
this.btnPaperCamera.Size = new System.Drawing.Size(123, 43);
|
||||
this.btnPaperCamera.TabIndex = 5;
|
||||
this.btnPaperCamera.Text = "Cam giấy tờ";
|
||||
this.btnPaperCamera.Text = "CMT PREVIEW";
|
||||
this.btnPaperCamera.UseVisualStyleBackColor = true;
|
||||
this.btnPaperCamera.Click += new System.EventHandler(this.btnPaperCamera_Click);
|
||||
//
|
||||
@@ -145,13 +152,13 @@
|
||||
this.dgvBluetoothDevices.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
this.dgvBluetoothDevices.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
|
||||
this.BluetoothDeviceName});
|
||||
this.dgvBluetoothDevices.Location = new System.Drawing.Point(396, 13);
|
||||
this.dgvBluetoothDevices.Location = new System.Drawing.Point(951, 60);
|
||||
this.dgvBluetoothDevices.Name = "dgvBluetoothDevices";
|
||||
this.dgvBluetoothDevices.ReadOnly = true;
|
||||
this.dgvBluetoothDevices.RowHeadersVisible = false;
|
||||
this.dgvBluetoothDevices.RowTemplate.Height = 25;
|
||||
this.dgvBluetoothDevices.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect;
|
||||
this.dgvBluetoothDevices.Size = new System.Drawing.Size(387, 156);
|
||||
this.dgvBluetoothDevices.Size = new System.Drawing.Size(387, 350);
|
||||
this.dgvBluetoothDevices.TabIndex = 6;
|
||||
this.dgvBluetoothDevices.CellMouseDoubleClick += new System.Windows.Forms.DataGridViewCellMouseEventHandler(this.dgvBluetoothDevices_CellMouseDoubleClick);
|
||||
//
|
||||
@@ -165,7 +172,7 @@
|
||||
// lblConnectedDevice
|
||||
//
|
||||
this.lblConnectedDevice.AutoSize = true;
|
||||
this.lblConnectedDevice.Location = new System.Drawing.Point(395, 176);
|
||||
this.lblConnectedDevice.Location = new System.Drawing.Point(949, 426);
|
||||
this.lblConnectedDevice.Name = "lblConnectedDevice";
|
||||
this.lblConnectedDevice.Size = new System.Drawing.Size(171, 13);
|
||||
this.lblConnectedDevice.TabIndex = 7;
|
||||
@@ -175,17 +182,93 @@
|
||||
//
|
||||
this.lblStatus.AutoSize = true;
|
||||
this.lblStatus.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lblStatus.Location = new System.Drawing.Point(558, 291);
|
||||
this.lblStatus.Location = new System.Drawing.Point(12, 523);
|
||||
this.lblStatus.Name = "lblStatus";
|
||||
this.lblStatus.Size = new System.Drawing.Size(60, 24);
|
||||
this.lblStatus.TabIndex = 8;
|
||||
this.lblStatus.Text = "label1";
|
||||
//
|
||||
// txtDeviceName
|
||||
//
|
||||
this.txtDeviceName.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.txtDeviceName.Location = new System.Drawing.Point(12, 23);
|
||||
this.txtDeviceName.Name = "txtDeviceName";
|
||||
this.txtDeviceName.Size = new System.Drawing.Size(350, 24);
|
||||
this.txtDeviceName.TabIndex = 9;
|
||||
this.txtDeviceName.Text = "BITABLE11";
|
||||
//
|
||||
// txtTimeout
|
||||
//
|
||||
this.txtTimeout.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F);
|
||||
this.txtTimeout.Location = new System.Drawing.Point(591, 23);
|
||||
this.txtTimeout.Name = "txtTimeout";
|
||||
this.txtTimeout.Size = new System.Drawing.Size(117, 24);
|
||||
this.txtTimeout.TabIndex = 9;
|
||||
this.txtTimeout.Text = "6";
|
||||
//
|
||||
// btnConnectIP
|
||||
//
|
||||
this.btnConnectIP.Location = new System.Drawing.Point(736, 21);
|
||||
this.btnConnectIP.Name = "btnConnectIP";
|
||||
this.btnConnectIP.Size = new System.Drawing.Size(144, 26);
|
||||
this.btnConnectIP.TabIndex = 10;
|
||||
this.btnConnectIP.Text = "Connect IP";
|
||||
this.btnConnectIP.UseVisualStyleBackColor = true;
|
||||
this.btnConnectIP.Click += new System.EventHandler(this.btnConnectIP_Click);
|
||||
//
|
||||
// radioButtonBluetooth
|
||||
//
|
||||
this.radioButtonBluetooth.AutoSize = true;
|
||||
this.radioButtonBluetooth.Location = new System.Drawing.Point(952, 26);
|
||||
this.radioButtonBluetooth.Name = "radioButtonBluetooth";
|
||||
this.radioButtonBluetooth.Size = new System.Drawing.Size(70, 17);
|
||||
this.radioButtonBluetooth.TabIndex = 11;
|
||||
this.radioButtonBluetooth.Text = "Bluetooth";
|
||||
this.radioButtonBluetooth.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// radioButtonIpApi
|
||||
//
|
||||
this.radioButtonIpApi.AutoSize = true;
|
||||
this.radioButtonIpApi.Checked = true;
|
||||
this.radioButtonIpApi.Location = new System.Drawing.Point(1108, 26);
|
||||
this.radioButtonIpApi.Name = "radioButtonIpApi";
|
||||
this.radioButtonIpApi.Size = new System.Drawing.Size(55, 17);
|
||||
this.radioButtonIpApi.TabIndex = 11;
|
||||
this.radioButtonIpApi.TabStop = true;
|
||||
this.radioButtonIpApi.Text = "IP API";
|
||||
this.radioButtonIpApi.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// lblStatusSign
|
||||
//
|
||||
this.lblStatusSign.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(128)))));
|
||||
this.lblStatusSign.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D;
|
||||
this.lblStatusSign.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.lblStatusSign.Location = new System.Drawing.Point(1285, 17);
|
||||
this.lblStatusSign.Name = "lblStatusSign";
|
||||
this.lblStatusSign.Padding = new System.Windows.Forms.Padding(10);
|
||||
this.lblStatusSign.Size = new System.Drawing.Size(30, 30);
|
||||
this.lblStatusSign.TabIndex = 12;
|
||||
//
|
||||
// txtIPAddress
|
||||
//
|
||||
this.txtIPAddress.Font = new System.Drawing.Font("Microsoft Sans Serif", 11.25F);
|
||||
this.txtIPAddress.Location = new System.Drawing.Point(385, 23);
|
||||
this.txtIPAddress.Name = "txtIPAddress";
|
||||
this.txtIPAddress.Size = new System.Drawing.Size(200, 24);
|
||||
this.txtIPAddress.TabIndex = 9;
|
||||
//
|
||||
// BiTable
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(798, 616);
|
||||
this.ClientSize = new System.Drawing.Size(1350, 616);
|
||||
this.Controls.Add(this.lblStatusSign);
|
||||
this.Controls.Add(this.radioButtonIpApi);
|
||||
this.Controls.Add(this.radioButtonBluetooth);
|
||||
this.Controls.Add(this.btnConnectIP);
|
||||
this.Controls.Add(this.txtTimeout);
|
||||
this.Controls.Add(this.txtIPAddress);
|
||||
this.Controls.Add(this.txtDeviceName);
|
||||
this.Controls.Add(this.lblStatus);
|
||||
this.Controls.Add(this.lblConnectedDevice);
|
||||
this.Controls.Add(this.dgvBluetoothDevices);
|
||||
@@ -199,7 +282,7 @@
|
||||
this.Controls.Add(this.pictureBoxIDCard);
|
||||
this.Controls.Add(this.pictureBoxFaceImage);
|
||||
this.Name = "BiTable";
|
||||
this.Text = "Cam giấy tờ";
|
||||
this.Text = "BI Table";
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxFaceImage)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pictureBoxIDCard)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.dgvBluetoothDevices)).EndInit();
|
||||
@@ -223,6 +306,13 @@
|
||||
private System.Windows.Forms.DataGridViewTextBoxColumn BluetoothDeviceName;
|
||||
private System.Windows.Forms.Label lblConnectedDevice;
|
||||
private System.Windows.Forms.Label lblStatus;
|
||||
private System.Windows.Forms.TextBox txtDeviceName;
|
||||
private System.Windows.Forms.TextBox txtTimeout;
|
||||
private System.Windows.Forms.Button btnConnectIP;
|
||||
private System.Windows.Forms.RadioButton radioButtonBluetooth;
|
||||
private System.Windows.Forms.RadioButton radioButtonIpApi;
|
||||
private System.Windows.Forms.Label lblStatusSign;
|
||||
private System.Windows.Forms.TextBox txtIPAddress;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using System.Drawing;
|
||||
using System.Net.Http;
|
||||
|
||||
namespace BITable
|
||||
{
|
||||
@@ -16,6 +17,7 @@ namespace BITable
|
||||
private BluetoothClient client;
|
||||
private BluetoothDeviceInfo[] devices;
|
||||
private string currentBluetoothDeviceName;
|
||||
private string deviceUrl;
|
||||
|
||||
public BiTable()
|
||||
{
|
||||
@@ -25,6 +27,32 @@ namespace BITable
|
||||
lblStatus.Text = string.Empty;
|
||||
}
|
||||
|
||||
//public void TextGotFocus(object sender, EventArgs e)
|
||||
//{
|
||||
// TextBox tb = (TextBox)sender;
|
||||
// if (tb.Text == "Your Text ..........")
|
||||
// {
|
||||
// tb.Text = "";
|
||||
// tb.ForeColor = Color.Black;
|
||||
// }
|
||||
//}
|
||||
|
||||
//public void TextLostFocus(object sender, EventArgs e)
|
||||
//{
|
||||
// TextBox tb = (TextBox)sender;
|
||||
// if (tb.Text == "")
|
||||
// {
|
||||
// tb.Text = "Your Text ..........";
|
||||
// tb.ForeColor = Color.LightGray;
|
||||
// }
|
||||
//}
|
||||
|
||||
//private void SetupTextBox()
|
||||
//{
|
||||
// txtDeviceName.GotFocus += new EventHandler(this.TextGotFocus);
|
||||
// txtDeviceName.LostFocus += new EventHandler(this.TextLostFocus);
|
||||
//}
|
||||
|
||||
private void ScanBluetoothDevices()
|
||||
{
|
||||
dgvBluetoothDevices.Invoke(new Action(() =>
|
||||
@@ -203,7 +231,23 @@ namespace BITable
|
||||
|
||||
private void btnFaceAndPaper_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(1, true, true);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(1, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked & !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(1, true, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private Bitmap ParseImageFromBase64(string imageBase64)
|
||||
@@ -236,27 +280,223 @@ namespace BITable
|
||||
|
||||
private void btnFace_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(2, true, false);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(2, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked & !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(2, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnFontPaper_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(3, false, true);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(3, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked && !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(3, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnBehindPaper_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(4, false, true);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(4, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked & !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(4, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnFaceCamera_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(5, true, false);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(5, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked & !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(5, true, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private void btnPaperCamera_Click(object sender, EventArgs e)
|
||||
{
|
||||
DoRequest(6, false, true);
|
||||
if (radioButtonBluetooth.Checked && !string.IsNullOrEmpty(currentBluetoothDeviceName) && client.Connected)
|
||||
{
|
||||
DoRequest(6, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table qua Bluetooth!");
|
||||
}
|
||||
|
||||
if (radioButtonIpApi.Checked & !string.IsNullOrEmpty(txtIPAddress.Text) && !string.IsNullOrEmpty(deviceUrl))
|
||||
{
|
||||
DoRequestAPI(6, false, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Chưa kết nối tới thiết bị BI Table!");
|
||||
}
|
||||
}
|
||||
|
||||
private void DoRequestAPI(int option, bool isClearFaceImage, bool isClearIDCard)
|
||||
{
|
||||
Task.Factory.StartNew(new Action(async () =>
|
||||
{
|
||||
lblStatus.Invoke(new Action(() =>
|
||||
{
|
||||
lblStatus.Text = "ĐANG XỬ LÝ";
|
||||
}));
|
||||
if (isClearIDCard)
|
||||
{
|
||||
pictureBoxIDCard.Invoke(new Action(() =>
|
||||
{
|
||||
pictureBoxIDCard.Image?.Dispose();
|
||||
pictureBoxIDCard.Image = null;
|
||||
}));
|
||||
}
|
||||
|
||||
if (isClearFaceImage)
|
||||
{
|
||||
pictureBoxFaceImage.Invoke(new Action(() =>
|
||||
{
|
||||
pictureBoxFaceImage.Image?.Dispose();
|
||||
pictureBoxFaceImage.Image = null;
|
||||
}));
|
||||
}
|
||||
|
||||
using (var client = new HttpClient { BaseAddress = new Uri($"http://{txtIPAddress.Text}:8096/"), Timeout = TimeSpan.FromMilliseconds(10000) })
|
||||
{
|
||||
string deviceName = string.Empty;
|
||||
txtDeviceName.Invoke(new Action(() =>
|
||||
{
|
||||
deviceName = txtDeviceName.Text;
|
||||
}));
|
||||
|
||||
HttpResponseMessage response = await client.GetAsync($"/bitable?option={option}&timeout={txtTimeout.Text}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadAsStringAsync();
|
||||
var objectParsed = JsonConvert.DeserializeObject<RequestResult>(result);
|
||||
ShowImageOnUI(objectParsed);
|
||||
}
|
||||
})).ContinueWith(t =>
|
||||
{
|
||||
lblStatus.Invoke(new Action(() =>
|
||||
{
|
||||
lblStatus.Text = string.Empty;
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
||||
private void btnConnectIP_Click(object sender, EventArgs e)
|
||||
{
|
||||
Task.Factory.StartNew(new Action(async () =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(txtIPAddress.Text))
|
||||
{
|
||||
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;
|
||||
}));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
using (var client = new HttpClient { BaseAddress = new Uri("http://api.bitableconnect.beetai.com/"), Timeout = TimeSpan.FromMilliseconds(10000) })
|
||||
{
|
||||
string deviceName = string.Empty;
|
||||
txtDeviceName.Invoke(new Action(() =>
|
||||
{
|
||||
deviceName = txtDeviceName.Text;
|
||||
}));
|
||||
|
||||
HttpResponseMessage response = await client.GetAsync($"/get-ip-box?id={deviceName}");
|
||||
response.EnsureSuccessStatusCode();
|
||||
var result = await response.Content.ReadAsAsync<DeviceUrlModel>();
|
||||
if (!string.IsNullOrEmpty(result.Error))
|
||||
{
|
||||
MessageBox.Show("Thiết bị chưa được đăng ký!");
|
||||
return;
|
||||
}
|
||||
deviceUrl = result.Url;
|
||||
txtIPAddress.Invoke(new Action(() =>
|
||||
{
|
||||
txtIPAddress.Text = deviceUrl.Substring(7, deviceUrl.Length - 28);
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Không có kết nối internet!");
|
||||
Console.WriteLine($"SendEngineRequest : {ex.Message}");
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public class DeviceUrlModel
|
||||
{
|
||||
[JsonProperty("url")]
|
||||
public string Url { get; set; }
|
||||
[JsonProperty("error")]
|
||||
public string Error { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
42
BITable/Util.cs
Normal file
42
BITable/Util.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BITable
|
||||
{
|
||||
public static class Util
|
||||
{
|
||||
public static bool IsPingable(string destinationIPAddress, out long pingTime, int timeOut = 500)
|
||||
{
|
||||
var pingTask = Task.Factory.StartNew(async () =>
|
||||
{
|
||||
Ping pinger = new Ping();
|
||||
try
|
||||
{
|
||||
PingReply reply = await pinger.SendPingAsync(destinationIPAddress, timeOut);
|
||||
return reply;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
pinger.Dispose();
|
||||
}
|
||||
});
|
||||
|
||||
var pingResult = pingTask.Result.Result;
|
||||
if (pingResult != null && pingResult.Status == IPStatus.Success)
|
||||
{
|
||||
pingTime = pingResult.RoundtripTime;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
pingTime = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@
|
||||
<package id="32feet.NET" version="3.5.0.0" targetFramework="net461" />
|
||||
<package id="ConsoleTables" version="2.3.0" targetFramework="net461" />
|
||||
<package id="InTheHand.Pontoon" version="10.2018.3.19" targetFramework="net461" />
|
||||
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.7" targetFramework="net461" />
|
||||
<package id="Microsoft.CSharp" version="4.5.0" targetFramework="net461" />
|
||||
<package id="Network.Bluetooth" version="4.0.1803.22" targetFramework="net461" />
|
||||
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net461" />
|
||||
|
||||
Reference in New Issue
Block a user