Compare commits

...

2 Commits

5 changed files with 18 additions and 16 deletions

View File

@ -154,7 +154,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInIn_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-IN");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneInIn();
@ -163,7 +163,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneInOut();
@ -172,7 +172,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-IN");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-IN");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneOutIn();
@ -181,7 +181,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-OUT");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "OUT-OUT");
UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes();
UpdateLaneOutOut();
@ -262,7 +262,7 @@ namespace AIParkingApplication
}
else
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected();
appLogger.Log(LogLevel.Info, $"Khởi động App đọc config không đủ 2 param: IN-OUT");
@ -271,7 +271,7 @@ namespace AIParkingApplication
}
catch (Exception ex)
{
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected();
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}");

View File

@ -4,6 +4,7 @@
<add key="DOOR_ACCESS_DEVICE_CONTROL_IP" value="192.168.1.200" />
<add key="DEFAULT_USERNAME" value="cong1vao" />
<add key="DEFAULT_PASSWORD" value="123456a@" />
<add key="DEFAULT_WEB_SERVER" value="192.168.1.122:80" />
<add key="CURRENT_LANE_SETTING" value="IN-OUT" />
<add key="AUTO_LOGIN" value="false" />
<add key="USE_PRINTER" value="false" />

View File

@ -152,7 +152,7 @@ namespace AIParkingApplication
}
catch (Exception ex)
{
Util.AddOrUpdateAppSettings("USE_PRINTER", "false");
Util.UpsertAppSettings("USE_PRINTER", "false");
appLogger.Log(LogLevel.Error, $"Không thể đọc cấu hình: USE_PRINTER. ex: {ex.Message }");
}
}

View File

@ -98,8 +98,9 @@ namespace AIParkingApplication
if (loginResult.IsLoginSuccess)
{
Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", txtUsername.Text);
Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", txtPassword.Text);
Util.UpsertAppSettings("DEFAULT_USERNAME", txtUsername.Text);
Util.UpsertAppSettings("DEFAULT_PASSWORD", txtPassword.Text);
Util.UpsertAppSettings("DEFAULT_WEB_SERVER", txtServerAddress.Text);
new AIParkingApplicationForm(apiController, ipAddress, loginResult.LoginData, applicationLogger).Show();
Hide();
applicationLogger.Log(LogLevel.Info, $"Đăng nhập thành công với tài khoản: {txtUsername.Text}");
@ -117,12 +118,11 @@ namespace AIParkingApplication
{
txtUsername.Text = ConfigurationManager.AppSettings["DEFAULT_USERNAME"];
txtPassword.Text = ConfigurationManager.AppSettings["DEFAULT_PASSWORD"];
txtServerAddress.Text = ConfigurationManager.AppSettings["DEFAULT_WEB_SERVER"];
bool.TryParse(ConfigurationManager.AppSettings["AUTO_LOGIN"], out isAutoLogin);
Thread.Sleep(500);
if (isAutoLogin)
{
chkAutoLogin.Checked = true;
lblLoginStatus.UpdateLabel("Đang đăng nhập", Color.Green, Color.White);
Login();
}
}
@ -130,9 +130,10 @@ namespace AIParkingApplication
{
txtUsername.Text = string.Empty;
txtPassword.Text = string.Empty;
Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", string.Empty);
Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", string.Empty);
Util.AddOrUpdateAppSettings("AUTO_LOGIN", "false");
Util.UpsertAppSettings("DEFAULT_USERNAME", string.Empty);
Util.UpsertAppSettings("DEFAULT_PASSWORD", string.Empty);
Util.UpsertAppSettings("AUTO_LOGIN", "false");
Util.UpsertAppSettings("DEFAULT_WEB_SERVER", "127.0.0.1:80");
chkAutoLogin.Checked = false;
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}");
applicationLogger.Log(LogLevel.Error, "Không thể đọc cấu hình tài khoản mặc định: DEFAULT_USERNAME, DEFAULT_PASSWORD");
@ -146,7 +147,7 @@ namespace AIParkingApplication
private void chkAutoLogin_CheckedChanged(object sender, EventArgs e)
{
Util.AddOrUpdateAppSettings("AUTO_LOGIN", (sender as CheckBox).Checked.ToString().ToLower());
Util.UpsertAppSettings("AUTO_LOGIN", (sender as CheckBox).Checked.ToString().ToLower());
}
}
}

View File

@ -113,7 +113,7 @@ namespace AIParkingApplication
int.TryParse(hostParts[1], out port);
}
public static void AddOrUpdateAppSettings(string key, string value)
public static void UpsertAppSettings(string key, string value)
{
try
{