diff --git a/AIParkingApplication/AIParkingApplicationForm.cs b/AIParkingApplication/AIParkingApplicationForm.cs
index 350d707..f389d2d 100644
--- a/AIParkingApplication/AIParkingApplicationForm.cs
+++ b/AIParkingApplication/AIParkingApplicationForm.cs
@@ -307,7 +307,7 @@ namespace AIParkingApplication
private void setupToolStripMenuItem_Click(object sender, EventArgs e)
{
- var configurationForm = new ConfigurationForm();
+ var configurationForm = new ConfigurationForm(appLogger);
configurationForm.ShowDialog(this);
}
}
diff --git a/AIParkingApplication/App.config b/AIParkingApplication/App.config
index 68a2749..10e04b3 100644
--- a/AIParkingApplication/App.config
+++ b/AIParkingApplication/App.config
@@ -8,6 +8,9 @@
+
+
+
diff --git a/AIParkingApplication/ConfigurationForm.Designer.cs b/AIParkingApplication/ConfigurationForm.Designer.cs
index 75b52c0..aa8f574 100644
--- a/AIParkingApplication/ConfigurationForm.Designer.cs
+++ b/AIParkingApplication/ConfigurationForm.Designer.cs
@@ -33,8 +33,8 @@
this.btnClose = new System.Windows.Forms.Button();
this.btnSaveSettings = new System.Windows.Forms.Button();
this.chkAllowChangeROIRect = new System.Windows.Forms.CheckBox();
- this.chkAllowAutoDoorOut = new System.Windows.Forms.CheckBox();
- this.chkAllowAutoDoorIn = new System.Windows.Forms.CheckBox();
+ this.chkAllowAutoDoor2 = new System.Windows.Forms.CheckBox();
+ this.chkAllowAutoDoor1 = new System.Windows.Forms.CheckBox();
this.lblAllowChangeROIRect = new System.Windows.Forms.Label();
this.lblAllowAutoOpenDoorIn = new System.Windows.Forms.Label();
this.txtDoorDeviceControlAccessIP = new System.Windows.Forms.TextBox();
@@ -93,25 +93,25 @@
this.chkAllowChangeROIRect.Text = "Cho phép";
this.chkAllowChangeROIRect.UseVisualStyleBackColor = true;
//
- // chkAllowAutoDoorOut
+ // chkAllowAutoDoor2
//
- this.chkAllowAutoDoorOut.AutoSize = true;
- this.chkAllowAutoDoorOut.Location = new System.Drawing.Point(252, 37);
- this.chkAllowAutoDoorOut.Name = "chkAllowAutoDoorOut";
- this.chkAllowAutoDoorOut.Size = new System.Drawing.Size(57, 17);
- this.chkAllowAutoDoorOut.TabIndex = 4;
- this.chkAllowAutoDoorOut.Text = "Cửa ra";
- this.chkAllowAutoDoorOut.UseVisualStyleBackColor = true;
+ this.chkAllowAutoDoor2.AutoSize = true;
+ this.chkAllowAutoDoor2.Location = new System.Drawing.Point(252, 37);
+ this.chkAllowAutoDoor2.Name = "chkAllowAutoDoor2";
+ this.chkAllowAutoDoor2.Size = new System.Drawing.Size(68, 17);
+ this.chkAllowAutoDoor2.TabIndex = 4;
+ this.chkAllowAutoDoor2.Text = "Cửa số 2";
+ this.chkAllowAutoDoor2.UseVisualStyleBackColor = true;
//
- // chkAllowAutoDoorIn
+ // chkAllowAutoDoor1
//
- this.chkAllowAutoDoorIn.AutoSize = true;
- this.chkAllowAutoDoorIn.Location = new System.Drawing.Point(141, 37);
- this.chkAllowAutoDoorIn.Name = "chkAllowAutoDoorIn";
- this.chkAllowAutoDoorIn.Size = new System.Drawing.Size(66, 17);
- this.chkAllowAutoDoorIn.TabIndex = 3;
- this.chkAllowAutoDoorIn.Text = "Cửa vào";
- this.chkAllowAutoDoorIn.UseVisualStyleBackColor = true;
+ this.chkAllowAutoDoor1.AutoSize = true;
+ this.chkAllowAutoDoor1.Location = new System.Drawing.Point(141, 37);
+ this.chkAllowAutoDoor1.Name = "chkAllowAutoDoor1";
+ this.chkAllowAutoDoor1.Size = new System.Drawing.Size(68, 17);
+ this.chkAllowAutoDoor1.TabIndex = 3;
+ this.chkAllowAutoDoor1.Text = "Cửa số 1";
+ this.chkAllowAutoDoor1.UseVisualStyleBackColor = true;
//
// lblAllowChangeROIRect
//
@@ -177,8 +177,8 @@
this.Controls.Add(this.btnSaveSettings);
this.Controls.Add(this.chkAllowUsePrinter);
this.Controls.Add(this.chkAllowChangeROIRect);
- this.Controls.Add(this.chkAllowAutoDoorOut);
- this.Controls.Add(this.chkAllowAutoDoorIn);
+ this.Controls.Add(this.chkAllowAutoDoor2);
+ this.Controls.Add(this.chkAllowAutoDoor1);
this.Controls.Add(this.lblAllowUsePrinter);
this.Controls.Add(this.lblAllowChangeROIRect);
this.Controls.Add(this.lblAllowAutoOpenDoorIn);
@@ -203,8 +203,8 @@
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnSaveSettings;
private System.Windows.Forms.CheckBox chkAllowChangeROIRect;
- private System.Windows.Forms.CheckBox chkAllowAutoDoorOut;
- private System.Windows.Forms.CheckBox chkAllowAutoDoorIn;
+ private System.Windows.Forms.CheckBox chkAllowAutoDoor2;
+ private System.Windows.Forms.CheckBox chkAllowAutoDoor1;
private System.Windows.Forms.Label lblAllowChangeROIRect;
private System.Windows.Forms.Label lblAllowAutoOpenDoorIn;
private System.Windows.Forms.TextBox txtDoorDeviceControlAccessIP;
diff --git a/AIParkingApplication/ConfigurationForm.cs b/AIParkingApplication/ConfigurationForm.cs
index 995feae..578c165 100644
--- a/AIParkingApplication/ConfigurationForm.cs
+++ b/AIParkingApplication/ConfigurationForm.cs
@@ -1,4 +1,5 @@
-using System;
+using NLog;
+using System;
using System.Configuration;
using System.Windows.Forms;
@@ -6,11 +7,17 @@ namespace AIParkingApplication
{
public partial class ConfigurationForm : Form
{
+ private Logger appLogger;
private string doorAccessControlDeviceIP;
+ private bool allowAutoOpenDoor1;
+ private bool allowAutoOpenDoor2;
+ private bool allowUsePrinter;
+ private bool allowChangeROIRect;
- public ConfigurationForm()
+ public ConfigurationForm(Logger appLogger)
{
InitializeComponent();
+ this.appLogger = appLogger;
}
private void btnClose_Click(object sender, EventArgs e)
@@ -25,13 +32,36 @@ namespace AIParkingApplication
private void ConfigurationForm_Load(object sender, EventArgs e)
{
-
+ LoadConfiguration();
+ txtDoorDeviceControlAccessIP.Text = doorAccessControlDeviceIP;
+ chkAllowAutoDoor1.Checked = allowAutoOpenDoor1;
+ chkAllowAutoDoor2.Checked = allowAutoOpenDoor2;
+ chkAllowUsePrinter.Checked = allowUsePrinter;
+ chkAllowChangeROIRect.Checked = allowChangeROIRect;
}
private void LoadConfiguration()
{
- doorAccessControlDeviceIP = ConfigurationManager.AppSettings["DOOR_ACCESS_DEVICE_CONTROL_IP"].Trim();
+ doorAccessControlDeviceIP = ReadConfigurationFromAppSettings("DOOR_ACCESS_DEVICE_CONTROL_IP", string.Empty);
+ bool.TryParse(ReadConfigurationFromAppSettings("AUTO_OPEN_DOOR_1", "false"), out allowAutoOpenDoor1);
+ bool.TryParse(ReadConfigurationFromAppSettings("AUTO_OPEN_DOOR_2", "false"), out allowAutoOpenDoor2);
+ bool.TryParse(ReadConfigurationFromAppSettings("USE_PRINTER", "false"), out allowUsePrinter);
+ bool.TryParse(ReadConfigurationFromAppSettings("ALLOW_CHANGE_ROI_RECT", "false"), out allowChangeROIRect);
+ }
+ private string ReadConfigurationFromAppSettings(string configurationKey, string defaultValueIfReadFailed)
+ {
+ try
+ {
+ return ConfigurationManager.AppSettings[configurationKey].Trim();
+ }
+ catch (Exception ex)
+ {
+ Util.UpsertAppSettings(configurationKey, defaultValueIfReadFailed);
+ Console.WriteLine($"ReadDoorDeviceControlAccessConfiguration. ex: {ex.Message}");
+ appLogger.Log(LogLevel.Info, $"ConfigurationForm - ReadConfigurationFromAppSettings. Key: {configurationKey} - DefaultValue: {defaultValueIfReadFailed}. ex: {ex.Message}");
+ return defaultValueIfReadFailed;
+ }
}
}
}