ConfigurationForm - add appLogger into constructor. Add LoadConfiguration()

This commit is contained in:
DucDangAnh 2020-07-20 15:18:19 +07:00
parent 89e766714a
commit a3543084b7
4 changed files with 60 additions and 27 deletions

View File

@ -307,7 +307,7 @@ namespace AIParkingApplication
private void setupToolStripMenuItem_Click(object sender, EventArgs e) private void setupToolStripMenuItem_Click(object sender, EventArgs e)
{ {
var configurationForm = new ConfigurationForm(); var configurationForm = new ConfigurationForm(appLogger);
configurationForm.ShowDialog(this); configurationForm.ShowDialog(this);
} }
} }

View File

@ -8,6 +8,9 @@
<add key="CURRENT_LANE_SETTING" value="IN-OUT" /> <add key="CURRENT_LANE_SETTING" value="IN-OUT" />
<add key="AUTO_LOGIN" value="false" /> <add key="AUTO_LOGIN" value="false" />
<add key="USE_PRINTER" value="false" /> <add key="USE_PRINTER" value="false" />
<add key="AUTO_OPEN_DOOR_1" value="true" />
<add key="AUTO_OPEN_DOOR_2" value="true" />
<add key="ALLOW_CHANGE_ROI_RECT" value="true" />
</appSettings> </appSettings>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />

View File

