XKRS2023Frm/XKRS.Common.Model/Helper/SettingHelper.cs

115 lines
3.4 KiB
C#
Raw Normal View History

2023-03-24 09:58:42 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace XKRS.Common.Model.Helper
{
public static class SettingHelper
{
const string SETTINGFILE = "Setting.json";
//声明一个SettingInfo类型的字段
public static SettingInfo SettingInfo;
public static string SettingPath => Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE);
/// <summary>
/// 声明一个静态方法,获取选择的布局
/// </summary>
/// <returns>返回当前布局</returns>
public static string GetSelectLayout()
{
return SettingInfo.CurrLayout;
}
/// <summary>
/// 获取生产代码,
/// </summary>
/// <returns>字符串类型的集合</returns>
public static List<string> GetProductionCodes()
{
if (SettingInfo.ProductionCodes.Count == 0)
{
SettingInfo.ProductionCodes.Add("Default");
}
if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProduction))
{
if (SettingInfo.ProductionCodes.Contains(SettingInfo.DefaultProduction))
{
SettingInfo.ProductionCodes.Remove(SettingInfo.DefaultProduction);
SettingInfo.ProductionCodes.Insert(0, SettingInfo.DefaultProduction);
}
}
return SettingInfo.ProductionCodes;
}
/// <summary>
/// 获取过程代码
/// </summary>
/// <returns></returns>
public static List<string> GetProcessCodes()
{
if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProcess))
{
if (SettingInfo.ProcessCodes.Contains(SettingInfo.DefaultProcess))
{
SettingInfo.ProcessCodes.Remove(SettingInfo.DefaultProcess);
SettingInfo.ProcessCodes.Insert(0, SettingInfo.DefaultProcess);
}
}
return SettingInfo.ProcessCodes;
}
2023-03-24 17:02:04 +08:00
public static string GetProgramDescription()
{
if (string.IsNullOrWhiteSpace(SettingInfo.Description))
{
SettingInfo.Description = "";
}
return SettingInfo.Description;
}
2023-03-24 09:58:42 +08:00
2023-03-24 17:02:04 +08:00
public static string GetProgramIcon()
{
string iconPath = SettingInfo.IconPath;
if (string.IsNullOrWhiteSpace(iconPath) || !File.Exists(iconPath))
{
iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico");
}
if (!File.Exists(iconPath))
{
iconPath = "";
}
return iconPath;
}
2023-03-24 09:58:42 +08:00
}
/// <summary>
/// 设置信息类,声明自动属性
/// </summary>
public class SettingInfo
{
public List<string> ProcessCodes { get; set; } = new List<string>();
public List<string> ProductionCodes { get; set; } = new List<string>();
public string DefaultProcess { get; set; }
public string DefaultProduction { get; set; }
2023-03-24 17:02:04 +08:00
public string IconPath { get; set; }
public string Description { get; set; }
2023-03-24 09:58:42 +08:00
public string CurrLayout { get; set; } = "";
2023-03-24 17:02:04 +08:00
2023-03-24 09:58:42 +08:00
}
}