You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.0 KiB
67 lines
2.0 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Text;
|
|
using System.Xml;
|
|
using System.Windows.Forms;
|
|
|
|
namespace SiaSun.LMS.Common
|
|
{
|
|
public static class AppSettings
|
|
{
|
|
public static string AppConfig()
|
|
{
|
|
return (Application.ExecutablePath.Substring(0,(Application.ExecutablePath.Length)) +".config");
|
|
}
|
|
|
|
public static string GetValue(string appKey)
|
|
{
|
|
XmlDocument xDoc = new XmlDocument();
|
|
try
|
|
{
|
|
xDoc.Load(AppSettings.AppConfig());
|
|
XmlNode xNode;
|
|
XmlElement xElem;
|
|
xNode = xDoc.SelectSingleNode("//appSettings");
|
|
xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
|
|
if (xElem != null)
|
|
return xElem.GetAttribute("value");
|
|
else
|
|
return "";
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return "";
|
|
}
|
|
}
|
|
|
|
public static void SetValue(string AppKey, string AppValue)
|
|
{
|
|
try
|
|
{
|
|
XmlDocument xDoc = new XmlDocument();
|
|
xDoc.Load(AppSettings.AppConfig());
|
|
XmlNode xNode;
|
|
XmlElement xElem1;
|
|
XmlElement xElem2;
|
|
xNode = xDoc.SelectSingleNode("//appSettings");
|
|
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
|
|
if (xElem1 != null)
|
|
{
|
|
xElem1.SetAttribute("value", AppValue);
|
|
}
|
|
else
|
|
{
|
|
xElem2 = xDoc.CreateElement("add");
|
|
xElem2.SetAttribute("key", AppKey);
|
|
xElem2.SetAttribute("value", AppValue);
|
|
xNode.AppendChild(xElem2);
|
|
}
|
|
xDoc.Save(AppSettings.AppConfig());
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
throw ex;
|
|
}
|
|
}
|
|
}
|
|
}
|