Click here to Skip to main content
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads
 
Add your own
alternative version

FrameControl - Framework for creating web applications

, 25 Jul 2003
FrameControl is a framework that contains the code common for most of the web applications.
FrameControl_demo.zip
FrameControl1.dll
doc
banner.jpg
darkcorner.jpg
FrameControl1
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
FrameControl_src.zip
banner.jpg
darkcorner.jpg
gradleft.jpg
gradtop.jpg
graycorner.jpg
minus.jpg
plus.jpg
titletile.jpg
obj
Debug
temp
TempPE
Release
FrameControl1.dll
FrameControl1.projdata
temp
TempPE
FrameControl1.csproj.user
FrameControl_install.zip
using System;
using System.Web;
using System.Collections;
using System.Collections.Specialized;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Xml;
using System.ComponentModel;
using System.Data.OleDb;



namespace JobMorning
{
	/// <summary>
	/// SessionTransit is the object stored in users Sessions that keeps all
	/// data entered by the user in a session life.
	/// </summary>
	public class SessionTransit
	{
		/// <summary>
		/// MCContext is a XmlDocument that contains all the information about the
		/// user's previous actions in the web application. The data is structured page
		/// by page.
		/// </summary>
		private XmlDocument MCContext;
		// the boolean isChangePath is used not to get Request information
		// when the user change paths.

		private string strCurDate;
		private string strCurTime;
		// reference to the ASP.NET Application Object
		private HttpApplicationState appObject;
		// reference to the current Session Object
		private System.Web.SessionState.HttpSessionState sessionObject;
		private DisplayCentral dispCent;
		private string strNextPage;
		// string used for the ActionClassContainer object. ActionClassContainer is stored in the Application
		// context, therefore they can not handle any Session information.
		private string strLastPageDoBeforeDisplay;

		// Hashtable to store the last input Parameters from the user.
		private Hashtable lastInputParameters;

		/// <summary>
		/// The SessionTransit constructor creates an empty structure for the MCContext XML
		/// document. It stores the creationDate of the SessionTransit object in the contextCreationDate
		/// tag. 
		/// It retrieves the number of simultaneous users in the application object and stored it
		/// in the simultaneousUsers tag.
		/// </summary>
		public SessionTransit()
		{
			// initialize the application Object
			appObject = HttpContext.Current.Application;
			sessionObject = HttpContext.Current.Session;

			strLastPageDoBeforeDisplay="";
			lastInputParameters = new Hashtable();
			
			string strMCContext;
			strCurDate = DateTime.Now.ToLongDateString();
			strCurTime = DateTime.Now.ToLongTimeString();
			strMCContext = "<context><generalInfo><contextCreationDate>";
			strMCContext += strCurDate;
			strMCContext += "</contextCreationDate>";
			strMCContext += "<contextCreationTime>";
			strMCContext += strCurTime+"</contextCreationTime>";
			strMCContext += "<LastUpdateTime></LastUpdateTime>";
			strMCContext += "</generalInfo>";
			strMCContext += "<pagesList></pagesList>";
			strMCContext += "<savepointsList></savepointsList>";
			strMCContext += "<customdataList></customdataList>";
			strMCContext += "</context>";
			MCContext = new XmlDocument();
			MCContext.LoadXml(strMCContext);

		} 


		public XmlDocument GetMCContext()
		{
			return MCContext;
		}

