This commit is contained in:
Le Chau 2020-07-20 11:55:53 +07:00
commit 1418b1077e
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) 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); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInIn(); UpdateLaneInIn();
@ -163,7 +163,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneInOut_Click(object sender, EventArgs e) 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); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneInOut(); UpdateLaneInOut();
@ -172,7 +172,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutIn_Click(object sender, EventArgs e) 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); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutIn(); UpdateLaneOutIn();
@ -181,7 +181,7 @@ namespace AIParkingApplication
private void toolStripMenuItemSwitchLaneOutOut_Click(object sender, EventArgs e) 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); UpdateMenuStripItemStatus(sender as ToolStripMenuItem);
StopAllLanes(); StopAllLanes();
UpdateLaneOutOut(); UpdateLaneOutOut();
@ -262,7 +262,7 @@ namespace AIParkingApplication
} }
else else
{ {
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT"); Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut(); UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected(); toolStripMenuItemSwitchLaneInOut.DisableSelected();
appLogger.Log(LogLevel.Info, $"Khởi động App đọc config không đủ 2 param: IN-OUT"); 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) catch (Exception ex)
{ {
Util.AddOrUpdateAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT"); Util.UpsertAppSettings(CURRENT_LANE_SETTING_KEY, "IN-OUT");
UpdateLaneInOut(); UpdateLaneInOut();
toolStripMenuItemSwitchLaneInOut.DisableSelected(); toolStripMenuItemSwitchLaneInOut.DisableSelected();
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadLaneSettingFromConfigurationFile\t{ex.Message}"); 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="DOOR_ACCESS_DEVICE_CONTROL_IP" value="192.168.1.200" />
<add key="DEFAULT_USERNAME" value="cong1vao" /> <add key="DEFAULT_USERNAME" value="cong1vao" />
<add key="DEFAULT_PASSWORD" value="123456a@" /> <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="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" />

View File

@ -160,7 +160,7 @@ namespace AIParkingApplication
} }
catch (Exception ex) 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 }"); 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) if (loginResult.IsLoginSuccess)
{ {
Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", txtUsername.Text); Util.UpsertAppSettings("DEFAULT_USERNAME", txtUsername.Text);
Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", txtPassword.Text); Util.UpsertAppSettings("DEFAULT_PASSWORD", txtPassword.Text);
Util.UpsertAppSettings("DEFAULT_WEB_SERVER", txtServerAddress.Text);
new AIParkingApplicationForm(apiController, ipAddress, loginResult.LoginData, applicationLogger).Show(); new AIParkingApplicationForm(apiController, ipAddress, loginResult.LoginData, applicationLogger).Show();
Hide(); Hide();
applicationLogger.Log(LogLevel.Info, $"Đăng nhập thành công với tài khoản: {txtUsername.Text}"); 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"]; txtUsername.Text = ConfigurationManager.AppSettings["DEFAULT_USERNAME"];
txtPassword.Text = ConfigurationManager.AppSettings["DEFAULT_PASSWORD"]; txtPassword.Text = ConfigurationManager.AppSettings["DEFAULT_PASSWORD"];
txtServerAddress.Text = ConfigurationManager.AppSettings["DEFAULT_WEB_SERVER"];
bool.TryParse(ConfigurationManager.AppSettings["AUTO_LOGIN"], out isAutoLogin); bool.TryParse(ConfigurationManager.AppSettings["AUTO_LOGIN"], out isAutoLogin);
Thread.Sleep(500);
if (isAutoLogin) if (isAutoLogin)
{ {
chkAutoLogin.Checked = true; chkAutoLogin.Checked = true;
lblLoginStatus.UpdateLabel("Đang đăng nhập", Color.Green, Color.White);
Login(); Login();
} }
} }
@ -130,9 +130,10 @@ namespace AIParkingApplication
{ {
txtUsername.Text = string.Empty; txtUsername.Text = string.Empty;
txtPassword.Text = string.Empty; txtPassword.Text = string.Empty;
Util.AddOrUpdateAppSettings("DEFAULT_USERNAME", string.Empty); Util.UpsertAppSettings("DEFAULT_USERNAME", string.Empty);
Util.AddOrUpdateAppSettings("DEFAULT_PASSWORD", string.Empty); Util.UpsertAppSettings("DEFAULT_PASSWORD", string.Empty);
Util.AddOrUpdateAppSettings("AUTO_LOGIN", "false"); Util.UpsertAppSettings("AUTO_LOGIN", "false");
Util.UpsertAppSettings("DEFAULT_WEB_SERVER", "127.0.0.1:80");
chkAutoLogin.Checked = false; chkAutoLogin.Checked = false;
Console.WriteLine($"{DateTime.Now.GetTimeFormatted()}\tReadAccessControlDeviceIPConfiguration\t{ex.Message}"); 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"); 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) 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

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