Skip Navigation Links.

Northwind\WebControls\WCCBase.cs

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

namespace Northwind.WebControls
{
	/// <summary>
	/// Summary description for NorthwindWCCBase.
	/// </summary>
	[ParseChildren(true)]
	[PersistChildren(false)]
	[Designer(typeof(Northwind.WebControls.NorthwindWebControlDesigner))]
	public abstract class NorthwindWCCBase : Northwind.WebControls.NorthwindCompositeControl, ISupportInitialize
	{
		protected CStructData m_Data;
		protected CStructData m_OriginData;
		protected NorthwindToolBarWCC m_TopToolBar;
		protected NorthwindToolBarWCC m_ToolBar;
		protected string m_ElementTitle;
		protected bool m_DesignMode = (System.Web.HttpContext.Current == null);
		protected CFieldAttributeCollection m_FieldAttributeCollection;
		protected CFieldAttributeCollection m_UserFieldAttributeCollection;
		protected CFieldAttributeCollection m_EmptyFieldAttributeCollection;
		protected CFieldAttributeCollection m_FieldsCollectionToCreateTheControlBy; // caculated
		protected bool m_bInsideBeginInit;
		protected EditModeEnum m_PageEditMode;
		protected EditModeEnum m_UserEditMode = 0;

		protected string m_HeaderText = String.Empty;
		protected Northwind.General.FrameTypeEnum m_FrameType = FrameTypeEnum.None;
		System.Web.UI.WebControls.Table m_Table;
		protected FieldsLayout m_FieldsLayout = FieldsLayout.EachFieldInRow;
		protected int m_FieldsListType = 0;
		protected Hashtable eventsFired;

		public delegate void GeneralWebEventHandler(Object sender, GeneralWebEvent args);
		public event GeneralWebEventHandler OnGeneralWebEvent;

		public NorthwindWCCBase()
		{
			m_EmptyFieldAttributeCollection = new CFieldAttributeCollection();
			InitAll();
		}

		protected virtual void InitAll()
		{
			m_Data = null;
			m_OriginData = null;

			DataObjectsContainer = null;
			//m_DesignMode = (System.Web.HttpContext.Current == null);
		}



		[Browsable(true)]
		[NotifyParentProperty(true)]
		public Northwind.General.FrameTypeEnum FrameType
		{
			set
			{

				m_FrameType = value;
			}

			get
			{
				return (m_FrameType);
			}
		}

		[Browsable(true)]
		[NotifyParentProperty(true)]
		public string HeaderText
		{
			set
			{
				m_HeaderText = value;
			}

			get
			{
				return (m_HeaderText);
			}
		}


