This repository has been archived by the owner on Dec 29, 2023. It is now read-only.
/
ModelProvider.cs
49 lines (44 loc) · 1.76 KB
/
ModelProvider.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System.Web;
using System.Web.SessionState;
using System.Xml;
using DevExpress.Web.ASPxTreeList;
namespace WebApplication1.Model {
public static class MyProvider {
const string XmlSessionKey = "DXUNIQ";
static HttpSessionState Session { get { return HttpContext.Current.Session; } }
static XmlDocument Xml {
get {
if(Session[XmlSessionKey] == null)
Session[XmlSessionKey] = CreateXml();
return (XmlDocument)Session[XmlSessionKey];
}
}
static XmlDocument CreateXml() {
XmlDocument doc = new XmlDocument();
doc.Load(HttpContext.Current.Request.MapPath("~/Models/XMLfile1.xml"));
return doc;
}
public static void Bind(ASPxTreeList tree, string path) {
tree.ClearNodes();
XmlElement root = Xml.SelectSingleNode(path) as XmlElement;
BindCore(tree, tree.RootNode, root);
}
static void BindCore(ASPxTreeList tree, TreeListNode node, XmlElement xmlNode) {
node.SetValue("Value", xmlNode.Attributes["value"].Value);
foreach(XmlElement element in xmlNode.ChildNodes) {
TreeListNode child = tree.AppendNode(element.GetAttribute("key"), node);
BindCore(tree, child, element);
}
}
public static void MoveNode(string key, string newParentKey) {
XmlElement element = FindNode(key);
XmlElement toElement = FindNode(newParentKey);
if(element != null && toElement != null)
toElement.AppendChild(element);
}
static XmlElement FindNode(string key) {
string xpath = string.Format("//node[@key='{0}']", key);
return Xml.SelectSingleNode(xpath) as XmlElement;
}
}
}