Skip Navigation Links.

Northwind\WebControls\WebEnvBase.cs

D:\Temp3\TestProjects\CSADO.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;
			DataTable dataTable;
			dataTable = DataManager.CodesRecord.GetCodesByTableNumDataTable(tableNum);
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,dataTable,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;
			DataTable dataTable;
			dataTable = DataManager.CodesRecord.GetCodesTablesDataTable();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,dataTable,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;
			DataTable dataTable;
			dataTable = DataManager.CodesRecord.GetAllCodesDataTable();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"CodeNum","Description",codeFieldName,dataTable,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;
			DataTable dataTable;
			dataTable = DataManager.CriteriaDefinitionRecord.GetCriteriaDefinitionsByUserIdRecordNumDataTable(userId, recordNum);
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","Name",codeFieldName,dataTable,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(CMessage message)
		{
			message.SetInitialValues();
			// you can override this function to set init values according to the user
			//message.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CMultiLangText multiLangText)
		{
			multiLangText.SetInitialValues();
			// you can override this function to set init values according to the user
			//multiLangText.HotelId = SessionManager.User.CurrentHotelId;
		}
		public virtual void SetInitialValues(CNorthwindMetaDataField northwindMetaDataField)
		{
			northwindMetaDataField.SetInitialValues();
			// you can override this function to set init values according to the user
			//northwindMetaDataField.HotelId = SessionManager.User.CurrentHotelId;
		}

		// Table CNorthwindMetaDataField
		// Access Method MetaDataFieldsByModelId
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4MetaDataFieldsByModelId(string DDLName, int codeFieldName,int modelId)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			DataTable dataTable;
			dataTable = DataManager.NorthwindMetaDataFieldRecord.GetMetaDataFieldsByModelIdDataTable(modelId);
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"FieldNum","Name",codeFieldName,dataTable,NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4MetaDataFieldsByModelId(string DDLName, int codeFieldNum,int modelId)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.NorthwindMetaDataFieldRecord.GetMetaDataFieldsByModelIdCollection(modelId);

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

		// Table CNorthwindMetaDataModel
		// Access Method AllMetaDataModels
		public virtual EditItemTemplateDDL CreateEditItemTemplateDDL4AllMetaDataModels(string DDLName, int codeFieldName)
		{
			EditItemTemplateDDL edititemTemplateDDL;
			DataTable dataTable;
			dataTable = DataManager.NorthwindMetaDataModelRecord.GetAllMetaDataModelsDataTable();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"ModelId","Name",codeFieldName,dataTable,NorthwindGeneral.ShowCodeFieldWithComboBox);
			return(edititemTemplateDDL);
		}

		public virtual ItemTemplateDDL CreateItemTemplateDDL4AllMetaDataModels(string DDLName, int codeFieldNum)
		{
			ItemTemplateDDL itemTemplateDDL;
			IStructDataCollection collection;
			collection = DataManager.NorthwindMetaDataModelRecord.GetAllMetaDataModelsCollection();

			itemTemplateDDL = new ItemTemplateDDL(DDLName,codeFieldNum,collection);
			return(itemTemplateDDL);
		}
		
		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;
			DataTable dataTable;
			dataTable = DataManager.NorthwindUserRecord.GetAllUsersDataTable();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","FullName",codeFieldName,dataTable,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(CRole role)
		{
			role.SetInitialValues();
			// you can override this function to set init values according to the user
			//role.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;
			DataTable dataTable;
			dataTable = DataManager.SupplierRecord.GetAllSuppliersDataTable();
			edititemTemplateDDL = new EditItemTemplateDDL(DDLName,"Id","CompanyName",codeFieldName,dataTable,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 GetControlsValues(CFieldAttributeCollection fieldAttributeCollection)
		{
			string controlId;
			Control fromControl, toControl;
			string fromValue, toValue;
			int fieldNum;
			CheckBox activeCheckBox;

			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				if (fieldAttribute.ShowMode == FieldShowModeEnum.SHOW_NORMAL)
				{
					fieldNum = fieldAttribute.Num;
					controlId = string.Format("{0}{1}{2}", this.StructData.GetType().Name.Substring(1), this.StructData.GetFieldName(fieldNum), "Active");
					activeCheckBox = (CheckBox)FindControlRecursive(ContainerControl, controlId);

					switch (fieldAttribute.SqlOperator)
					{
						case SqlOperatorEnum.BETWEEN:
							fromValue = GetControlValue(fieldNum, "From");
							if (fromValue == null)
								fromValue = "";
							fieldAttribute.Value = fromValue;

							toValue = GetControlValue(fieldNum, "To");
							if (toValue == null)
								toValue = "";
							fieldAttribute.Value += ";" + toValue;
							if (activeCheckBox != null)
								if (activeCheckBox.Checked)
									fieldAttribute.Value += ";1";
								else
									fieldAttribute.Value += ";0";
							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:
							fromValue = GetControlValue(fieldNum, "");
							if (fromValue == null)
								fromValue = "";
							fieldAttribute.Value = fromValue;
							if (activeCheckBox != null)
								if (activeCheckBox.Checked)
									fieldAttribute.Value += ";1";
								else
									fieldAttribute.Value += ";0";
							break;
						default:
							throw new Exception("Unsupported SqlCommandTypeEnum operator " + fieldAttribute.SqlOperator.ToString() + " in function GetControlsValues(CFieldAttributeCollection fieldAttributeCollection)");
					}

				}
			}
		}

		public virtual void SetControlsValues()
		{
		}
		
		public virtual Control CreateIntegerValidator(Control containerControl,  string controlNameToValidate, int maxDigits)
		{
			return CreateIntegerValidator(containerControl, controlNameToValidate, 1, maxDigits);
		}

		public virtual Control CreateIntegerValidator(Control containerControl, string controlNameToValidate, int minDigits, int maxDigits)
		{
			RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator();
			regularExpressionValidator.Display = ValidatorDisplay.Dynamic;
			regularExpressionValidator.ID = controlNameToValidate + "RegularExpressionValidator";
			regularExpressionValidator.ControlToValidate = controlNameToValidate;
			regularExpressionValidator.ValidationExpression = RegExs.GetIntegerPattern(minDigits, maxDigits);
			regularExpressionValidator.Text = string.Format("{0}-{1} Digits", minDigits, maxDigits);
			regularExpressionValidator.ErrorMessage = string.Format("Please enter {0} to {1} digits only for {2}", minDigits, maxDigits, controlNameToValidate);
			containerControl.Controls.Add(regularExpressionValidator);
			return regularExpressionValidator;
		}

		public virtual Control CreateDecimalValidator(Control containerControl, string controlNameToValidate, int leftDigits, int rightDigits)
		{
			RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator();
			regularExpressionValidator.Display = ValidatorDisplay.Dynamic;
			regularExpressionValidator.ID = controlNameToValidate + "RegularExpressionValidator";
			regularExpressionValidator.ControlToValidate = controlNameToValidate;
			regularExpressionValidator.ValidationExpression = RegExs.GetDecimalPattern(leftDigits, rightDigits);
			regularExpressionValidator.Text = string.Format("{0}.{1} Digits", leftDigits, rightDigits);
			regularExpressionValidator.ErrorMessage = string.Format("Please enter max {0} digits before point and max {1} digits after point for {2}", leftDigits, rightDigits, controlNameToValidate);
			containerControl.Controls.Add(regularExpressionValidator);
			return regularExpressionValidator;
		}

		public virtual Control CreateRequiredValidator(Control containerControl, string controlNameToValidate, string fieldLabel)
		{
			RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
			requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
			requiredFieldValidator.ID = controlNameToValidate + "RequiredValidator";
			requiredFieldValidator.ControlToValidate = controlNameToValidate;
			requiredFieldValidator.Text = string.Format("* Required");
			requiredFieldValidator.InitialValue = "";
			requiredFieldValidator.ErrorMessage = string.Format("{0} is required", fieldLabel);
			containerControl.Controls.Add(requiredFieldValidator);
			return requiredFieldValidator;
		}

		public virtual Control CreateRangeValidator(Control containerControl, ValidationDataType validationDataType, string controlNameToValidate, string minimumValue, string maximumValue)
		{
			RangeValidator rangeValidator = new RangeValidator();
			rangeValidator.Display = ValidatorDisplay.Dynamic;
			rangeValidator.ID = controlNameToValidate + "RanfeValidator";
			rangeValidator.Type = validationDataType;
			rangeValidator.ControlToValidate = controlNameToValidate;
			rangeValidator.MinimumValue = minimumValue;
			rangeValidator.MaximumValue = maximumValue;
			rangeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			rangeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			containerControl.Controls.Add(rangeValidator);
			return rangeValidator;
		}


		public virtual Control CreateTypeValidator(Control containerControl, short value,string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = short.MinValue.ToString();
			string maximumValue = short.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateShortSign);
			typeValidator.ClientValidationFunction = "validateShortSign";
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}

		public virtual Control CreateTypeValidator(Control containerControl, short? value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = short.MinValue.ToString();
			string maximumValue = short.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateShortSign);
			typeValidator.ClientValidationFunction = "validateShortSign";
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}

		public virtual void ValidateShortSign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			short shortValue;
			if (!short.TryParse(args.Value as string, out shortValue))
			{
				args.IsValid = false;
			}
		}

		public virtual Control CreateTypeValidator(Control containerControl, ushort value,string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = ushort.MinValue.ToString();
			string maximumValue = ushort.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateShortUnsign);
			typeValidator.ClientValidationFunction = "validateShortUnsign";
			
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}

		public virtual void ValidateShortUnsign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			ushort shortValue;
			if (!ushort.TryParse(args.Value as string, out shortValue))
			{
				args.IsValid = false;
			}
		}
		

		public virtual Control CreateTypeValidator(Control containerControl, int value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = int.MinValue.ToString();
			string maximumValue = int.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateIntSign);
			typeValidator.ClientValidationFunction = "validateIntSign";
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}

		public virtual Control CreateTypeValidator(Control containerControl, int? value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = int.MinValue.ToString();
			string maximumValue = int.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateIntSign);
			typeValidator.ClientValidationFunction = "validateIntSign";
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}


		public virtual void ValidateIntSign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			int intValue;
			if (!int.TryParse(args.Value as string, out intValue))
			{
				args.IsValid = false;
			}
		}

		public virtual Control CreateTypeValidator(Control containerControl, uint value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = uint.MinValue.ToString();
			string maximumValue = uint.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateIntUnsign);
			typeValidator.ClientValidationFunction = "validateIntUnsign";

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

		public virtual void ValidateIntUnsign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			uint intValue;
			if (!uint.TryParse(args.Value as string, out intValue))
			{
				args.IsValid = false;
			}
		}

		public virtual Control CreateTypeValidator(Control containerControl, long value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = long.MinValue.ToString();
			string maximumValue = long.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateLongSign);
			typeValidator.ClientValidationFunction = "validateLongSign";
			containerControl.Controls.Add(typeValidator);
			return typeValidator;
		}

		public virtual void ValidateLongSign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			long longValue;
			if (!long.TryParse(args.Value as string, out longValue))
			{
				args.IsValid = false;
			}
		}

		public virtual Control CreateTypeValidator(Control containerControl, ulong value, string controlNameToValidate)
		{
			CustomValidator typeValidator = new CustomValidator();
			typeValidator.Display = ValidatorDisplay.Dynamic;
			typeValidator.ID = controlNameToValidate + "TypeValidator";
			string minimumValue = ulong.MinValue.ToString();
			string maximumValue = ulong.MaxValue.ToString();
			typeValidator.ControlToValidate = controlNameToValidate;
			typeValidator.Text = string.Format("Range({0}-{1})", minimumValue, maximumValue);
			typeValidator.ErrorMessage = string.Format("{0} value should be between {1} to {2}", controlNameToValidate, minimumValue, maximumValue);
			typeValidator.ServerValidate += new ServerValidateEventHandler(ValidateLongUnsign);
			typeValidator.ClientValidationFunction = "validateLongUnsign";

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

		public virtual void ValidateLongUnsign(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			ulong longValue;
			if (!ulong.TryParse(args.Value as string, out longValue))
			{
				args.IsValid = false;
			}
		}
		

		public virtual Control CreateCompareValidator(Control containerControl,  ValidationDataType validationDataType, string controlNameToValidate, ValidationCompareOperator validationCompareOperator, string valueToCompare)
		{
			CompareValidator compareValidator = new CompareValidator();
			compareValidator.Display = ValidatorDisplay.Dynamic;
			compareValidator.ID = controlNameToValidate + "CompareValidator";
			compareValidator.Operator = validationCompareOperator;
			compareValidator.ControlToValidate = controlNameToValidate;
			compareValidator.ValueToCompare = valueToCompare;
			compareValidator.Text = string.Format("Must be {0} {1}", NorthwindGeneral.ExpandFromCSName(validationCompareOperator.ToString()), valueToCompare);
			compareValidator.ErrorMessage = string.Format("{0} value must be {0} {1}", controlNameToValidate, NorthwindGeneral.ExpandFromCSName(validationCompareOperator.ToString()));
			containerControl.Controls.Add(compareValidator);
			return compareValidator;
		}


		public virtual Control CreateRegularExpressionValidator(Control containerControl, string controlNameToValidate, string validationExpression, string shortMessage, string longMessage)
		{
			RegularExpressionValidator regularExpressionValidator = new RegularExpressionValidator();
			regularExpressionValidator.Display = ValidatorDisplay.Dynamic;
			regularExpressionValidator.ID = controlNameToValidate + "RegularExpressionValidator";
			regularExpressionValidator.ControlToValidate = controlNameToValidate;
			regularExpressionValidator.ValidationExpression = validationExpression;
			regularExpressionValidator.Text = shortMessage;
			regularExpressionValidator.ErrorMessage = longMessage;
			containerControl.Controls.Add(regularExpressionValidator);
			return regularExpressionValidator;
		}

		public virtual Control CreateDateValidator(Control containerControl, string controlNameToValidate)
		{
			CustomValidator customValidator = new CustomValidator();
			customValidator.Display = ValidatorDisplay.Dynamic;
			customValidator.ID = controlNameToValidate + "DateValidator";
			customValidator.ControlToValidate = controlNameToValidate;
			if (NorthwindGeneral.GetDateFormat().ToLower().Substring(0, 2).Equals("dd"))
			{
				// Europe style
				customValidator.ClientValidationFunction = "validateDateD_M_YYYY";
			}
			else
			{
				// USA style
				customValidator.ClientValidationFunction = "validateDateM_D_YYYY";
			}
			customValidator.ServerValidate += new ServerValidateEventHandler(ValidateDate);
			customValidator.Text = NorthwindGeneral.GetDateFormat();
			customValidator.ErrorMessage = String.Format("{0} has invalid date format, use {1}", controlNameToValidate, NorthwindGeneral.GetDateFormat());
			containerControl.Controls.Add(customValidator);
			return customValidator;
		}

		public virtual void ValidateDate(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			try
			{
				NorthwindGeneral.ConvertToDate(args.Value.Split(' ')[0], NorthwindGeneral.IFormatProvider);
			}
			catch (Exception)
			{
				args.IsValid = false;
			}
		}


		public virtual Control CreateDateTimeValidator(Control containerControl, string controlNameToValidate)
		{
			CustomValidator customValidator = new CustomValidator();
			customValidator.Display = ValidatorDisplay.Dynamic;
			customValidator.ID = controlNameToValidate + "DateTimeValidator";
			customValidator.ControlToValidate = controlNameToValidate;
			if (NorthwindGeneral.GetDateFormat().ToLower().Substring(0, 2).Equals("dd"))
			{
				// Europe style
				customValidator.ClientValidationFunction = "validateDateD_M_YYYY_Time";
			}
			else
			{
				// USA style
				customValidator.ClientValidationFunction = "validateDateM_D_YYYY_Time";
			}
			customValidator.ServerValidate += new ServerValidateEventHandler(ValidateDateTime);
			customValidator.Text = NorthwindGeneral.GetDateFormat()+" hh:mm[:ss]";
			customValidator.ErrorMessage = String.Format("{0} has invalid date format, use {1}", controlNameToValidate, NorthwindGeneral.GetDateFormat());
			containerControl.Controls.Add(customValidator);
			return customValidator;
		}

		public virtual void ValidateDateTime(object source, ServerValidateEventArgs args)
		{
			string value = args.Value as string;
			if (value.Equals("{null}") || value.Length == 0) return;

			try
			{
				NorthwindGeneral.ConvertToDate(args.Value, NorthwindGeneral.IFormatProvider);
			}
			catch (Exception)
			{
				args.IsValid = false;
			}
		}

		public virtual void HideControl(TextBox textBox)
		{
			textBox.Visible = false;
		}

		public virtual void ProtectControl(TextBox textBox)
		{
			textBox.Enabled = false;
		}
		
		public static TextBox CreateTextBox(FieldShowModeEnum fieldShowMode)
		{
			TextBox textBox;
			if (fieldShowMode == FieldShowModeEnum.SHOW_NORMAL)
				textBox = NorthwindWebEnv.CreateTextBox();
			else
				textBox = new TextBox();
			return textBox;
		}

		public static TextBox CreateTextBox()
		{
			switch (NorthwindGeneral.WebControlsStyle)
			{
				case WebControlsStyle.MicrosoftStandard:
					{
						System.Web.UI.WebControls.TextBox textBox = new TextBox();
						return textBox;
					}
				case WebControlsStyle.Obout:
					{
						Obout.Interface.OboutTextBox textBox = new Obout.Interface.OboutTextBox();
						textBox.FolderStyle = NorthwindGeneral.GetWebServerRootURL() + @"obout\Interface\styles\black_glass\OboutTextBox";
						return textBox;
					}
				default:
					throw new Exception("Un supported WebControl Style " + NorthwindGeneral.WebControlsStyle.ToString());
			}
		}

		public static DropDownList CreateDropDownList()
		{
			switch (NorthwindGeneral.WebControlsStyle)
			{
				case WebControlsStyle.MicrosoftStandard:
					{
						System.Web.UI.WebControls.DropDownList dropDownList = new DropDownList();
						return dropDownList;
					}
				case WebControlsStyle.Obout:
					{
						Obout.Interface.OboutDropDownList dropDownList = new Obout.Interface.OboutDropDownList();
						dropDownList.FolderStyle = NorthwindGeneral.GetWebServerRootURL() + @"obout\Interface\styles\black_glass\OboutDropDownList";
						return dropDownList;
					}
				default:
					throw new Exception("Un supported WebControl Style " + NorthwindGeneral.WebControlsStyle.ToString());
			}
		}

		public static CheckBox CreateCheckBox()
		{
			switch (NorthwindGeneral.WebControlsStyle)
			{
				case WebControlsStyle.MicrosoftStandard:
					{
						System.Web.UI.WebControls.CheckBox checkBox = new CheckBox();
						return checkBox;
					}
				case WebControlsStyle.Obout:
					{
						Obout.Interface.OboutCheckBox checkBox = new Obout.Interface.OboutCheckBox();
						checkBox.FolderStyle = NorthwindGeneral.GetWebServerRootURL() + @"obout\Interface\styles\black_glass\OboutCheckBox";
						return checkBox;
					}
				default:
					throw new Exception("Un supported WebControl Style " + NorthwindGeneral.WebControlsStyle.ToString());
			}
		}

		public static RadioButton CreateRadioButton()
		{
			switch (NorthwindGeneral.WebControlsStyle)
			{
				case WebControlsStyle.MicrosoftStandard:
					{
						System.Web.UI.WebControls.RadioButton radioButton = new RadioButton();
						return radioButton;
					}
				case WebControlsStyle.Obout:
					{
						Obout.Interface.OboutRadioButton radioButton = new Obout.Interface.OboutRadioButton();
						radioButton.FolderStyle = NorthwindGeneral.GetWebServerRootURL() + @"obout\Interface\styles\black_glass\OboutRadioButton";
						return radioButton;
					}
				default:
					throw new Exception("Un supported WebControl Style " + NorthwindGeneral.WebControlsStyle.ToString());
			}
		}

		public bool EditAllRows
		{
			get
			{
				return m_EditAllRows;
			}
			set
			{
				m_EditAllRows = value;
			}
		}

		public virtual void CustomiseControlsAttributes()
		{
			// you can overide this function to hide, diable, or change any attributes of the conrols
			// this is call afetr the data was set and before render
		}

		public virtual void SetFieldVisibility(int fieldnum, bool visible)
		{
		}

		public virtual void SetFieldProtected(int fieldnum, bool bProtected)
		{
		}

		public virtual Control GetFieldControl(int fieldNumParam)
		{
			return null;
		}

		public virtual void HideField(int  fieldNum)
		{
			if (ContainerControl is NorthwindWCC)
			{
				NorthwindWCC northwindWcc = (NorthwindWCC)ContainerControl;
				if (northwindWcc.FieldsLayout == FieldsLayout.EachFieldInRow)
					HideFieldTR(northwindWcc, (int)fieldNum);
				else
					HideFieldTD(northwindWcc, (int)fieldNum);
				return;
			}
			else if (ContainerControl is DataGridItem)
			{
				Control control = GetFieldControl(fieldNum);
				if (control != null)
					control.Visible = false;
			}
		}

		public virtual void ProtectField(int fieldNum)
		{
			Control control = GetFieldControl(fieldNum);
			if (control != null && control is WebControl)
				(control as WebControl).Enabled = false;
		}

		public virtual void DisableField(int fieldNum)
		{
			ProtectField(fieldNum);
		}

		public virtual void EnableField(int fieldNum)
		{
			Control control = GetFieldControl(fieldNum);
			if (control != null && control is WebControl)
				(control as WebControl).Enabled = true;
		}

		public void ShowField(int fieldNum)
		{
			if (ContainerControl is NorthwindWCC)
			{
				NorthwindWCC northwindWcc = (NorthwindWCC)ContainerControl;
				if (northwindWcc.FieldsLayout == FieldsLayout.EachFieldInRow)
					ShowFieldTR(northwindWcc, (int)fieldNum);
				else
					ShowFieldTD(northwindWcc, (int)fieldNum);
				return;
			}
		}

		public virtual string EntityPageUrl
		{
			get
			{
				StringBuilder entityPageUrlStringBilder = new StringBuilder();
				entityPageUrlStringBilder.Append(Northwind.General.NorthwindGeneral.GetWebServerRootURL());
				if (m_StructData is CRecordData)
					entityPageUrlStringBilder.Append("Records/");
				else
					entityPageUrlStringBilder.Append("Struct/");
				string structName = m_StructData.GetType().Name.Substring(1); // without the C prefix for the DataModel like COrder
				entityPageUrlStringBilder.Append(structName + "/");
				entityPageUrlStringBilder.Append(structName + "Entity.aspx");
				return entityPageUrlStringBilder.ToString();
			}
		}

		public virtual void SetControlsValues(CFieldAttributeCollection fieldAttributeCollection)
		{
			string controlId;
			Control fromControl, toControl;
			string fromValue, toValue;
			string[] values;
			int fieldNum;
			string fieldValue = null;
			CheckBox activeCheckBox;

			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				fieldNum = fieldAttribute.Num;

				if (fieldAttribute.Value != null && fieldAttribute.Value.Length > 0)
				{
					fieldValue = fieldAttribute.Value;
				}
				else if (fieldAttribute.DefaultValue != null && fieldAttribute.DefaultValue.Length > 0)
				{
					fieldValue = ChangeSymbolsToValues(fieldAttribute.DefaultValue);
					fieldAttribute.Value = fieldValue;
					if (fieldAttribute.ShowMode != FieldShowModeEnum.SHOW_NORMAL && fieldAttribute.SqlOperator != SqlOperatorEnum.BETWEEN)
					{
						StructData.SetFieldStringValue(fieldNum, fieldValue);
					}
				}
				else
				{
					if (fieldAttribute.SqlOperator != SqlOperatorEnum.BETWEEN)
						SetControlValue(fieldNum);
					continue;
				}
				if (fieldValue != null && fieldValue.Length > 0 && fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
				{
					values = fieldValue.Split(new char[] { ';' });
					controlId = string.Format("{0}{1}{2}", this.StructData.GetType().Name.Substring(1), this.StructData.GetFieldName(fieldNum), "Active");
					activeCheckBox = (CheckBox)FindControlRecursive(ContainerControl, controlId);

					switch ((SqlOperatorEnum)fieldAttribute.SqlOperator)
					{
						case SqlOperatorEnum.BETWEEN:
							if (values.Length == 3)
							{
								SetControlValue(fieldNum, "From", values[0]);
								SetControlValue(fieldNum, "To", values[1]);
								// set active as the last items in value
								if (activeCheckBox != null)
								{
									if (values[2].Equals("0"))
										activeCheckBox.Checked = false;
									else
										activeCheckBox.Checked = true;
								}
							}
							else
							{
								SetControlValue(fieldNum, "From", "");
								SetControlValue(fieldNum, "To", "");
								if (activeCheckBox != null)
								{
									activeCheckBox.Checked = false;
								}
							}
							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:
							if (values.Length > 0)
							{
								SetControlValue(fieldNum, "", values[0]);
								if (activeCheckBox != null && values.Length > 1)
								{
									if (values[1].Equals("0"))
										activeCheckBox.Checked = false;
									else
										activeCheckBox.Checked = true;
								}
							}
							break;
						default:
							throw new Exception("Unsupported SqlCommandTypeEnum operator " + fieldAttribute.SqlOperator.ToString() + " in function SetControlsValues(CFieldAttributeCollection fieldAttributeCollection)");
					}
				}

			}

		}

		protected virtual string ChangeSymbolsToValues(string fieldValue)
		{
			string fromValue, toValue;
			string[] values;

			values = fieldValue.Split(new char[] { ';' });
			if (values.Length == 2)
			{
				fromValue = GetSymbolValue(values[0]);
				toValue = GetSymbolValue(values[1]);
				return fromValue + ";" + toValue;
			}
			if (values.Length == 1)
			{
				fromValue = GetSymbolValue(values[0]);
				return fromValue;
			}
			else
				return fieldValue;
		}

		protected string GetSymbolValue(string symName)
		{
			if (SessionManager.Session[symName] != null)
				return SessionManager.Session[symName].ToString();
			if (HttpContext.Current.Application[symName] != null)
				return HttpContext.Current.Application[symName].ToString();
			else
				return symName;
		}

		protected virtual void ChangeSymbolToValue(string symbolName,CStructData structData,int fieldNum)
		{
			string symbolValue;

			symbolValue = GetSymbolValue(symbolName);
			if (!symbolValue.Equals(symbolName))
			{
				structData.SetFieldStringValue(fieldNum,symbolValue);
			}
		}

		public virtual string CreateSqlCommandFromParams(CFieldAttributeCollection fieldAttributeCollection)
		{
			CRecord record = DataManager.GetRecordByRecordData((CRecordData)this.StructData);
			string sqlCommand = record.CreateSelectAllFieldsSql();
			string suffixForControlId;
			string controlId;
			string fromValue, toValue;
			string[] values;

			Control fromControl, toControl;
			GetControlsValues(fieldAttributeCollection);
			int fieldNum;
			CheckBox activeCheckBox;

			foreach (CFieldAttribute fieldAttribute in fieldAttributeCollection)
			{
				fieldNum = fieldAttribute.Num;
				if ( fieldAttribute.ShowMode == FieldShowModeEnum.SHOW_NORMAL)
				{
					// check if active is checked - if not skip
					controlId = string.Format("{0}{1}{2}", this.StructData.GetType().Name.Substring(1), this.StructData.GetFieldName(fieldNum), "Active");
					activeCheckBox = (CheckBox)FindControlRecursive(ContainerControl, controlId);
					if (activeCheckBox != null && !activeCheckBox.Checked)
						continue;
				
				}

				if (fieldAttribute.ShowMode != FieldShowModeEnum.HIDDEN)
				{
					
					switch (fieldAttribute.SqlOperator)
					{
						case SqlOperatorEnum.BETWEEN:
							values = fieldAttribute.Value.Split(new char[] { ';' });
							if (values.Length >= 2)
							{
								fromValue = values[0];
								toValue = values[1];

								if (!fromValue.Equals(""))
									if (!toValue.Equals(""))
										sqlCommand = record.AddCriteria(sqlCommand, "AND", fieldNum, SqlOperatorEnum.BETWEEN, fromValue, toValue);
									else
										sqlCommand = record.AddCriteria(sqlCommand, "AND", fieldNum, SqlOperatorEnum.GREAT_OR_EQUAL, fromValue);
								else
									if (!toValue.Equals(""))
										sqlCommand = record.AddCriteria(sqlCommand, "AND", fieldNum, SqlOperatorEnum.LESS_OR_EQUAL, toValue);
							}
							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:
							values = fieldAttribute.Value.Split(new char[] { ';' });
							if (values.Length >= 1)
								sqlCommand = record.AddCriteria(sqlCommand, "AND", fieldNum, fieldAttribute.SqlOperator, values[0]);
							break;
					}
				}
			}

			return sqlCommand;
		}

		public virtual CFieldAttributeCollection GetAdvancedCriterias(CFieldAttributeCollection fieldAttributeCollection)
		{
			CRecordData recordData = (CRecordData)this.StructData;
			CFieldAttribute fieldAttribute;

			int fieldNum;
			for (int i = 0; i < recordData.NumFields; i++)
			{
				fieldNum = i + 1;
				fieldAttribute = fieldAttributeCollection.FindByFieldValue(CFieldAttribute.FIELDS_ENUM.NUM, fieldNum);
				if (fieldAttribute == null)
				{
					fieldAttribute = new CFieldAttribute();
					fieldAttribute.Num = fieldNum;
					fieldAttribute.ShowMode = FieldShowModeEnum.SHOW_NORMAL;
					fieldAttribute.SqlOperator = GetDefaultSqlOperator(recordData.GetFieldValueAsObject(fieldNum));
					fieldAttributeCollection.Add(fieldAttribute);
				}

			}
			return fieldAttributeCollection;
		}

		public virtual SqlOperatorEnum GetDefaultSqlOperator(object fieldValue)
		{
			if (fieldValue is Int16)
				return SqlOperatorEnum.EQUAL;
			if (fieldValue is String)
				return SqlOperatorEnum.CONTAINS;
			else
				return SqlOperatorEnum.BETWEEN;
		}

		public virtual Control GetControl(int fieldNum, string suffixForControlId = "")
		{
			string controlId = string.Format("{0}{1}{2}", this.StructData.GetType().Name.Substring(1), this.StructData.GetFieldName(fieldNum), suffixForControlId);
			Control control = (Control)FindControlRecursive(ContainerControl, controlId);
			return control;
		}
				
		public virtual void CreateGridColumn(NorthwindGrid grid, CFieldAttribute fieldAttribute)
		{
			throw new NotImplementedException("CreateGridColumn(NorthwindGrid grid, CFieldAttribute fieldAttribute) not implemented in " + this.GetType().ToString());
		}

		public virtual void AddDropDownListOptions(Control containerControl, System.Web.UI.HtmlControls.HtmlGenericControl wrapper, Control control, int fieldNum)
		{
			System.Web.UI.WebControls.ImageButton edit = new System.Web.UI.WebControls.ImageButton();
			System.Web.UI.WebControls.ImageButton zoom = new System.Web.UI.WebControls.ImageButton();

			edit.ImageUrl = @"~\images\edit.png";
			edit.CssClass = "DropDownEdit";
			zoom.ImageUrl = @"~\images\zoom.png";
			zoom.CssClass = "DropDownZoom";
			zoom.ToolTip = "Zoom to it";
			zoom.Attributes["FieldNum"] = fieldNum + "";
			//zoom.OnClientClick = "zoomClick('Policy'); return false;";
			zoom.Click += Zoom_Click;
			containerControl.Controls.Add(wrapper);
			wrapper.Controls.Add(zoom);
			wrapper.Controls.Add(edit);
		}

		public virtual void Zoom_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			GetControlsValues();
			System.Web.UI.WebControls.ImageButton imageButton = (System.Web.UI.WebControls.ImageButton)sender;

			int fieldNum = Convert.ToInt32(imageButton.Attributes["FieldNum"]);
			DropDownList dropDownList = (DropDownList)GetControl(fieldNum, "");

			if (dropDownList.SelectedValue != "0")
			{
				CRecordData selectedRecordData = (CRecordData)(dropDownList.DataSource as IRecordDataCollection)[dropDownList.SelectedIndex];
				CRecord record = DataManager.GetRecordByRecordData(selectedRecordData);
				string recordName = selectedRecordData.GetObjectName().ToString();

				record.SetRecordData(selectedRecordData);
				string accessMethodParams = record.GetAccessMethodParamsAsString(1);
				string url = HttpContext.Current.Request.Url.AbsoluteUri;
				string page = HttpContext.Current.Request.Url.AbsolutePath;
				int startPage = url.IndexOf("/Records/");
				if (startPage == -1)
					startPage = url.IndexOf("/Secords/");

				if (startPage != -1)
				{
					string newURL = url.Substring(0, startPage) + String.Format("/Records/{0}/{0}Entity.aspx?AcmNum=1&AcmParams={1}", recordName, accessMethodParams);
					string scriptText = String.Format("function Zoom() {{ window.open('{0}','_blank'); prm.remove_endRequest(Zoom);}}", newURL);
					(ContainerControl.Page as NorthwindPage).InjectStartupScript(PostBackMode.AsyncPostBack, ContainerControl, "Zoom", scriptText);
				}
				else
					; //log the exception
			}
		}

		public static string GetUniqueDateSourceName(Control control, string dataSourceControlName)
		{
			if (control is Page)
				return control.GetType().ToString()+dataSourceControlName;
			else
				return control.Page.GetType().ToString()+dataSourceControlName;
		}				
	}