You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DS7/DSWeb/ConfigManager/ConfigManager.cs

94 lines
2.7 KiB
C#

2 years ago
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Xml;
using DSWeb.Models;
using System.Web;
namespace DSWeb.ConfigManager
{
public class ConfigManager
{
private static ConfigManager configManager = new ConfigManager();
private ConfigManager() { }
public static ConfigManager Instance()
{
return configManager;
}
public object GetConfigInfo(ConfigType tempConfigType)
{
object resultObj = null;
switch (tempConfigType)
{
case ConfigType.INVOICECONFIG:
IList<InvoiceConfigEntity> invoiceConfigEntities = new List<InvoiceConfigEntity>();
XmlNode xmlNode = GetXmlConfigObj("configs/config.xml", "invoice");
int iCount = 0;
for (int i = 0; i < xmlNode.ChildNodes.Count; i++)
{
InvoiceConfigEntity invoiceConfigEntity = new InvoiceConfigEntity();
invoiceConfigEntity.ItemName = xmlNode.ChildNodes[i].Name;
invoiceConfigEntity.ItemValue = xmlNode.ChildNodes[i].InnerText;
invoiceConfigEntities.Add(invoiceConfigEntity);
iCount++;
}
if (iCount > 0)
{
resultObj = invoiceConfigEntities;
}
else
{
resultObj = invoiceConfigEntities;
}
break;
case ConfigType.USERSETTING:
break;
}
return resultObj;
}
private XmlNode GetXmlConfigObj(string tempXmlUrl, string tempNodeName)
{
XmlDocument xmlDoc = new XmlDocument();
XmlNode tempNode = null;
string currentUrl = HttpContext.Current.Request.Url.AbsoluteUri;
string xmlUrl = currentUrl.Substring(0, currentUrl.Substring(0, currentUrl.LastIndexOf("/")).LastIndexOf("/") + 1) + tempXmlUrl;
try
{
xmlDoc.Load(xmlUrl);
for(int i=0;i<xmlDoc.ChildNodes[1].ChildNodes.Count;i++)
{
if (xmlDoc.ChildNodes[1].ChildNodes[i].Name.Trim().ToLower().Equals(tempNodeName))
{
tempNode = xmlDoc.ChildNodes[1].ChildNodes[i];
}
}
}
catch(Exception)
{
}
return tempNode;
}
}
public enum ConfigType
{
INVOICECONFIG = 0,
USERSETTING = 1
}
}