public static double GetConfigValue(string keyname, double defaultValue)
{
XmlDocument oXml = null;
XmlNodeList oList = null;
try
{
string pConfigFiles = GetConfigFile();
string keyvalue = "";
if (File.Exists(pConfigFiles))
{
oXml = new XmlDocument();
oXml.Load(pConfigFiles);
oList = oXml.GetElementsByTagName("appSettings");
if (oList == null) return defaultValue;
foreach (XmlNode oNode in oList)
{
foreach (XmlNode oKey in oNode.ChildNodes)
{
if ((oKey != null) && (oKey.Attributes != null))
{
if (oKey.Attributes["key"].Value.Equals(keyname))
{
if (oKey.Attributes["value"].Value.Trim().Length > 0)
{
keyvalue = oKey.Attributes["value"].Value;
//Try to convert to double
if (Globals.IsDouble(keyvalue))
{
return (Convert.ToDouble(keyvalue));
}
}
}
}
}
}
oXml = null;
}
return defaultValue;
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message + "\nTypically an error here is from an improperly formatted config file. \nThe structure(XML) is compromised by a change you made.");
return defaultValue;
}
finally
{
oXml = null;
oList = null;
}
}