|
using System;
using System.Web;
using System.Collections;
using System.Configuration;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
namespace JobMorning
{
/// <summary>
/// ApplicationTransit describes methods that are common between all users. This object is stored in
/// the application Object which methods are defined in Global.asax.
/// </summary>
public class ApplicationTransit
{
// number of user paths
private int nbUserPaths;
// Define an ArrayList for each UserPaths defined
// At this stage, the number of UserPaths should be defined.
private ArrayList[] allLists;
// = new ArrayList[nbUserPaths];
private HttpApplicationState appObject;
public ApplicationTransit(int nbPaths)
{
nbUserPaths = nbPaths;
allLists = new ArrayList[nbPaths];
appObject = HttpContext.Current.Application;
}
/// <summary>
/// The CreateXmlFlow function creates a XML description of all children controls contained
/// in a container control. CreateXmlFlow supports the following children controls:
/// WebControls.TextBox, HtmlControls.HtmlInputText, WebControls.CheckBox,
/// WebControls.RadioButton, WebControls.DropDownList, WebControls.CheckBoxList,
/// WebControls.RadioButtonList, WebControls.Panel.
/// In the case of a WebControls.Panel control, all children Controls inside the Panel
/// are also described.
/// </summary>
/// <param name="container">Can be a child control or a container control. In case it is a container control,
/// strXml will encapsulate the result in a <c>container</c> tag</param>
/// <param name="pageInputs">
/// An Hashtable containing a list of all input forms values indexed by the name tag (the control name )
/// of the HTML element.
/// </param>
/// <returns>
/// The CreateXmlFlow function creates a XML description of all children controls contained
/// in a container control. The description contains the data entered by the user (node InnerText),
/// the type of the control (attribute type of the node) and also the ID of the control
/// (attribute name of the node).
/// </returns>
public string CreateXmlFlow(Control container, ref Hashtable pageInputs)
{
string strReturnXml = "";
// strDBControl is used to retrieve the DBParam for each control
// needed to be saved in the database
string strDBParam;
foreach (Control c in container.Controls)
{
// the type of the container begins by ASP. if it is a control.ascx
if ((c is INamingContainer)&(c.GetType().ToString().Substring(0,3).Equals("ASP")))
{
strReturnXml += "<container>";
strReturnXml += "<name>"+c.ID+"</name>";
strReturnXml += CreateXmlFlow(c, ref pageInputs);
strReturnXml += "</container>";
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
{
strReturnXml += "<panel>";
strReturnXml += "<name>"+c.ID+"</name>";
strReturnXml += CreateXmlFlow(c, ref pageInputs);
strReturnXml += "</panel>";
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
{
strDBParam = ((TextBox) c).Attributes["dbcontrol"];
strReturnXml += @"<item type=""TextBox"" name="""+c.ID+@"""";
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += ">";
strReturnXml += ((TextBox) c).Text;
strReturnXml += "</item>";
pageInputs.Add(c.ID,((TextBox) c).Text);
}
if (c.GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputText"))
{
strDBParam = ((HtmlInputText) c).Attributes["dbcontrol"];
strReturnXml += @"<item type=""HtmlInputText"" name="""+c.ID+@"""";
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += ">";
strReturnXml += ((HtmlInputText) c).Value;
strReturnXml += "</item>";
pageInputs.Add(c.ID,((HtmlInputText) c).Value);
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
{
strDBParam = ((CheckBox) c).Attributes["dbcontrol"];
strReturnXml += @"<item type=""CheckBox"" name="""+c.ID+@"""";
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += @" text=""";
strReturnXml += ((CheckBox) c).Text +@""">";
strReturnXml += ((CheckBox) c).Checked.ToString();
strReturnXml += "</item>";
pageInputs.Add(c.ID,((CheckBox) c).Checked);
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButton"))
{
strDBParam = ((RadioButton) c).Attributes["dbcontrol"];
strReturnXml += @"<item type=""RadioButton"" name="""+c.ID+@"""";
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += @" text=""";
strReturnXml += ((RadioButton) c).Text +@""">";
strReturnXml += ((RadioButton) c).Checked.ToString();
strReturnXml += "</item>";
pageInputs.Add(c.ID,((RadioButton) c).Checked);
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList"))
{
strReturnXml += "<DropDownList><name>"+c.ID+"</name>";
// items will describe all the Selected values of the DropDownList items,
// this time the key index is the item string content.
Hashtable itemsHT = new Hashtable();
foreach (ListItem litem in ((DropDownList) c).Items)
{
strDBParam = litem.Attributes["dbcontrol"];
strReturnXml += @"<item type=""DropDownList.item"" text="""+litem.Text;
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += @""">";
strReturnXml += litem.Selected.ToString();
strReturnXml += "</item>";
itemsHT.Add(litem.Text,litem.Selected);
}
strReturnXml += "</DropDownList>";
pageInputs.Add(c.ID, itemsHT);
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.CheckBoxList"))
{
Hashtable itemsHT = new Hashtable();
strReturnXml += "<CheckBoxList><name>"+c.ID+"</name>";
foreach (ListItem litem in ((CheckBoxList) c).Items)
{
strDBParam = litem.Attributes["dbcontrol"];
strReturnXml += @"<item type=""CheckBoxList.item"" text="""+litem.Text;
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += @""">";
strReturnXml += litem.Selected.ToString();
strReturnXml += "</item>";
itemsHT.Add(litem.Text,litem.Selected);
}
strReturnXml += "</CheckBoxList>";
pageInputs.Add(c.ID, itemsHT);
}
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList"))
{
Hashtable itemsHT = new Hashtable();
strReturnXml += "<RadioButtonList><name>"+c.ID+"</name>";
foreach (ListItem litem in ((RadioButtonList) c).Items)
{
strDBParam = litem.Attributes["dbcontrol"];
strReturnXml += @"<item type=""RadioButtonList.item"" text="""+litem.Text;
if (strDBParam!=null)
{
strReturnXml += @" dbcontrol="""+strDBParam+@"""";
}
strReturnXml += @""">";
strReturnXml += litem.Selected.ToString();
strReturnXml += "</item>";
itemsHT.Add(litem.Text,litem.Selected);
}
strReturnXml += "</RadioButtonList>";
pageInputs.Add(c.ID, itemsHT);
}
}
return strReturnXml;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.