@ -33,8 +33,8 @@
this.btnClose = new System.Windows.Forms.Button(); this.btnClose = new System.Windows.Forms.Button();
this.btnSaveSettings = new System.Windows.Forms.Button(); this.btnSaveSettings = new System.Windows.Forms.Button();
this.chkAllowChangeROIRect = new System.Windows.Forms.CheckBox(); this.chkAllowChangeROIRect = new System.Windows.Forms.CheckBox();
this.chkAllowAutoDoorOut = new System.Windows.Forms.CheckBox(); this.chkAllowAutoDoor2 = new System.Windows.Forms.CheckBox();
this.chkAllowAutoDoorIn = new System.Windows.Forms.CheckBox(); this.chkAllowAutoDoor1 = new System.Windows.Forms.CheckBox();
this.lblAllowChangeROIRect = new System.Windows.Forms.Label(); this.lblAllowChangeROIRect = new System.Windows.Forms.Label();
this.lblAllowAutoOpenDoorIn = new System.Windows.Forms.Label(); this.lblAllowAutoOpenDoorIn = new System.Windows.Forms.Label();
this.txtDoorDeviceControlAccessIP = new System.Windows.Forms.TextBox(); this.txtDoorDeviceControlAccessIP = new System.Windows.Forms.TextBox();
@ -93,25 +93,25 @@
this.chkAllowChangeROIRect.Text = "Cho phép"; this.chkAllowChangeROIRect.Text = "Cho phép";
this.chkAllowChangeROIRect.UseVisualStyleBackColor = true; this.chkAllowChangeROIRect.UseVisualStyleBackColor = true;
// //
// chkAllowAutoDoorOut // chkAllowAutoDoor2
// //
this.chkAllowAutoDoorOut.AutoSize = true; this.chkAllowAutoDoor2.AutoSize = true;
this.chkAllowAutoDoorOut.Location = new System.Drawing.Point(252, 37); this.chkAllowAutoDoor2.Location = new System.Drawing.Point(252, 37);
this.chkAllowAutoDoorOut.Name = "chkAllowAutoDoorOut"; this.chkAllowAutoDoor2.Name = "chkAllowAutoDoor2";
this.chkAllowAutoDoorOut.Size = new System.Drawing.Size(57, 17); this.chkAllowAutoDoor2.Size = new System.Drawing.Size(68, 17);
this.chkAllowAutoDoorOut.TabIndex = 4; this.chkAllowAutoDoor2.TabIndex = 4;
this.chkAllowAutoDoorOut.Text = "Cửa ra"; this.chkAllowAutoDoor2.Text = "Cửa số 2";
this.chkAllowAutoDoorOut.UseVisualStyleBackColor = true; this.chkAllowAutoDoor2.UseVisualStyleBackColor = true;
// //
// chkAllowAutoDoorIn // chkAllowAutoDoor1
// //
this.chkAllowAutoDoorIn.AutoSize = true; this.chkAllowAutoDoor1.AutoSize = true;
this.chkAllowAutoDoorIn.Location = new System.Drawing.Point(141, 37); this.chkAllowAutoDoor1.Location = new System.Drawing.Point(141, 37);
this.chkAllowAutoDoorIn.Name = "chkAllowAutoDoorIn"; this.chkAllowAutoDoor1.Name = "chkAllowAutoDoor1";
this.chkAllowAutoDoorIn.Size = new System.Drawing.Size(66, 17); this.chkAllowAutoDoor1.Size = new System.Drawing.Size(68, 17);
this.chkAllowAutoDoorIn.TabIndex = 3; this.chkAllowAutoDoor1.TabIndex = 3;
this.chkAllowAutoDoorIn.Text = "Cửa vào"; this.chkAllowAutoDoor1.Text = "Cửa số 1";
this.chkAllowAutoDoorIn.UseVisualStyleBackColor = true; this.chkAllowAutoDoor1.UseVisualStyleBackColor = true;
// //
// lblAllowChangeROIRect // lblAllowChangeROIRect
// //
@ -177,8 +177,8 @@
this.Controls.Add(this.btnSaveSettings); this.Controls.Add(this.btnSaveSettings);
this.Controls.Add(this.chkAllowUsePrinter); this.Controls.Add(this.chkAllowUsePrinter);
this.Controls.Add(this.chkAllowChangeROIRect); this.Controls.Add(this.chkAllowChangeROIRect);
this.Controls.Add(this.chkAllowAutoDoorOut); this.Controls.Add(this.chkAllowAutoDoor2);
this.Controls.Add(this.chkAllowAutoDoorIn); this.Controls.Add(this.chkAllowAutoDoor1);
this.Controls.Add(this.lblAllowUsePrinter); this.Controls.Add(this.lblAllowUsePrinter);
this.Controls.Add(this.lblAllowChangeROIRect); this.Controls.Add(this.lblAllowChangeROIRect);
this.Controls.Add(this.lblAllowAutoOpenDoorIn); this.Controls.Add(this.lblAllowAutoOpenDoorIn);
@ -203,8 +203,8 @@
private System.Windows.Forms.Button btnClose; private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.Button btnSaveSettings; private System.Windows.Forms.Button btnSaveSettings;
private System.Windows.Forms.CheckBox chkAllowChangeROIRect; private System.Windows.Forms.CheckBox chkAllowChangeROIRect;
private System.Windows.Forms.CheckBox chkAllowAutoDoorOut; private System.Windows.Forms.CheckBox chkAllowAutoDoor2;
private System.Windows.Forms.CheckBox chkAllowAutoDoorIn; private System.Windows.Forms.CheckBox chkAllowAutoDoor1;
private System.Windows.Forms.Label lblAllowChangeROIRect; private System.Windows.Forms.Label lblAllowChangeROIRect;
private System.Windows.Forms.Label lblAllowAutoOpenDoorIn; private System.Windows.Forms.Label lblAllowAutoOpenDoorIn;
private System.Windows.Forms.TextBox txtDoorDeviceControlAccessIP; private System.Windows.Forms.TextBox txtDoorDeviceControlAccessIP;

View File

@ -1,4 +1,5 @@
using System; using NLog;
using System;
using System.Configuration; using System.Configuration;
using System.Windows.Forms; using System.Windows.Forms;
@ -6,11 +7,17 @@ namespace AIParkingApplication
{ {
public partial class ConfigurationForm : Form public partial class ConfigurationForm : Form
{ {
private Logger appLogger;
private string doorAccessControlDeviceIP; private string doorAccessControlDeviceIP;
private bool allowAutoOpenDoor1;
private bool allowAutoOpenDoor2;
private bool allowUsePrinter;
private bool allowChangeROIRect;
public ConfigurationForm() public ConfigurationForm(Logger appLogger)
{ {
InitializeComponent(); InitializeComponent();
this.appLogger = appLogger;
} }
private void btnClose_Click(object sender, EventArgs e) private void btnClose_Click(object sender, EventArgs e)
@ -25,13 +32,36 @@ namespace AIParkingApplication
private void ConfigurationForm_Load(object sender, EventArgs e) 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() 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;
}
} }
} }
} }