App.config - add Key AUTO_RUN_AT_STARTUP. ConfigurationForm - add features: auto startup with Windows.
This commit is contained in:
parent
aa73bf8129
commit
59208674e0
|
@ -11,6 +11,7 @@
|
|||
<add key="AUTO_OPEN_DOOR_1" value="true" />
|
||||
<add key="AUTO_OPEN_DOOR_2" value="true" />
|
||||
<add key="ALLOW_CHANGE_ROI_RECT" value="true" />
|
||||
<add key="AUTO_RUN_AT_STARTUP" value="false" />
|
||||
</appSettings>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
|
||||
|
|
27
AIParkingApplication/ConfigurationForm.Designer.cs
generated
27
AIParkingApplication/ConfigurationForm.Designer.cs
generated
|
@ -45,6 +45,8 @@
|
|||
this.chkAllowAutoLogin = new System.Windows.Forms.CheckBox();
|
||||
this.statusStrip = new System.Windows.Forms.StatusStrip();
|
||||
this.toolStripStatusLabelSavedSettingStatus = new System.Windows.Forms.ToolStripStatusLabel();
|
||||
this.lblAllowAutoRun = new System.Windows.Forms.Label();
|
||||
this.chkAllowAutoRunAtStartUp = new System.Windows.Forms.CheckBox();
|
||||
this.statusStrip.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
|
@ -83,7 +85,7 @@
|
|||
this.btnSaveSettings.Location = new System.Drawing.Point(416, 207);
|
||||
this.btnSaveSettings.Name = "btnSaveSettings";
|
||||
this.btnSaveSettings.Size = new System.Drawing.Size(106, 41);
|
||||
this.btnSaveSettings.TabIndex = 6;
|
||||
this.btnSaveSettings.TabIndex = 0;
|
||||
this.btnSaveSettings.Text = "Lưu";
|
||||
this.btnSaveSettings.UseVisualStyleBackColor = true;
|
||||
this.btnSaveSettings.Click += new System.EventHandler(this.btnSaveSettings_Click);
|
||||
|
@ -206,6 +208,25 @@
|
|||
this.toolStripStatusLabelSavedSettingStatus.Size = new System.Drawing.Size(110, 17);
|
||||
this.toolStripStatusLabelSavedSettingStatus.Text = "Cấu hình ứng dụng";
|
||||
//
|
||||
// lblAllowAutoRun
|
||||
//
|
||||
this.lblAllowAutoRun.AutoSize = true;
|
||||
this.lblAllowAutoRun.Location = new System.Drawing.Point(11, 161);
|
||||
this.lblAllowAutoRun.Name = "lblAllowAutoRun";
|
||||
this.lblAllowAutoRun.Size = new System.Drawing.Size(122, 13);
|
||||
this.lblAllowAutoRun.TabIndex = 9;
|
||||
this.lblAllowAutoRun.Text = "Tự khởi động ứng dụng:";
|
||||
//
|
||||
// chkAllowAutoRunAtStartUp
|
||||
//
|
||||
this.chkAllowAutoRunAtStartUp.AutoSize = true;
|
||||
this.chkAllowAutoRunAtStartUp.Location = new System.Drawing.Point(141, 160);
|
||||
this.chkAllowAutoRunAtStartUp.Name = "chkAllowAutoRunAtStartUp";
|
||||
this.chkAllowAutoRunAtStartUp.Size = new System.Drawing.Size(66, 17);
|
||||
this.chkAllowAutoRunAtStartUp.TabIndex = 5;
|
||||
this.chkAllowAutoRunAtStartUp.Text = "Sử dụng";
|
||||
this.chkAllowAutoRunAtStartUp.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// ConfigurationForm
|
||||
//
|
||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||
|
@ -216,9 +237,11 @@
|
|||
this.Controls.Add(this.btnCheckDoorDeviceControlAccessIP);
|
||||
this.Controls.Add(this.btnClose);
|
||||
this.Controls.Add(this.btnSaveSettings);
|
||||
this.Controls.Add(this.chkAllowAutoRunAtStartUp);
|
||||
this.Controls.Add(this.chkAllowAutoLogin);
|
||||
this.Controls.Add(this.chkAllowUsePrinter);
|
||||
this.Controls.Add(this.chkAllowChangeROIRect);
|
||||
this.Controls.Add(this.lblAllowAutoRun);
|
||||
this.Controls.Add(this.chkAllowAutoDoor2);
|
||||
this.Controls.Add(this.lblAllowAutoLogin);
|
||||
this.Controls.Add(this.chkAllowAutoDoor1);
|
||||
|
@ -260,5 +283,7 @@
|
|||
private System.Windows.Forms.CheckBox chkAllowAutoLogin;
|
||||
private System.Windows.Forms.StatusStrip statusStrip;
|
||||
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabelSavedSettingStatus;
|
||||
private System.Windows.Forms.Label lblAllowAutoRun;
|
||||
private System.Windows.Forms.CheckBox chkAllowAutoRunAtStartUp;
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@ namespace AIParkingApplication
|
|||
private bool allowUsePrinter;
|
||||
private bool allowChangeROIRect;
|
||||
private bool allowAutoLogin;
|
||||
private bool allowAutoRunAtStartUp;
|
||||
|
||||
public ConfigurationForm(Logger appLogger)
|
||||
{
|
||||
|
@ -34,6 +35,15 @@ namespace AIParkingApplication
|
|||
Util.UpsertAppSettings("USE_PRINTER", chkAllowUsePrinter.Checked.ToString().ToLower());
|
||||
Util.UpsertAppSettings("ALLOW_CHANGE_ROI_RECT", chkAllowChangeROIRect.Checked.ToString().ToLower());
|
||||
Util.UpsertAppSettings("AUTO_LOGIN", chkAllowAutoLogin.Checked.ToString().ToLower());
|
||||
Util.UpsertAppSettings("AUTO_RUN_AT_STARTUP", chkAllowAutoRunAtStartUp.Checked.ToString().ToLower());
|
||||
if (chkAllowAutoRunAtStartUp.Checked)
|
||||
{
|
||||
Util.AddApplicationToStartup();
|
||||
}
|
||||
else
|
||||
{
|
||||
Util.RemoveApplicationFromStartup();
|
||||
}
|
||||
toolStripStatusLabelSavedSettingStatus.Text = $"{DateTime.Now.GetTimeFormatted()} Đã lưu cài đặt";
|
||||
}
|
||||
|
||||
|
@ -46,6 +56,7 @@ namespace AIParkingApplication
|
|||
chkAllowUsePrinter.Checked = allowUsePrinter;
|
||||
chkAllowChangeROIRect.Checked = allowChangeROIRect;
|
||||
chkAllowAutoLogin.Checked = allowAutoLogin;
|
||||
chkAllowAutoRunAtStartUp.Checked = allowAutoRunAtStartUp;
|
||||
}
|
||||
|
||||
private void LoadConfiguration()
|
||||
|
@ -56,6 +67,7 @@ namespace AIParkingApplication
|
|||
bool.TryParse(ReadConfigurationFromAppSettings("USE_PRINTER", "false"), out allowUsePrinter);
|
||||
bool.TryParse(ReadConfigurationFromAppSettings("ALLOW_CHANGE_ROI_RECT", "false"), out allowChangeROIRect);
|
||||
bool.TryParse(ReadConfigurationFromAppSettings("AUTO_LOGIN", "false"), out allowAutoLogin);
|
||||
bool.TryParse(ReadConfigurationFromAppSettings("AUTO_RUN_AT_STARTUP", "false"), out allowAutoRunAtStartUp);
|
||||
}
|
||||
|
||||
private string ReadConfigurationFromAppSettings(string configurationKey, string defaultValueIfReadFailed)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Newtonsoft.Json;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
using OpenCvSharp;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
|
@ -161,6 +162,22 @@ namespace AIParkingApplication
|
|||
Width = roi.Width
|
||||
};
|
||||
}
|
||||
|
||||
public static void AddApplicationToStartup()
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
|
||||
{
|
||||
key.SetValue("AIParkingApplication", "\"" + Application.ExecutablePath + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveApplicationFromStartup()
|
||||
{
|
||||
using (RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true))
|
||||
{
|
||||
key.DeleteValue("AIParkingApplication", false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PlateRequestEngineModel
|
||||
|
|
Loading…
Reference in New Issue
Block a user