32 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			32 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
| 
								 | 
							
								using System;
							 | 
						|||
| 
								 | 
							
								using System.Collections.Generic;
							 | 
						|||
| 
								 | 
							
								using System.Configuration;
							 | 
						|||
| 
								 | 
							
								using System.Linq;
							 | 
						|||
| 
								 | 
							
								using System.Text;
							 | 
						|||
| 
								 | 
							
								using System.Threading.Tasks;
							 | 
						|||
| 
								 | 
							
								using System.Xml;
							 | 
						|||
| 
								 | 
							
								
							 | 
						|||
| 
								 | 
							
								namespace DM_Weight.Common
							 | 
						|||
| 
								 | 
							
								{
							 | 
						|||
| 
								 | 
							
								    public class CommonClass
							 | 
						|||
| 
								 | 
							
								    {
							 | 
						|||
| 
								 | 
							
								        //手动实现调用配置的逻辑 规避修改配置文件后不起作用的问题
							 | 
						|||
| 
								 | 
							
								        public static string ReadAppSetting(string key)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            string xPath = "/configuration/appSettings//add[@key='" + key + "']";
							 | 
						|||
| 
								 | 
							
								            XmlDocument doc = new XmlDocument();
							 | 
						|||
| 
								 | 
							
								            string exeFileName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name;
							 | 
						|||
| 
								 | 
							
								            doc.Load(exeFileName + ".dll.config");
							 | 
						|||
| 
								 | 
							
								            XmlNode node = doc.SelectSingleNode(xPath);
							 | 
						|||
| 
								 | 
							
								            return node.Attributes["value"].Value;
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								        public static void SaveAppSetting(string key,string value)
							 | 
						|||
| 
								 | 
							
								        {
							 | 
						|||
| 
								 | 
							
								            Configuration _configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
							 | 
						|||
| 
								 | 
							
								            _configuration.AppSettings.Settings[key].Value = value;
							 | 
						|||
| 
								 | 
							
								            _configuration.Save();
							 | 
						|||
| 
								 | 
							
								            ConfigurationManager.RefreshSection(key);
							 | 
						|||
| 
								 | 
							
								        }
							 | 
						|||
| 
								 | 
							
								    }
							 | 
						|||
| 
								 | 
							
								}
							 |