Skip Navigation Links.

Northwind\WebControls\ColumnTemplatesBase.cs

D:\NorthwindForWeb\Northwind\CS\DotNet\ADO.Net\Northwind\WebControls\ColumnTemplatesBase.cs
/*
 * This file was generated by ProCG version 2.0
 *
 * File name:	Northwind\WebControls\ColumnTemplatesBase.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.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Reflection;
   
using Northwind.General;
using Northwind.Data;

namespace Northwind.WebControls
{
	#region Item Template for Link Button

	public class ItemTemplateLinkBtnBase : ITemplate
	{
		string strColumnText;
		string strLinkButtonName;
		string strCommandName;
		bool Visible = true;
		bool Enable = true;
		public ItemTemplateLinkBtnBase(string LinkButtonName, string ColText, string CommandName)
		{
			this.strColumnText = ColText;
			this.strLinkButtonName = LinkButtonName;
			this.strCommandName = CommandName;
		}

		public ItemTemplateLinkBtnBase(string LinkButtonName, string ColText, string CommandName, bool Enabling, bool Visibility)
		{
			this.strColumnText = ColText;
			this.strLinkButtonName = LinkButtonName;
			this.Enable = Enabling;
			this.Visible = Visibility;
			this.strCommandName = CommandName;
		}

		public void InstantiateIn(Control objContainer)
		{
			LinkButton lnkbtn = new LinkButton();
			lnkbtn.CommandName = strCommandName;
			lnkbtn.DataBinding += new EventHandler(lnkbtn_DataBinding);
			objContainer.Controls.Add(lnkbtn);
		}

		private void lnkbtn_DataBinding(object sender, EventArgs e)
		{
			LinkButton lnkbtn = (LinkButton)sender;
			lnkbtn.ID = strLinkButtonName;
			lnkbtn.Text = strColumnText;
			lnkbtn.Visible = Visible;
			lnkbtn.Enabled = Enable;
			lnkbtn.CommandName = strCommandName;
			lnkbtn.CausesValidation = false;
		}
	}
	#endregion

	#region Item Template for Push button

	public class ItemTemplatePushButtonBase : ITemplate
	{

		string strColumnText;
		string strButtonName;
		string strCommandName;
		bool Visibile = true;
		bool Enable = true;

		public ItemTemplatePushButtonBase(string ButtonName, string ColText, string CommandName)
		{
			this.strColumnText = ColText;
			this.strButtonName = ButtonName;
			this.strCommandName = CommandName;
		}

		public ItemTemplatePushButtonBase(string ButtonName, string ColText, string CommandName, bool Enabling, bool Visibiling)
		{
			this.strColumnText = ColText;
			this.strButtonName = ButtonName;
			this.Visibile = Visibiling;
			this.Enable = Enabling;
			this.strCommandName = CommandName;
		}

		public void InstantiateIn(Control objContainer)
		{
			Button btn = new Button();
			btn.ID = strButtonName;
			btn.CommandName = strCommandName;
			btn.DataBinding += new EventHandler(btn_DataBinding);
			objContainer.Controls.Add(btn);
		}

		private void btn_DataBinding(object sender, EventArgs e)
		{
			Button btn = (Button)sender;
			btn.ID = strButtonName;
			btn.Text = strColumnText;
			btn.Visible = Visibile;
			btn.Enabled = Enable;
			btn.CommandName = strCommandName;
			btn.CausesValidation = false;
		}
	}

	#endregion Item Template for Push button

	#region Item Template for Label and drop down list in read mode

	public class ItemTemplateLabelBase : ITemplate
	{
		IStructDataCollection m_StructDataCollection;
		string strLabelName;
		int m_FieldNum;
		public ItemTemplateLabelBase(string LabelName, int fieldNum)
		{
			this.strLabelName = LabelName;
			m_FieldNum = fieldNum;
		}

		public ItemTemplateLabelBase(string LabelName, int fieldNum, IStructDataCollection DDLSource)
		{
			this.strLabelName = LabelName;
			m_FieldNum = fieldNum;
			m_StructDataCollection = DDLSource;
		}

		public void InstantiateIn(Control objContainer)
		{
			Label lbl = new Label();
			lbl.ID = strLabelName;
			lbl.DataBinding += new EventHandler(lbl_DataBinding);
			objContainer.Controls.Add(lbl);
		}


		private void lbl_DataBinding(object sender, EventArgs e)
		{
			Label lbl = (Label)sender;
			lbl.ID = strLabelName;

			DataGridItem dataGridItem = (DataGridItem)lbl.NamingContainer;

			CStructData structData = (CStructData)dataGridItem.DataItem;
			string fieldValue = structData.GetFieldStringValue(m_FieldNum);
			if (m_StructDataCollection == null)
				lbl.Text = fieldValue;
			else
			{
				fieldValue = m_StructDataCollection.GetDescriptionForCode(fieldValue);
				if (fieldValue == null)
					lbl.Text = "**Unknown**";
				else
					lbl.Text = fieldValue;
			}
		}
	}

	#endregion

	#region Item Template for TextBox

	public class ItemTemplateTextBoxBase : ITemplate
	{
		protected string m_ControlName;
		protected int m_FieldNum;
		protected int m_MaxLength = 0;
		protected int m_NumCharacters;
		protected int m_NumRows;
		protected bool m_ReadOnly = false;
		protected System.TypeCode m_Type = System.TypeCode.String;
		protected WebControl m_Control; // can be TextBox or Label if it is read only
		protected bool m_Required = false;
		protected ValidationDataType m_ValidationDataType;

		public ItemTemplateTextBoxBase(int fieldNum, string controlName, int maxLength, bool readOnly, int numRows)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = readOnly;
			m_NumRows = numRows;
		}

		public ItemTemplateTextBoxBase(int fieldNum, string controlName, int maxLength, bool readOnly)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = readOnly;
			m_NumRows = 1;
		}

		public ItemTemplateTextBoxBase(int fieldNum, string controlName, int maxLength)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = false;
			m_NumRows = 1;
		}

		public ItemTemplateTextBoxBase(int fieldNum, string controlName)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;

			m_MaxLength = 0;
			m_ReadOnly = false;
			m_NumRows = 1;
		}

		public ItemTemplateTextBoxBase(int fieldNum, string controlName, bool readOnly)
		{
			m_FieldNum = fieldNum;

			m_ControlName = controlName;
			m_MaxLength = 0;
			m_ReadOnly = readOnly;
			m_NumRows = 1;
		}

		public System.TypeCode Type
		{
			get { return m_Type; }
			set { m_Type = value; }
		}

		public ValidationDataType ValidationDataType
		{
			get { return m_ValidationDataType; }
			set { m_ValidationDataType = value; }
		}

		public bool Required
		{
			get { return m_Required; }
			set { m_Required = value; }
		}

		public int MaxLength
		{
			get { return m_MaxLength; }
			set { m_MaxLength = value; }
		}

		public int NumCharacters
		{
			get { return m_NumCharacters; }
			set { m_NumCharacters = value; }
		}

		public int NumRows
		{
			get { return m_NumRows; }
			set { m_NumRows = value; }
		}

		public virtual void InstantiateIn(Control objContainer)
		{
			if (m_ReadOnly)
			{
				m_Control = new Label();
				m_Control.ID = m_ControlName + "Label";
				if (m_NumCharacters != 0)
					m_Control.Width = (Unit)(int)(m_NumCharacters * 7.5);
			}
			else
			{
				m_Control = NorthwindWebEnv.CreateTextBox();
				m_Control.ID = m_ControlName;
				if (m_NumCharacters != 0)
					m_Control.Attributes["Size"] = m_NumCharacters.ToString();
				if (m_MaxLength != 0)
					((TextBox)(m_Control)).MaxLength = m_MaxLength;
			}

			m_Control.DataBinding += new EventHandler(textBox_DataBinding);
			objContainer.Controls.Add(m_Control);

			if (!m_ReadOnly)
				AddValidators(objContainer);
		}

		protected virtual void AddValidators(Control objContainer)
		{
			if (m_Required)
			{
				RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
				requiredFieldValidator.ID = m_ControlName + "_RequiredValidator";
				requiredFieldValidator.ControlToValidate = m_Control.ID;

				requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
				requiredFieldValidator.Text = "Field Required";

				objContainer.Controls.Add(requiredFieldValidator);
			}
			CompareValidator compareValidator;


			switch (m_ValidationDataType)
			{
				case ValidationDataType.Integer:
					compareValidator = new CompareValidator();
					compareValidator.ControlToValidate = m_Control.ID;
					compareValidator.Operator = ValidationCompareOperator.DataTypeCheck;
					compareValidator.Type = ValidationDataType.Integer;
					compareValidator.Display = ValidatorDisplay.Dynamic;
					compareValidator.ErrorMessage = "<br>Invalid number format";
					objContainer.Controls.Add(compareValidator);
					break;

				case ValidationDataType.Double:
					compareValidator = new CompareValidator();
					compareValidator.ControlToValidate = m_Control.ID;
					compareValidator.Operator = ValidationCompareOperator.DataTypeCheck;
					compareValidator.Type = ValidationDataType.Double;
					compareValidator.Display = ValidatorDisplay.Dynamic;
					compareValidator.ErrorMessage = "Invalid double format";
					objContainer.Controls.Add(compareValidator);
					break;

				case ValidationDataType.Date:
					compareValidator = new CompareValidator();
					compareValidator.ControlToValidate = m_Control.ID;
					compareValidator.Operator = ValidationCompareOperator.DataTypeCheck;
					compareValidator.Type = ValidationDataType.Date;
					compareValidator.Display = ValidatorDisplay.Dynamic;
					compareValidator.ErrorMessage = "<br>Invalid date format";
					objContainer.Controls.Add(compareValidator);
					break;
			}
		}

		private void textBox_DataBinding(object sender, EventArgs e)
		{
			WebControl webControl = (WebControl)sender;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;

				string fieldText = structData.GetFieldStringValue(m_FieldNum);
				if (m_ReadOnly)
					((Label)webControl).Text = fieldText;
				else
					((TextBox)webControl).Text = fieldText;


				Object field = structData.GetFieldValue(m_FieldNum);
				SetTypeFromField(field);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else 
				return; 
			if (!m_ReadOnly)
			{
				TextBox textBox = (TextBox)webControl;
				if (m_NumRows > 1)
				{
					textBox.TextMode = TextBoxMode.MultiLine;
					if (m_NumCharacters == 0)
					{
						if (m_MaxLength > 0)
						{
							m_NumCharacters = m_MaxLength / m_NumRows;
						}
						else
						{
							m_NumCharacters = 60;
						}
					}
					textBox.Rows = m_NumRows;
					textBox.Columns = m_NumCharacters;
				}
				else
				{
					textBox.TextMode = TextBoxMode.SingleLine;
					if (m_NumCharacters == 0)
					{
						m_NumCharacters = NumCharacterByTheType();
						if (m_NumCharacters > 0)
							textBox.Columns = m_NumCharacters;
					}
				}
				textBox.ReadOnly = m_ReadOnly;
			}
		}

		public void SetTypeFromField(object field)
		{
			if (field is DateTime)
			{
				m_Type = System.TypeCode.DateTime;
			}
			else if (field is Int16)
			{
				m_Type = System.TypeCode.Int16;
			}
			else if (field is Int32)
			{
				m_Type = System.TypeCode.Int32;
			}
			else if (field is Int64)
			{
				m_Type = System.TypeCode.Int64;
			}
			else if (field is float)
			{
				m_Type = System.TypeCode.Single;
			}
			else if (field is double)
			{
				m_Type = System.TypeCode.Double;
			}
			else if (field is String)
			{
				m_Type = System.TypeCode.String;
			}
		}

		public int NumCharacterByTheType()
		{
			switch (m_Type)
			{
				case System.TypeCode.Int16:
				case System.TypeCode.UInt16:
					return (5);

				case System.TypeCode.Int32:
				case System.TypeCode.UInt32:
					return (10);

				case System.TypeCode.Int64:
				case System.TypeCode.UInt64:

					return (20);

				default:
					return (0);
			}
		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{

			TextBox textBox = (TextBox)objContainer.Controls[0];
			structData.SetFieldStringValue(m_FieldNum, textBox.Text);
		}
	}

	#endregion

	#region Item Template for CheckBox
	public class ItemTemplateCheckBoxBase : ITemplate
	{
		protected string m_ControlName;
		protected int m_FieldNum;
		protected bool m_ReadOnly = false;
		protected CheckBox m_Control;

		public ItemTemplateCheckBoxBase(int fieldNum, string controlName, bool readOnly)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_ReadOnly = readOnly;
		}

		public ItemTemplateCheckBoxBase(int fieldNum, string controlName)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_ReadOnly = false;
		}

		public virtual void InstantiateIn(Control objContainer)
		{
			m_Control = NorthwindWebEnv.CreateCheckBox();
			if (m_ReadOnly)
			{
				m_Control.Enabled = false;
			}
			else
			{
				m_Control.Enabled = true;
			}
			m_Control.ID = m_ControlName;
			m_Control.DataBinding += new EventHandler(checkBox_DataBinding);
			objContainer.Controls.Add(m_Control);
		}


		private void checkBox_DataBinding(object sender, EventArgs e)
		{
			CheckBox checkBox = (CheckBox)sender;
			// set the field value 

			DataGridItem dataGridItem = (DataGridItem)checkBox.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				string fieldText = structData.GetFieldStringValue(m_FieldNum);

				checkBox.Checked = Northwind.General.NorthwindGeneral.BooleanValue(fieldText);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{
			CheckBox checkBox = (CheckBox)objContainer.Controls[0];
			string checkBoxValue;

			string originValue = structData.GetFieldStringValue(m_FieldNum);


			if (originValue == Boolean.TrueString || originValue == Boolean.FalseString)
			{
				if (checkBox.Checked)

					checkBoxValue = Boolean.TrueString;
				else
					checkBoxValue = Boolean.FalseString;
			}

			else
			{
				if (checkBox.Checked)
					checkBoxValue = "1";
				else
					checkBoxValue = "0";
			}
			structData.SetFieldStringValue(m_FieldNum, checkBoxValue);
		}
	}


	#endregion


	#region Item Template for Lookup TextBox



	public class ItemTemplateLookupTextBoxBase : ItemTemplateTextBox
	{
		protected NorthwindWebEnv m_WebEnv;
		public Label m_DescriptionLabel;

		public ItemTemplateLookupTextBoxBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, int maxLength, bool readOnly)
			: base(fieldNum, controlName, maxLength, readOnly)
		{
			m_WebEnv = webEnv;
		}


		public ItemTemplateLookupTextBoxBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, int maxLength)
			: base(fieldNum, controlName, maxLength)
		{
			m_WebEnv = webEnv;
		}


		public ItemTemplateLookupTextBoxBase(NorthwindWebEnv webEnv, int fieldNum, string controlName)
			: base(fieldNum, controlName)
		{
			m_WebEnv = webEnv;
		}

		public ItemTemplateLookupTextBoxBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, bool readOnly)
			: base(fieldNum, controlName, readOnly)
		{
			m_WebEnv = webEnv;
		}

		public override void InstantiateIn(Control objContainer)
		{
			if (m_ReadOnly)
			{
				m_Control = new Label();
				m_Control.ID = m_ControlName + "Label";
				//m_Control.Width=0;
			}
			else
			{
				m_Control = new TextBox();
				m_Control.ID = m_ControlName;
				//((TextBox)m_Control).TextChanged +=new EventHandler(ItemTemplateLookupTextBox_TextChanged);
				((TextBox)m_Control).AutoPostBack = true;
			}
			m_Control.DataBinding += new EventHandler(textBox_DataBinding);
			objContainer.Controls.Add(m_Control);

			Label space = new Label();

			space.Text = "&nbsp;";
			objContainer.Controls.Add(space);

			m_DescriptionLabel = new Label();
			m_DescriptionLabel.ID = m_ControlName + "Description";


			if (m_DescriptionLabel != null)
				objContainer.Controls.Add(m_DescriptionLabel);


			if (!m_ReadOnly)
				AddValidators(objContainer);
		}




		private void textBox_DataBinding(object sender, EventArgs e)
		{
			WebControl webControl = (WebControl)sender;
			CStructData structData = null;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				structData = (CStructData)dataGridItem.DataItem;
				string fieldText = structData.GetFieldStringValue(m_FieldNum);
				if (m_ReadOnly)
					((Label)webControl).Text = fieldText;
				else
					((TextBox)webControl).Text = fieldText;


				Object field = structData.GetFieldValue(m_FieldNum);
				SetTypeFromField(field);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else
				return;

			if (!m_ReadOnly)
			{
				TextBox textBox = (TextBox)webControl;
				textBox.TextMode = TextBoxMode.SingleLine;
				if (m_NumCharacters == 0)
				{
					m_NumCharacters = NumCharacterByTheType();
					if (m_NumCharacters > 0)
						textBox.Columns = m_NumCharacters;
				}
				textBox.ReadOnly = m_ReadOnly;
			}

			SetDescriptionValue(m_FieldNum, structData);
		}



		protected void SetDescriptionValue(int fieldNum, CStructData structData)
		{
			if (m_WebEnv == null)
				throw new Exception("Please set WebEnv for this Item Template");
			m_WebEnv.SetDescriptionValue(fieldNum, structData, m_DescriptionLabel);
		}




		public NorthwindWebEnv WebEnv
		{
			get { return m_WebEnv; }
			set { m_WebEnv = value; }
		}

		private void ItemTemplateLookupTextBox_TextChanged(object sender, EventArgs e)
		{
			CStructData structData;
			TextBox textBox = (TextBox)sender;

			DataGridItem dataGridItem = (DataGridItem)textBox.NamingContainer;

			if (dataGridItem.DataItem is CStructData)
			{
				structData = (CStructData)dataGridItem.DataItem;

				structData.SetFieldStringValue(m_FieldNum, textBox.Text);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else
				return;

			SetDescriptionValue(m_FieldNum, structData);
		}
	}


	#endregion

	#region Item Template for Choose Window



	public class ItemTemplateChooseWindowBase : ItemTemplateTextBox, INamingContainer
	{
		protected NorthwindWebEnv m_WebEnv;
		public Label m_DescriptionLabel;
		public ImageButton m_ImageButton;


		public ItemTemplateChooseWindowBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, int maxLength, bool readOnly)
			: base(fieldNum, controlName, maxLength, readOnly)
		{
			m_WebEnv = webEnv;
		}


		public ItemTemplateChooseWindowBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, int maxLength)
			: base(fieldNum, controlName, maxLength)
		{
			m_WebEnv = webEnv;
		}


		public ItemTemplateChooseWindowBase(NorthwindWebEnv webEnv, int fieldNum, string controlName)
			: base(fieldNum, controlName)
		{
			m_WebEnv = webEnv;
		}


		public ItemTemplateChooseWindowBase(NorthwindWebEnv webEnv, int fieldNum, string controlName, bool readOnly)
			: base(fieldNum, controlName, readOnly)
		{
			m_WebEnv = webEnv;
		}




		public override void InstantiateIn(Control objContainer)
		{
			if (m_ReadOnly)
			{
				m_Control = new Label();
				//m_Control.Width=0;
			}
			else
			{
				m_Control = NorthwindWebEnv.CreateTextBox();
				//((TextBox)m_Control).TextChanged +=new EventHandler(ItemTemplateLookupTextBox_TextChanged);
				((TextBox)m_Control).AutoPostBack = false;
			}
			m_Control.ID = m_ControlName;
			m_Control.DataBinding += new EventHandler(textBox_DataBinding);
			objContainer.Controls.Add(m_Control);
			Label space = new Label();
			space.Text = "&nbsp;";

			objContainer.Controls.Add(space);


			if (!m_ReadOnly)
			{
				m_ImageButton = new ImageButton();

				objContainer.Controls.Add(m_ImageButton);
				Label space2 = new Label();

				space2.Text = "&nbsp;";


				objContainer.Controls.Add(space2);
			}
			m_DescriptionLabel = new Label();
			m_DescriptionLabel.ID = m_ControlName + "Description";
			objContainer.Controls.Add(m_DescriptionLabel);

			if (!m_ReadOnly)
			{
				//WebEnv.SetChooseWindowControlAttributes(this.m_FieldNum,(TextBox)m_Control,m_ImageButton,m_DescriptionLabel,Northwind.General.FieldShowModeEnum.SHOW_NORMAL);
				AddValidators(objContainer);
			}
		}


		private void textBox_DataBinding(object sender, EventArgs e)
		{
			WebControl webControl = (WebControl)sender;
			CStructData structData;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;

			if (dataGridItem.DataItem is CStructData)
			{
				structData = (CStructData)dataGridItem.DataItem;
				string fieldText = structData.GetFieldStringValue(m_FieldNum);
				if (m_ReadOnly)
					((Label)webControl).Text = fieldText;
				else
					((TextBox)webControl).Text = fieldText;



				Object field = structData.GetFieldValue(m_FieldNum);
				SetTypeFromField(field);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else
				return;

			if (!m_ReadOnly)
			{
				TextBox textBox = (TextBox)webControl;
				textBox.TextMode = TextBoxMode.SingleLine;

				if (m_NumCharacters == 0)
				{
					m_NumCharacters = NumCharacterByTheType();
					if (m_NumCharacters > 0)
						textBox.Columns = m_NumCharacters;
				}
				textBox.ReadOnly = m_ReadOnly;
			}
			if (!m_ReadOnly)
			{
				WebEnv.SetChooseWindowControlAttributes(this.m_FieldNum, (TextBox)m_Control, m_ImageButton, m_DescriptionLabel, Northwind.General.FieldShowModeEnum.SHOW_NORMAL);
			}

			SetDescriptionValue(m_FieldNum, structData);
		}




		protected void SetDescriptionValue(int fieldNum, CStructData structData)
		{

			if (m_WebEnv == null)
				throw new Exception("Please set WebEnv for this Item Template");



			m_WebEnv.SetDescriptionValue(fieldNum, structData, m_DescriptionLabel);
		}



		public NorthwindWebEnv WebEnv
		{
			get { return m_WebEnv; }
			set { m_WebEnv = value; }
		}


		private void ItemTemplateLookupTextBox_TextChanged(object sender, EventArgs e)
		{



			CStructData structData;
			TextBox textBox = (TextBox)sender;
			DataGridItem dataGridItem = (DataGridItem)textBox.NamingContainer;

			if (dataGridItem.DataItem is CStructData)
			{
				structData = (CStructData)dataGridItem.DataItem;
				structData.SetFieldStringValue(m_FieldNum, textBox.Text);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else
				return;

			SetDescriptionValue(m_FieldNum, structData);
		}
	}



	#endregion


	#region Item Template for Image Button


	public class ItemTemplateImageButtonBase : ITemplate
	{
		string strImageURL;
		string strImageButtonName;
		string strCommandName;
		bool Visibility = true;

		public ItemTemplateImageButtonBase(string ImageButtonName, string ImageUrl, string CommandName)
		{
			this.strImageURL = ImageUrl;
			this.strImageButtonName = ImageButtonName;
			this.strCommandName = CommandName;
		}


		public ItemTemplateImageButtonBase(string ImageButtonName, string ImageUrl, string CommandName, bool Visibility)
		{
			this.strImageURL = ImageUrl;
			this.strImageButtonName = ImageButtonName;
			this.Visibility = Visibility;
			this.strCommandName = CommandName;
		}



		public void InstantiateIn(Control objContainer)
		{
			ImageButton imgbtn = new ImageButton();
			imgbtn.CommandName = strCommandName;
			imgbtn.DataBinding += new EventHandler(imgbtn_DataBinding);
			objContainer.Controls.Add(imgbtn);
		}




		private void imgbtn_DataBinding(object sender, EventArgs e)
		{
			ImageButton imgBtn = (ImageButton)sender;
			imgBtn.ImageUrl = strImageURL;
			imgBtn.Visible = Visibility;

			imgBtn.CommandName = strCommandName;
			imgBtn.CausesValidation = false;
		}

	}


	#endregion


	#region Item Template for DropDownList in read only mode



	public class ItemTemplateDDLBase : ITemplate
	{
		IStructDataCollection m_StructDataCollection;
		string strLabelName;
		int m_FieldNum;


		public ItemTemplateDDLBase(string LabelName, int fieldNum, IStructDataCollection DDLSource)
		{
			this.strLabelName = LabelName;
			m_FieldNum = fieldNum;
			m_StructDataCollection = DDLSource;
		}



		public void InstantiateIn(Control objContainer)
		{
			Label lbl = new Label();
			lbl.ID = strLabelName + "Label";
			//lbl.DataBinding += new EventHandler(lbl_DataBinding);
			objContainer.Controls.Add(lbl);
		}



		private void lbl_DataBinding(object sender, EventArgs e)
		{
			Label lbl = (Label)sender;
			lbl.ID = strLabelName + "Label";
			DataGridItem dataGridItem = (DataGridItem)lbl.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string fieldValue = structData.GetFieldStringValue(m_FieldNum);
			fieldValue = m_StructDataCollection.GetDescriptionForCode(fieldValue);
			if (fieldValue == null)
				lbl.Text = "**Unknown**";
			else
				lbl.Text = fieldValue;
		}
	}


	#endregion


	#region Edit Item Template for DropDownList


	public class EditItemTemplateDDLBase : ITemplate
	{
		DataTable dtBind;
		string m_DDLName;
		string strDataValueField;
		string strDataTextField;
		IStructDataCollection m_StructDataCollection;
		int intDataValueField;
		DropDownList m_DropDownList;
		TextBox m_TextBox;
		int m_CodeFieldNum;
		bool m_bShowCodeField;



		public EditItemTemplateDDLBase(string DDLName, string DataValueField, string DataTextField, int codeFieldNum, DataTable DDLSource, bool b_ShowCodeField)
		{

			this.dtBind = DDLSource;
			this.strDataValueField = DataValueField;
			this.strDataTextField = DataTextField;
			this.m_CodeFieldNum = codeFieldNum;

			this.m_DDLName = DDLName;
			this.m_bShowCodeField = b_ShowCodeField;

		}



		public EditItemTemplateDDLBase(string DDLName, int DataValueField, string strDataValueField, string DataTextField, int codeFieldNum, IStructDataCollection DDLSource, bool b_ShowCodeField)
		{
			this.m_StructDataCollection = DDLSource;
			this.intDataValueField = DataValueField;
			this.strDataValueField = strDataValueField;
			this.strDataTextField = DataTextField;
			this.m_CodeFieldNum = codeFieldNum;
			this.m_DDLName = DDLName;
			this.m_bShowCodeField = b_ShowCodeField;
		}

		public DropDownList DropDownList
		{
			get { return m_DropDownList; }
		}



		public TextBox TextBox
		{
			get { return m_TextBox; }
		}



		public void InstantiateIn(Control objContainer)
		{
			m_DropDownList = NorthwindWebEnv.CreateDropDownList();
			m_DropDownList.ID = this.m_DDLName;
			m_DropDownList.DataBinding += new EventHandler(ddl_DataBinding);
			objContainer.Controls.Add(m_DropDownList);
			Label space = new Label();
			space.Text = "&nbsp;";
			objContainer.Controls.Add(space);
			m_TextBox = new TextBox();
			m_TextBox.ID = m_DDLName + "_Text";
			m_TextBox.Width = 40;
			m_TextBox.DataBinding += new EventHandler(codeText_DataBinding);
			objContainer.Controls.Add(m_TextBox);
			if (!m_bShowCodeField)
				m_TextBox.Width = 0; // We still need to hold the field in the html


		}


		private void ddl_DataBinding(object sender, EventArgs e)
		{
			DropDownList ddl = (DropDownList)sender;
			ddl.ID = m_DDLName;
			/*
			if (dtBind != null)
			{
				ddl.DataSource = dtBind;
			}
			else
			{
				ddl.DataSource = m_StructDataCollection;
			}


			ddl.DataValueField = strDataValueField;
			ddl.DataTextField = strDataTextField;
			*/


			DataGridItem dataGridItem = (DataGridItem)ddl.NamingContainer;

			CStructData structData = (CStructData)dataGridItem.DataItem;
			string selectedValue = structData.GetFieldStringValue(m_CodeFieldNum);

			/*
			if (dtBind != null)
			{

				for (int i = 0; i < dtBind.Rows.Count; i++)
				{

					if (selectedValue == dtBind.Rows[i][strDataValueField].ToString())
					{
						ddl.SelectedIndex = i;
						break;
					}
				}
			}

			else
			{
				for (int i = 0; i < m_StructDataCollection.Count; i++)
				{
					if (selectedValue == m_StructDataCollection.GetAt(i).GetFieldStringValue(intDataValueField))
					{
						ddl.SelectedIndex = i;
						break;
					}
				}
			}*/
			//ddl.DataBind();
		}



		private void codeText_DataBinding(object sender, EventArgs e)
		{



			TextBox textBox = (TextBox)sender;
			textBox.ID = m_DDLName + "_Text";
			DataGridItem dataGridItem = (DataGridItem)textBox.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string selectedValue = structData.GetFieldStringValue(m_CodeFieldNum);
			textBox.Text = selectedValue;


			m_DropDownList.Attributes.Add("onchange", m_TextBox.UniqueID.Replace(":", "_") + @".value = this.options[this.selectedIndex].value;");
		}
	}


	#endregion Edit Item Template for DropDownList



	#region Item Template for Codes DropDownList


	public class EditItemTemplateCodesDDLBase : ITemplate
	{
		string m_DDLName;
		int m_CodesTableNum;
		int m_FieldNum;
		DropDownList m_DropDownList;
		TextBox m_TextBox;
		bool m_bShowCodeField;


		public EditItemTemplateCodesDDLBase(string DDLName, int codesTableNum, int fieldNum, bool b_ShowCodeField)
		{
			m_DDLName = DDLName;
			m_CodesTableNum = codesTableNum;
			m_FieldNum = fieldNum;
			m_bShowCodeField = b_ShowCodeField;
		}


		public EditItemTemplateCodesDDLBase(string DDLName, int codesTableNum, int fieldNum)
		{
			m_DDLName = DDLName;
			m_CodesTableNum = codesTableNum;
			m_FieldNum = fieldNum;
			m_bShowCodeField = true;

		}



		public DropDownList DropDownList
		{
			get { return m_DropDownList; }
		}

		public TextBox TextBox
		{
			get { return m_TextBox; }
		}



		public void InstantiateIn(Control objContainer)
		{
			m_DropDownList = NorthwindWebEnv.CreateDropDownList();

			m_DropDownList.DataBinding += new EventHandler(ddl_DataBinding);
			objContainer.Controls.Add(m_DropDownList);


			Label space = new Label();
			space.Text = "&nbsp;";



			objContainer.Controls.Add(space);
			m_TextBox = new TextBox();
			m_TextBox.ID = m_DDLName + "_Text";



			m_TextBox.Width = 40;
			m_TextBox.DataBinding += new EventHandler(codeText_DataBinding);
			objContainer.Controls.Add(m_TextBox);
			if (!m_bShowCodeField)
			{
				m_TextBox.Width = 0;
				m_TextBox.CssClass = "hidden";
				space.Width = 0;
				space.CssClass = "hidden";
			}
		}




		private void ddl_DataBinding(object sender, EventArgs e)
		{
			DropDownList ddl = (DropDownList)sender;
			ddl.ID = m_DDLName;
			DataGridItem dataGridItem = (DataGridItem)ddl.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string selectedValue = structData.GetFieldStringValue(m_FieldNum);

			DataTable codesTableDataTable = Northwind.Data.NorthwindCodesManager.GetInstance().GetTableCodesDataTable(m_CodesTableNum); //
			ddl.DataSource = codesTableDataTable;
			ddl.DataValueField = "CodeNum";
			ddl.DataTextField = "Description";

			for (int i = 0; i < codesTableDataTable.Rows.Count; i++)
			{
				if (selectedValue == codesTableDataTable.Rows[i]["CodeNum"].ToString())
				{
					ddl.SelectedIndex = i;
					break;
				}
			}
			//ddl.DataBind();
		}


		private void codeText_DataBinding(object sender, EventArgs e)
		{
			TextBox textBox = (TextBox)sender;
			textBox.ID = m_DDLName + "_Text";
			DataGridItem dataGridItem = (DataGridItem)textBox.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;

			string selectedValue = structData.GetFieldStringValue(m_FieldNum);
			textBox.Text = selectedValue;

			// alert for debug  



			//m_DropDownList.Attributes.Add("onchange", m_TextBox.UniqueID.Replace(":","_")+@".value = this.options[this.selectedIndex].value;alert(""selection was changed:""+this.options[this.selectedIndex].value)");
			m_DropDownList.Attributes.Add("onchange", m_TextBox.UniqueID.Replace(":", "_") + @".value = this.options[this.selectedIndex].value;");
		}



		public void GetControlValue(Control objContainer, CStructData structData)
		{
			//DropDownList ddl = (DropDownList)objContainer.Controls[0];	
			structData.SetFieldStringValue(m_FieldNum, m_TextBox.Text);
		}
	}


	#endregion Edit Item Template for DropDownList

	#region Item Template for CodesDescription



	public class EditItemTemplateCodesDescriptionBase : ITemplate
	{
		string m_LabelName;
		int m_CodesTableNum;
		int m_FieldNum;


		public EditItemTemplateCodesDescriptionBase(string LabelName, int codesTableNum, int fieldNum)
		{
			m_LabelName = LabelName;
			m_CodesTableNum = codesTableNum;
			m_FieldNum = fieldNum;
		}



		public void InstantiateIn(Control objContainer)
		{
			Label label = new Label();
			label.ID = m_LabelName;
			label.DataBinding += new EventHandler(label_DataBinding);
			objContainer.Controls.Add(label);
		}



		private void label_DataBinding(object sender, EventArgs e)
		{
			Label label = (Label)sender;
			label.ID = m_LabelName;
			int intCodeValue;


			DataGridItem dataGridItem = (DataGridItem)label.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string strCodeValue = structData.GetFieldStringValue(m_FieldNum);

			try
			{
				intCodeValue = Convert.ToInt32(strCodeValue);
			}
			catch (Exception ex) // any conversion problem {Null}
			{
				intCodeValue = 0;
			}


			string codeDescription = Northwind.Data.NorthwindCodesManager.GetInstance().GetCodeDescription(m_CodesTableNum, intCodeValue);

			label.Text = codeDescription;
		}
	}


	#endregion Edit Item Template for CodesDescription


	#region Item Template for Radio Button




	public class ItemTemplateRadioButtonBase : ITemplate
	{
		string strText;

		string strRadioButtonName;

		bool Visibility = true;
		bool blChecked = false;

		public ItemTemplateRadioButtonBase(string RadioButtonName, string Text, bool AutoCheck)
		{
			this.strText = Text;
			this.strRadioButtonName = RadioButtonName;
			this.blChecked = AutoCheck;
		}

		public ItemTemplateRadioButtonBase(string RadioButtonName, string Text, bool AutoCheck, bool Visibility)
		{
			this.strText = Text;
			this.strRadioButtonName = RadioButtonName;
			this.Visibility = Visibility;
			this.blChecked = AutoCheck;
		}



		public void InstantiateIn(Control objContainer)
		{
			HtmlInputRadioButton rad = new HtmlInputRadioButton();
			rad.DataBinding += new EventHandler(rad_DataBinding);
			objContainer.Controls.Add(rad);
		}

		private void rad_DataBinding(object sender, EventArgs e)
		{
			HtmlInputRadioButton rad = (HtmlInputRadioButton)sender;
			rad.Value = strText;
			rad.Checked = blChecked;
			rad.Visible = Visibility;
		}
	}


	#endregion



	#region Item Template for Html Image


	public class ItemTemplateHtmlImageBase : ITemplate
	{
		string strImageName;
		string strImageUrl;
		int intHeight = -1;
		int intWidth = -1;



		public ItemTemplateHtmlImageBase(string ImageName, string ImageUrl)
		{
			this.strImageName = ImageName;
			this.strImageUrl = ImageUrl;
		}

		public ItemTemplateHtmlImageBase(string ImageName, string ImageUrl, int Height_IN_PX, int Width_IN_PX)
		{
			this.strImageName = ImageName;
			this.strImageUrl = ImageUrl;

			if (Height_IN_PX == -1)
			{
				this.intHeight = 25;
			}


			if (Width_IN_PX == -1)
			{
				this.intWidth = 25;
			}


			this.intHeight = Height_IN_PX;
			this.intWidth = Width_IN_PX;
		}



		public void InstantiateIn(Control objCntrl)
		{
			HtmlImage hImg = new HtmlImage();
			hImg.ID = strImageName;
			hImg.DataBinding += new EventHandler(hImg_DataBinding);
			objCntrl.Controls.Add(hImg);
		}



		private void hImg_DataBinding(object sender, EventArgs e)
		{
			HtmlImage hImg = (HtmlImage)sender;
			hImg.ID = strImageName;

			hImg.Src = strImageUrl;

			if (intHeight != -1)
			{
				hImg.Height = intHeight;
			}



			if (intWidth != -1)
			{
				hImg.Width = intWidth;
			}
		}
	}


	#endregion Item Template for Html Image

	#region Item Template for File Field




	public class ItemTemplateFileFieldBase : ITemplate
	{
		string strfileFieldName;
		int intWidth;
		bool blValidation;
		string strExpr = ".jpg|.jpeg";

		public ItemTemplateFileFieldBase(string FileFieldName, int Width, bool RequireValidation, string AllowingFiles)
		{
			this.strfileFieldName = FileFieldName;
			this.intWidth = Width;
			this.blValidation = RequireValidation;
			if (AllowingFiles == "")
			{
				this.strExpr = ".jpg|.jpeg";
			}
			else
			{
				this.strExpr = AllowingFiles;
			}
		}


		public ItemTemplateFileFieldBase(string FileFieldName, int Width)
		{
			this.strfileFieldName = FileFieldName;
			this.intWidth = Width;
		}



		public void InstantiateIn(Control objCntrl)
		{
			HtmlInputFile hFile = new HtmlInputFile();
			hFile.DataBinding += new EventHandler(hFile_DataBinding);
			objCntrl.Controls.Add(hFile);
		}



		private void hFile_DataBinding(object sender, EventArgs e)
		{
			HtmlInputFile hFile = (HtmlInputFile)sender;
			hFile.Size = intWidth;

			if (blValidation == true)
			{
				RegularExpressionValidator rgv = new RegularExpressionValidator();
				rgv.ControlToValidate = "hFile";
				rgv.Display = ValidatorDisplay.None;
				rgv.ErrorMessage = "Please Select the File names of the type : " + strExpr;
				rgv.ValidationExpression = @"^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(" + @strExpr + ")$";
			}

		}
	}


	#endregion Item Template for Html Image


	#region Item Template for Date and Time


	public class ItemTempDateTimeBase : ITemplate
	{
		string m_ControlName;
		int m_FieldNum;
		bool m_bShowTime;

		bool m_bReadOnly;

		public ItemTempDateTimeBase(string controlName, int fieldNum, bool showTime, bool readOnly)
		{
			m_ControlName = controlName;

			m_FieldNum = fieldNum;
			m_bShowTime = showTime;
			m_bReadOnly = readOnly;
		}

		public void InstantiateIn(Control objContainer)
		{
			if (m_bReadOnly)
			{
				Label label = new Label();
				label.ID = m_ControlName;
				label.DataBinding += new EventHandler(label_DataBinding);
				objContainer.Controls.Add(label);
			}
			else
			{
				Calendar calendar = new Calendar();
				calendar.ID = m_ControlName;
				calendar.SelectionMode = CalendarSelectionMode.Day;
				calendar.EnableViewState = true;
				calendar.DataBinding += new EventHandler(calendar_DataBinding);
				calendar.SelectionChanged += new EventHandler(calendar_SelectionChanged);
				objContainer.Controls.Add(calendar);
				if (m_bShowTime)
				{
					Literal literal = new Literal();
					literal.Text = "Time: ";
					objContainer.Controls.Add(literal);
					TextBox timeTextBox = NorthwindWebEnv.CreateTextBox();
					timeTextBox.ID = m_ControlName + "Time";
					timeTextBox.DataBinding += new EventHandler(time_DataBinding);
					objContainer.Controls.Add(timeTextBox);
				}
			}
		}

		private void label_DataBinding(object sender, EventArgs e)
		{
			Label label = (Label)sender;
			DataGridItem dataGridItem = (DataGridItem)label.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string labelText = structData.GetFieldStringValue(m_FieldNum);
			label.Text = labelText;
		}

		private void calendar_DataBinding(object sender, EventArgs e)
		{
			Calendar calendar = (Calendar)sender;
			DataGridItem dataGridItem = (DataGridItem)calendar.NamingContainer;

			CStructData structData = (CStructData)dataGridItem.DataItem;
			DateTime dateTime = (DateTime)structData.GetFieldValue(m_FieldNum);
			//calendar.VisibleDate = dateTime;
			calendar.SelectedDate = dateTime;
		}


		private void time_DataBinding(object sender, EventArgs e)
		{
			TextBox timeTextBoxr = (TextBox)sender;

			DataGridItem dataGridItem = (DataGridItem)timeTextBoxr.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			DateTime dateTime = (DateTime)structData.GetFieldValue(m_FieldNum);
			string timeValue;
			timeValue = dateTime.Hour + ":" + dateTime.Minute;
			if (dateTime.Second != 0)
				timeValue += ":" + dateTime.Second;

			timeTextBoxr.Text = timeValue;
		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{
			DateTime dateTime;
			TextBox timeTextBox;
			Calendar calendar = (Calendar)objContainer.Controls[0];
			dateTime = calendar.SelectedDate;
			if (m_bShowTime)
			{
				timeTextBox = (TextBox)objContainer.Controls[2]; // 1 is the literal Time:
				string timeValue = timeTextBox.Text;
				string[] timeParts = timeValue.Split(":".ToCharArray());
				int hour = Convert.ToInt32(timeParts[0]);
				int minute = Convert.ToInt32(timeParts[1]);
				int second = 0;
				if (timeParts.Length == 3)
					second = Convert.ToInt32(timeParts[2]);
				dateTime = new DateTime(dateTime.Year, dateTime.Month, dateTime.Day, dateTime.Hour, dateTime.Minute, dateTime.Second);
			}
			DateTime dateTimeOrigin = (DateTime)structData.GetFieldValue(m_FieldNum);
			structData.SetFieldValue(m_FieldNum, dateTime);
		}

		private void calendar_SelectionChanged(object sender, EventArgs e)
		{
			int i = 5;
			i++;
			Calendar calendar = (Calendar)sender;

			DataGridItem dataGridItem = (DataGridItem)calendar.NamingContainer;
			NorthwindGrid grid = (NorthwindGrid)dataGridItem.NamingContainer;

			CStructData structData = (CStructData)grid.RowsData[dataGridItem.ItemIndex];
			GetControlValue(calendar.Parent, structData);

		}
	}


	#endregion

	#region Item Template for Xin Date and Time


	public class ItemTemplateXinCalendarBase : ITemplate
	{

		string m_ControlName;
		int m_FieldNum;
		bool m_bShowTime;
		bool m_bReadOnly;

		public ItemTemplateXinCalendarBase(string controlName, int fieldNum, bool showTime, bool readOnly)
		{
			m_ControlName = controlName;

			m_FieldNum = fieldNum;
			m_bShowTime = showTime;
			m_bReadOnly = readOnly;
		}

		public void InstantiateIn(Control objContainer)
		{
			if (m_bReadOnly)
			{
				Label label = new Label();
				label.ID = m_ControlName;
				label.DataBinding += new EventHandler(label_DataBinding);
				objContainer.Controls.Add(label);
			}
			else
			{
				XinCalendarWCC calendar = new XinCalendarWCC();
				calendar.ID = m_ControlName;
				calendar.ShowMode = Northwind.General.FieldShowModeEnum.SHOW_NORMAL;
				calendar.EnableViewState = true;

				calendar.DataBinding += new EventHandler(calendar_DataBinding);
				objContainer.Controls.Add(calendar);
			}
		}



		private void label_DataBinding(object sender, EventArgs e)
		{
			Label label = (Label)sender;
			DataGridItem dataGridItem = (DataGridItem)label.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			string labelText = structData.GetFieldStringValue(m_FieldNum);
			label.Text = labelText;
		}


		private void calendar_DataBinding(object sender, EventArgs e)
		{
			XinCalendarWCC calendar = (XinCalendarWCC)sender;
			DataGridItem dataGridItem = (DataGridItem)calendar.NamingContainer;
			CStructData structData = (CStructData)dataGridItem.DataItem;
			calendar.Title = structData.GetFieldLabel(m_FieldNum);
			DateTime dateTime = (DateTime)structData.GetFieldValue(m_FieldNum);
			//calendar.VisibleDate = dateTime;
			calendar.Text = structData.GetFieldStringValue(m_FieldNum);
		}




		public void GetControlValue(Control objContainer, CStructData structData)
		{
			DateTime dateTime;

			XinCalendarWCC calendar = (XinCalendarWCC)objContainer.Controls[0];
			structData.SetFieldStringValue(m_FieldNum, calendar.Text);
		}
	}



	#endregion

	public class ItemTemplatePopupDateTimeBase : ItemTemplateTextBox
	{
		public ItemTemplatePopupDateTimeBase(int fieldNum, string controlName, int maxLength, bool readOnly, int numRows)

			: base(fieldNum, controlName, maxLength, readOnly, numRows)
		{
		}

		public ItemTemplatePopupDateTimeBase(int fieldNum, string controlName, int maxLength, bool readOnly)

			: base(fieldNum, controlName, maxLength, readOnly)
		{
		}

		public ItemTemplatePopupDateTimeBase(int fieldNum, string controlName, int maxLength)
			: base(fieldNum, controlName, maxLength)
		{
		}


		public ItemTemplatePopupDateTimeBase(int fieldNum, string controlName)
			: base(fieldNum, controlName)
		{
		}

		public ItemTemplatePopupDateTimeBase(int fieldNum, string controlName, bool readOnly)
			: base(fieldNum, controlName, readOnly)
		{
		}

		override public void InstantiateIn(Control objContainer)
		{
			if (m_ReadOnly)
			{
				base.InstantiateIn(objContainer);
				return;
			}
			else
			{
				base.InstantiateIn(objContainer); // create the text box first
				Label label = new Label();
				label.ID = this.m_ControlName + "_calSpace";
				//label.Text = @"&nbsp&nbsp <A href=""javascript:showCal2('"+m_Control.UniqueID+@"',Form1)""><IMG src=""/Northwind/images/cal.jpg"" border=""0""></A>";
				objContainer.Controls.Add(label);
				/*
				System.Web.UI.WebControls.HyperLink hyperLink = new HyperLink();
				hyperLink.ID = this.m_ControlName+"_href";
				hyperLink.Attributes["href"] = "javascript:showCal2('"+m_Control.ClientID+"',Form1)";
				ImageButton imageButton = new ImageButton();
				imageButton.ID = this.m_ControlName+"_image";

				imageButton.ImageUrl = NorthwindGeneral.GetWebImagesURL()+"cal.jpg";
				hyperLink.Controls.Add(imageButton);
				objContainer.Controls.Add(hyperLink);
				*/
			}
		}
	}

	#region Item Template for FCKeditor


	public class ItemTemplateFCKeditorBase : ITemplate
	{

		protected string m_ControlName;
		protected int m_FieldNum;
		protected int m_MaxLength = 0;
		protected int m_NumCharacters;
		protected int m_NumRows;
		protected bool m_ReadOnly = false;
		protected System.TypeCode m_Type = System.TypeCode.String;
		protected Control m_Control; // can be FredCK.FCKeditorV2.FCKeditor htmlEditorSmallHtml or Label if it is read only
		protected bool m_Required = false;
		protected ValidationDataType m_ValidationDataType;


		public ItemTemplateFCKeditorBase(int fieldNum, string controlName, int maxLength, bool readOnly, int numRows)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = readOnly;
			m_NumRows = numRows;
		}



		public ItemTemplateFCKeditorBase(int fieldNum, string controlName, int maxLength, bool readOnly)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = readOnly;
			m_NumRows = 1;
		}



		public ItemTemplateFCKeditorBase(int fieldNum, string controlName, int maxLength)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = maxLength;
			m_ReadOnly = false;
			m_NumRows = 1;
		}



		public ItemTemplateFCKeditorBase(int fieldNum, string controlName)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = 0;
			m_ReadOnly = false;
			m_NumRows = 1;
		}



		public ItemTemplateFCKeditorBase(int fieldNum, string controlName, bool readOnly)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_MaxLength = 0;
			m_ReadOnly = readOnly;
			m_NumRows = 1;
		}



		public System.TypeCode Type
		{
			get { return m_Type; }
			set { m_Type = value; }
		}



		public ValidationDataType ValidationDataType
		{
			get { return m_ValidationDataType; }
			set { m_ValidationDataType = value; }
		}


		public bool Required
		{
			get { return m_Required; }
			set { m_Required = value; }
		}


		public int MaxLength
		{
			get { return m_MaxLength; }
			set { m_MaxLength = value; }
		}


		public int NumCharacters
		{
			get { return m_NumCharacters; }
			set { m_NumCharacters = value; }
		}

		public int NumRows
		{
			get { return m_NumRows; }
			set { m_NumRows = value; }
		}



		public virtual void InstantiateIn(Control objContainer)
		{
			if (m_ReadOnly)
			{
				m_Control = new Label();
				m_Control.ID = m_ControlName + "Label"; 
				if (m_NumCharacters != 0)
				{
					((Label)m_Control).Width = (Unit)(int)(m_NumCharacters * 7.5);
				}
				if (m_NumRows != 0)
				{
					((Label)m_Control).Height = (Unit)(int)(m_NumRows * 10);
				}
			}
			else
			{
				m_Control.ID = m_ControlName;
				FredCK.FCKeditorV2.FCKeditor editor = new FredCK.FCKeditorV2.FCKeditor();
				m_Control = editor;
				editor.BasePath = NorthwindGeneral.GetFCKEditorBasePath();

				editor.ContentLangDirection = NorthwindWebEnv.FCKContentLangDirection;
				editor.Width = 280;
				editor.Height = 150;
				editor.ID = this.m_ControlName; ;
				editor.ToolbarCanCollapse = true;

				if (m_NumCharacters != 0)
					((Label)m_Control).Attributes["Size"] = m_NumCharacters.ToString();

				//if (m_MaxLength != 0)
				//	((FredCK.FCKeditorV2.FCKeditor)(m_Control)).MaxLength = m_MaxLength;
			}

			m_Control.DataBinding += new EventHandler(textBox_DataBinding);
			objContainer.Controls.Add(m_Control);

			if (!m_ReadOnly)
				AddValidators(objContainer);
		}

		protected virtual void AddValidators(Control objContainer)
		{
			if (m_Required)
			{
				RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
				requiredFieldValidator.ID = m_ControlName + "_RequiredValidator";

				requiredFieldValidator.ControlToValidate = m_Control.ID;
				requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
				requiredFieldValidator.Text = "Field Required";

				objContainer.Controls.Add(requiredFieldValidator);
			}
		}



		private void textBox_DataBinding(object sender, EventArgs e)
		{
			Control webControl = (Control)sender;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				string fieldText = structData.GetFieldStringValue(m_FieldNum);
				if (m_ReadOnly)
					((Label)webControl).Text = fieldText;
				else

					((FredCK.FCKeditorV2.FCKeditor)webControl).Value = fieldText;
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
			else
				return;

		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{
			FredCK.FCKeditorV2.FCKeditor fCKEditor = (FredCK.FCKeditorV2.FCKeditor)objContainer.Controls[0];
			structData.SetFieldStringValue(m_FieldNum, fCKEditor.Value);
		}
	}


	#endregion


	#region Item Template for FileBinary
	public class ItemTemplateFileBinaryBase : ITemplate
	{
		protected string m_ControlName;
		protected int m_FieldNum;
		protected bool m_ReadOnly = false;
		protected FileBinaryWUC m_Control;
		protected FileTypeEnum m_FileType;
		protected bool m_Required = false;
		protected ValidationDataType m_ValidationDataType;
		public static int CurrentImageId = 0;

		public ItemTemplateFileBinaryBase(int fieldNum, string controlName, FileTypeEnum fileType, bool readOnly)
		{
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_FileType = fileType;
			m_ReadOnly = readOnly;
		}

		public bool Required
		{
			get { return m_Required; }
			set { m_Required = value; }
		}

		public virtual void InstantiateIn(Control objContainer)
		{
			m_Control = new FileBinaryWUC();
			m_Control.ID = m_ControlName;
			m_Control.FileType = m_FileType;

			if (m_ReadOnly)
			{

				m_Control.ShowMode = FieldShowModeEnum.SHOW_READ_ONLY;
			}
			else
			{

				m_Control.ShowMode = FieldShowModeEnum.SHOW_NORMAL;
			}

			m_Control.DataBinding += new EventHandler(m_Control_DataBinding);
			objContainer.Controls.Add(m_Control);

			if (!m_ReadOnly)
				AddValidators(objContainer);
		}

		void m_Control_DataBinding(object sender, EventArgs e)
		{
			FileBinaryWUC webControl = (FileBinaryWUC)sender;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				object fileBinary = structData.GetFieldValue(m_FieldNum);
				string fileId;

				if (dataGridItem.DataItem is CRecordData)
					fileId = ((CRecordData)structData).GetPrimaryKeyAsString() + m_ControlName;
				else
					fileId = m_ControlName + CurrentImageId++;

				webControl.FileID = fileId;
				if (HttpContext.Current.Session[fileId] == null)
					HttpContext.Current.Session[fileId] = fileBinary;
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
		}

		protected virtual void AddValidators(Control objContainer)
		{

			if (m_Required)
			{
				RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();
				requiredFieldValidator.ID = m_ControlName + "_RequiredValidator";
				requiredFieldValidator.ControlToValidate = m_Control.ID;
				requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
				requiredFieldValidator.Text = "Field Required";

				objContainer.Controls.Add(requiredFieldValidator);
			}
		}
	}

	#endregion

	#region Item Template for File

	public class ItemTemplateFileBase : ITemplate
	{
		protected string m_ControlName;
		protected int m_FieldNum;
		protected bool m_ReadOnly = false;
		protected FileWUC m_Control;
		protected bool m_Required = false;

		protected FileTypeEnum m_FileType;

		public ItemTemplateFileBase(int fieldNum, string controlName, FileTypeEnum fileType, bool readOnly)
		{

			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_FileType = fileType;
			m_ReadOnly = readOnly;
		}

		public bool Required
		{
			get { return m_Required; }
			set { m_Required = value; }
		}


		public virtual void InstantiateIn(Control objContainer)
		{
			m_Control = new FileWUC();
			m_Control.ID = m_ControlName;
			m_Control.FileType = m_FileType;
			if (m_ReadOnly)
			{
				m_Control.ShowMode = FieldShowModeEnum.SHOW_READ_ONLY;
			}
			else
			{
				m_Control.ShowMode = FieldShowModeEnum.SHOW_NORMAL;
			}

			m_Control.DataBinding += new EventHandler(m_Control_DataBinding);
			objContainer.Controls.Add(m_Control);

			if (!m_ReadOnly)
				AddValidators(objContainer);
		}

		void m_Control_DataBinding(object sender, EventArgs e)
		{
			FileWUC webControl = (FileWUC)sender;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				webControl.StructData = structData;
				m_Control.DataInstanceIndex = dataGridItem.DataSetIndex;
				webControl.FieldNum = m_FieldNum;
				string generalFile = structData.GetFieldStringValue(m_FieldNum);

				webControl.FileUrlInDBColumn = generalFile;
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
		}

		protected virtual void AddValidators(Control objContainer)
		{

			if (m_Required)
			{
				RequiredFieldValidator requiredFieldValidator = new RequiredFieldValidator();

				requiredFieldValidator.ID = m_ControlName + "_RequiredValidator";
				requiredFieldValidator.ControlToValidate = m_Control.ID;
				requiredFieldValidator.Display = ValidatorDisplay.Dynamic;
				requiredFieldValidator.Text = "Field Required";


				objContainer.Controls.Add(requiredFieldValidator);
			}
		}


	}

	#endregion

	#region Item Template for CustomControl - Programmer Develope

	public class ItemTemplateCustomControlBase : ITemplate
	{
		protected string m_ControlName;
		protected int m_FieldNum;
		protected FieldShowModeEnum m_FieldShowMode;
		protected WebControl m_Control;
		protected string m_ControlTypeName;

		public ItemTemplateCustomControlBase(string controlTypeName, int fieldNum, string controlName, FieldShowModeEnum fieldShowMode)
		{
			m_ControlTypeName = controlTypeName;
			m_FieldNum = fieldNum;
			m_ControlName = controlName;
			m_FieldShowMode = fieldShowMode;
		}

		public virtual void InstantiateIn(Control objContainer)
		{
			Assembly assembly = Assembly.GetExecutingAssembly();
			m_Control = (WebControl)assembly.CreateInstance(m_ControlTypeName);
			m_Control.ID = m_ControlName;
			IWebCustomControl webCustomControl = (IWebCustomControl)m_Control;
			webCustomControl.WebCustomeControlPlace = WebCustomeControlPlaceEnum.Grid;
			webCustomControl.FieldShowMode = m_FieldShowMode;
			m_Control.DataBinding += new EventHandler(costomControl_DataBinding);
			objContainer.Controls.Add(m_Control);

		}

		private void costomControl_DataBinding(object sender, EventArgs e)
		{
			WebControl webControl = (WebControl)sender;
			IWebCustomControl webCustomControl = (IWebCustomControl)m_Control;
			// set the field value 
			DataGridItem dataGridItem = (DataGridItem)webControl.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				string fieldText = structData.GetFieldStringValue(m_FieldNum);
				webCustomControl.DataRowIndex = dataGridItem.ItemIndex;
				webCustomControl.StructData = structData;
				webCustomControl.FieldNum = this.m_FieldNum;
				webCustomControl.Value = fieldText;
			}
			else if (dataGridItem.DataItem != null) 

				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{

			IWebCustomControl webCustomContol = (IWebCustomControl)objContainer.Controls[0];
			structData.SetFieldStringValue(m_FieldNum, webCustomContol.Value);
		}
	}

	#endregion

	#region Item Template for  Standard - General and  Standard Way

	public class ItemTempBaseOnWebEnvBase : ITemplate
	{
		protected int m_FieldNum;
		protected NorthwindWebEnv m_WebEnv;
		protected Control m_Control;
		protected FieldShowModeEnum m_FieldShowMode;
		protected Control m_Container;

		public ItemTempBaseOnWebEnvBase(NorthwindWebEnv webEnv, int fieldNum, FieldShowModeEnum fieldShowMode)
		{
			m_WebEnv = webEnv;
			m_FieldNum = fieldNum;
			m_FieldShowMode = fieldShowMode;
		}

		public virtual void InstantiateIn(Control objContainer)
		{
			m_Container = objContainer;
			m_WebEnv.ContainerControl = objContainer;
			m_Control = (Control)m_WebEnv.CreateControl(objContainer, m_FieldNum, m_FieldShowMode);
			if (m_FieldShowMode == FieldShowModeEnum.SHOW_NORMAL)
				m_WebEnv.CreateControlValidator(m_Container, m_FieldNum);

			/*
			if (m_FieldShowMode == FieldShowModeEnum.SHOW_NORMAL)
			{
				m_WebEnv.SetControlInfo(m_FieldNum);
			}
			*/
			m_Control.DataBinding += new EventHandler(costomControl_DataBinding);
		}

		private void costomControl_DataBinding(object sender, EventArgs e)
		{
			Control control = (Control)sender;
			DataGridItem dataGridItem = (DataGridItem)control.NamingContainer;
			if (dataGridItem.DataItem is CStructData)
			{
				CStructData structData = (CStructData)dataGridItem.DataItem;
				m_WebEnv.ContainerControl = dataGridItem;
				m_WebEnv.StructData = structData;
				m_WebEnv.ComboBoxManager.EmptyOptionText = "";
				if (control is FileWUC) // vv
					(control as FileWUC).DataInstanceIndex = dataGridItem.DataSetIndex;

				if (m_FieldShowMode == FieldShowModeEnum.SHOW_NORMAL)
				{
					bool bOriginVisible = control.Visible;
					control.Visible = false;
					m_WebEnv.SetControlDynamicAttributes(m_FieldNum);
					control.Visible = bOriginVisible;
				}
				m_WebEnv.SetControlValue(m_FieldNum);
			}
			else if (dataGridItem.DataItem != null) 
				throw new Exception("Invalid type in DataBinding - Only CStructData supports");
		}

		public void GetControlValue(Control objContainer, CStructData structData)
		{
			m_WebEnv.StructData = structData;
			m_WebEnv.GetControlValue(m_FieldNum);
		}
	}

	#endregion

}



  //     61629 ProCG uses this line - don't edit it