From d06507ffdbad5db95156e114d5e8a0f89672529a Mon Sep 17 00:00:00 2001 From: patrick.xu <patrick.xu@broconcentric.com> Date: 星期二, 02 二月 2021 08:43:07 +0800 Subject: [PATCH] MES上传数据checkTime参数更改为DateTime类型 --- src/Bro.Common.Model/Helper/SettingHelper.cs | 209 +++++++++++++++++++++++++++++---------------------- 1 files changed, 119 insertions(+), 90 deletions(-) diff --git a/src/Bro.Common.Model/Helper/SettingHelper.cs b/src/Bro.Common.Model/Helper/SettingHelper.cs index a14100e..f22e684 100644 --- a/src/Bro.Common.Model/Helper/SettingHelper.cs +++ b/src/Bro.Common.Model/Helper/SettingHelper.cs @@ -7,137 +7,166 @@ namespace Bro.Common.Helper { - public class SettingHelper + public static class SettingHelper { const string SETTINGFILE = "Setting.json"; - const string PROPERTY_PRODUCTIONCODES = "ProductionCodes"; - const string PROPERTY_CONFIGPATH = "ConfigPath"; - const string PROPERTY_PROCESSCODES = "ProcessCodes"; - const string PROPERTY_DESCRIPTION = "Description"; - const string PROPERTY_ICONPATH = "IconPath"; - static string ConfigPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE); - //static JObject data = null; - //static JObject Data - //{ - // get - // { - // if (File.Exists(ConfigPath)) - // { - // using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8)) - // { - // string dataStr = reader.ReadToEnd(); - // data = JsonConvert.DeserializeObject<JObject>(dataStr); - // } - // } - // return data; - // } - //} + public static SettingInfo SettingInfo = null; + static string SettingPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE); - public static JObject GetSettingData() + static SettingHelper() { - JObject settingData = null; - if (File.Exists(ConfigPath)) + if (File.Exists(SettingPath)) { - using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8)) + using (StreamReader reader = new StreamReader(SettingPath, System.Text.Encoding.UTF8)) { string dataStr = reader.ReadToEnd(); - settingData = JsonConvert.DeserializeObject<JObject>(dataStr); + SettingInfo = JsonConvert.DeserializeObject<SettingInfo>(dataStr); } } - return settingData; } public static List<string> GetProductionCodes() { - List<string> codes = new List<string>(); - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES)) + if (SettingInfo.ProductionCodes.Count == 0) { - codes = Data.Value<JArray>(PROPERTY_PRODUCTIONCODES).ToList().ConvertAll(u => u.ToString()); + SettingInfo.ProductionCodes.Add("Default"); } - if (codes.Count == 0) + if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProduction)) { - codes.Add("Default"); + if (SettingInfo.ProductionCodes.Contains(SettingInfo.DefaultProduction)) + { + SettingInfo.ProductionCodes.Remove(SettingInfo.DefaultProduction); + SettingInfo.ProductionCodes.Insert(0, SettingInfo.DefaultProduction); + } } - return codes; + return SettingInfo.ProductionCodes; } public static List<string> GetProcessCodes() { - List<string> codes = new List<string>(); - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_PROCESSCODES)) + if (!string.IsNullOrWhiteSpace(SettingInfo.DefaultProcess)) { - codes = Data.Value<JArray>(PROPERTY_PROCESSCODES).ToList().ConvertAll(u => u.ToString()); + if (SettingInfo.ProcessCodes.Contains(SettingInfo.DefaultProcess)) + { + SettingInfo.ProcessCodes.Remove(SettingInfo.DefaultProcess); + SettingInfo.ProcessCodes.Insert(0, SettingInfo.DefaultProcess); + } } - return codes; + + return SettingInfo.ProcessCodes; } - public static List<string> AddNewProductionCode(string code) + public static void AddNewProductionCode(string code) { - var dataTemp = GetSettingData(); - if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) + if (!SettingInfo.ProductionCodes.Contains(code)) { - List<string> codes = GetProductionCodes(); - if (!codes.Contains(code)) - { - codes.Add(code); - } - dataTemp[PROPERTY_PRODUCTIONCODES] = new JArray(codes); + SettingInfo.ProductionCodes.Add(code); + } - string newDataStr = JsonConvert.SerializeObject(dataTemp, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); - using (StreamWriter writer = new StreamWriter(ConfigPath, false, System.Text.Encoding.UTF8)) + SaveSettingInfo(); + } + + public static string GetConfigFilePath() + { + return SettingInfo.ConfigPath; + } + + public static string GetProgramDescription() + { + if (string.IsNullOrWhiteSpace(SettingInfo.Description)) + { + SettingInfo.Description = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�"; + } + + return SettingInfo.Description; + } + + 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; + } + + #region 淇濆瓨 + public static void SetDefaultProcess(string processCode) + { + if (SettingInfo.DefaultProcess != processCode) + { + SettingInfo.DefaultProcess = processCode; + SaveSettingInfo(); + } + } + + public static void SetDefaultProduction(string productionCode) + { + if (SettingInfo.DefaultProduction != productionCode) + { + SettingInfo.DefaultProduction = productionCode; + SaveSettingInfo(); + } + } + + public static void SetDefault(string processCode,string productionCode) + { + bool isChanged = false; + if (SettingInfo.DefaultProcess != processCode) + { + isChanged = true; + SettingInfo.DefaultProcess = processCode; + } + + if (SettingInfo.DefaultProduction != productionCode) + { + isChanged = true; + SettingInfo.DefaultProduction = productionCode; + } + + if (isChanged) + { + SaveSettingInfo(); + } + } + + static object saveLock = new object(); + private static void SaveSettingInfo() + { + string newDataStr = JsonConvert.SerializeObject(SettingInfo); + lock (saveLock) + { + using (StreamWriter writer = new StreamWriter(SettingPath, false, System.Text.Encoding.UTF8)) { writer.Write(newDataStr); writer.Flush(); writer.Close(); } } - return GetProductionCodes(); } + #endregion + } - public static string GetConfigFilePath() - { - string path = ""; - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_CONFIGPATH)) - { - path = Data.Value<string>(PROPERTY_CONFIGPATH); - } + public class SettingInfo + { + public List<string> ProcessCodes { get; set; } = new List<string>(); + public List<string> ProductionCodes { get; set; } = new List<string>(); - return path; - } + public string DefaultProcess { get; set; } - public static string GetProgramDescription() - { - string desc = "浼偗妫嚜鍔ㄥ寲鎶�鏈湁闄愬叕鍙�"; - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_DESCRIPTION)) - { - desc = Data.Value<string>(PROPERTY_DESCRIPTION); - } + public string DefaultProduction { get; set; } - return desc; - } - - public static string GetProgramIcon() - { - string iconPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logo.ico"); - - if (!File.Exists(iconPath)) - { - iconPath = ""; - } - var Data = GetSettingData(); - if (Data != null && Data.ContainsKey(PROPERTY_ICONPATH)) - { - iconPath = Data.Value<string>(PROPERTY_ICONPATH); - } - - return iconPath; - } + public string ConfigPath { get; set; } + public string Description { get; set; } + public string IconPath { get; set; } } } -- Gitblit v1.8.0