重构项目,将项目拆分(临时提交)
This commit is contained in:
45
DMS.Infrastructure/Configurations/ConnectionSettings.cs
Normal file
45
DMS.Infrastructure/Configurations/ConnectionSettings.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace DMS.Config
|
||||
{
|
||||
public class ConnectionSettings
|
||||
{
|
||||
public string DbType { get; set; } = "MySql";
|
||||
public string Server { get; set; } = "127.0.0.1";
|
||||
public int Port { get; set; } = 3306;
|
||||
public string UserId { get; set; } = "root";
|
||||
public string Password { get; set; } = "Pgw15221236646";
|
||||
public string Database { get; set; } = "pmswpf";
|
||||
public string Theme { get; set; } = "跟随系统";
|
||||
public bool EnableS7Service { get; set; } = true;
|
||||
public bool EnableMqttService { get; set; } = true;
|
||||
public bool EnableOpcUaService { get; set; } = true;
|
||||
public bool MinimizeToTrayOnClose { get; set; } = true;
|
||||
|
||||
private static readonly string SettingsFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "connectionSettings.json");
|
||||
|
||||
public static ConnectionSettings Load()
|
||||
{
|
||||
if (File.Exists(SettingsFilePath))
|
||||
{
|
||||
string json = File.ReadAllText(SettingsFilePath);
|
||||
return JsonConvert.DeserializeObject<ConnectionSettings>(json);
|
||||
}
|
||||
return new ConnectionSettings(); // Return default settings if file doesn't exist
|
||||
}
|
||||
|
||||
public void Save()
|
||||
{
|
||||
string json = JsonConvert.SerializeObject(this, Formatting.Indented);
|
||||
File.WriteAllText(SettingsFilePath, json);
|
||||
}
|
||||
|
||||
public string ToConnectionString()
|
||||
{
|
||||
// This example is for MySQL. You'll need to adjust for other database types.
|
||||
return $"server={Server};port={Port};user={UserId};password={Password};database={Database};";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user