		[Browsable(true)]
		[NotifyParentProperty(true)]
		public FieldsLayout FieldsLayout
		{
			set
			{
				m_FieldsLayout = value;
				this.ViewState["FieldsLayout"] = value;
			}

			get
			{
				if (this.ViewState["FieldsLayout"] == null)
					m_FieldsLayout = FieldsLayout.EachFieldInRow;
				else
					m_FieldsLayout = (FieldsLayout)this.ViewState["FieldsLayout"];
				return (m_FieldsLayout);
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		protected int InternalFieldsListType
		{

			get
			{
				if (this.ViewState["FieldsListType"] == null)
					m_FieldsListType = 0;
				else
					m_FieldsListType = (int)this.ViewState["FieldsListType"];

				return (m_FieldsListType);
			}
			set
			{
				if (value != 0 && value != m_FieldsListType)
				{
					// do it in onload
					//this.m_FieldAttributeCollection = CreateFieldsCollection();
				}
				m_FieldsListType = value;
				this.ViewState["FieldsListType"] = value;
			}
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			if (InternalFieldsListType != 0)
				this.m_FieldAttributeCollection = CreateFieldsCollection();

			if (UserEditMode != 0 && UserEditMode != EditMode)
			{
				EditMode = UserEditMode;
				Recreate();
				SetControlsValues();
			}

			if (this.Controls.Count == 0)
			{
				Recreate();
				SetControlsValues();
			}

			if (this.Page.IsPostBack)
			{
				if (this.Visible)
				{
					WebEnv.ContainerControl = this;
					WebEnv.OnPostback();
				}
			}
		}
		[Browsable(false)]
		public bool HasDynamicFields
		{
			get { return true; }
		}

		protected virtual void OnDataManagerWasSet()
		{
		}



		[Browsable(false)]
		protected CStructData FreshData
		{
			get
			{
				m_Data = null;
				return (Data);
			}
		}

		[Browsable(false)]
		protected CStructData NewData
		{
			set
			{

				Data = value;
				KeepOrigin();
			}

		}


		public void KeepOrigin()
		{
			OriginData = Data.Clone();
		}

		[Browsable(false)]
		public CStructData OriginData
		{
			get
			{
				//if (m_OriginData != null)
				//	return (m_OriginData);

				if (DataInstanceName == "")
					throw new Exception("DataInstanceName must be specified");

				if (DataObjectsContainer != null)
				{

					m_OriginData = (CStructData)DataObjectsContainer[DataInstanceName + "OriginData"];
				}
				else
				{
					if (KeepDataInSession)
						m_OriginData = (CStructData)this.Page.Session[DataInstanceName + "OriginData"];
					else
						m_OriginData = (CStructData)this.ViewState[DataInstanceName + "OriginData"];
				}

				return (m_OriginData);
			}
			set
			{
				if (DataInstanceName == "")
					throw new Exception("DataInstanceName must be specified");

				m_OriginData = value;
				if (DataObjectsContainer != null)
				{

					DataObjectsContainer[DataInstanceName + "OriginData"] = m_OriginData;
				}
				else
				{
					if (KeepDataInSession)
						this.Page.Session[DataInstanceName + "OriginData"] = m_OriginData;
					else
						this.ViewState[DataInstanceName + "OriginData"] = m_OriginData;
				}
			}
		}



		[Browsable(true)]
		[NotifyParentProperty(true)]
		public bool ShowToolBar
		{
			get
			{
				if (ViewState["ShowToolBar"] == null)
				{
					ShowToolBar = false;
				}
				return ((bool)ViewState["ShowToolBar"]);
			}
			set
			{

				ViewState["ShowToolBar"] = value;
			}
		}


		[Browsable(true)]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[NotifyParentProperty(true)]
		public virtual NorthwindToolBarWCC ToolBar
		{
			get
			{

				if (ShowToolBar)
				{

					if (m_ToolBar == null)
					{
						m_ToolBar = new NorthwindToolBarWCC();

						m_ToolBar.ID = this.ID + "_ToolBar";
						m_ToolBar.ToolBarType = NorthwindToolBarWCC.ToolBarTypeEnum.DataControl;
						m_ToolBar.WCC = (NorthwindWCC)this;
						m_ToolBar.Page = this.Page;
					}
					return m_ToolBar;
				}
				else
					return null;
			}

			set
			{
				m_ToolBar = value;
				m_ToolBar.Page = this.Page;
				///m_ToolBar.ToolBarType = NorthwindToolBarWCC.ToolBarTypeEnum.DataControl;
				m_ToolBar.WCC = (NorthwindWCC)this;
			}
		}
		
		[Browsable(true)]
		[PersistenceMode(PersistenceMode.InnerProperty)]
		[NotifyParentProperty(true)]
		public NorthwindToolBarWCC TopToolBar
		{
			get
			{

				return m_TopToolBar;
			}

			set
			{
				m_TopToolBar = value;
				///m_ToolBar.ToolBarType = NorthwindToolBarWCC.ToolBarTypeEnum.DataControl;
				m_TopToolBar.WCC = (NorthwindWCC)this;
				m_TopToolBar.Page = this.Page;
			}
		}

		protected virtual void CreateToolbarControlsAsTR(Table table, NorthwindToolBarWCC toolbar)
		{
			TableRow tableRow;
			TableCell tableCell;
			System.Web.UI.WebControls.WebControl createdControl = toolbar;
			if (toolbar.Controls.Count == 0)
				toolbar.Recreate();

			tableRow = new TableRow();
			tableRow.ID = "ToolBarRow" + table.Rows.Count;
			table.Controls.Add(tableRow);

			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			tableCell.CssClass = "datacontrol_toolbar";
			tableCell.Wrap = false;
			int numColumns = table.Controls.Count;
			tableCell.ColumnSpan = 4; // numColumns;			
			tableCell.Controls.Add(toolbar);
			

			ImageButton copyButton = toolbar.CopyButton;
			if (copyButton != null)
			{

				copyButton.Click += new ImageClickEventHandler(copyButton_Click);
			}

			ImageButton pastButton = toolbar.PasteButton;
			if (pastButton != null)
			{
				pastButton.Click += new ImageClickEventHandler(pastButton_Click);
			}

			ImageButton discardChangesButton = toolbar.DiscardChangesButton;

			if (discardChangesButton != null)
			{

				discardChangesButton.Click += new ImageClickEventHandler(discardChangesButton_Click);
			}

			ImageButton saveButton = toolbar.SaveButton;
			if (saveButton != null)
			{
				saveButton.Click += new ImageClickEventHandler(saveButton_Click);
			}

			ImageButton deleteButton = toolbar.DeleteLinesButton;
			if (deleteButton != null)
			{
				deleteButton.Click += new ImageClickEventHandler(deleteButton_Click);
			}

			ImageButton printButton = toolbar.PrintButton;
			if (printButton != null)
			{
				printButton.OnClientClick = "CallPrint(this,'" + this.ClientID + "');return false;";
			}

			ImageButton digButton = toolbar.DigButton;
			if (digButton != null)
			{
				digButton.Click += new ImageClickEventHandler(digButton_Click);
			}

		}


		protected virtual void digButton_Click(object sender, ImageClickEventArgs e)
		{
			NorthwindPage northwindPage = (NorthwindPage)this.Page;

			string digUrl = WebEnv.EntityPageUrl + @"?AcmNum=1&AcmParams=" + (Data as CRecordData).GetPrimaryKeyAsString() + "&Collection=0";
			if (NorthwindGeneral.DigIntoSamePlace)
				northwindPage.Redirect(digUrl, true);
			else
				northwindPage.GetShowEntityTextBoxControl().Text = digUrl; // tells the form to open this page on load
		}
		

		protected void copyButton_Click(object sender, ImageClickEventArgs e)
		{
			Copy();
		}

		public void Copy()
		{
			CStructData structData;
			this.Page.Session["Clipboard"] = Data.CopyText;
		}

		protected void pastButton_Click(object sender, ImageClickEventArgs e)
		{
			Past();
		}

		public void Past()
		{
			string clipBoardText = (string)Page.Session["Clipboard"];

			if (clipBoardText != null)
			{

				if (IsDataIsRecordData())
					((CRecordData)Data).Past(clipBoardText);
				else
					Data.Past(clipBoardText);
			}
			SetControlsValues();
		}


		protected void discardChangesButton_Click(object sender, ImageClickEventArgs e)
		{
			if (!IsEventWasFired("DiscardChanges"))
			{
				DiscardChanges();
				EventWasFired("DiscardChanges");
			}
		}

		public void DiscardChanges()
		{
			if (OriginData != null)
			{
				Data = OriginData.Clone();
				SetControlsValues();
			}
		}

		protected void saveButton_Click(object sender, ImageClickEventArgs e)
		{
			if (!IsEventWasFired("Save"))
			{
				Save();
				SetControlsValues(); // to get auto incremenet fields and calculated fields
				EventWasFired("Save");
			}
		}


		public void Save()
		{
			GetControlsValues();
			if (!(Data is CRecordData))
				return;
			bool needToBeSaved = ((CRecordData)Data).NeedToBeSaved();
			if (!needToBeSaved)
			{
				AddInformationMessage("Nothing changed");
				return;
			}

			if (this.DataManager == null)
			{
				this.DataManager = (this.Page as NorthwindPage).DataManager;
			}
			try
			{
				bool needToInsert = ((CRecordData)Data).NeedToBeInserted();
				bool needToUpdated = ((CRecordData)Data).NeedToBeUpdated();
				bool needToDeleted = ((CRecordData)Data).NeedToBeDeleted();
				if (needToInsert || needToUpdated)
				{
					string message = "";
					// vv validate
					//bool validate = ((CRecordData)Data).Validate(ref message);
					//if (!validate)
					//{
					//	this.AddErrorMessage("Validation Error: " + message);
					//	return;
					//}
				}
				DataManager.BeginTrans();
				DataManager.Save((CRecordData)Data);
				DataManager.CommitTrans();

				DataManager.CommitStatusAfterSave((CRecordData)Data);
				if (!CollectionDataInstanceName.Equals(string.Empty))
					SetDataToCollection(Data);
				Data = Data; // to keep it in session
				KeepOrigin();
				if (needToInsert)
				{
					AddInformationMessage(string.Format("{0} was inserted successfully", (ElementTitle == null) ? "Data" : ElementTitle));
					AfterInsert();
				}
				else if (needToDeleted)
				{
					AddInformationMessage(string.Format("{0} was deleted successfully", (ElementTitle == null) ? "Data" : ElementTitle));
					AfterDelete();
				}
				else
				{
					AddInformationMessage(string.Format("{0} was saved successfully", (ElementTitle == null) ? "Data" : ElementTitle));
					AfterUpdate();
				}
			}
			catch (Exception ex)
			{
				if (DataManager != null)
				{
					if (DataManager.IsInsideTransaction)
					{
						DataManager.RollbackTrans();
					}
				}
				AddErrorMessage(string.Format("Failed to save {0} <br> Error: {1}", (ElementTitle == null) ? "data" : ElementTitle, ex.Message));
			}
		}

		virtual protected void AfterInsert()
		{			
		}

		virtual protected void AfterUpdate()
		{
		}

		virtual protected void AfterDelete()
		{
		}

		protected void deleteButton_Click(object sender, ImageClickEventArgs e)
		{
			if (!IsEventWasFired("Delete"))
			{
				Delete();
				SetControlsValues(); // to get auto incremenet fields and calculated fields
				EventWasFired("Delete");
			}
		}


		public virtual void Delete()
		{
			GetControlsValues();
			if (! (Data is CRecordData))
				return;

			((CRecordData)Data).SetDeleted();
			this.AddInformationMessage("Was marked as deleted");
		}


		[PersistenceMode(PersistenceMode.InnerProperty)]
		[NotifyParentProperty(true)]
		public CFieldAttributeCollection FieldsCollection
		{
			get
			{
				if (m_FieldsListType != 0)
				{

					return m_EmptyFieldAttributeCollection;
				}
				if (m_FieldAttributeCollection == null)
					m_FieldAttributeCollection = new CFieldAttributeCollection();

				m_FieldAttributeCollection.RemoveDuplicates();
				return (m_FieldAttributeCollection);
			}
			/*
			set
			{
				if (InternalFieldsListType != 0)
				{
					m_FieldAttributeCollection = null;
				}
				else
				{

					m_FieldAttributeCollection = value;
				}
			}
			 * */
		}

		protected CFieldAttributeCollection InternalFieldsCollection
		{
			get
			{
				if (m_FieldAttributeCollection == null)
				{
					m_FieldAttributeCollection = CreateFieldsCollection();
				}
				m_FieldAttributeCollection.RemoveDuplicates();
				return (m_FieldAttributeCollection);
			}
		}


		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public CFieldAttributeCollection UserFieldsCollection
		{
			get
			{
				if (m_UserFieldAttributeCollection != null)
				{
					return m_UserFieldAttributeCollection;
				}
				if (ViewState["UserFieldsCollection"] != null)
					m_UserFieldAttributeCollection = (CFieldAttributeCollection)ViewState["UserFieldsCollection"];
				else
				{
					m_UserFieldAttributeCollection = new CFieldAttributeCollection();
				}
				return (m_UserFieldAttributeCollection);
			}
			set
			{
				m_UserFieldAttributeCollection = value;
				m_FieldsCollectionToCreateTheControlBy = null;
				ViewState["UserFieldsCollection"] = m_UserFieldAttributeCollection;
				Recreate();
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public virtual CFieldAttributeCollection FieldsCollectionToCreateTheControlBy
		{
			get
			{
				if (m_FieldsCollectionToCreateTheControlBy != null && m_FieldsCollectionToCreateTheControlBy.Count > 0)
					return m_FieldsCollectionToCreateTheControlBy;
				if (this.ViewState["FieldsCollectionToCreateTheControlBy"] != null)
					return (CFieldAttributeCollection)this.ViewState["FieldsCollectionToCreateTheControlBy"];

				m_FieldsCollectionToCreateTheControlBy = new CFieldAttributeCollection();
				if (UserFieldsCollection.Count > 0)
				{
					m_FieldsCollectionToCreateTheControlBy.CopyFrom(UserFieldsCollection);
				}
				else
				{
					m_FieldsCollectionToCreateTheControlBy.CopyFrom(InternalFieldsCollection);
				}
				this.CustomiseFieldsCollection(m_FieldsCollectionToCreateTheControlBy);
				return m_FieldsCollectionToCreateTheControlBy;
			}
			set
			{
				this.ViewState["FieldsCollectionToCreateTheControlBy"] = value;
			}
		}

		virtual protected CFieldAttributeCollection CreateFieldsCollection()
		{

			m_FieldAttributeCollection = WebEnv.CreateFieldsCollection(InternalFieldsListType);
			return m_FieldAttributeCollection;
		}

		/// <summary>
		/// Required to be able to properly deal with the Collection object
		/// </summary>
		protected override void AddParsedSubObject(object obj)
		{

			if (obj is CFieldAttribute)
			{

				CFieldAttribute fieldAttribute = (CFieldAttribute)FieldsCollection.FindByFieldValue(CFieldAttribute.FIELDS_ENUM.NUM, (obj as CFieldAttribute).Num);
				if (fieldAttribute != null)
					fieldAttribute.CopyFrom(obj as CFieldAttribute);
				else
					FieldsCollection.Add(obj as CFieldAttribute);
				return;
			}
			else
				base.AddParsedSubObject(obj);
		}

		public virtual void SetControlsValues()
		{
			EnsureChildControls();
			WebEnv.SetControlsValues(this);
		}

		public virtual void GetControlsValues()
		{
			throw new NotImplementedException("GetControlsValues()");
		}

		public bool IsDataIsRecordData()
		{
			if (Data.GetType().IsSubclassOf(typeof(CRecordData)))
				return (true);
			else
				return (false);
		}



		public virtual void Recreate()
		{
			this.CreateChildControls();
		}


		public virtual void HideAll()
		{
			throw new NotImplementedException("HideAll()");
		}


		public virtual void ShowAll()
		{
			this.m_FieldAttributeCollection = CreateFieldsCollection();
		}

		public virtual void ShowSummary()
		{

			throw new NotImplementedException("ShowSummary()");
		}

		public virtual void ShowAllExceptSummary()
		{
			throw new NotImplementedException("ShowAllExceptSummary()");
		}
		#region ISupportInitialize Members

		public void BeginInit()
		{
			m_bInsideBeginInit = true;
		}

		public void EndInit()
		{

			m_bInsideBeginInit = false;
		}

		#endregion
		
		protected override void CreateChildControls()
		{
			SendGeneralWebEvent(GeneralWebEvent.EventTypeEnum.BeforeCreateChildControls);
			this.Controls.Clear();

			// vv !this.DesignMode
			if (!DesignMode)
			{
				/*
				if (SessionManager.UserExist  && SessionManager.User.Type == (short)UserTypeEnum.DEBUG)
				{
					FieldsCollectionToCreateTheControlBy.ShowAll();
				}*/
			}
			if ( !HeaderText.Equals(string.Empty))
			{

				TableRow tableRow;
				TableCell tableCell;

				// Table
				m_Table = new Table();
				//m_Table.BorderWidth = 0;

				m_Table.CellSpacing = 1;
				m_Table.CellPadding = 0;
				m_Table.CssClass = "WCCTableWithHeader";
				this.Controls.Add(m_Table);

				CreateHeaderRow(m_Table);

				// <tr> for the control itslef
				tableRow = new TableRow();
				tableRow.CssClass = "WCCControlRow";
				m_Table.Controls.Add(tableRow);


				// td - 1
				tableCell = new TableCell();
				tableCell.CssClass = "WCCControlCellWithHeader";
				tableRow.Controls.Add(tableCell);

				CreateControlWithItsFields(tableCell);

			}
			else
				CreateControlWithItsFields(this);

			base.CreateChildControls();
			this.ChildControlsCreated = true;

		}

		/*
		protected virtual string CreateAsAscx()
		{
			StringBuilder sb = new StringBuilder();

			if (FrameType != FrameTypeEnum.None || !HeaderText.Equals(string.Empty))
			{
				sb.Append(@"<table style='background-color: #D7E3DC; border-width: 0px; border-collapse: collapse;'>\n");


				if (!HeaderText.Equals(string.Empty))
					CreateHeaderRow(sb);

				// <tr> for the control itslef
				sb.Append(@"	<tr>\n");

				// td - 1
				//tableCell = new TableCell();
				//tableCell.Attributes["style"] = "padding:20 0 0 50";
				//tableRow.Controls.Add(tableCell);
				sb.Append(@"		<td></td><\n");

				// td - 2
				sb.Append(@"		<td><\n");
				if (HeaderText.Equals(string.Empty))
				{
					sb.Append(@"			<div style=""float: left"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>\n");
				}
				else
				{
					sb.Append(@"			<div style=""float: left"">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</div>\n");
				}

				CreateControlWithItsFields(sb);

				// td - 3
				sb.Append(@"		<td></td><\n");
			}
			else
				CreateControlWithItsFields(sb);

			return sb.ToString();
		}

		*/
		// you need to override this function
		public virtual void CreateControlWithItsFields(Control container)
		{

			System.Web.UI.WebControls.Table table = new Table();
			container.Controls.Add(table);
			table.BorderWidth = this.BorderWidth; 
			table.BorderColor = this.BorderColor;
			table.BorderStyle = this.BorderStyle;
			table.CssClass += "WCCTable";

			CFieldAttributeCollection tempFieldAttributeCollection = this.FieldsCollectionToCreateTheControlBy;
			CustomiseFieldsCollection(tempFieldAttributeCollection);
			/*
			CustomiseFieldsCollection(tempFieldAttributeCollection);
			 */ 
			/* vv
			if (this.Data is CRecordData && (this.Data as CRecordData).IsDeleted())
			{
				tempFieldAttributeCollection = this.FieldsCollectionToCreateTheControlBy.Clone();
				for (int i = 0; i < tempFieldAttributeCollection.Count; i++)
				{
					if (tempFieldAttributeCollection[i].ShowMode == FieldShowModeEnum.SHOW_NORMAL)
						tempFieldAttributeCollection[i].ShowMode = FieldShowModeEnum.SHOW_READ_ONLY;
				}
			}
			 */ 
			if (TopToolBar != null)
			{
				this.CreateToolbarControlsAsTR(table, TopToolBar);
			}
			if (FieldsLayout == FieldsLayout.EachFieldInRow)
				WebEnv.CreateAllFieldsAsTR(table, tempFieldAttributeCollection);
			else
				WebEnv.CreateAllFieldsAsTD(table, tempFieldAttributeCollection);


			if (ShowToolBar)
			{
				this.CreateToolbarControlsAsTR(table,ToolBar);
			}
			WebEnv.ContainerControl = this;
			WebEnv.SetControlsDynamicAttributes();
		}

		public virtual void CustomiseFieldsCollection()
		{
			CustomiseFieldsCollection(FieldsCollectionToCreateTheControlBy);
		}

		public virtual void CustomiseFieldsCollection(CFieldAttributeCollection fieldAttributeCollection)
		{
			if (!AllowEdit)
			{
				fieldAttributeCollection.SetReadOnly();
			}			
		}
		
		private Control CreateTopRoundedFrame()
		{
			TableRow tableRow;
			TableCell tableCell;

			// tr
			tableRow = new TableRow();
			m_Table.Controls.Add(tableRow);

			// td - 1 left top corner
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			Image image = new Image();
			image.ImageUrl = Northwind.General.NorthwindGeneral.GetWebImagesURL(this.Page.Theme) + "l_top.gif";
			image.Width = 7;

			image.Height = 6;
			image.BorderWidth = 0;
			tableCell.Controls.Add(image);

			// td - 2- empty just color
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);

			// td - 3= right top corner
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			image = new Image();
			image.ImageUrl = Northwind.General.NorthwindGeneral.GetWebImagesURL(this.Page.Theme) + "r_top.gif";
			image.Width = 7;
			image.Height = 6;
			image.BorderWidth = 0;

			tableCell.Controls.Add(image);

			return m_Table;
		}

		virtual protected void CreateHeaderRow(Table table)
		{
			TableRow tableRow;
			TableCell tableCell;

			// tr
			tableRow = new TableRow();
			m_Table.Controls.Add(tableRow);

			// td - 1- Header
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			tableCell.CssClass = "ControlHeader";
			tableCell.Text = HeaderText;


		}

		private void CreateHeaderRow(StringBuilder sb)
		{

			// tr
			sb.Append("<tr>\n");
			// td - 1 
			sb.Append("\t<td></td>\n");
			// td - 2- Header
			sb.Append("\t<td class='ControlHeader'>" + "&nbsp;&nbsp;&nbsp;" + HeaderText + "</td>" + "\n");
			// td - 3 
			sb.Append("\t<td></td>\n");

			sb.Append("</tr>\n");

		}


		public virtual void CreateButtomFrame(Control container)
		{
			if (FrameType == FrameTypeEnum.Rounded)
			{

				CreateButtomRoundedFrame(container);
			}
		}

		private void CreateButtomRoundedFrame(Control container)
		{
			// tr
			System.Web.UI.WebControls.TableRow tableRow = new TableRow();
			container.Controls.Add(tableRow);

			// td - left top corner
			System.Web.UI.WebControls.TableCell tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);
			Image image = new Image();
			image.ImageUrl = Northwind.General.NorthwindGeneral.GetWebImagesURL(this.Page.Theme) + "l_down.gif";
			image.Width = 7;
			image.Height = 6;
			image.BorderWidth = 0;
			tableCell.Controls.Add(image);

			// td - empty just color
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);

			// td = right top corner
			tableCell = new TableCell();
			tableRow.Controls.Add(tableCell);

			image = new Image();
			image.ImageUrl = Northwind.General.NorthwindGeneral.GetWebImagesURL(this.Page.Theme) + "r_down.gif";
			image.Width = 7;
			image.Height = 6;
			image.BorderWidth = 0;
			tableCell.Controls.Add(image);

		}


		[Browsable(false)]
		public CNorthwindUser User
		{
			get
			{
				if (this.Page.Session["User"] != null)
					return (CNorthwindUser)this.Page.Session["User"];
				else
					return null;
			}
		}

		public virtual void CreateUserFieldsCollection(CStructData structData, Northwind.General.StandardFieldsListEnum standardFieldsListEnum, bool bViewOnly)
		{
			CreateUserFieldsCollection(structData, (int)standardFieldsListEnum, bViewOnly);
		}

		public virtual void CreateUserFieldsCollection(CStructData structData, int fieldList, bool bViewOnly)
		{
			int[] fielsList = structData.GetFieldsList(fieldList);

			int i;
			CFieldAttributeCollection fieldAttributeCollection = new CFieldAttributeCollection();
			CFieldAttribute fieldAttribute;

			for (i = 0; i < fielsList.Length; i++)
			{
				fieldAttribute = fieldAttributeCollection.InsertNewFieldAttribute(-1); // add at the end
				fieldAttribute.Num = fielsList[i];
				fieldAttribute.Name = this.Data.GetFieldName(fieldAttribute.Num);

				fieldAttribute.ShowMode = (Northwind.General.FieldShowModeEnum)Northwind.General.FieldShowModeEnum.SHOW_NORMAL;
			}
			UserFieldsCollection = fieldAttributeCollection;
		}

		protected virtual void SendGeneralWebEvent(GeneralWebEvent.EventTypeEnum eventType)
		{
			// Has any objects registered interest with our event? 
			if (OnGeneralWebEvent != null)
			{
				GeneralWebEvent generalWebEvent = new GeneralWebEvent();
				generalWebEvent.EvenetType = eventType;
				// Yes, notify all the objects in the delegate linked list
				OnGeneralWebEvent(this, generalWebEvent);
			}
		}


		[NotifyParentProperty(true)]
		public bool AllowEdit
		{
			get
			{
				if (Attributes["AllowEdit"] == null)
				{
					if (EditMode == EditModeEnum.ALL || EditMode == EditModeEnum.UPDATE)
						return true;
					else
						return false;
				}
				return (Attributes["AllowEdit"] == "yes");
			}
			set { Attributes["AllowEdit"] = (value ? "yes" : "no"); }


		}

		[NotifyParentProperty(true)]
		public bool AllowDelete
		{
			get
			{
				if (Attributes["AllowDelete"] == null)
				{
					if (EditMode == EditModeEnum.ALL)
						return true;
					else
						return false;
				}
				return (Attributes["AllowDelete"] == "yes");
			}
			set { Attributes["AllowDelete"] = (value ? "yes" : "no"); }
		}

		public virtual void RecreateControls()
		{
			this.CreateChildControls();
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			CustomiseControlsAttributes();
		}

		public virtual void CustomiseControlsAttributes()
		{
			WebEnv.CustomiseControlsAttributes();
		}

		protected override void Render(HtmlTextWriter writer)
		{
			EnsureChildControls();
			//Recreate();
			writer.Write("<div class='WCCWraper'>");
			base.Render(writer);
			writer.Write("  <div style='clear: both;'></div>"); // to alow the container to have the size of all it's childs even float elements - good for border or background of the container
			writer.Write("</div>");
		}

		public string ElementTitle
		{
			get 
			{ 
				if (m_ElementTitle != null)
					return m_ElementTitle;
				if (ViewState["ElementTitle"] == null)
					return null;
				return (string)ViewState["ElementTitle"];
			}
			set
			{
				ViewState["ElementTitle"] = value;
			}
		}

		protected override void LoadViewState(object savedState)
		{
			base.LoadViewState(savedState);

			if (ViewState["UserEditMode"] != null)
			{
				m_UserEditMode = (EditModeEnum)ViewState["UserEditMode"];
			}
			if (this.Controls.Count == 0)
				Recreate();

		}

		public EditModeEnum EditMode
		{
			get
			{
				if (ViewState["EditMode"] == null)
				{
					if (!DesignMode && SessionManager.UserExist) // maybe session expired
					{
						if (SessionManager.UserExist  && SessionManager.User.Type == (short)UserTypeEnum.DEBUG)
							return EditModeEnum.ALL;
						else
							return EditModeEnum.ALL;
					}
					else
						return EditModeEnum.VIEW_ONLY;

				}
				return (EditModeEnum)ViewState["EditMode"];
			}
			set
			{
				if (EditMode != value)
				{
					ViewState["EditMode"] = value;
				}
			}
		}

		[Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
		public EditModeEnum UserEditMode
		{
			get
			{
				if (m_UserEditMode != 0)
					return m_UserEditMode;

				if (ViewState["UserEditMode"] != null)
				{
					return (EditModeEnum)ViewState["UserEditMode"];
				}
				return 0;
			}
			set
			{
				ViewState["UserEditMode"] = value;
				m_UserEditMode = value;
			}
		}


		public virtual void CustomToolbarItemControl_Click(object sender)
		{
			(this.Page as NorthwindPage).OnCustomToolbarItemControlClicked(sender, this as NorthwindWCC);
		}

		virtual protected void AddInformationMessage(string informationMessage)
		{
			ToolBar.AddInformationMessage(informationMessage);
		}

		virtual protected void SetInformationMessage(string informationMessage)
		{
			ToolBar.SetInformationMessage(informationMessage);
		}

		virtual protected void AddErrorMessage(string errorMessage)
		{
			ToolBar.AddErrorMessage(errorMessage);
		}

		virtual protected void SetErrorMessage(string errorMessage)
		{
			ToolBar.SetErrorMessage(errorMessage);
		}

		virtual public void ClearAllMessages()
		{
			ToolBar.ClearAllMessages();
		}

		protected bool IsEventWasFired(string eventname)
		{
			if (eventsFired == null)
				return false;
			if (eventsFired[eventname] != null)
				return true;
			else
				return false;
		}

		protected void EventWasFired(string eventname)
		{
			if (eventsFired == null)
				eventsFired = new Hashtable();
			eventsFired[eventname] = "1";
		}
		protected override void OnDataBinding(EventArgs e)
		{
			Recreate();
			base.OnDataBinding(e);
		}

        public virtual void UpdateToolbarAttributes(CToolbarAttributeCollection toolbarAttributeCollection)
        {
            (this.Page as NorthwindPage).UpdateToolbarAttributes((this as NorthwindWCC), toolbarAttributeCollection);
        }

	}
}




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