Skip Navigation Links.

Northwind\WebControls\WebEnvBase.cs

D:\NorthwindForWeb\Northwind\CS\DotNet\ADO.Net\Northwind\WebControls\WebEnvBase.cs
/*
 * This file was generated by ProCG version 2.0
 *
 * File name:	Northwind\WebControls\WebEnvBase.cs
 * Language:	C# - ADO.Net 
 * Database:	My Sql
 *
 * Copyright (c) 2002-2019 iGenXSoft.
 * For more information visit http://www.igenxsoft.com
 */


using System;
using System.Data;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;
using System.Web.UI.WebControls;
using System.Web;
using System.Web.UI;
using Northwind.General;
using Northwind.Data;

namespace Northwind.WebControls
{
	/// <summary>
	/// Summary description for NorthwindWebEnvBase.
	/// </summary>
	public abstract class NorthwindWebEnvBase
	{

		protected DataManager		m_DataManager;
		protected ComboBoxManager	m_ComboBoxManager;
		protected System.Web.UI.Control m_ContainerControl;
		protected string m_TDClass;
		protected string m_TRClass;
		protected bool	 m_bDesignMode;
		protected System.Web.UI.WebControls.Label m_LabelNoParams;
		protected System.Web.UI.WebControls.Label m_LabelNoParamsText;
		protected CStructData m_StructData;
		protected bool m_EditAllRows = false;

		public const string DiscardChangesConst = "DISCARD_CHANGES";
		public const string SaveConst = "SAVE";
				
		public NorthwindWebEnvBase()
		{
		}

		public CStructData StructData
		{
			get { return m_StructData; }
			set { m_StructData = value; }
		}

		public virtual System.Web.UI.Control ContainerControl
		{
			get
			{
				return m_ContainerControl;
			}
			set
			{ 
				m_ContainerControl = value;
			}
		}

		public virtual DataManager DataManager
		{
			get
			{
				if (m_DataManager != null)
					return m_DataManager;

				if (this.ContainerControl.Page is NorthwindPage)
				{
					NorthwindPage page = (NorthwindPage)(this.ContainerControl.Page);
					m_DataManager = (page.DataManager);
				}
				else
				{
					throw new Exception("Running in an invalid context - This can only in NorthwindPage page type Current PageType=" + this.ContainerControl.Page.GetType().ToString());
				}
				return ((NorthwindPage)(this.ContainerControl.Page)).DataManager;
			}
			set
			{
				m_DataManager = value;
			}
		}

		public virtual ComboBoxManager ComboBoxManager
		{
			get
			{
				if (m_ComboBoxManager != null)
					return m_ComboBoxManager;

				if (this.ContainerControl.Page is NorthwindPage)
				{
					NorthwindPage page = (NorthwindPage)(this.ContainerControl.Page);
					m_ComboBoxManager = (page.ComboBoxManager);
				}

				else
				{
					throw new Exception("Running in an invalid context - This can only in NorthwindPage page type");
				}

				return m_ComboBoxManager;
			}
			set
			{
				m_ComboBoxManager = value;
			}
		}

		public string TDClass
		{
			get { return m_TDClass; }
			set { m_TDClass = value;}
		}

		public string TRClass
		{

			get { return m_TRClass; }
			set { m_TRClass = value;}
		}

		public bool IsInDesignMode(System.Web.UI.Control containerControl)
		{
			if (containerControl.Site != null) 
				return containerControl.Site.DesignMode; 
			return false;				  
		} 

		public virtual void GetColumnsControlsValues(NorthwindGrid grid, int rowIndex, CStructData structData)
		{
			throw new NotImplementedException("GetColumnsControlsValues(NorthwindGrid grid, int rowIndex, CStructData structData) not implemented in " + this.GetType().ToString());
		}

		public virtual void CreateGridColumns(NorthwindGrid grid)
		{
			throw new NotImplementedException("CreateGridColumns(NorthwindGrid grid) not implemented in " + this.GetType().ToString());
		}

		public virtual void CreateGridColumns(NorthwindGrid grid, FieldShowModeEnum[] fieldsShowMode)
		{
			throw new NotImplementedException("CreateGridColumns(NorthwindGrid grid, FieldShowModeEnum[] fieldsShowMode) not implemented in " + this.GetType().ToString());
		}

		public virtual void CreateGridColumns(NorthwindGrid grid, CFieldAttributeCollection fieldAttributeCollection)
		{
			throw new NotImplementedException("CreateGridColumns(NorthwindGrid grid, CFieldAttributeCollection fieldAttributeCollection) not implemented in "+this.GetType().ToString());
		}

		public virtual int NumTotalFields 
		{ 
			get 
			{
				throw new NotImplementedException("NumTotalFields property not implemented in " + this.GetType().ToString()); 
			}
		}

		public virtual bool DesignMode
		{
			get { return m_bDesignMode;}
			set { m_bDesignMode = value;}
		}

		public virtual System.Web.UI.WebControls.WebControl AddNoParamsTextAsTR(System.Web.UI.Control tableControl)
		{
			TableRow	tableRow;
			TableCell	tableCell;
			System.Web.UI.WebControls.WebControl createdControl;
			
			tableRow = new TableRow();
			tableRow.ID ="NoParamsdRow";
			tableControl.Controls.Add(tableRow);

			// Label
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			tableCell.CssClass = "sslabel"; 
			this.CreateNoParamsLabelControl(tableCell);

			// Control
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			createdControl = this.CreateNoParamsTextLabelControl(tableCell);

			return (createdControl);
		}

		public virtual System.Web.UI.WebControls.WebControl CreateNoParamsLabelControl(System.Web.UI.Control containerControl)
		{
			// 
			// m_LabelNoParams
			// 
			m_LabelNoParams = new System.Web.UI.WebControls.Label();			
			m_LabelNoParams.ID = "labelNoParams";
			m_LabelNoParams.Text = "Parameters";

			containerControl.Controls.Add(m_LabelNoParams);
			return (m_LabelNoParams);
		}

		public virtual System.Web.UI.WebControls.WebControl CreateNoParamsTextLabelControl(System.Web.UI.Control containerControl)
		{
			// 
			// m_LabelNoParams
			// 
			m_LabelNoParamsText = new System.Web.UI.WebControls.Label();			
			m_LabelNoParamsText.ID = "labelNoParamsText";
			m_LabelNoParamsText.Text = "No Parameters";
			containerControl.Controls.Add(m_LabelNoParamsText);
			return (m_LabelNoParamsText);
		}

		public virtual  void SetDynamicFieldsAttributes(System.Web.UI.Control tableControl)
		{
			throw new NotImplementedException("SetDynamicFieldsAttributes(System.Web.UI.Control tableControl) not implemented in "+this.GetType().ToString());
		}


