| | |
| | | const string PROPERTY_DESCRIPTION = "Description"; |
| | | const string PROPERTY_ICONPATH = "IconPath"; |
| | | |
| | | static JObject data = null; |
| | | static JObject Data |
| | | { |
| | | get |
| | | { |
| | | string configPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SETTINGFILE); |
| | | if (File.Exists(configPath)) |
| | | { |
| | | using (StreamReader reader = new StreamReader(configPath, System.Text.Encoding.UTF8)) |
| | | { |
| | | string dataStr = reader.ReadToEnd(); |
| | | data = JsonConvert.DeserializeObject<JObject>(dataStr); |
| | | } |
| | | } |
| | | 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; |
| | | // } |
| | | //} |
| | | |
| | | return data; |
| | | public static JObject GetSettingData() |
| | | { |
| | | JObject settingData = null; |
| | | if (File.Exists(ConfigPath)) |
| | | { |
| | | using (StreamReader reader = new StreamReader(ConfigPath, System.Text.Encoding.UTF8)) |
| | | { |
| | | string dataStr = reader.ReadToEnd(); |
| | | settingData = JsonConvert.DeserializeObject<JObject>(dataStr); |
| | | } |
| | | } |
| | | return settingData; |
| | | } |
| | | |
| | | public static List<string> GetProductionCodes() |
| | | { |
| | | List<string> codes = new List<string>(); |
| | | |
| | | var Data = GetSettingData(); |
| | | if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES)) |
| | | { |
| | | codes = Data.Value<JArray>(PROPERTY_PRODUCTIONCODES).ToList().ConvertAll(u => u.ToString()); |
| | |
| | | public static List<string> GetProcessCodes() |
| | | { |
| | | List<string> codes = new List<string>(); |
| | | |
| | | var Data = GetSettingData(); |
| | | if (Data != null && Data.ContainsKey(PROPERTY_PROCESSCODES)) |
| | | { |
| | | codes = Data.Value<JArray>(PROPERTY_PROCESSCODES).ToList().ConvertAll(u => u.ToString()); |
| | |
| | | return codes; |
| | | } |
| | | |
| | | public static List<string> AddNewProductionCode(string code) |
| | | public static void AddNewProductionCode(string code) |
| | | { |
| | | List<string> codes = GetProcessCodes(); |
| | | if (!codes.Contains(code)) |
| | | var dataTemp = GetSettingData(); |
| | | |
| | | if (!dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) |
| | | { |
| | | codes.Add(code); |
| | | dataTemp.Add(PROPERTY_PRODUCTIONCODES, new JArray()); |
| | | } |
| | | if (Data != null && Data.ContainsKey(PROPERTY_PRODUCTIONCODES)) |
| | | |
| | | if (dataTemp != null && dataTemp.ContainsKey(PROPERTY_PRODUCTIONCODES)) |
| | | { |
| | | Data[PROPERTY_PRODUCTIONCODES] = new JArray(codes); |
| | | string newDataStr = JsonConvert.SerializeObject(Data, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); |
| | | using (StreamWriter writer = new StreamWriter(GetSettingFilePath(), false, System.Text.Encoding.UTF8)) |
| | | List<string> codes = GetProductionCodes(); |
| | | if (!codes.Contains(code)) |
| | | { |
| | | codes.Add(code); |
| | | } |
| | | dataTemp[PROPERTY_PRODUCTIONCODES] = new JArray(codes); |
| | | |
| | | string newDataStr = JsonConvert.SerializeObject(dataTemp, new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.Auto }); |
| | | using (StreamWriter writer = new StreamWriter(ConfigPath, false, System.Text.Encoding.UTF8)) |
| | | { |
| | | writer.Write(newDataStr); |
| | | writer.Flush(); |
| | | writer.Close(); |
| | | } |
| | | } |
| | | |
| | | return GetProcessCodes(); |
| | | } |
| | | |
| | | public static string GetConfigFilePath() |
| | | { |
| | | string path = ""; |
| | | |
| | | var Data = GetSettingData(); |
| | | if (Data != null && Data.ContainsKey(PROPERTY_CONFIGPATH)) |
| | | { |
| | | path = Data.Value<string>(PROPERTY_CONFIGPATH); |
| | |
| | | return path; |
| | | } |
| | | |
| | | public static string GetSettingFilePath() |
| | | { |
| | | string path = ""; |
| | | |
| | | if (Data != null && Data.ContainsKey(SETTINGFILE)) |
| | | { |
| | | path = Data.Value<string>(SETTINGFILE); |
| | | } |
| | | |
| | | return path; |
| | | } |
| | | |
| | | public static string GetProgramDescription() |
| | | { |
| | | string desc = "伯肯森自动化技术有限公司"; |
| | | |
| | | var Data = GetSettingData(); |
| | | if (Data != null && Data.ContainsKey(PROPERTY_DESCRIPTION)) |
| | | { |
| | | desc = Data.Value<string>(PROPERTY_DESCRIPTION); |
| | |
| | | { |
| | | iconPath = ""; |
| | | } |
| | | |
| | | var Data = GetSettingData(); |
| | | if (Data != null && Data.ContainsKey(PROPERTY_ICONPATH)) |
| | | { |
| | | iconPath = Data.Value<string>(PROPERTY_ICONPATH); |