		/// <summary>
		/// StoreState adds the content of the XML string provided to one of the
		/// list node pagesList, savepointsList, or customdataList in MCContext.
		/// <param name="strNameAttribute">The strNameAttribute is used to set the name attribute for either the page, savepoint
		/// saved in MCContext. </param>
		/// <param name="strXml">The strXml defines the XML that will be added to the node. The system will also add
		/// the insertDate child node that saves the date where the date has been inserted.</param>
		/// <param name="strStoreType">The type of the list node to use in MCContext is set using the string
		/// strStoreType. The three values possible for strStoreType are page, savepoint,
		/// and customdata.</param>
		/// </summary>
		public void StoreState(string strNameAttribute, string strXml, string strStoreType)
		{

			XmlNodeList oldPages;
			XmlNode pagesListNode;
			XmlNodeList oldSavePoints;
			XmlNode savepointsListNode;
			XmlNode lastUpdate;
			string strFormatXml="";
			string strFinalXml = "";
			DateTime today=DateTime.Now;

			lastUpdate = MCContext.DocumentElement.SelectSingleNode("//LastUpdateTime");
			lastUpdate.InnerText =  DateTime.Now.ToLongTimeString();
				
			// Format a node from the incoming strXml string
			if (strStoreType.Equals("page"))
			{
				strFormatXml = "<page name='"+strNameAttribute+"' version='0'>";
				strFormatXml += "<insertDate>"+today.ToString()+"</insertDate>";
				strFormatXml += strXml;
				strFormatXml += "</page>";

				pagesListNode = MCContext.DocumentElement.SelectSingleNode("pagesList");
				oldPages = pagesListNode.SelectNodes("//page[@name!='"+strNameAttribute+"']");
				
				strFinalXml += strFormatXml;
				for (int i=0; i<oldPages.Count; i++)
				{
					strFinalXml += oldPages.Item(i).OuterXml;
				}
				MCContext.DocumentElement.SelectSingleNode("pagesList").InnerXml=strFinalXml;
				
			}
			if (strStoreType.Equals("savepoint"))
			{
				strFormatXml = "<savepoint name='"+strNameAttribute+"' version='0'>";
				strFormatXml += "<insertDate>"+today.ToString()+"</insertDate>";
				strFormatXml += strXml;
				strFormatXml += "</savepoint>";

				savepointsListNode = MCContext.DocumentElement.SelectSingleNode("savepointsList");
				oldSavePoints = savepointsListNode.SelectNodes("//savepoint[@name!='"+strNameAttribute+"']");
				
				strFinalXml += strFormatXml;
				for (int i=0; i<oldSavePoints.Count; i++)
				{
					strFinalXml += oldSavePoints.Item(i).OuterXml;
				}
				MCContext.DocumentElement.SelectSingleNode("savepointsList").InnerXml=strFinalXml;
			}
			if (strStoreType.Equals("customdata"))
			{
				strFormatXml = "<customData name='"+strNameAttribute+"' version='0'>";
				strFormatXml += "<insertDate>"+today.ToString()+"</insertDate>";
				strFormatXml += "<text>"+strXml+"</text>";
				strFormatXml += "</customData>";

				savepointsListNode = MCContext.DocumentElement.SelectSingleNode("customdataList");
				oldSavePoints = savepointsListNode.SelectNodes("//customdata[@name!='"+strNameAttribute+"']");
				
				strFinalXml += strFormatXml;
				for (int i=0; i<oldSavePoints.Count; i++)
				{
					strFinalXml += oldSavePoints.Item(i).OuterXml;
				}
				MCContext.DocumentElement.SelectSingleNode("customdataList").InnerXml=strFinalXml;
			}
		}

		/// <summary>
		/// JumpPath takes the user from his current Page to the first page of a specified 
		/// path (defined in the XML configuration file). 
		/// <param name="pathName">pathName defines the name of the new path where the user will be sent.</param>
		/// <param name="saveCurPage">The saveCurPage string can be set to 'Y' or 'N', depending on whether the data in the
		/// current page needs to be saved before jumping to the new path first page.</param>
		/// </summary>
		public void JumpPath(string pathName, string saveCurPage)
		{
			if (saveCurPage.Equals("Y"))
			{
				string strPN = (String) sessionObject["CurrentPage"];
				string strPageHTML;
				strPageHTML = dispCent.GetPageXml(ref lastInputParameters);
				StoreState(strPN, strPageHTML, "page");
				ActionClassContainer theContainer;
				theContainer = (ActionClassContainer)appObject["ActionClasses"];
				theContainer.DoAfterContextSave(strPN, MCContext.OuterXml);
			}
			XmlDocument xmlPathDoc = (XmlDocument)appObject["userPaths"];
			XmlNode currNodePathRoot;
			currNodePathRoot = xmlPathDoc.DocumentElement;

			XmlNode curPageNode = currNodePathRoot.SelectSingleNode("//Path[@Name='"+pathName+"']/Page[1]");
			
			if (curPageNode!=null)
			{
				strNextPage = curPageNode.Attributes["Name"].InnerText;
				sessionObject["CurrentPage"] = strNextPage;
			}
		}
		
		// Update the menu PlaceHolder only, without updating all the
		// Table1 server control