		public virtual DataGridColumn CreateRowStatusColumn(NorthwindGrid grid)
		{			
			BoundColumn boundColumn = new BoundColumn();
			boundColumn.HeaderText = "Row<br/>Status";
			boundColumn.DataField = "StatusName";
			boundColumn.ReadOnly = true;
			boundColumn.SortExpression = "0"; // column 0 means row status
			TableItemStyle tableItemStyle = new TableItemStyle();
			boundColumn.HeaderStyle.CssClass = "DataGridRowStatus";
			boundColumn.ItemStyle.CssClass = "DataGridRowStatus";

			grid.Columns.Add(boundColumn);
			grid.CellsPosition["StatusName"] = grid.Columns.Count-1;

			return (boundColumn);
		}

		public virtual void SetDropDownListInfoFromCodesTable(System.Web.UI.WebControls.DropDownList dropDownList, int codesTableNum, bool valueRequired)
		{
			CCodesCollection codesCollection = NorthwindCodesManager.GetInstance().GetTableCodesCollection(codesTableNum);
			SetDropDownListInfoFromCodesTable(dropDownList,codesCollection, valueRequired);
		}

		public virtual void SetDropDownListInfoFromCodesTable(System.Web.UI.WebControls.DropDownList dropDownList, CCodesCollection codesCollection, bool valueRequired)
		{
			if (!valueRequired && codesCollection.FindByCodeField(0) == null)
			{
				CCodes codes = codesCollection.InsertNewCodes(0); // at the begining
				codes.Description = ComboBoxManager.EmptyOptionText;
			}
				
			if (dropDownList.Visible) // indication it is inside databind event
			{
				try
				{
					dropDownList.Items.Clear();
					dropDownList.DataSource = codesCollection;
					dropDownList.DataTextField = "Description";
					dropDownList.DataValueField = "CodeNum";
					dropDownList.DataBind();
				}
				catch (Exception) { } // ignore if selected value does not exist in utems
			}	
		}


		public virtual void SetRadioButtonListInfoFromCodesTable(System.Web.UI.WebControls.RadioButtonList radioButtonList, int codesTableNum)
		{
			CCodesCollection codesCollection = NorthwindCodesManager.GetInstance().GetTableCodesCollection(codesTableNum);
			SetRadioButtonListInfoFromCodesTable(radioButtonList,codesCollection);
		}

		public virtual void SetRadioButtonListInfoFromCodesTable(System.Web.UI.WebControls.RadioButtonList radioButtonList, CCodesCollection codesCollection)
		{
				
			radioButtonList.Items.Clear(); 
			radioButtonList.DataSource = codesCollection;
			radioButtonList.DataTextField = "Description";  
			radioButtonList.DataValueField = "CodeNum";
			if (radioButtonList.Visible) // indication it is inside databind event
			{
				try
				{
					radioButtonList.DataBind();
				}
				catch (Exception) { } // ignore - invalid value
			}
		}

		public virtual void SetDescriptionValue(int fieldNum, CStructData structData, Label descriptionLabel)
		{
			throw new NotImplementedException("SetDescriptionValue(int fieldNum, CStructData structData, Label descriptionLabel) not implemented in "+this.GetType().ToString());
		}

