908 lines
32 KiB
C#
908 lines
32 KiB
C#
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using Ease.CoreV35;
|
|||
|
using Ease.CoreV35.Model;
|
|||
|
using Ease.CoreV35.Caching;
|
|||
|
using System.Data.Linq.Mapping;
|
|||
|
using System.Xml;
|
|||
|
namespace Payroll.BO
|
|||
|
{
|
|||
|
#region Configaration
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class Configaration :AuditTrailBase
|
|||
|
{
|
|||
|
#region Cache Store
|
|||
|
|
|||
|
private static Cache _cache = new Cache(typeof(Payroll.BO.Configaration));
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Constructor
|
|||
|
|
|||
|
public Configaration()
|
|||
|
{
|
|||
|
_node = string.Empty;
|
|||
|
_value = string.Empty;
|
|||
|
_parentID = null;
|
|||
|
_type = EnumConfigurationType.None;
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Properties
|
|||
|
|
|||
|
#region Node : string
|
|||
|
|
|||
|
private string _node;
|
|||
|
public string Node
|
|||
|
{
|
|||
|
get { return _node; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<string>("Node", _node, value);
|
|||
|
_node = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Value : string
|
|||
|
|
|||
|
private string _value;
|
|||
|
public string Value
|
|||
|
{
|
|||
|
get { return _value; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<string>("Value", _value, value);
|
|||
|
_value = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region ParentID : ID
|
|||
|
|
|||
|
private ID _parentID;
|
|||
|
public ID ParentID
|
|||
|
{
|
|||
|
get { return _parentID; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<ID>("ParentID", _parentID, value);
|
|||
|
_parentID = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Type : EnumConfigurationType
|
|||
|
|
|||
|
private EnumConfigurationType _type;
|
|||
|
public EnumConfigurationType Type
|
|||
|
{
|
|||
|
get { return _type; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<short>("Type",(short)_type,(short) value);
|
|||
|
_type = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region ConfigurationAttribute
|
|||
|
[Serializable]
|
|||
|
public class ConfigurationAttribute : ObjectTemplate
|
|||
|
{
|
|||
|
#region Constructor
|
|||
|
public ConfigurationAttribute()
|
|||
|
{
|
|||
|
_configurationID = null;
|
|||
|
_value = "";
|
|||
|
_attributeName = "";
|
|||
|
}
|
|||
|
public ConfigurationAttribute(ID configurationID)
|
|||
|
{
|
|||
|
_configurationID = configurationID;
|
|||
|
_value = "";
|
|||
|
_attributeName = "";
|
|||
|
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
#region Property ParentID : ID
|
|||
|
|
|||
|
private ID _configurationID;
|
|||
|
public ID ConfigurationID
|
|||
|
{
|
|||
|
get { return _configurationID; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<ID>("configurationID", _configurationID, value);
|
|||
|
_configurationID = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region AttributeName : string
|
|||
|
|
|||
|
private string _attributeName;
|
|||
|
public string AttributeName
|
|||
|
{
|
|||
|
get { return _attributeName; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<string>("AttributeName", _attributeName, value);
|
|||
|
_attributeName = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Value : String
|
|||
|
|
|||
|
private string _value;
|
|||
|
public string Value
|
|||
|
{
|
|||
|
get { return _value; }
|
|||
|
set
|
|||
|
{
|
|||
|
base.OnPropertyChange<string>("Value", _value, value);
|
|||
|
_value = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
public new void SetID(ID id)
|
|||
|
{
|
|||
|
base.SetID(id);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region ConfigurationAttributes
|
|||
|
[Serializable]
|
|||
|
public class ConfigurationAttributes : ObjectsTemplate<ConfigurationAttribute>
|
|||
|
{
|
|||
|
#region Constructor
|
|||
|
public ConfigurationAttributes()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public ConfigurationAttribute GetItemByParentID(ID configurationID)
|
|||
|
{
|
|||
|
return this.Find(delegate(ConfigurationAttribute item) { return item.ConfigurationID == configurationID; });
|
|||
|
}
|
|||
|
|
|||
|
public void Add(ID configurationId, string nodeName, string svalue)
|
|||
|
{
|
|||
|
ConfigurationAttribute att = new ConfigurationAttribute();
|
|||
|
att.Value = svalue;
|
|||
|
att.AttributeName = nodeName;
|
|||
|
att.SetID(ID.FromInteger(this.Count + 1));
|
|||
|
this.Add(att);
|
|||
|
}
|
|||
|
public string GetAttributeValue(string attributeName)
|
|||
|
{
|
|||
|
foreach (ConfigurationAttribute oItem in this)
|
|||
|
{
|
|||
|
if (oItem.AttributeName.ToLower() == attributeName.ToLower())
|
|||
|
{
|
|||
|
return oItem.Value;
|
|||
|
}
|
|||
|
}
|
|||
|
return "";
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Property ConfigurationAttributes : ConfigurationAttributes
|
|||
|
|
|||
|
private ConfigurationAttributes _configurationAttributes;
|
|||
|
public ConfigurationAttributes ConAttributes
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
if (_configurationAttributes == null)
|
|||
|
_configurationAttributes = new ConfigurationAttributes();
|
|||
|
|
|||
|
return _configurationAttributes;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Service Factory IConfigarationService : IConfigarationService
|
|||
|
|
|||
|
internal static IConfigarationService Service
|
|||
|
{
|
|||
|
get { return Services.Factory.CreateService<IConfigarationService>(typeof(IConfigarationService)); }
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
#region Functions
|
|||
|
|
|||
|
//public Configaration Get(ID nID)
|
|||
|
//{
|
|||
|
// Configaration oConfigaration = null;
|
|||
|
// //#region Cache Header
|
|||
|
// //oConfigaration = (Configaration)_cache["Get", ID];
|
|||
|
// //if (oConfigaration != null)
|
|||
|
// // return oConfigaration;
|
|||
|
// //#endregion
|
|||
|
// oConfigaration = Configaration.Service.Get(ID);
|
|||
|
// //#region Cache Footer
|
|||
|
// //_cache.Add(oConfigaration, "Get", ID);
|
|||
|
// //#endregion
|
|||
|
// return oConfigaration;
|
|||
|
//}
|
|||
|
//public ID Save()
|
|||
|
//{
|
|||
|
|
|||
|
// return Configaration.Service.Save(this);
|
|||
|
//}
|
|||
|
//public void Delete()
|
|||
|
//{
|
|||
|
// Configaration.Service.Delete(ID);
|
|||
|
//}
|
|||
|
|
|||
|
public Configaration Get(ID id)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
Configaration configuration = _cache["Get", id] as Configaration;
|
|||
|
|
|||
|
if (configuration != null)
|
|||
|
return configuration;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
configuration = Service.Get(id);
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
#region Cache Footer
|
|||
|
|
|||
|
_cache.Add(configuration, "Get", id);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
return configuration;
|
|||
|
}
|
|||
|
public static ObjectsTemplate<Configaration> Get(EnumConfigurationType configType)
|
|||
|
{
|
|||
|
#region Cache Header
|
|||
|
|
|||
|
ObjectsTemplate<Configaration> cofigurations = _cache["Get", configType] as ObjectsTemplate<Configaration>;
|
|||
|
if (cofigurations != null)
|
|||
|
return cofigurations;
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
cofigurations = Service.Get(configType);
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
#region Cache Footer
|
|||
|
|
|||
|
_cache.Add(cofigurations, "Get", configType);
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
|
|||
|
return cofigurations;
|
|||
|
}
|
|||
|
public void Save(ObjectsTemplate<Configaration> configurations, EnumConfigurationType confictype)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
foreach (Configaration conf in configurations)
|
|||
|
{
|
|||
|
conf.SetAuditTrailProperties();
|
|||
|
}
|
|||
|
DolowerCase(configurations);
|
|||
|
Service.Save(configurations, confictype);
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
}
|
|||
|
private void DolowerCase(ObjectsTemplate<Configaration> configs)
|
|||
|
{
|
|||
|
foreach (Configaration item in configs)
|
|||
|
{
|
|||
|
item.Node = item.Node.ToLower();
|
|||
|
foreach (ConfigurationAttribute att in item.ConAttributes)
|
|||
|
{
|
|||
|
att.AttributeName = att.AttributeName.ToLower();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
public void Delete(ID attributeID)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
Service.Delete(attributeID);
|
|||
|
|
|||
|
//Clear Cache
|
|||
|
//CacheInfo.ClearCache(typeof(Country).FullName);
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static ObjectsTemplate<Configaration.ConfigurationAttribute> GetAttributesByParentID(int nParentID)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration.ConfigurationAttribute> cofigurations = new ObjectsTemplate<Configaration.ConfigurationAttribute>();
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
cofigurations = Service.GetAttributesByParentID(nParentID);
|
|||
|
}
|
|||
|
catch (ServiceException e)
|
|||
|
{
|
|||
|
throw new Exception(e.Message, e);
|
|||
|
}
|
|||
|
|
|||
|
return cofigurations;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration.ConfigurationAttribute> GetAllChildren()
|
|||
|
{
|
|||
|
return Configaration.Service.GetAllChildren();
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
public void SetObjectID(ID id)
|
|||
|
{
|
|||
|
base.SetID(id);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region IConfigaration Service
|
|||
|
|
|||
|
public interface IConfigarationService
|
|||
|
{
|
|||
|
Configaration Get(ID id);
|
|||
|
ObjectsTemplate<Configaration> Get(EnumConfigurationType confictype);
|
|||
|
void Save(ObjectsTemplate<Configaration> configurations, EnumConfigurationType confictype);
|
|||
|
void Delete(ID id);
|
|||
|
ObjectsTemplate<Configaration.ConfigurationAttribute> GetAllChildrens();
|
|||
|
ObjectsTemplate<Configaration.ConfigurationAttribute> GetAllChildren();
|
|||
|
ObjectsTemplate<Configaration> GetAllParent(EnumConfigurationType type);
|
|||
|
ObjectsTemplate<Configaration> GetAllParent();
|
|||
|
ObjectsTemplate<Configaration.ConfigurationAttribute> GetAttributesByParentID(int nParentID);
|
|||
|
}
|
|||
|
|
|||
|
#endregion
|
|||
|
|
|||
|
[Serializable]
|
|||
|
public class ConfigurationManager
|
|||
|
{
|
|||
|
public ConfigurationManager()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
private static ObjectsTemplate<Configaration> _logicCofiguration;
|
|||
|
private static ObjectsTemplate<Configaration> _uiCofiguration;
|
|||
|
private static ObjectsTemplate<Configaration> _menuCofiguration;
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration> LogicConfiguration
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _logicCofiguration;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration> UICofiguration
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _uiCofiguration;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration> MenuCofiguration
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _menuCofiguration;
|
|||
|
}
|
|||
|
}
|
|||
|
public void SetStaticConfiguration(ObjectsTemplate<Configaration> configs, EnumConfigurationType type)
|
|||
|
{
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case EnumConfigurationType.UI:
|
|||
|
_uiCofiguration = configs;
|
|||
|
break;
|
|||
|
case EnumConfigurationType.Logic:
|
|||
|
_logicCofiguration = configs;
|
|||
|
break;
|
|||
|
case EnumConfigurationType.Menu:
|
|||
|
_menuCofiguration = configs;
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
//public void LoadConfiguration()
|
|||
|
//{
|
|||
|
// _logicCofiguration = Configaration.Service.Get(EnumConfigurationType.Logic);
|
|||
|
// _uiCofiguration = Configaration.Service.Get(EnumConfigurationType.UI);
|
|||
|
// _menuCofiguration = Configaration.Service.Get(EnumConfigurationType.Menu);
|
|||
|
//}
|
|||
|
public void LoadConfiguration()
|
|||
|
{
|
|||
|
|
|||
|
List<Configaration> oAllParents = this.GetAllParent();
|
|||
|
List<Configaration.ConfigurationAttribute> oAllChilds = this.GetAllChildrens();
|
|||
|
ObjectsTemplate<Configaration> logicParents = new ObjectsTemplate<Configaration>();
|
|||
|
ObjectsTemplate<Configaration> uiParents = new ObjectsTemplate<Configaration>();
|
|||
|
ObjectsTemplate<Configaration> menuParents = new ObjectsTemplate<Configaration>();
|
|||
|
foreach (Configaration item in oAllParents)
|
|||
|
{
|
|||
|
if (item.Type == EnumConfigurationType.Logic)
|
|||
|
logicParents.Add(item);
|
|||
|
}
|
|||
|
foreach (Configaration item in oAllParents)
|
|||
|
{
|
|||
|
if (item.Type == EnumConfigurationType.UI)
|
|||
|
uiParents.Add(item);
|
|||
|
}
|
|||
|
foreach (Configaration item in oAllParents)
|
|||
|
{
|
|||
|
if (item.Type == EnumConfigurationType.Menu)
|
|||
|
menuParents.Add(item);
|
|||
|
}
|
|||
|
|
|||
|
foreach (Configaration item in logicParents)
|
|||
|
{
|
|||
|
List<Configaration.ConfigurationAttribute> oChilds = oAllChilds.FindAll(delegate(Configaration.ConfigurationAttribute child) { return child.ConfigurationID == item.ID; });
|
|||
|
foreach (Configaration.ConfigurationAttribute con in oChilds)
|
|||
|
item.ConAttributes.Add(con);
|
|||
|
}
|
|||
|
foreach (Configaration item in uiParents)
|
|||
|
{
|
|||
|
List<Configaration.ConfigurationAttribute> oChilds = oAllChilds.FindAll(delegate(Configaration.ConfigurationAttribute child) { return child.ConfigurationID == item.ID; });
|
|||
|
foreach (Configaration.ConfigurationAttribute con in oChilds)
|
|||
|
item.ConAttributes.Add(con);
|
|||
|
}
|
|||
|
foreach (Configaration item in menuParents)
|
|||
|
{
|
|||
|
List<Configaration.ConfigurationAttribute> oChilds = oAllChilds.FindAll(delegate(Configaration.ConfigurationAttribute child) { return child.ConfigurationID == item.ID; });
|
|||
|
foreach (Configaration.ConfigurationAttribute con in oChilds)
|
|||
|
item.ConAttributes.Add(con);
|
|||
|
}
|
|||
|
_logicCofiguration = logicParents;
|
|||
|
_uiCofiguration = uiParents;
|
|||
|
_menuCofiguration = menuParents;
|
|||
|
}
|
|||
|
public static ObjectsTemplate<Configaration> LogicCofiguration
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _logicCofiguration;
|
|||
|
}
|
|||
|
}
|
|||
|
public ObjectsTemplate<Configaration> GetAllParent(EnumConfigurationType type)
|
|||
|
{
|
|||
|
return Configaration.Service.GetAllParent(type);
|
|||
|
}
|
|||
|
public ObjectsTemplate<Configaration> GetAllParent()
|
|||
|
{
|
|||
|
return Configaration.Service.GetAllParent();
|
|||
|
}
|
|||
|
public ObjectsTemplate<Configaration.ConfigurationAttribute> GetAllChildrens()
|
|||
|
{
|
|||
|
return Configaration.Service.GetAllChildrens();
|
|||
|
}
|
|||
|
public static ObjectsTemplate<Configaration> UIConfiguration
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _uiCofiguration;
|
|||
|
}
|
|||
|
}
|
|||
|
private void GetChilds(ObjectsTemplate<Configaration> Source, ObjectsTemplate<Configaration> destination
|
|||
|
, Configaration parent)
|
|||
|
{
|
|||
|
IEnumerable<Configaration> Items = from Cnfgs in Source
|
|||
|
where Cnfgs.ParentID == parent.ID
|
|||
|
select Cnfgs;
|
|||
|
|
|||
|
if (Items == null) return;
|
|||
|
foreach (var item in Items)
|
|||
|
{
|
|||
|
destination.Add(item);
|
|||
|
GetChilds(Source, destination, item);
|
|||
|
}
|
|||
|
}
|
|||
|
public ObjectsTemplate<Configaration> GetChilds(string NodeName
|
|||
|
, EnumConfigurationType type)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration> destinations = new ObjectsTemplate<Configaration>();
|
|||
|
|
|||
|
ObjectsTemplate<Configaration> SourceObject = getSource(type);
|
|||
|
Configaration fParent = SourceObject.Find(delegate(Configaration item) { return (item.Node == NodeName); });
|
|||
|
if (fParent != null) GetChilds(SourceObject, destinations, fParent);
|
|||
|
|
|||
|
return destinations;
|
|||
|
}
|
|||
|
private ObjectsTemplate<Configaration> getSource(EnumConfigurationType type)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration> SourceObject = null;
|
|||
|
switch (type)
|
|||
|
{
|
|||
|
case EnumConfigurationType.UI:
|
|||
|
SourceObject = _uiCofiguration;
|
|||
|
break;
|
|||
|
case EnumConfigurationType.Logic:
|
|||
|
SourceObject = _logicCofiguration;
|
|||
|
break;
|
|||
|
case EnumConfigurationType.Menu:
|
|||
|
SourceObject = _menuCofiguration;
|
|||
|
break;
|
|||
|
default:
|
|||
|
throw new ServiceException("Invalid configuration type");
|
|||
|
break;
|
|||
|
}
|
|||
|
return SourceObject;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration> GetChilds(ID configid, EnumConfigurationType type)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration> destinations = new ObjectsTemplate<Configaration>();
|
|||
|
ObjectsTemplate<Configaration> SourceObject = getSource(type);
|
|||
|
Configaration fParent = SourceObject.Find(delegate(Configaration item) { return (item.ID == configid); });
|
|||
|
if (fParent != null) GetChilds(SourceObject, destinations, fParent);
|
|||
|
|
|||
|
return destinations;
|
|||
|
}
|
|||
|
|
|||
|
public ObjectsTemplate<Configaration> GetChilds(ObjectsTemplate<Configaration> sourceObject, string NodeName)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration> destinations = new ObjectsTemplate<Configaration>();
|
|||
|
|
|||
|
Configaration fParent = sourceObject.Find(delegate(Configaration item) { return (item.Node == NodeName); });
|
|||
|
if (fParent != null) GetChilds(sourceObject, destinations, fParent);
|
|||
|
|
|||
|
return destinations;
|
|||
|
}
|
|||
|
|
|||
|
public Configaration GetItem(ObjectsTemplate<Configaration> sourceObject, string NodeName)
|
|||
|
{
|
|||
|
Configaration fParent = sourceObject.Find(delegate(Configaration item) { return (item.Node == NodeName); });
|
|||
|
return fParent;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// if parent and child node not found in the configuration, it will return
|
|||
|
/// empty string, because to setup default configuration
|
|||
|
/// </summary>
|
|||
|
/// <param name="parentNodeName"></param>
|
|||
|
/// <param name="childNodeName"></param>
|
|||
|
/// <param name="type"></param>
|
|||
|
/// <returns></returns>
|
|||
|
private static string getValue(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
ConfigurationManager manager = new ConfigurationManager();
|
|||
|
ObjectsTemplate<Configaration> parent = manager.GetChilds(parentNodeName, type);
|
|||
|
if (parent == null) return "";//throw new ServiceException("parent-Tag-Name not found in the logic configuration");
|
|||
|
Configaration child = manager.GetItem(parent, childNodeName);
|
|||
|
if (child == null) return "";//throw new ServiceException("child-node-name not found in the logic collection");
|
|||
|
return child.Value;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// If system does not find the value, it will return '0'.
|
|||
|
/// if configuration contain other than integer value value, it will return zero ///
|
|||
|
/// </summary>
|
|||
|
/// <param name="parentNodeName"> parent node name</param>
|
|||
|
/// <param name="childNodeName"> child node name of the parent</param>
|
|||
|
/// <param name="type"> logic or UI configuration </param>
|
|||
|
/// <returns>boolian value</returns>
|
|||
|
public static int GetIntValue(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
int intvalue= 0;
|
|||
|
try
|
|||
|
{
|
|||
|
string stringvalue = ConfigurationManager.getValue(parentNodeName, childNodeName, type);
|
|||
|
if (int.TryParse(stringvalue, out intvalue))
|
|||
|
return intvalue;
|
|||
|
else return 0;
|
|||
|
//throw new ServiceException("Value in the "
|
|||
|
// + "logic-Configuration; Node:Root, Child-Node:RoundOfDegit, Value:" + stringvalue +" is not Integer");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new ServiceException(ex.InnerException.Message);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
public static Configaration Get(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
ConfigurationManager manager = new ConfigurationManager();
|
|||
|
ObjectsTemplate<Configaration> parent = manager.GetChilds(parentNodeName, type);
|
|||
|
if (parent == null) return null;
|
|||
|
Configaration child = manager.GetItem(parent, childNodeName);
|
|||
|
if (child == null) return null;
|
|||
|
return child;
|
|||
|
}
|
|||
|
public static int GetAttributeIntValue(string parentNodeName, string childNodeName, string AttributeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
int intvalue = 0;
|
|||
|
try
|
|||
|
{
|
|||
|
Configaration oTag = ConfigurationManager.Get(parentNodeName, childNodeName, type);
|
|||
|
if (oTag == null) return 0;
|
|||
|
string stringvalue = oTag.ConAttributes.GetAttributeValue(AttributeName);
|
|||
|
if (stringvalue == "") return 0;
|
|||
|
|
|||
|
if (int.TryParse(stringvalue, out intvalue))
|
|||
|
return intvalue;
|
|||
|
else return 0;
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new ServiceException(ex.InnerException.Message);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public static string GetStringValue(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string stringvalue = ConfigurationManager.getValue(parentNodeName, childNodeName, type);
|
|||
|
return stringvalue;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new ServiceException(ex.InnerException.Message);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// If system does not find the value, it will return false.
|
|||
|
/// if configuration contain other than 'YES' value, it will return false
|
|||
|
/// </summary>
|
|||
|
/// <param name="parentNodeName"> parent node name</param>
|
|||
|
/// <param name="childNodeName"> child node name of the parent</param>
|
|||
|
/// <param name="type"> logic or UI configuration </param>
|
|||
|
/// <returns>boolian value</returns>
|
|||
|
public static bool GetBoolValue(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
string stringvalue = ConfigurationManager.getValue(parentNodeName, childNodeName, type);
|
|||
|
if (stringvalue.ToUpper() == "YES" || stringvalue.ToUpper() == "NO")
|
|||
|
return ((stringvalue.ToUpper() == "YES") ? true : false);
|
|||
|
else return false;
|
|||
|
//throw new ServiceException("Value in the "
|
|||
|
// + "logic-Configuration; Node:Root, Child-Node:RoundOfDegit, Value:" + stringvalue + " is not Integer");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new ServiceException(ex.InnerException.Message);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// If system does not find the value, it will return min value of dateTime(DateTime.minvalue).
|
|||
|
/// if configuration value not dateTime format, it will also return min value of dateTime(DateTime.minvalue).
|
|||
|
/// </summary>
|
|||
|
/// <param name="parentNodeName"> parent node name</param>
|
|||
|
/// <param name="childNodeName"> child node name of the parent</param>
|
|||
|
/// <param name="type"> logic or UI configuration </param>
|
|||
|
/// <returns>DateTime value</returns>
|
|||
|
public static DateTime GetDateTimeValue(string parentNodeName, string childNodeName, EnumConfigurationType type)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
DateTime dateValue = DateTime.MinValue;
|
|||
|
string stringvalue = ConfigurationManager.getValue(parentNodeName, childNodeName, type);
|
|||
|
if (DateTime.TryParse(stringvalue, out dateValue))
|
|||
|
return dateValue;
|
|||
|
else return dateValue;
|
|||
|
//throw new ServiceException("Value in the "
|
|||
|
// + "logic-Configuration; Node:Root, Child-Node:RoundOfDegit, Value:" + stringvalue + " is not Integer");
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw new ServiceException(ex.InnerException.Message);
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#region Read configuration from XMLFile to Object
|
|||
|
public ObjectsTemplate<Configaration> LoadXMLtoObject(EnumConfigurationType type, string fileName)
|
|||
|
{
|
|||
|
XmlDocument xmlDoc = new XmlDocument();
|
|||
|
//Load the file into the XmlDocument
|
|||
|
ObjectsTemplate<Configaration> configs = new ObjectsTemplate<Configaration>();
|
|||
|
xmlDoc.Load(fileName);
|
|||
|
|
|||
|
//Find the root nede, and add it togather with its childeren
|
|||
|
XmlNode xnod = xmlDoc.DocumentElement;
|
|||
|
// Add Parent node in Collection
|
|||
|
Configaration parent = AddToColl(configs, xnod, null, type);
|
|||
|
|
|||
|
ReadFromXML(configs, xnod, parent, type);
|
|||
|
|
|||
|
return configs;
|
|||
|
}
|
|||
|
//public ObjectsTemplate<Configaration> LoadXMLtoObject(EnumConfigurationType type)
|
|||
|
//{
|
|||
|
// XmlDocument xmlDoc = new XmlDocument();
|
|||
|
// //Load the file into the XmlDocument
|
|||
|
// ObjectsTemplate<Configaration> configs = new ObjectsTemplate<Configaration>();
|
|||
|
// switch (type)
|
|||
|
// {
|
|||
|
// case EnumConfigurationType.Logic:
|
|||
|
// xmlDoc.Load("LogicConfiguration.xml");
|
|||
|
// break;
|
|||
|
// case EnumConfigurationType.UI:
|
|||
|
// xmlDoc.Load("UIConfiguration.xml");
|
|||
|
// break;
|
|||
|
// case EnumConfigurationType.Menu:
|
|||
|
// xmlDoc.Load("Menu.xml");
|
|||
|
// break;
|
|||
|
// }
|
|||
|
// //Find the root nede, and add it togather with its childeren
|
|||
|
// XmlNode xnod = xmlDoc.DocumentElement;
|
|||
|
// // Add Parent node in Collection
|
|||
|
// Configaration parent = AddToColl(configs, xnod, null, type);
|
|||
|
|
|||
|
// ReadFromXML(configs, xnod, parent, type);
|
|||
|
// return configs;
|
|||
|
//}
|
|||
|
private void ReadFromXML(ObjectsTemplate<Configaration> configs, XmlNode xnod, Configaration parent, EnumConfigurationType type)
|
|||
|
{
|
|||
|
XmlNode xnodWorking;
|
|||
|
//For an element node, retrieve the attributes
|
|||
|
if (xnod.NodeType == XmlNodeType.Element)
|
|||
|
{
|
|||
|
XmlNamedNodeMap mapAttributes = xnod.Attributes;
|
|||
|
if (xnod.HasChildNodes)
|
|||
|
{
|
|||
|
xnodWorking = xnod.FirstChild;
|
|||
|
while (xnodWorking != null)
|
|||
|
{
|
|||
|
if (xnodWorking.NodeType == XmlNodeType.Element)
|
|||
|
{
|
|||
|
Configaration oparent = AddToColl(configs, xnodWorking, parent.ID, type);
|
|||
|
//Add the attributes to the ListBox
|
|||
|
foreach (XmlAttribute xnodAttribute in xnodWorking.Attributes)
|
|||
|
oparent.ConAttributes.Add(oparent.ID, xnodAttribute.Name, xnodAttribute.Value);
|
|||
|
//If there are any child node, call this procedure recursively
|
|||
|
ReadFromXML(configs, xnodWorking, oparent, type);
|
|||
|
}
|
|||
|
xnodWorking = xnodWorking.NextSibling;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
private Configaration AddToColl(ObjectsTemplate<Configaration> configs, XmlNode node, ID parentID, EnumConfigurationType type)
|
|||
|
{
|
|||
|
Payroll.BO.Configaration oConfig = new Payroll.BO.Configaration();
|
|||
|
oConfig.Node = node.Name;
|
|||
|
//
|
|||
|
if(parentID == null)
|
|||
|
oConfig.Value = "";
|
|||
|
else if (node.ChildNodes.Count != 1 || (node.ChildNodes.Count == 1 && node.ChildNodes[0].ChildNodes.Count != 0))
|
|||
|
{
|
|||
|
oConfig.Value = "";
|
|||
|
}
|
|||
|
else
|
|||
|
oConfig.Value = node.InnerText;
|
|||
|
oConfig.ParentID = parentID;
|
|||
|
oConfig.Type = type;
|
|||
|
|
|||
|
oConfig.SetObjectID(ID.FromInteger(configs.Count + 1));
|
|||
|
configs.Add(oConfig);
|
|||
|
return oConfig;
|
|||
|
}
|
|||
|
#endregion Read configuration from Object to XMLFile
|
|||
|
|
|||
|
#region Write configuration from object to XMLFile
|
|||
|
|
|||
|
public static void WriteXML(string path, EnumConfigurationType type)
|
|||
|
{
|
|||
|
ObjectsTemplate<Configaration> configs;
|
|||
|
if (type == EnumConfigurationType.Logic)
|
|||
|
configs = _logicCofiguration;
|
|||
|
else if(type == EnumConfigurationType.UI)
|
|||
|
configs = _uiCofiguration;
|
|||
|
else configs = _menuCofiguration;
|
|||
|
|
|||
|
if (configs == null || configs.Count == 0)
|
|||
|
throw new ServiceException("Source is empty");
|
|||
|
|
|||
|
//XmlTextWriter tw = new XmlTextWriter("C:\\testXml.xml", System.Text.Encoding.UTF8);
|
|||
|
//tw.Flush();
|
|||
|
//tw.Formatting = Formatting.Indented;
|
|||
|
//tw.WriteStartDocument();
|
|||
|
//tw.WriteStartElement(configs[0].Node);
|
|||
|
//ConfigurationManager.WriteXML(tw, configs, configs[0].ID);
|
|||
|
//tw.WriteEndElement();
|
|||
|
//tw.WriteEndDocument();
|
|||
|
XmlDocument xdoc = new XmlDocument();
|
|||
|
XmlElement root = xdoc.CreateElement(configs[0].Node);
|
|||
|
xdoc.AppendChild(root);
|
|||
|
WriteXML(root, xdoc, configs, configs[0].ID);
|
|||
|
xdoc.Save(path);
|
|||
|
}
|
|||
|
//private static void WriteXML(XmlTextWriter tw, ObjectsTemplate<Configaration> configs, ID NodeId)
|
|||
|
//{
|
|||
|
// List<Configaration> childs = configs.FindAll((delegate(Configaration item) {return item.ParentID == NodeId;}));
|
|||
|
// if (childs !=null || childs.Count> 0)
|
|||
|
// {
|
|||
|
// foreach(Configaration con in childs)
|
|||
|
// {
|
|||
|
// tw.WriteStartElement(
|
|||
|
// if (con.Value == "" || con.Value == String.Empty) tw.WriteStartElement(con.Node);
|
|||
|
// else tw.WriteElementString(con.Node, con.Value);
|
|||
|
// foreach(Configaration.ConfigurationAttribute att in con.ConAttributes)
|
|||
|
// {
|
|||
|
// tw.WriteStartAttribute(att.AttributeName, att.Value);
|
|||
|
// }
|
|||
|
// WriteXML(tw, configs, con.ID);
|
|||
|
// if (con.Value == "" || con.Value == String.Empty) tw.WriteEndElement();
|
|||
|
// }
|
|||
|
// }
|
|||
|
//}
|
|||
|
private static void WriteXML(XmlElement element, XmlDocument xdoc, ObjectsTemplate<Configaration> configs, ID NodeId)
|
|||
|
{
|
|||
|
List<Configaration> childs = configs.FindAll((delegate(Configaration item) {return item.ParentID == NodeId;}));
|
|||
|
if (childs !=null || childs.Count> 0)
|
|||
|
{
|
|||
|
foreach(Configaration con in childs)
|
|||
|
{
|
|||
|
XmlElement chilenode = xdoc.CreateElement(con.Node);
|
|||
|
chilenode.InnerText = con.Value;
|
|||
|
|
|||
|
foreach(Configaration.ConfigurationAttribute att in con.ConAttributes)
|
|||
|
{
|
|||
|
chilenode.SetAttribute(att.AttributeName, att.Value);
|
|||
|
}
|
|||
|
element.AppendChild(chilenode);
|
|||
|
WriteXML(chilenode, xdoc, configs, con.ID);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion Write configuration from object to XMLFile
|
|||
|
}
|
|||
|
}
|
|||
|
|