		/// <summary>
		/// FillTable is used to fill the WebControl table1 and the menuPlaceHolder of the pages inheriting from the
		/// class disaplyCentral. The use of this function is not recommended.
		/// </summary>
		public void FillTable(DisplayCentral dispCent, ref System.Web.UI.WebControls.Table table1, ref System.Web.UI.WebControls.PlaceHolder menuPlaceHolder, ref System.Collections.Hashtable h, string strPN)
		{
			// Add the page attribute to the main table of the page
			table1.Attributes.Add("_page",strPN);
			
			string strControlFolder = ConfigurationSettings.AppSettings["APP_USERCONTROLS_FOLDER"];
			bool isPrefill = false;
			System.Web.UI.WebControls.PlaceHolder curPlaceHolder;				
			// Create the array
			XmlDocument xmlDoc2 = (XmlDocument)sessionObject["PageControls"];

			XmlNode currNode2;
			currNode2 = xmlDoc2.DocumentElement;
			XmlNode curPageNode;
			XmlNode curPrefillAttribute;
			curPageNode = currNode2.SelectSingleNode("//Page[@Name='"+strPN+"']");

			XmlAttribute actionAttribute = curPageNode.Attributes["action"];

			// The design of the application (regarding browserBack Button events)
			// made it necessary to call FillTable twice for a change of page.
			// FillTable is called once for the previous page name, and then once
			// again for the page which will appear next.
			if (actionAttribute!=null)
			{
				if (strLastPageDoBeforeDisplay!=strPN)
				{
					string actionClassName = actionAttribute.InnerText;
					bool wasItNotInstantiated;
					ActionClassContainer theContainer;
					theContainer = (ActionClassContainer)appObject["ActionClasses"];
					wasItNotInstantiated = theContainer.InstantiateActionClass(actionClassName,strPN);
				
					// call the method doBeforeLoad
					theContainer.DoBeforeDisplay(strPN,MCContext.OuterXml);
					strLastPageDoBeforeDisplay=strPN;

				} // if (strLastPageDoBeforeLoad!=strPN)
			}

			// Update the Session object with the BackButton information
			sessionObject["BackButton"]="YES";
			XmlAttribute bckBttn = curPageNode.Attributes["BackButton"];
			// only update BacButton information if the current page is different than the previous page
			
			XmlAttribute formMethod = curPageNode.Attributes["FormMethod"];
			// only update BacButton information if the current page is different than the previous page
			
			if (bckBttn!=null)
			{
				if (bckBttn.InnerText.Equals("NO"))
				{
					sessionObject["BackButton"]="NO";
				}
				else
				{
					sessionObject["BackButton"]="YES";
				}
			}
			else
			{
				sessionObject["BackButton"]="YES";
			}
			if (formMethod!=null)
			{
				if (formMethod.InnerText.Equals("GET"))
				{
					sessionObject["formMethod"]="GET";
				}
				else
				{
					sessionObject["formMethod"]="POST";
				}
			}
			else
			{
				sessionObject["formMethod"]="POST";
			}
			
		
			// End update the Session object with the ClearPageCache information

			// Update the Session object with the BackButton information
			sessionObject["ClearPageCache"]="NO";
			XmlAttribute clPCBttn = curPageNode.Attributes["ClearPageCache"];
			if (clPCBttn!=null)
			{
				if (clPCBttn.InnerText.Equals("YES"))
				{
					sessionObject["ClearPageCache"]="YES";
				}
				else
				{
					sessionObject["ClearPageCache"]="NO";
				}
			}
			else
			{
				sessionObject["ClearPageCache"]="NO";
			}
			// End update the Session object with the ClearPageCache information

			XmlNode arrayNode = curPageNode.SelectSingleNode("PlaceHolderArray");
			curPrefillAttribute = curPageNode.SelectSingleNode("@prefill");

			XmlNode titleNode = curPageNode.SelectSingleNode("Title");
			if (titleNode!=null)
			{
				sessionObject["Title"]=titleNode.InnerText;
			}
			else
			{
				sessionObject["Title"]="FrameControl application";
			}
			
			// The Prefill attribute is not null, if it set to yes prefill the control
			// input WebControls by session values
			if (curPrefillAttribute!=null)
			{
				if (curPrefillAttribute.InnerText.ToUpper()=="Y")
				{
					isPrefill = true;
				}
			}

			

			XmlNodeList lines = arrayNode.SelectNodes("tr");
			
			// Update the menu place holder
			XmlNode menuControlNode = currNode2.SelectSingleNode("//menuControl");
			if (menuControlNode!=null)
			{
				try
				{
					string strControlFileName = strControlFolder+"/"+menuControlNode.InnerText+".ascx";
					System.Web.UI.Control menuControl = (System.Web.UI.Control) dispCent.LoadControl(strControlFileName);
					// in any case don't put the menu control twice
					// Test without the HasControls property
					object obj = menuPlaceHolder;
					if (!menuPlaceHolder.HasControls())
					{
						menuPlaceHolder.Controls.Add(menuControl);
					}
				}
				catch (System.IO.FileNotFoundException ex)
				{
					string strEx;
					strEx = ex.ToString();
					sessionObject["ERROR"]=ex.Message;
					sessionObject["ERROR"]="The control defined in the node &#0060;menuControl&#0062; does not exist in the folder defined in APP_USERCONTROLS_FOLDER.";
					Console.WriteLine(ex.Message);
				}
				catch (System.IO.FileLoadException ex)
				{
					string strEx;
					strEx = ex.ToString();
					sessionObject["ERROR"]=ex.Message;
					sessionObject["ERROR"]="The control defined in the node &#0060;menuControl&#0062; could not be loaded.";
					Console.WriteLine(ex.Message);
				}
				
			}   
			else
			{
				sessionObject["ERROR"]="Define a node &#0060;menuControl&#0062; in the XML APP_PAGECONTROLS.";
			}
			for (int j=0; j<lines.Count; j++)
			{
				string debug3;
				string strControlName="";
				System.Web.UI.WebControls.TableCell c;

				debug3 = lines.Item(j).InnerXml;
				System.Web.UI.WebControls.TableRow r = new TableRow();
				XmlNodeList cols = lines.Item(j).SelectNodes("td");
				for (int i=0; i<cols.Count; i++)
				{
					// add a test to do nothing if there is nothing
					// between the two tags <td></td>

					c = new TableCell();

					if (cols.Item(i).SelectSingleNode("name")!=null)
					{
						strControlName = cols.Item(i).SelectSingleNode("name").InnerText;
					
						// Copy all the attributes of the cell TD and add them to c
						XmlAttributeCollection attrColl= cols.Item(i).Attributes;
						//Declare the array.
						XmlAttribute[] array = new XmlAttribute[attrColl.Count];
						int index=0;

						//Copy all the attributes into the array.
						attrColl.CopyTo(array, index);
										
						foreach (XmlAttribute attr in array)
						{
							switch((attr.Name).ToLower())
							{   
								case "width": 
									c.Width=Unit.Parse(attr.Value);
									break;
								case "colspan": 
									c.ColumnSpan=int.Parse(attr.Value);
									break;
								case "rowspan":
									c.RowSpan=int.Parse(attr.Value);
									break;
								case "border": 
									c.BorderWidth=Unit.Parse(attr.Value);
									break;
								case "heigth":
									c.Height=Unit.Parse(attr.Value);
									break;
								case "align":
								switch ((attr.Value).ToLower())
								{
									case "center":
										c.HorizontalAlign=HorizontalAlign.Center;
										break;
									case "justify":
										c.HorizontalAlign=HorizontalAlign.Justify;
										break;
									case "left":
										c.HorizontalAlign=HorizontalAlign.Left;
										break;
									case "right":
										c.HorizontalAlign=HorizontalAlign.Right;
										break;
								}
									break;
								case "valign":
								switch ((attr.Value).ToLower())
								{
									case "bottom":
										c.VerticalAlign=VerticalAlign.Bottom;
										break;
									case "middle":
										c.VerticalAlign=VerticalAlign.Middle;
										break;
									case "top":
										c.VerticalAlign=VerticalAlign.Top;
										break;
								}
									break;
							} // switch((attr.Name).ToLower())

						}
						// END Copy all the attributes of the cell TD and add them to c
						if (strControlName!="")
						{
							curPlaceHolder = new PlaceHolder();
							try
							{
								System.Web.UI.Control curControl = (System.Web.UI.Control) dispCent.LoadControl(strControlFolder+"/"+strControlName+".ascx");
								if (isPrefill)
								{
									PrefillControl(strPN, ref curControl);
								}
								// Update the buttons with the page name information
								AddPageAttribute(strPN, ref curControl);


								curControl.ID = strControlName;
								curPlaceHolder.Controls.Add(curControl);
								h.Add(strControlName,curPlaceHolder);
								c.Controls.Add((System.Web.UI.Control)h[strControlName]);
							}
							catch (Exception ex)
							{
								// Probably the exception comes from the fact that the .ascx
								// file does not exist
								dispCent.Trace.Warn("error while loading PageControl.ascx",ex.ToString());
							}

						} // if (strControlName!="")

					} // if (cols.Item(i).SelectSingleNode("name")!=null)

					
					r.Cells.AddAt(i,c);
				} // for (int i=0; i<cols.Count; i++)

				table1.Rows.Add(r);
			} // for (int j=0; j<lines.Count; j++)
		}