		protected static void SetControlAttributes(System.Web.UI.WebControls.TextBox textBox, 
			string id, FieldShowModeEnum fieldShowMode, int maxLength, int size, int numLines , 
			System.Web.UI.WebControls.TextBoxMode textBoxMode)
		{
			if (!(textBox.NamingContainer is ListViewDataItem) &&
				!(textBox.NamingContainer is GridViewRow))
				textBox.ID = id;
			//else
			// leave the ID as it was

			// don't change the class name if was set manually
			string originCss = textBox.CssClass;
			textBox.CssClass = "";

			if (textBox.CssClass == null || textBox.CssClass == "")
			{
				if (textBoxMode == System.Web.UI.WebControls.TextBoxMode.MultiLine)
					textBox.CssClass = Northwind.General.NorthwindGeneral.WebTextAreaClassName;
				else 
					textBox.CssClass = Northwind.General.NorthwindGeneral.WebTextBoxClassName;
			}

			if (fieldShowMode == FieldShowModeEnum.SHOW_NORMAL || fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				if (textBoxMode == System.Web.UI.WebControls.TextBoxMode.MultiLine)
				{
					if (size != 0)
					{
						textBox.Columns = size;
					}

					if (numLines != 0)
					{
						textBox.Rows = numLines;
					}
					else
					{
						textBox.Rows = numLines;
					}
				}
				else
				{
					//m_TextBoxDescription.Attributes["Align"] = "Right";

					if (maxLength != 0)
					{
						textBox.MaxLength = maxLength;
					}
				}
				if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
				{
					if (textBox.NamingContainer is NorthwindWCC)
					{
						textBox.CssClass += " Disabled";
					}
					textBox.CssClass += " Disabled ";
				}
			}

			if (size > 0)
			{
				int pixels = GetNumPixelsFromChars(size);
				//textBox.Attributes["style"] = "width:" + pixels + "px";
				if (textBox is Obout.Interface.OboutTextBox)
					textBox.Width = pixels + 20; // extra 10 pix for each size for the gif
				else
					textBox.Width = pixels;

			}
			if (!textBox.CssClass.Equals(originCss))
				textBox.CssClass += " " + originCss;

			textBox.TextMode = textBoxMode;
			
			if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				textBox.ReadOnly = true;
			}
			else if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				textBox.CssClass = "hidden";
			}
		}

		public static int GetNumPixelsFromChars(int numChars, bool rounded = true)
		{
			if (rounded)
			{
				int remain = numChars % 5;
				int fives = numChars / 5;
				if (remain > 0) fives++;
				return fives * 37;
			}
			else
			{
				float sizePerChar = 37.0F / 5.0F;
				float totalSize = numChars;
				totalSize *= sizePerChar;
				int intTotalSize = (int)totalSize;
				if (intTotalSize < totalSize)
				{
					intTotalSize++;
				}
				return intTotalSize;
			}
		}

		public static void SetControlAttributes(System.Web.UI.WebControls.TextBox textBox, string id, FieldShowModeEnum fieldShowMode, int maxLength, int size, int numLines)
		{
			if (numLines > 1)
			{
				SetControlAttributes(textBox,id,fieldShowMode,maxLength,size,numLines,TextBoxMode.MultiLine);
			}
			else
			{
				SetControlAttributes(textBox,id,fieldShowMode,maxLength,size,1,TextBoxMode.SingleLine);
			}
		}

		public static void SetControlAttributes(System.Web.UI.WebControls.TextBox textBox, string id, FieldShowModeEnum fieldShowMode, int maxLength, int size)
		{
				SetControlAttributes(textBox,id,fieldShowMode,maxLength,size,1,TextBoxMode.SingleLine);
		}

		public static void SetControlAttributes(System.Web.UI.WebControls.TextBox textBox, string id, FieldShowModeEnum fieldShowMode, int size)
		{
			SetControlAttributes(textBox,id,fieldShowMode,size,size,1,TextBoxMode.SingleLine);
		}

		public static void SetControlAttributes(System.Web.UI.WebControls.TextBox textBox, string id, FieldShowModeEnum fieldShowMode)
		{
			SetControlAttributes(textBox,id,fieldShowMode,0,0,1,TextBoxMode.SingleLine);
		}
				
		public virtual void SetDropDownTextAttributes(System.Web.UI.WebControls.TextBox textBox, string id, FieldShowModeEnum fieldShowMode)
		{
			textBox.ID = id;
			textBox.CssClass = "TextBoxOfDDLCss";
		}

		public virtual void SetChooseWindowLabelAttributes(System.Web.UI.WebControls.Label label, string id, FieldShowModeEnum fieldShowMode)
		{
			label.ID = id;

			label.CssClass = "descrptionOfLookupCss";
			label.Width = 100;
			label.Text = "Description";
		}

		public virtual void SetChooseWindowButtonAttributes(System.Web.UI.WebControls.ImageButton imageButton, string id, FieldShowModeEnum fieldShowMode)
		{
			imageButton.ID = id;
			imageButton.CssClass = "imageOfChooseWindowCss";
		}

		public void SetControlAttributes(System.Web.UI.WebControls.DropDownList dropDownList, string id, FieldShowModeEnum fieldShowMode)
		{
			dropDownList.ID = id;
			// don't change the class name if was set manually
			if (dropDownList.CssClass == null || dropDownList.CssClass == "")
				dropDownList.CssClass = Northwind.General.NorthwindGeneral.WebDropDownClassName;

			dropDownList.Enabled = true;

			if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				dropDownList.Enabled = false;
			}
			else if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				dropDownList.CssClass = "hidden";
			}
		}

		public void SetControlAttributes(System.Web.UI.WebControls.RadioButtonList radioButtonList, string id, FieldShowModeEnum fieldShowMode)
		{
			radioButtonList.ID = id;
			// don't change the class name if was set manually
			if (radioButtonList.CssClass == null || radioButtonList.CssClass == "")
				radioButtonList.CssClass = Northwind.General.NorthwindGeneral.WebRadioButtonListClassName;

			radioButtonList.Enabled = true;

			if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				radioButtonList.Enabled = false;
			}
			else if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				radioButtonList.CssClass = "hidden";
			}
		}

		public void SetControlAttributes(System.Web.UI.WebControls.CheckBox checkBox, string id, FieldShowModeEnum fieldShowMode)
		{
			checkBox.ID = id;
			// don't change the class name if was set manually
			if (checkBox.CssClass == null || checkBox.CssClass == "")
				checkBox.CssClass = Northwind.General.NorthwindGeneral.WebCheckBoxClassName;

			checkBox.Enabled = true;


			if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				checkBox.Enabled = false;
			}
			else if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				checkBox.CssClass = "hidden";
			}
		}

		public virtual void SetLabelAttributes(System.Web.UI.WebControls.Label label, string id, string text, FieldShowModeEnum fieldShowMode)
		{
			label.ID = id;
			label.Text = text;

			SetLabelAttributes(label, fieldShowMode);
		}
		
		public virtual void SetLabelAttributes(System.Web.UI.WebControls.Label label, FieldShowModeEnum fieldShowMode)
		{
			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				label.CssClass = "hidden";
			}
			else
				label.CssClass = Northwind.General.NorthwindGeneral.WebLabelClassName;
		}

		public virtual void SetChooseWindowControlAttributes(int fieldNum, System.Web.UI.WebControls.TextBox codeTextBox, System.Web.UI.WebControls.ImageButton imageButton, System.Web.UI.WebControls.Label descriptionTextBox, FieldShowModeEnum fieldShowMode)
		{			
			throw new NotImplementedException("SetChooseWindowControlAttributes(int fieldNum, System.Web.UI.WebControls.TextBox codeTextBox, System.Web.UI.WebControls.ImageButton imageButton, System.Web.UI.WebControls.Label descriptionTextBox, FieldShowModeEnum fieldShowMode) not implemented in "+this.GetType().ToString());
		}

		public void SetControlAttributes(XinCalendarWCC calendar, string id, FieldShowModeEnum fieldShowMode)
		{
			calendar.ShowMode = fieldShowMode;
			calendar.ID = id;
			// don't change the class name if was set manually
			if (calendar.CssClass == null || calendar.CssClass == "")
				calendar.CssClass = Northwind.General.NorthwindGeneral.WebCalendarClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				calendar.CssClass = "hidden";
			}
		}
		
		public void SetControlAttributes(DateAndTimeWCC dateAndTime, string id, FieldShowModeEnum fieldShowMode)
		{
			dateAndTime.FieldShowMode = fieldShowMode;
			dateAndTime.ID = id;
			// don't change the class name if was set manually
			if (dateAndTime.CssClass == null || dateAndTime.CssClass == "")
				dateAndTime.CssClass = Northwind.General.NorthwindGeneral.WebCalendarClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				dateAndTime.CssClass = "hidden";
			}
		}

		public void SetControlAttributes(System.Web.UI.WebControls.Image image, string id, FieldShowModeEnum fieldShowMode)
		{
			image.ID = id;
			// don't change the class name if was set manually
			if (image.CssClass == null || image.CssClass == "")
				image.CssClass = Northwind.General.NorthwindGeneral.WebImageClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				image.CssClass = "hidden";
			}
		}

		public void SetControlAttributes(FileWUC file, string id, FieldShowModeEnum fieldShowMode)
		{
			file.ID = id;
			// don't change the class name if was set manually
			if (file.CssClass == null || file.CssClass == "")
				file.CssClass = Northwind.General.NorthwindGeneral.WebFileClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				file.CssClass = "hidden";
			}
		}

		public void SetControlAttributes(FileBinaryWUC fileBinary, string id, FieldShowModeEnum fieldShowMode)
		{
			fileBinary.ID = id;
			// don't change the class name if was set manually
			if (fileBinary.CssClass == null || fileBinary.CssClass == "")
				fileBinary.CssClass = NorthwindGeneral.WebFileBinaryClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				fileBinary.CssClass = "hidden";
			}
		}
		
		public void SetControlAttributes(IWebCustomControl webCustomControl, string id, FieldShowModeEnum fieldShowMode)
		{
			webCustomControl.ID = id;
			// don't change the class name if was set manually
			webCustomControl.FieldShowMode = fieldShowMode;
			webCustomControl.WebCustomeControlPlace = WebCustomeControlPlaceEnum.DataControl;
		}

		public void SetControlAttributes(Calendar calendar, string id, FieldShowModeEnum fieldShowMode)
		{
			calendar.ID = id;
			// don't change the class name if was set manually
			if (calendar.CssClass == null || calendar.CssClass == "")
				calendar.CssClass = NorthwindGeneral.WebCalendarClassName;

			if (fieldShowMode == FieldShowModeEnum.HIDDEN)
			{
				calendar.CssClass = "hidden";
			}
		}

		// XinCalendar functions
		public virtual DataGridColumn CreateXinCalendarColumn(NorthwindGrid grid, CStructData structData, int fieldNum, string fieldName, FieldShowModeEnum fieldShowMode)
		{
			// 
			// textBoxExpirationDate
			// 
			TemplateColumn templateColumn = new TemplateColumn();
			templateColumn.HeaderText = structData.GetFieldLabel((int)fieldNum);
			templateColumn.SortExpression = fieldNum.ToString();
			ItemTemplatePopupDateTime editItemTemplateTextBox;
			ItemTemplatePopupDateTime itemTemplateTextBox;
			if (!m_bDesignMode)
			{
				if (fieldShowMode == FieldShowModeEnum.SHOW_NORMAL)
				{
					editItemTemplateTextBox = new Northwind.WebControls.ItemTemplatePopupDateTime(fieldNum, fieldName);
					templateColumn.EditItemTemplate = editItemTemplateTextBox;
				}
				else if (fieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
				{
					itemTemplateTextBox = new Northwind.WebControls.ItemTemplatePopupDateTime(fieldNum, fieldName, true);
					templateColumn.EditItemTemplate = itemTemplateTextBox;
				}

				itemTemplateTextBox = new Northwind.WebControls.ItemTemplatePopupDateTime(fieldNum, fieldName, true);
				templateColumn.ItemTemplate = itemTemplateTextBox;
			}
			grid.Columns.Add(templateColumn);
			grid.CellsPosition[fieldName] = grid.Columns.Count - 1;
			return (templateColumn);
		}

		public System.Web.UI.Control CreateXinCalendarImage(System.Web.UI.Control containerControl, TextBox textBox, string title)
		{
			string strTextBoxName = textBox.ClientID;
			Label label = new Label();
			label.ID = textBox.ID + "_calSpace";
			label.Text = @"&nbsp; <A href=""javascript:showPopupXinCalendar('" + strTextBoxName + @"','" + title + @"')""><IMG src="""+NorthwindGeneral.GetWebImagesURL(ContainerControl.Page.Theme)+@"cal.jpg"" class=""XinCalendarImage"" border=""0""></A>";
			containerControl.Controls.Add(label);
			return label;
		}

		public virtual void SetInitialValues(CStructData structData)
		{

		}

		public TreeView PopulateTreeView(CRecordData recordData, TreeView treeView = null)
		{
			if (treeView == null)
			{
				treeView = new TreeView();
			}
			else
			{
				treeView.Nodes.Clear();
			}

			Debug.Assert(recordData != null);
			List<CRecordData> relatedRecords = new List<CRecordData>();

			TreeNode fatherNode = CreateNode(recordData);
			treeView.Nodes.Add(fatherNode);
			DataManager.GetRelatedTablesRecords(recordData, relatedRecords);
			int currentLevelNum = 0;
			int index = 1;
			AddNodesForLevel(relatedRecords, currentLevelNum, fatherNode, index);

			return treeView;
		}

		private static TreeNode CreateNode(CRecordData recordData)
		{
			StringBuilder text = new StringBuilder();
			var fieldInfo = recordData.GetType().GetField("_ModelName", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.Static);

			text.Append(fieldInfo.GetValue(null).ToString());
			String value = recordData.GetPrimaryKeyAsString();

			PropertyInfo propertyInfo = recordData.GetType().GetProperty("_CodeField");
			if (propertyInfo != null)
			{
				String textId = propertyInfo.GetValue(recordData).ToString();
				text.Append(" - " + textId);
				propertyInfo = recordData.GetType().GetProperty("_CodeDescriptionField");
				String description = propertyInfo.GetValue(recordData).ToString();
				text.Append(" - " + description);
			}
			else
			{
				text.Append(" - " + value);
			}

			TreeNode node = new TreeNode(text.ToString(), value);
			return node;
		}

		private void AddNodesForLevel(List<CRecordData> relatedRecords, int fatherLevelNum, TreeNode fatherNode, int startFromIndex)
		{
			int childLevelNum = fatherLevelNum+1; // all it's children
			int currentLevel;
			CRecordData recordData;

			for (int i = startFromIndex; i < relatedRecords.Count; i++)
			{
				recordData = relatedRecords[i];
				currentLevel = (int)recordData.GetFieldValue("Level");

				if (currentLevel == childLevelNum)
				{
					TreeNode childNode = CreateNode(recordData);
					fatherNode.ChildNodes.Add(childNode);
					AddNodesForLevel(relatedRecords, currentLevel, childNode, i);
				}
				else
					return;
			}
		}


		public virtual void SetInitialValues(CBackupEntity backupEntity)
		{
			backupEntity.SetInitialValues();
			// you can override this function to set init values according to the user
			//backupEntity.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CCodes codes)
		{
			codes.SetInitialValues();
			// you can override this function to set init values according to the user
			//codes.HotelId = SessionManager.User.CurrentHotelId;
		}

		// Table CCodes
		// Access Method CodesByTableNum
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4CodesByTableNum(string DDLName, int codeFieldName,short tableNum)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.CodesRecord.GetCodesByTableNumCollection(tableNum);
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4CodesByTableNum(string DDLName, int codeFieldNum,short tableNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.CodesRecord.GetCodesByTableNumCollection(tableNum);

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		

		// Table CCodes
		// Access Method CodesTables
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4CodesTables(string DDLName, int codeFieldName)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.CodesRecord.GetCodesTablesCollection();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4CodesTables(string DDLName, int codeFieldNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.CodesRecord.GetCodesTablesCollection();

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		

		// Table CCodes
		// Access Method AllCodes
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4AllCodes(string DDLName, int codeFieldName)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.CodesRecord.GetAllCodesCollection();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4AllCodes(string DDLName, int codeFieldNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.CodesRecord.GetAllCodesCollection();

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		
		public virtual void SetInitialValues(CCriteriaDefinition criteriaDefinition)
		{
			criteriaDefinition.SetInitialValues();
			// you can override this function to set init values according to the user
			//criteriaDefinition.HotelId = SessionManager.User.CurrentHotelId;
		}

		// Table CCriteriaDefinition
		// Access Method CriteriaDefinitionsByUserIdRecordNum
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4CriteriaDefinitionsByUserIdRecordNum(string DDLName, int codeFieldName,int userId,int recordNum)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.CriteriaDefinitionRecord.GetCriteriaDefinitionsByUserIdRecordNumCollection(userId, recordNum);
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","Name",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4CriteriaDefinitionsByUserIdRecordNum(string DDLName, int codeFieldNum,int userId,int recordNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.CriteriaDefinitionRecord.GetCriteriaDefinitionsByUserIdRecordNumCollection(userId, recordNum);

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		
		public virtual void SetInitialValues(CCriteriaField criteriaField)
		{
			criteriaField.SetInitialValues();
			// you can override this function to set init values according to the user
			//criteriaField.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CCriteriaOrderBy criteriaOrderBy)
		{
			criteriaOrderBy.SetInitialValues();
			// you can override this function to set init values according to the user
			//criteriaOrderBy.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CCustomer customer)
		{
			customer.SetInitialValues();
			// you can override this function to set init values according to the user
			//customer.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CGlobalParams globalParams)
		{
			globalParams.SetInitialValues();
			// you can override this function to set init values according to the user
			//globalParams.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CLastValue lastValue)
		{
			lastValue.SetInitialValues();
			// you can override this function to set init values according to the user
			//lastValue.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CNorthwindUser northwindUser)
		{
			northwindUser.SetInitialValues();
			// you can override this function to set init values according to the user
			//northwindUser.HotelId = SessionManager.User.CurrentHotelId;
		}

		// Table CNorthwindUser
		// Access Method AllUsers
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4AllUsers(string DDLName, int codeFieldName)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.NorthwindUserRecord.GetAllUsersCollection();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","FullName",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4AllUsers(string DDLName, int codeFieldNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.NorthwindUserRecord.GetAllUsersCollection();

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		
		public virtual void SetInitialValues(COrder order)
		{
			order.SetInitialValues();
			// you can override this function to set init values according to the user
			//order.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(COrderItem orderItem)
		{
			orderItem.SetInitialValues();
			// you can override this function to set init values according to the user
			//orderItem.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CProduct product)
		{
			product.SetInitialValues();
			// you can override this function to set init values according to the user
			//product.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CSupplier supplier)
		{
			supplier.SetInitialValues();
			// you can override this function to set init values according to the user
			//supplier.HotelId = SessionManager.User.CurrentHotelId;
		}

		// Table CSupplier
		// Access Method AllSuppliers
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4AllSuppliers(string DDLName, int codeFieldName)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			var collection = DataManager.SupplierRecord.GetAllSuppliersCollection();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","CompanyName",codeFieldName,collection.GetDataTable(),NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4AllSuppliers(string DDLName, int codeFieldNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.SupplierRecord.GetAllSuppliersCollection();

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		
		
		public static System.Web.UI.Control FindControlRecursive(System.Web.UI.Control root, string id)
		{
			System.Web.UI.Control controlFound;
			if (root != null)
			{
				/*
				if (root.Controls.Count == 0)
					return null;
				*/ 
				controlFound = root.FindControl(id);
				// there is a bug in the above FindControl so I double check it
				if (controlFound != null && controlFound.ID.Equals(id))
				{ 
					return controlFound; 
				}
				foreach (System.Web.UI.Control c in root.Controls) 
				{
					//Trace(c,"ControlId=" + c.ID);

					controlFound = FindControlRecursive(c,id); 
					if (controlFound != null) 
					{
						//Trace(c, "Control Found ControlId=" + id);
						return controlFound; 
					} 
				}
			} return null;
		}

		public static List<System.Web.UI.Control> GetControlRecursive(System.Web.UI.Control root)
		{
			List<System.Web.UI.Control> controls = new List<Control>();

			if (root != null && root.Controls.Count > 0 )
			{
				foreach (System.Web.UI.Control c in root.Controls)
				{
					//Trace(c, "ControlId=" + c.ID);
					controls.Add(c);
					List<System.Web.UI.Control> nestedControls;
					nestedControls = GetControlRecursive(c);
					controls.AddRange(nestedControls);
				}
			}
			return controls;
		}
		
		public static void SetEnableViewStateRecursivly(System.Web.UI.Control root, bool bEnableViewState)
		{
			System.Web.UI.Control controlFound;
			if (root != null)
			{
				if (root.Controls.Count == 0)
					return;
				foreach (System.Web.UI.Control c in root.Controls) 
				{
					c.EnableViewState = bEnableViewState;
					SetEnableViewStateRecursivly(c, bEnableViewState); 
				}
			} 
		}

		public static void Trace(System.Web.UI.Control c , string text)
		{
			try
			{
				c.Page.Trace.Write(text);
			}
			catch (Exception)
			{ } // ignore - design mode
		}
		
		public virtual Control CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode)
		{
			throw new NotImplementedException("CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode) not implemented in "+this.GetType().ToString());
		}

		public virtual Control CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, bool inCriteria)
		{
			throw new NotImplementedException("CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, bool inCriteria) not implemented in "+this.GetType().ToString());
		}
		
		public virtual Control CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, string suffixForControlId = "")
		{
			if (suffixForControlId.Equals(""))
				return CreateControl(container, fieldNum, fieldShowMode, false);
			else
				throw new NotImplementedException("CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, string suffixForControlId) not implemented in " + this.GetType().ToString());
		}
		
		public virtual Control CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, bool inCriteria=false, string suffixForControlId="")
		{
			if (suffixForControlId.Equals(""))
				return CreateControl(container, fieldNum, fieldShowMode, inCriteria);
			else
				throw new NotImplementedException("CreateControl(System.Web.UI.Control container, int fieldNum, FieldShowModeEnum fieldShowMode, bool inCriteria, string suffixForControlId) not implemented in " + this.GetType().ToString());
		}
		
		public virtual Control CreateControlValidator(System.Web.UI.Control container, int m_FieldNum)
		{
			throw new NotImplementedException("CreateControlValidator(System.Web.UI.Control container, int m_FieldNum) not implemented in "+this.GetType().ToString());
		}

		public virtual Control CreateControlValidator(System.Web.UI.Control container, int m_FieldNum, string suffixForControlId = "")
		{
			if (suffixForControlId.Equals(""))
				return CreateControlValidator(container, m_FieldNum);
			else
				throw new NotImplementedException("CreateControlValidator(System.Web.UI.Control container, int m_FieldNum, string suffixForControlId) not implemented in " + this.GetType().ToString());
		}
		
		public virtual void SetControlValue(int fieldNum)
		{
			throw new NotImplementedException("SetControlValue(int fieldNum) not implemented in "+this.GetType().ToString());
		}

		public virtual void SetControlValue(int fieldNum, string suffixForControlId, string value = null)
		{
			throw new NotImplementedException("SetControlValue(int fieldNum, string suffixForControlId, string value = null) not implemented in " + this.GetType().ToString());
		}

		public virtual void SetControlsValues(System.Web.UI.Control containerControl)
		{
			ContainerControl = containerControl;
			SetControlsValues();
		}

		public virtual void SetControlsDynamicAttributes()
		{
			throw new NotImplementedException("SetControlsDynamicAttributes() not implemented in "+this.GetType().ToString());
		}
		
		public virtual void SetControlDynamicAttributes(int fieldNum)
		{
			throw new NotImplementedException("SetControlDynamicAttributes(int fieldNum) not implemented in "+this.GetType().ToString());
		}

		public virtual void SetDynamicFieldAttributes(int fieldNum, string suffixForControlId = "")
		{
			throw new NotImplementedException("SetDynamicFieldAttributes(int fieldNum, string suffixForControlId = \"\") not implemented in " + this.GetType().ToString());
		}

		public virtual void SetControlsDynamicAttributes(CFieldAttributeCollection fieldAttributeCollection)
		{
			int fieldNum;
			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				if (fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
				{
					fieldNum = fieldAttribute.Num;
					switch (fieldAttribute.SqlOperator)
					{
						case SqlOperatorEnum.BETWEEN:
							SetDynamicFieldAttributes(fieldNum, "From");
							SetDynamicFieldAttributes(fieldNum, "To");
							break;

						default:
							SetDynamicFieldAttributes(fieldNum);
							break;
					}

				}
			}
		}

		public virtual void GetControlValue(int fieldNum)
		{
			throw new NotImplementedException("GetControlValue(int fieldNum) not implemented in "+this.GetType().ToString());
		}
		
		public virtual string GetControlValue(int fieldNum, string suffixForControlId = "")
		{
			throw new NotImplementedException("GetControlValue(int fieldNum,string suffixForControlId) not implemented in " + this.GetType().ToString());
		}

		public virtual string GetControlValue(Control control)
		{
			if (control is TextBox)
				return (control as TextBox).Text;
			else if (control is DropDownList)
				return (control as DropDownList).SelectedValue;
			else if (control is CheckBox)
			{
				if ((control as CheckBox).Checked)
					return "1";
				else
					return "0";
			}
			else
				throw new NotImplementedException("GetControlValue(Control control) not implemented in " + this.GetType().ToString()+" for control type "+ control.GetType());
		}

		public virtual void SetControlValue(Control control, string value)
		{
			if (control is TextBox)
				(control as TextBox).Text = value;
			else if (control is DropDownList)
				(control as DropDownList).SelectedValue = value;
			else if (control is CheckBox)
			{
				if (value.Equals("0"))
					(control as CheckBox).Checked = false;
				else
					(control as CheckBox).Checked = true;
			}
			else
				throw new NotImplementedException("SetControlValue(Control control, string value) not implemented in " + this.GetType().ToString() + " for control type " + control.GetType());
		}

		public virtual Control CreateReadOnlyControl(Control containerControl, string controlId)
		{
			Label label = new Label();
			containerControl.Controls.Add(label);
			label.ID = controlId + "Label";
			label.CssClass = "TextBoxCss Disabled";
			return label;
		}

		public virtual Control CreateReadOnlyControl(Control containerControl, string controlId, int numDigits)
		{
			Label label = new Label();
			containerControl.Controls.Add(label);
			label.ID = controlId + "Label";
			label.Width = NorthwindWebEnv.GetNumPixelsFromChars(numDigits);
			label.CssClass = "TextBoxCss Disabled";
			return label;
		}
		
		public virtual void CreateAllFieldsAsTR(System.Web.UI.Control tableControl, CFieldAttributeCollection fieldAttributeCollection)
		{
			UpdateFieldsCollectionPerCase(fieldAttributeCollection);
			
			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				if (fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
					CreateFieldAsTR((Table)tableControl, fieldAttribute);
			}
			SetTableAttributes((Table)tableControl);
		}

		public virtual void SetTableAttributes(Table table)
		{
		}

		public virtual Control CreateFieldAsTR(Table tableControl, int fieldNum, FieldShowModeEnum fieldShowMod)
		{
			return CreateFieldAsTR(tableControl, fieldNum, fieldShowMod, false);
		}
		public virtual Control CreateFieldAsTR(Table tableControl, int fieldNum , FieldShowModeEnum fieldShowMod, bool inCriteria)
		{
			TableRow	tableRow;
			TableCell	tableCell;
			System.Web.UI.Control createdControl;
			
			tableRow = new TableRow();
			tableRow.ID = this.StructData.GetFieldName(fieldNum) + "Row";
			tableControl.Controls.Add(tableRow);

			CreateLabelAsTD(tableRow, fieldNum, fieldShowMod, Northwind.General.FieldsLayout.EachFieldInRow);

			createdControl = CreateFieldAsTD(tableRow, fieldNum, fieldShowMod, inCriteria);

			return (createdControl);
		}

		public virtual Control CreateFieldAsTR(Table tableControl, CFieldAttribute fieldAttribute)
		{
			TableRow tableRow;
			TableCell tableCell;
			System.Web.UI.Control createdControl;

			tableRow = new TableRow();
			int fieldNum = fieldAttribute.Num;

			tableRow.ID = this.StructData.GetFieldName(fieldNum) + "Row";
			tableControl.Controls.Add(tableRow);

			CreateLabelAsTD(tableRow, fieldNum, fieldAttribute.ShowMode, Northwind.General.FieldsLayout.EachFieldInRow, fieldAttribute.SqlOperator);
			createdControl = CreateFieldAsTD(tableRow, fieldNum, fieldAttribute.ShowMode, fieldAttribute.SqlOperator, true);

			return (createdControl);
		}

		public virtual bool HideFieldTR(Control container,int fieldNum)
		{
			TableRow tableRow = (TableRow)FindControlRecursive(container, this.StructData.GetFieldName(fieldNum) + "Row");
			if (tableRow != null)
			{
				tableRow.Visible = false;
				return true;
			}
			return false;
		}

		public virtual bool ShowFieldTR(Control container, int fieldNum)
		{
			TableRow tableRow = (TableRow)FindControlRecursive(container, this.StructData.GetFieldName(fieldNum) + "Row");
			if (tableRow != null)
			{
				tableRow.Visible = true;
				return true;
			}
			return false;
		}

		public virtual void CreateLabelAsTD(TableRow tableRow, int fieldNum, FieldShowModeEnum fieldShowMode)
		{
			CreateLabelAsTD(tableRow, fieldNum, fieldShowMode, Northwind.General.FieldsLayout.EachFieldInRow);
		}

		public virtual void CreateLabelAsTD(TableRow tableRow, int fieldNum, FieldShowModeEnum fieldShowMode, Northwind.General.FieldsLayout fieldsLayout, SqlOperatorEnum sqlOperator = SqlOperatorEnum.NONE)
		{
			// Label
			TableCell tableCell = new TableCell();
			if (fieldsLayout == FieldsLayout.EachFieldInCol)
				tableCell.CssClass = "HeaderStyle";
			else
				tableCell.CssClass = "LeftHeaderStyle";

			tableRow.Controls.Add(tableCell);
			Label labelId = new Label();
			SetLabelAttributes(labelId, fieldNum, fieldShowMode, sqlOperator);
			tableCell.Controls.Add(labelId);
			string shortHelp = StructData.GetShortHelp(fieldNum);
			if (!string.IsNullOrEmpty(shortHelp))
			{
				AddShortHelp(tableCell, fieldNum, shortHelp);
			}

		}


		public void AddShortHelp(Control container,int fieldNum, string shortHelp)
		{
			Label shortHelpLabel = new Label();
			string fieldName = StructData.GetFieldName(fieldNum);
			shortHelpLabel.ID = fieldName + "ShortHelpLabel";
			shortHelpLabel.CssClass = "shortHelp";
			shortHelpLabel.Text = string.Format("<br />({0})", shortHelp);
			container.Controls.Add(shortHelpLabel);
		}

		public void AddLongHelp(Control container, int fieldNum, string longtHelp)
		{
			Image longHelpImage = new Image();
			string fieldName = StructData.GetFieldName(fieldNum);
			longHelpImage.ID = fieldName + "HelpImage";
			longHelpImage.CssClass = "shortHelpImage";
			longHelpImage.ImageUrl = "~/App_Themes/ThemeCameron/images/32x32/help.png";
			container.Controls.Add(longHelpImage);

			string longHelpPanelName = string.Format("{0}LongHelpPanel", fieldName);
			Panel helpPanel = (Panel)FindControlRecursive(ContainerControl, longHelpPanelName);
			if (helpPanel == null)
			{
				helpPanel = new Panel();
				helpPanel.ID = longHelpPanelName;
				Literal helpTextLiteral = new Literal();
				helpTextLiteral.Text = longtHelp;
				helpPanel.Controls.Add(helpTextLiteral);
				helpPanel.Style["display"] = "none";
				container.Controls.Add(helpPanel);

				//Literal js = new Literal();
				string js = string.Format(
					@"
							function {0}() {{
								//jQuery.noConflict();
								jQuery('#{0}').qtip({{ content: {{ text: jQuery('#{1}').clone() }} }}); 
							}}
					 ", longHelpImage.ClientID, helpPanel.ClientID);
				//container.Controls.Add(js);
				(ContainerControl.Page as NorthwindPage).InjectStartupScript(PostBackMode.Both, longHelpImage, longHelpImage.ClientID, js);
			}
		}

		public virtual Label GetLabelControl(int fieldNum)
		{
			string controlName = "label" + StructData.GetFieldName(fieldNum);
			Label label = (Label)FindControlRecursive(ContainerControl, controlName);
			return label;
		}


		public virtual void SetLabelAttributes(System.Web.UI.WebControls.Label label, int fieldNum, FieldShowModeEnum fieldShowMode, SqlOperatorEnum sqlOperator = SqlOperatorEnum.NONE)
		{
			SetLabelAttributes(label, "label" + StructData.GetFieldName(fieldNum), StructData.GetFieldLabel(fieldNum), fieldShowMode);
			if (sqlOperator != SqlOperatorEnum.NONE)
				label.Text += " "+GetExtraTextLabelFor(sqlOperator);
		}

		public virtual string GetExtraTextLabelFor(SqlOperatorEnum sqlOperator)
		{
			switch (sqlOperator)
			{
				case SqlOperatorEnum.BETWEEN:
					return " (Between)";
				case SqlOperatorEnum.CONTAINS:
					return " (Contains)";
				case SqlOperatorEnum.EQUAL:
					return "";
				case SqlOperatorEnum.GREAT_OR_EQUAL:
					return " (>=)";
				case SqlOperatorEnum.GREAT_THAN:
					return " (>)";
				case SqlOperatorEnum.LESS_OR_EQUAL:
					return " (<=)";
				case SqlOperatorEnum.LESS_THAN:
					return " (<)";
				case SqlOperatorEnum.LIKE:
					return " (Like)";
				default:
					throw new Exception("Unsupported SqlOperator " + sqlOperator.ToString());
			}

		}

		public virtual string GetAndText()
		{
			return " and ";

		}

		public virtual void SetLabelAttributes(System.Web.UI.WebControls.Label label, int fieldNum, FieldShowModeEnum fieldShowMode)
		{
			SetLabelAttributes(label, "label" + StructData.GetFieldName(fieldNum), StructData.GetFieldLabel(fieldNum), fieldShowMode);
		}

		public virtual Control CreateFieldAsTD(TableRow tableRow, CFieldAttribute fieldAttribute)
		{
			return CreateFieldAsTD(tableRow, fieldAttribute.Num, fieldAttribute.ShowMode);
		}

		public virtual Control CreateFieldAsTD(TableRow tableRow, int fieldNum, FieldShowModeEnum fieldShowMod)
		{
			return CreateFieldAsTD(tableRow, fieldNum, fieldShowMod, false);
		}

		public virtual Control CreateFieldAsTD(TableRow tableRow, int fieldNum, FieldShowModeEnum fieldShowMod, bool inCriteria)
		{
			// Control
			TableCell tableCell = new TableCell();
			tableCell.ID = this.StructData.GetFieldName(fieldNum) + "Col";

			tableRow.Controls.Add(tableCell);
			Control createdControl;

			if (!inCriteria)
				createdControl = this.CreateControl(tableCell, fieldNum, fieldShowMod);
			else
				createdControl = this.CreateControl(tableCell, fieldNum, fieldShowMod, inCriteria);

			if (fieldShowMod == FieldShowModeEnum.SHOW_NORMAL)
			{
				// Validator
				// create it inside the field control cell
				this.CreateControlValidator(tableCell, fieldNum);
			}
			return createdControl;
		}

		public virtual Control CreateFieldAsTD(TableRow tableRow, int fieldNum, FieldShowModeEnum fieldShowMod, SqlOperatorEnum sqlOperator, bool inCriteria)
		{
			// Control
			TableCell tableCell = new TableCell();
			tableCell.ID = this.StructData.GetFieldName(fieldNum) + "Col";

			tableRow.Controls.Add(tableCell);
			Control createdControl = null;

			if (ContainerControl is NorthwindCriteriasWCC && fieldShowMod == FieldShowModeEnum.SHOW_NORMAL)
			{
				// add active check box 
				CheckBox activeCheckBox = new CheckBox();
				string controlId = string.Format("{0}{1}{2}", this.StructData.GetType().Name.Substring(1), this.StructData.GetFieldName(fieldNum), "Active");
				activeCheckBox.ID = controlId;
				activeCheckBox.CssClass = "ActiveCheckBox";
				tableCell.Controls.Add(activeCheckBox);
			}
			string suffixForControlId = "";
			switch (sqlOperator)
			{
				case SqlOperatorEnum.BETWEEN:
					suffixForControlId = "From";
					createdControl = this.CreateControl(tableCell, fieldNum, fieldShowMod, inCriteria, suffixForControlId);
					Literal andLiteral = new Literal();
					andLiteral.Text = GetAndText();
					tableCell.Controls.Add(andLiteral);
					suffixForControlId = "To";
					createdControl = this.CreateControl(tableCell, fieldNum, fieldShowMod, inCriteria, suffixForControlId);
					break;
				case SqlOperatorEnum.CONTAINS:
				case SqlOperatorEnum.EQUAL:
				case SqlOperatorEnum.GREAT_OR_EQUAL:
				case SqlOperatorEnum.GREAT_THAN:
				case SqlOperatorEnum.LESS_OR_EQUAL:
				case SqlOperatorEnum.LESS_THAN:
				case SqlOperatorEnum.LIKE:
				case SqlOperatorEnum.NONE:
					createdControl = this.CreateControl(tableCell, fieldNum, fieldShowMod, inCriteria, suffixForControlId);
					break;
			}
				

			if (fieldShowMod == FieldShowModeEnum.SHOW_NORMAL)
			{
				// Validator
				// create it inside the field control cell
				this.CreateControlValidator(tableCell, fieldNum, suffixForControlId);
			}
			return createdControl;
		}

		public virtual bool HideFieldTD(Control container, int fieldNum)
		{
			TableCell tableCell = (TableCell)FindControlRecursive(container, this.StructData.GetFieldName(fieldNum) + "Col");
			if (tableCell != null)
			{
				tableCell.Visible = false;
				return true;
			}
			return false;
		}

		public virtual bool ShowFieldTD(Control container, int fieldNum)
		{
			TableCell tableCell = (TableCell)FindControlRecursive(container, this.StructData.GetFieldName(fieldNum) + "Col");
			if (tableCell != null)
			{
				tableCell.Visible = true;
				return true;
			}
			return false;
		}

		public virtual void CreateAllFieldsAsTD(Table tableControl, CFieldAttributeCollection fieldAttributeCollection)
		{
			UpdateFieldsCollectionPerCase(fieldAttributeCollection);
			
			TableRow tableRow = new TableRow(); // for headers
			tableControl.Controls.Add(tableRow);

			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				if (fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
				{
					CreateLabelAsTD(tableRow, fieldAttribute.Num, fieldAttribute.ShowMode, Northwind.General.FieldsLayout.EachFieldInCol, fieldAttribute.SqlOperator);
				}
			}

			tableRow = new TableRow(); // for fields
			tableControl.Controls.Add(tableRow);

			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				if (fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
					CreateFieldAsTD(tableRow, fieldAttribute);
			}
			SetTableAttributes((Table)tableControl);
		}
		
		public virtual CFieldAttributeCollection CreateFieldsCollection(int fieldsListType)
		{
			int i;
			CFieldAttributeCollection fieldAttributeCollection = new CFieldAttributeCollection();
			CFieldAttribute fieldAttribute;

			foreach (int fieldNum in GetFieldsList(fieldsListType))
			{
				fieldAttribute = fieldAttributeCollection.InsertNewFieldAttribute(-1); // add at the end
				fieldAttribute.Num = fieldNum;
				fieldAttribute.Name = m_StructData.GetFieldName(fieldNum);
				fieldAttribute.ShowMode = (Northwind.General.FieldShowModeEnum)Northwind.General.FieldShowModeEnum.SHOW_NORMAL;
			}
			UpdateFieldsCollectionPerCase(fieldAttributeCollection);
			return fieldAttributeCollection;
		}

		protected virtual void UpdateFieldsCollectionPerCase(CFieldAttributeCollection fieldAttributeCollection)
		{
			// do nothing as default
		}

		public virtual CFieldAttributeCollection CreateFieldsCollectionDynamically(Control control)
		{
			// parameters for this function should come from the session
			// this function decide which fileds to show and their mode by the parameters 
			// from the session - Use SessionManager for simplicity
			throw new NotImplementedException("CreateFieldsCollectionDynamically(Control control) not implemented in "+this.GetType().ToString());
		}

		public virtual int[] GetFieldsList(int fieldListType)
		{

			if (fieldListType == 0) // means all
			{
				int[] fieldsList = new int[m_StructData.NumFields];
				for (int i = 1; i < m_StructData.NumFields; i++)
				{
					fieldsList[i - 1] = i;
				}
				return fieldsList;
			}


			return m_StructData.GetFieldsList(fieldListType);
		}

		public static FredCK.FCKeditorV2.LanguageDirection FCKContentLangDirection
		{
			get
			{
				switch (NorthwindGeneral.HtmlEditotLangDirectionEnum)
				{
					case HtmlEditorLangDirectionEnum.LeftToRight:
						return FredCK.FCKeditorV2.LanguageDirection.LeftToRight;
					case HtmlEditorLangDirectionEnum.RightToLeft:
						return FredCK.FCKeditorV2.LanguageDirection.RightToLeft;
				}
				throw new Exception("Unknown NorthwindGeneral.HtmlEditotLangDirectionEnum value " + NorthwindGeneral.HtmlEditotLangDirectionEnum.ToString());
			}
		}

		public virtual void OnPostback()
		{
			GetControlsValues();
			CalcRelatedFields();
			SetControlsDynamicAttributes();
			SetControlsValues(); 
		}

		public virtual void CalcRelatedFields()
		{
		}

		public virtual void GetControlsValues()
		{
		}

		protected virtual void GetControlsValu