212 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			212 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System;
 | 
						|
using System.Xml;
 | 
						|
using System.Text;
 | 
						|
 | 
						|
namespace VlnXml
 | 
						|
{
 | 
						|
	/// <summary>
 | 
						|
	/// Summary description for Class1.
 | 
						|
	/// </summary>
 | 
						|
 
 | 
						|
	public class VlnXmlDocument:XmlDocument 
 | 
						|
	{
 | 
						|
		public VlnXmlDocument():base() 
 | 
						|
		{
 | 
						|
		}
 | 
						|
 | 
						|
		public override XmlElement CreateElement( string prefix, string localname, string nsURI) 
 | 
						|
		{
 | 
						|
			VlnXmlElement elem = new VlnXmlElement(prefix, localname, nsURI, this);
 | 
						|
			return elem;
 | 
						|
		}
 | 
						|
 | 
						|
	}
 | 
						|
 | 
						|
	public class VlnXmlElement:XmlElement 
 | 
						|
	{
 | 
						|
 | 
						|
		public VlnXmlElement( string prefix, string localname, string nsURI, XmlDocument doc ):base( prefix,localname,nsURI, doc )
 | 
						|
		{
 | 
						|
		}
 | 
						|
 | 
						|
		public string GetMenuString(string grpmenuitm, bool isgrp)
 | 
						|
		{
 | 
						|
			VlnXmlElement elm = this;
 | 
						|
			StringBuilder strbld = new StringBuilder();
 | 
						|
 | 
						|
			bool usespecial; // flags need for (Table) or (Graph)
 | 
						|
			string strspecial="";
 | 
						|
 | 
						|
			// use grpmenuitm, parse for field(s) and generate a string to return
 | 
						|
			int left = grpmenuitm.IndexOf("<");
 | 
						|
			int right;
 | 
						|
			int stindx = 0;
 | 
						|
			if (left > 0) strbld.Append(grpmenuitm.Substring(0,left));
 | 
						|
	
 | 
						|
			while (left != -1)
 | 
						|
			{
 | 
						|
				// get right bracket and then check for valid field & if commas with
 | 
						|
				// this, check for integer values.
 | 
						|
				right = grpmenuitm.IndexOf(">",stindx);
 | 
						|
				string substring = grpmenuitm.Substring(left+1,right-left-1);
 | 
						|
				// do comma parts now.
 | 
						|
				string inusename;
 | 
						|
				substring = substring.Replace(" ","_");
 | 
						|
				int comma1 = substring.IndexOf(",");
 | 
						|
				int frmt1=0, frmt2=0;
 | 
						|
				if (comma1 != -1)
 | 
						|
				{
 | 
						|
					// get any numbers for formatting & check for ints.
 | 
						|
					int comma2 = substring.IndexOf(",",comma1+1);
 | 
						|
					if (comma2 != -1) // two ints.
 | 
						|
					{
 | 
						|
						if (comma2-comma1 > 1) // first format field - not empty 
 | 
						|
						{
 | 
						|
							string int1 = substring.Substring(comma1+1,comma2-comma1-1);
 | 
						|
							frmt1 = System.Convert.ToInt32(int1);
 | 
						|
						}
 | 
						|
						if (comma2<substring.Length)  // second part - not empty
 | 
						|
						{
 | 
						|
							string int2 = substring.Substring(comma2+1,substring.Length-comma2-1);
 | 
						|
							frmt2 = System.Convert.ToInt32(int2);
 | 
						|
						}
 | 
						|
					}
 | 
						|
					else  // just one format 
 | 
						|
					{
 | 
						|
						string int1 = substring.Substring(comma1,comma2-comma1);
 | 
						|
						frmt1 = System.Convert.ToInt32(int1);
 | 
						|
					}
 | 
						|
					inusename = substring.Substring(0,comma1);
 | 
						|
				}
 | 
						|
				else  // no commas, it's just a field name.
 | 
						|
					inusename = substring;
 | 
						|
 | 
						|
				// get contents of field & append it onto the string builder.
 | 
						|
				usespecial = false;
 | 
						|
				XmlNode elmnode = (XmlNode) elm;
 | 
						|
				XmlNode nd = elmnode.SelectSingleNode(inusename);
 | 
						|
				// if not found it may be a combination, try this.
 | 
						|
				if (nd == null)
 | 
						|
				{
 | 
						|
					string tmp = inusename + "a";
 | 
						|
					nd = elmnode.SelectSingleNode(tmp);
 | 
						|
				}
 | 
						|
				if (nd == null)
 | 
						|
				{
 | 
						|
					string tmp = inusename + "b";
 | 
						|
					nd = elmnode.SelectSingleNode(tmp);
 | 
						|
				}
 | 
						|
				if (nd == null)
 | 
						|
				{
 | 
						|
					string tmp = inusename + "c";
 | 
						|
					nd = elmnode.SelectSingleNode(tmp);
 | 
						|
					if (nd!=null)
 | 
						|
					{
 | 
						|
						usespecial = true;
 | 
						|
						strspecial = "(Table)";
 | 
						|
					}
 | 
						|
				}
 | 
						|
				if (nd == null)
 | 
						|
				{
 | 
						|
					string tmp = inusename + "d";
 | 
						|
					nd = elmnode.SelectSingleNode(tmp);
 | 
						|
					if (nd!=null)
 | 
						|
					{
 | 
						|
						usespecial = true;
 | 
						|
						strspecial = "(Graph)";
 | 
						|
					}
 | 
						|
				}
 | 
						|
				if(nd != null) 
 | 
						|
				{
 | 
						|
					string text;
 | 
						|
					if (usespecial)
 | 
						|
						text = strspecial;
 | 
						|
					else
 | 
						|
						text = nd.InnerText;
 | 
						|
					
 | 
						|
					if (isgrp)
 | 
						|
					{
 | 
						|
						if (frmt2 != 0)
 | 
						|
							strbld.Append(text.Replace("_"," ").PadRight(frmt2,' '));
 | 
						|
						else
 | 
						|
							strbld.Append(text.Replace("_"," "));
 | 
						|
					}
 | 
						|
					else
 | 
						|
					{
 | 
						|
						if (frmt1 == 0)
 | 
						|
						{
 | 
						|
							if (frmt2>0)
 | 
						|
								strbld.Append(text.PadRight(frmt2,' '));
 | 
						|
							else
 | 
						|
								strbld.Append(text);
 | 
						|
						}
 | 
						|
						else if (frmt1 != frmt2)
 | 
						|
						{
 | 
						|
							char[] tmp = text.ToCharArray();
 | 
						|
							int cnt = 0;
 | 
						|
							while (tmp[cnt] <= '9' && tmp[cnt] >= '0') cnt++;
 | 
						|
							int padcnt = (cnt>frmt1)?0:frmt1-cnt;
 | 
						|
							StringBuilder strtmp = new StringBuilder();
 | 
						|
							cnt = 0;
 | 
						|
							while(cnt<padcnt) 
 | 
						|
							{
 | 
						|
								strtmp.Append(" ");
 | 
						|
								cnt++;
 | 
						|
							}
 | 
						|
							strtmp.Append(text);
 | 
						|
							string tmpstr = strtmp.ToString();
 | 
						|
							strbld.Append(tmpstr.PadRight(frmt2,' '));
 | 
						|
						}
 | 
						|
						else
 | 
						|
							strbld.Append(text.PadLeft(frmt2,' '));
 | 
						|
					}
 | 
						|
				}
 | 
						|
				stindx = right+1;
 | 
						|
				left = grpmenuitm.IndexOf("<",left+1);
 | 
						|
				if (left != -1 && left > right+1)  // append any plain text.
 | 
						|
					strbld.Append(grpmenuitm.Substring(right+1,left-right-1));
 | 
						|
			}
 | 
						|
			return strbld.ToString();
 | 
						|
		}
 | 
						|
 | 
						|
		public string GetMenuValueTemplate(string menuitm)
 | 
						|
		{
 | 
						|
			VlnXmlElement parent;
 | 
						|
			string grpmenuitm;
 | 
						|
			VlnXmlElement tmp;
 | 
						|
			if (menuitm == "GroupMenuItem")
 | 
						|
			{		
 | 
						|
				// if at top of tree, use this top GroupMenuItem. but if not,
 | 
						|
				// the parent node defines the GroupMenuItem for the subgroups.
 | 
						|
				if (this.ParentNode.Name == "RO_Root")
 | 
						|
				{
 | 
						|
					tmp = (VlnXmlElement) this.ParentNode;
 | 
						|
					grpmenuitm=tmp.GetAttribute(menuitm);
 | 
						|
					return(grpmenuitm);
 | 
						|
				}
 | 
						|
				else
 | 
						|
					parent = (VlnXmlElement) this.ParentNode;
 | 
						|
				while (parent != null) 
 | 
						|
				{
 | 
						|
					if (parent.HasAttribute(menuitm) == true) break;
 | 
						|
					parent = (VlnXmlElement) parent.ParentNode;
 | 
						|
				}
 | 
						|
				if (parent == null) return null;
 | 
						|
				grpmenuitm = parent.GetAttribute(menuitm);
 | 
						|
				return grpmenuitm;
 | 
						|
			}
 | 
						|
 | 
						|
			// Now just do 'MenuItem', which is for ROs
 | 
						|
			parent = (VlnXmlElement) this;
 | 
						|
			grpmenuitm = parent.GetAttribute(menuitm);
 | 
						|
			while (parent != null && grpmenuitm == "")
 | 
						|
			{
 | 
						|
				// walk up tree to get parent.
 | 
						|
				grpmenuitm = parent.GetAttribute(menuitm);
 | 
						|
				parent = (VlnXmlElement) parent.ParentNode;
 | 
						|
			}
 | 
						|
			return grpmenuitm;
 | 
						|
		}
 | 
						|
	}
 | 
						|
}
 |