		/// <summary>
		/// Add a private attribute to all active controls (Button,...) in the container.
		/// The Controls that need to be updated with the page Name are just the controls that
		/// can trigger a page change.
		/// <param name="strPN">The name of the page which controls need to be updated.</param>
		/// <param name="container">The name of the container control, which should be a web user control </param>
		/// </summary>
		private void AddPageAttribute(string strPN, ref System.Web.UI.Control container)
		{
			System.Web.UI.ControlCollection allCC;
			allCC = container.Controls;
			for (int k=0; k<allCC.Count; k++)
			{
				// Button type
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.Button")) 
				{
					((System.Web.UI.WebControls.Button)allCC[k]).Attributes.Add("_page",strPN);
				}
				
				// HyperLink type
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.HyperLink")) 
				{
					((System.Web.UI.WebControls.HyperLink)allCC[k]).Attributes.Add("_page",strPN);
				}
				
				// ImageButton type
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.ImageButton")) 
				{
					((System.Web.UI.WebControls.ImageButton)allCC[k]).Attributes.Add("_page",strPN);
				}
				
				// LinkButton type
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.LinkButton")) 
				{
					((System.Web.UI.WebControls.LinkButton)allCC[k]).Attributes.Add("_page",strPN);
				}
			}
		}

		/// <summary>
		/// Update the control with Sessions information
		// This function is used to prefill the controls with values previously entered
		// by the user.
		/// </summary>
		/// <param name="strPN">The name of the page which controls need to be filled.</param>
		/// <param name="container">The name of the control, which should be a web user control, 
		/// whose children controls will be filled with data previously entered by the user</param>
		private void PrefillControl(string strPN, ref System.Web.UI.Control container)
		{
			XmlNode curPageNode;
			XmlDocument debugXml = MCContext;
			curPageNode = MCContext.DocumentElement.SelectSingleNode("//page[@name='"+strPN+"']");
			if (curPageNode == null)
			{
				// No need to perform further, the page has not been visited yet
				return;
			}
			
			System.Web.UI.ControlCollection allCC;
			allCC = container.Controls;
			System.Web.UI.Control childControl;
			for (int k=0; k<allCC.Count; k++)
			{
				// the type of the control is a panel: we have to recurse in its inner controls
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.Panel")) 
				{
					childControl = allCC[k];
					PrefillControl(strPN, ref childControl);

				}
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.TextBox"))
				{
					XmlNode ctxtTextBox = curPageNode.SelectSingleNode(@"//item[@name='"+allCC[k].ID+@"']");

					if (ctxtTextBox!=null)
					{
						((TextBox)allCC[k]).Text=ctxtTextBox.InnerText;
					}
				}
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.HtmlControls.HtmlInputText"))
				{
					XmlNode ctxtHtmlInputBox = curPageNode.SelectSingleNode(@"//item[@name='"+allCC[k].ID+@"']");
					if (ctxtHtmlInputBox!=null)
					{
						((HtmlInputText) allCC[k]).Value = ctxtHtmlInputBox.InnerText;
					}
				}
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.CheckBox"))
				{
					XmlNode ctxtCheckBox = curPageNode.SelectSingleNode(@"//item[@name='"+allCC[k].ID+@"']");
					if (ctxtCheckBox!=null)
					{
						if (ctxtCheckBox.InnerText.ToUpper()=="TRUE")
						{
							((CheckBox)allCC[k]).Checked = true;
						}
					}
				}
				
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.RadioButton"))
				{
					XmlNode ctxtCheckBox = curPageNode.SelectSingleNode(@"//item[@name='"+allCC[k].ID+@"']");
					if (ctxtCheckBox!=null)
					{
						if (ctxtCheckBox.InnerText.ToUpper()=="TRUE")
						{
							((RadioButton)allCC[k]).Checked = true;
						}
					}
				}

				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.DropDownList"))
				{
					foreach (ListItem litem in ((DropDownList) allCC[k]).Items)
					{
						XmlNode ctxtListItem = curPageNode.SelectSingleNode(@"//item[@text='"+litem.Text+@"']");
						if (ctxtListItem!=null)
						{
							if (ctxtListItem.InnerText.ToUpper()=="TRUE")
							{
								litem.Selected=true;
							}
						}
					}
				}
				
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.CheckBoxList"))
				{
					foreach (ListItem litem in ((CheckBoxList) allCC[k]).Items)
					{
						XmlNode ctxtListItem = curPageNode.SelectSingleNode(@"//item[@text='"+litem.Text+@"']");
						if (ctxtListItem!=null)
						{
							if (ctxtListItem.InnerText.ToUpper()=="TRUE")
							{
								litem.Selected=true;
							}
						}
					}
				}
				if (allCC[k].GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList"))
				{
					foreach (ListItem litem in ((RadioButtonList) allCC[k]).Items)
					{
						XmlNode ctxtListItem = curPageNode.SelectSingleNode(@"//item[@text='"+litem.Text+@"']");
						if (ctxtListItem!=null)
						{
							if (ctxtListItem.InnerText.ToUpper()=="TRUE")
							{
								litem.Selected=true;
							}
						}
					}
				}
			}
			
		}
	
		/// <summary>
		/// The function ExecuteSavePoint executes the stored procedure that has been defined
		/// in the specific SavePoint in the XML configuration file. 
		/// 
		/// All the input parameters of the stored procedure are taken from the values contained
		/// in the MCContext document. 
		/// 
		/// </summary>
		/// <param name="strSavePoint">The name of the savePoint that needs to be executed.</param>
		/// <returns>The return string contains the stored procedure output parameters</returns>
		public string ExecuteSavePoint(string strSavePoint)
		{
			// retrieve the configuration string of the database link
			// for JobMorning
			string connStr = ConfigurationSettings.AppSettings["JobMorning_DB"];
			// nv1 will contain all the stored procedure name and value
			NameValueCollection nv1 = new NameValueCollection();
			bool automateParams = false;

			XmlDocument ControlParamXML = (XmlDocument)sessionObject["DBSavePoints"];
 

			// retrieve the right SavePoint node 
			
			XmlNode curSavePt = ControlParamXML.SelectSingleNode("//SavePoint[@Name='"+strSavePoint+"']");

			if (curSavePt==null)
			{
				string strError = "<error>Save point ";
				strError += strSavePoint;
				strError += " node not existing</error>";
				return strError;
			}
			else
			{
				
				XmlNode paramAuto = ControlParamXML.SelectSingleNode("//SavePoint[@Name='"+strSavePoint+"']/@autoParam");
				if (paramAuto!=null)
				{
					if (paramAuto.InnerText=="Y")
					{
						automateParams = true;
					}
				}
				
				XmlNode procNameNode = ControlParamXML.SelectSingleNode("//SavePoint[@Name='"+strSavePoint+"']/Procedure");
				if (procNameNode==null)
				{
					return "<error>Procedure name is not defined in the save point node</error>";
				}
				else
				{
					string strCurPar;
					string strCurPage;
					
					XmlNodeList dbControlList = ControlParamXML.SelectNodes("//SavePoint[@Name='"+strSavePoint+"']/InputParams/Param/DBControl");
					if (MCContext!=null)
					{
						foreach (XmlNode ll in dbControlList)
						{
							int postDot = ll.InnerText.IndexOf(".");
							if ((postDot == -1)|(postDot == (ll.InnerText.Length-1)))
							{
								string strError0;
								strError0 = "<error>Use a dot before control name</error>";
								return strError0;
							}
							strCurPage = ll.InnerText.Substring(0,postDot);
							strCurPar = ll.InnerText.Substring(postDot+1,ll.InnerText.Length-postDot-1);
							
							if (strCurPage.ToUpper().Equals("SESSION"))
							{
								
								object objectValue = sessionObject[strCurPar];
								System.Type objectType;
								if (objectValue==null)
								{
									string strError0;
									strError0 = "<error>"+strCurPar+" is not defined in SESSION</error>";
									return strError0;
								}
								else
								{
									objectType = objectValue.GetType();
								}
								
								XmlNode curParamNode2 = ll.ParentNode.SelectSingleNode("DBParam");
								if (curParamNode2==null)
								{
									// Add the parameter only if it's of type string
									if (objectType.Equals(System.Type.GetType("System.String")))
									{
										nv1.Add(strCurPar,(string)objectValue);
									}
									if (objectType.Equals(System.Type.GetType("System.Int32")))
									{
										nv1.Add(strCurPar,(Convert.ToString((int)objectValue)));
									}
									if (objectType.Equals(System.Type.GetType("System.Single")))
									{
										nv1.Add(strCurPar,(Convert.ToString((float)objectValue)));
									}
									if (objectType.Equals(System.Type.GetType("System.Double")))
									{
										nv1.Add(strCurPar,(Convert.ToString((double)objectValue)));
									}
								}
								else
								{
									// Add the parameter only if it's of type string
									if (objectType.Equals(System.Type.GetType("System.String")))
									{
										nv1.Add(curParamNode2.InnerText,(string)objectValue);
									}
									if (objectType.Equals(System.Type.GetType("System.Int32")))
									{
										nv1.Add(curParamNode2.InnerText,(Convert.ToString((int)objectValue)));
									}
									if (objectType.Equals(System.Type.GetType("System.Single")))
									{
										nv1.Add(curParamNode2.InnerText,(Convert.ToString((float)objectValue)));
									}
									if (objectType.Equals(System.Type.GetType("System.Double")))
									{
										nv1.Add(curParamNode2.InnerText,(Convert.ToString((double)objectValue)));
									}
								}
							}
							else
							{
								XmlDocument xmlDoc2 = (XmlDocument)sessionObject["PageControls"];
								XmlNode currNode2;
								currNode2 = xmlDoc2.DocumentElement;
								XmlNode arrayNode = currNode2.SelectSingleNode("//Page[@Name='"+strCurPage+"']/PlaceHolderArray");
								// If the page does not exist, jump to the next one
								// until you find one existing
								if (arrayNode == null)
								{
									string strError0;
									strError0 = "<error> In "+ll.InnerText+" the first parameter should be a page name</error>";
									return strError0;
								}
								if (MCContext!=null)
								{
									XmlNodeList dbControlNodesList = MCContext.DocumentElement.SelectNodes("//page[@name='"+strCurPage+"']//item[@dbcontrol='"+strCurPar+"']");
									if (dbControlNodesList.Count>1)
									{
										string strError1;
										strError1 = "<error>dbcontrol "+strCurPar+" has been defined more than one time in the same page</error>";
										return strError1;
									}
									if (dbControlNodesList.Count==0)
									{
										string strError1;
										strError1 = "<error>No dbcontrol "+strCurPar+" has been defined</error>";
										return strError1;
									}
									if (dbControlNodesList.Count==1)
									{
										// only on that case retrieve DBParam from DBSavePoints
										XmlNode curParamNode = ll.ParentNode.SelectSingleNode("DBParam");
										if (curParamNode==null)
										{
											nv1.Add(strCurPar,dbControlNodesList.Item(0).InnerText);
										}
										else
										{
											nv1.Add(curParamNode.InnerText,dbControlNodesList.Item(0).InnerText);
										}
									}
								}
							}
						}
					}
					else
					{
						return "<error>MCContext document is null</error>";
					}
					
					string sprocName = procNameNode.InnerText;
					

					SqlConnection dataConn = null;
					SqlDataAdapter da = null;
					try 
					{
						dataConn = new SqlConnection(connStr);
						//Create DataAdapter
						da = new SqlDataAdapter();
						SqlCommand selcon;
						if (!automateParams)
						{
							string sprocConfigPath = (string)appObject["SprocParametersFile"];
							dataConn.Open();
							SPGenerator sprocGen = new SPGenerator(sprocConfigPath);
							selcon = sprocGen.GenerateSqlCommandandParams(dataConn.Database,
								sprocName,nv1);
						}
						else
						{
							//TODO
							selcon =JobMorning.SPGenerator.GenerateSqlAutomatic(dataConn,sprocName,nv1);
							dataConn.Open();
						}
						da.SelectCommand = selcon;
						string commandDesc;
						commandDesc = selcon.CommandText.ToString();
						da.SelectCommand.Connection = dataConn;               
						DataSet ds = new DataSet();
						da.Fill(ds);	
						
						string strReturn = "";
						foreach ( SqlParameter parameter in da.SelectCommand.Parameters)
						{
							if (parameter.Direction== ParameterDirection.Output)
							{		
								strReturn+="<Output>";
								strReturn+= "<Name>"+parameter.ParameterName+"</Name>";
								strReturn+= "<Value>"+parameter.Value+"</Value>";
								strReturn+="</Output>";
							} // if (parameter.Direction=  ParameterDirection.Output)
							if (parameter.Direction==  ParameterDirection.ReturnValue)
							{		
								strReturn+="<ReturnValue>";
								strReturn+= "<Name>"+parameter.ParameterName+"</Name>";
								strReturn+= "<Value>"+parameter.Value+"</Value>";
								strReturn+="</ReturnValue>";
							} // if (parameter.Direction=  ParameterDirection.ReturnValue)
							if (parameter.Direction==  ParameterDirection.InputOutput)
							{		
								strReturn+="<InputOutput>";
								strReturn+= "<Name>"+parameter.ParameterName+"</Name>";
								strReturn+= "<Value>"+parameter.Value+"</Value>";
								strReturn+="</InputOutput>";
							}
						}
						if (strReturn.Length==0)
						{
							strReturn+="<OutParam>None</OutParam>";
						}	
						return strReturn;
					} 
					catch (System.Data.SqlClient.SqlException exp) 
					{
						string strError = "<error>";
						strError += "<description>error while executing stored procedure.";
						strError += "SQLException occured.</description>";
						strError += "<SavePointInputParams>";
						foreach (string str in nv1)
						{
							strError += "<item>"+str+"</item>";
						}
						strError += "</SavePointInputParams>";
						strError += "<exceptionMessage>"+exp.Message+"</exceptionMessage>";
						strError += "<StackTrace>"+exp.StackTrace+"</StackTrace>";
						strError += "</error>";
						return strError;
					}
					finally 
					{
						if (dataConn.State == ConnectionState.Open) dataConn.Close();
					}
					
				}
			}
		}
		

		/// <summary>
		/// The function JumPage goes to a specific page defined in the Pages XML configuration files.
		/// It does not take into account the any path information, and the data of the current page 
		/// is not saved. The current path remains the same.
		/// </summary>
		/// <param name="strPage">The name of the new page where the user will be led.</param>
		public void JumpPage(string strPage)
		{
			dispCent = (DisplayCentral)sessionObject["currentMainPage"];
			sessionObject["CurrentPage"] = strPage;
			dispCent.UpdateControlArray();
		}

		/// <summary>
		/// The ClickAction method uses the path parameter to jump to the page following the current
		/// page in this path node. If the node following the current page in the specified path is
		/// a savepoint, it is executed. If many savepoints follow the current page in the path node, 
		/// they
		/// </summary>
		/// <param name="paths">The name of the path which defines the transition from the current 
		/// page to the next page.</param>
		public void ClickAction(string paths, string strPN)
		{
			XmlDocument xmlPathDoc = (XmlDocument)appObject["userPaths"];
			XmlNode currNodePathRoot;
			currNodePathRoot = xmlPathDoc.DocumentElement;

			sessionObject["CurrentPage"] = strPN;
			
			dispCent = (DisplayCentral)sessionObject["currentMainPage"];
			string strPageHTML;
			
			strPageHTML = dispCent.GetPageXml(ref lastInputParameters);
			StoreState(strPN, strPageHTML, "page");
			
			// Launch ActionClass events for the current page.
			// State is after saving into the context and beofre executing savePoints.
			
			ActionClassContainer theContainer;
			theContainer = (ActionClassContainer)appObject["ActionClasses"];
			theContainer.DoAfterContextSave(strPN, MCContext.OuterXml);

			string strErrorMessage = "";
			bool isPageValidated = true;
			isPageValidated = theContainer.ValidatePageBeforeSavePoints(strPN,lastInputParameters,out strErrorMessage);
			if ((strErrorMessage.Length!=0)&&(!isPageValidated))
			{
				string strPopUp = 
					@"<script language=""JavaScript"">alert('"+strErrorMessage+"');</script>";
				dispCent.RegisterStartupScript("PopUp",strPopUp);
			} // if ((strErrorMessage!="")&&(!isPageValidated))

			XmlNode curPageNode = currNodePathRoot.SelectSingleNode("//Path[@number='"+paths+"']/Page[@Name='"+strPN+"']");
			if ((curPageNode!=null)&&(isPageValidated))
			{
				// The path designated as a parameter in the button exists,
				// and refers the current page.
				// In that case, the framework should link to the following page.
				XmlNode nextPageNode = curPageNode.NextSibling;
				if ((nextPageNode!=null)&(nextPageNode.Name.Equals("Page")))
				{
					// Check if the page exists in the document PageControls
					
					XmlDocument xmlDoc2 = (XmlDocument)sessionObject["PageControls"];
					XmlNode currNode2;
					currNode2 = xmlDoc2.DocumentElement;

					strNextPage = nextPageNode.Attributes["Name"].InnerText;

					XmlNode arrayNode = currNode2.SelectSingleNode("//Page[@Name='"+strNextPage+"']/PlaceHolderArray");
					// If the page does not exist, jump to the next one
					// until you find one existing
					sessionObject["CurrentPage"] = strNextPage;
					if (arrayNode == null)
					{
						this.ClickAction(paths, strNextPage);
						return;
					}
					
				}
				else
				{
					while ((nextPageNode!=null)&(nextPageNode.Name.Equals("SavePoint")))
					{
						// executes a stored procedure
						// string strCurSavePoint = nextPageNode.SelectSingleNode("@Name").InnerText;
						// for debug:
						string strCurSavePoint = nextPageNode.SelectSingleNode("@Name").InnerText;
						string strSavePointResult = ExecuteSavePoint(strCurSavePoint);
						StoreState(strCurSavePoint, strSavePointResult, "savepoint");
						
						// ******* Execute the doAfterSavePoint method of ActionClass
						strErrorMessage = "";
						isPageValidated = true;
						isPageValidated = theContainer.ValidatePageAfterSavePoint(strPN,strCurSavePoint,MCContext.OuterXml,out strErrorMessage);
						// ValidatePageBeforeSavePoints(strPN,lastInputParameters,ref strErrorMessage);
						if ((strErrorMessage.Length!=0)&&(!isPageValidated))
						{
							string strPopUp = 
								@"<script language=""JavaScript"">alert('"+strErrorMessage+"');</script>";
							dispCent.RegisterStartupScript("PopUp",strPopUp);
						} // if ((strErrorMessage!="")&&(!isPageValidated))
						if (!isPageValidated)
						{
							return;
						}
						// ******* End Execute the doAfterSavePoint method of ActionClass

						nextPageNode = nextPageNode.NextSibling;
					}
					if ((nextPageNode!=null)&(nextPageNode.Name.Equals("Page")))
					{
						strNextPage = nextPageNode.Attributes["Name"].InnerText;
						sessionObject["CurrentPage"] = strNextPage;
					}
				}
			}
			dispCent.UpdateControlArray();
		}

	}
}

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

S. Jehan

Japan Japan
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 26 Jul 2003
Article Copyright 2003 by S. Jehan
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid