Skip Navigation Links.

Northwind\WebControls\DateAndTimeWCCBase.cs

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

namespace Northwind.WebControls
{
	/// <summary>
	/// Summary description for DateAndTimeWCC.
	/// </summary>
	[DefaultProperty("Value"),
	ToolboxData("<lt>{0}:DateAndTimeWCCBase runat=server><lt>/{0}:DateAndTimeWCCBase>")]
	public class DateAndTimeWCCBase : WebCustomControlWCC
	{
		public DateAndTimeWCCBase()
			: base()
		{
		}

		public DateAndTimeWCCBase(bool bShowTime)
			: base()
		{
			ShowTime = bShowTime;
		}

		public virtual string TimeTitle
		{
			get
			{
				if (this.ViewState["TimeTitle"] != null)
					return (string)this.ViewState["TimeTitle"];
				else
					return "Time"; 
			}

			set
			{
				this.ViewState["TimeTitle"] = value;
			}
		}

		public virtual bool ShowTime
		{
			get
			{
				if (this.ViewState["ShowTime"] != null)
					return (bool)this.ViewState["ShowTime"];
				else
					return true;
			}

			set
			{
				this.ViewState["ShowTime"] = value;
			}
		}

		public virtual bool ShowTimeAsDropDownLists
		{
			get
			{
				if (this.ViewState["ShowTimeAsDropDownLists"] != null)
					return (bool)this.ViewState["ShowTimeAsDropDownLists"];
				else
					return true;
			}

			set
			{
				this.ViewState["ShowTimeAsDropDownLists"] = value;
			}
		}

		protected override void CreateChildControls()
		{
			System.Web.UI.WebControls.TextBox dateText;
			System.Web.UI.WebControls.Label label;
			System.Web.UI.WebControls.TextBox timeText = null;

			System.Web.UI.HtmlControls.HtmlGenericControl spanControl = new System.Web.UI.HtmlControls.HtmlGenericControl("span");
			spanControl.Attributes["style"] = "display: inline-table;";
			this.Controls.Add(spanControl);

			dateText = new System.Web.UI.WebControls.TextBox();
			dateText.ID = "Date";
			int numPixels = NorthwindWebEnv.GetNumPixelsFromChars(10);
			dateText.Attributes["style"] = "width:" + numPixels + "px";
			dateText.CssClass = "TextBoxCss";
			spanControl.Controls.Add(dateText);

			if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
			{
				dateText.CssClass += " Disabled";
			}
			else
			{
				AjaxControlToolkit.CalendarExtender calebdarExtender = new AjaxControlToolkit.CalendarExtender();
				calebdarExtender.ID = "CalendatExtender";
				calebdarExtender.TargetControlID = dateText.ID;
				calebdarExtender.PopupPosition = AjaxControlToolkit.CalendarPosition.BottomLeft;
				calebdarExtender.Format = NorthwindGeneral.GetDateFormat();
				spanControl.Controls.Add(calebdarExtender);
			}
			if (ShowTime)
			{
				if (ShowTimeAsDropDownLists)
				{
					// hour drop down list
					DropDownList hoursDropDownList = new DropDownList();
					hoursDropDownList.ID = "HoursDDL";
					ListItem listItem = new ListItem();
					listItem.Value = "";
					listItem.Text = "";
					hoursDropDownList.Items.Add(listItem);

					for (int i = 1; i < 25; i++)
					{
						listItem = new ListItem();
						listItem.Value = i.ToString("00");
						listItem.Text = i.ToString("00");
						hoursDropDownList.Items.Add(listItem);
					}
					hoursDropDownList.CssClass = "HoursDropDownList";
					spanControl.Controls.Add(hoursDropDownList);

					// min drop down list
					DropDownList minutesDropDownList = new DropDownList();
					minutesDropDownList.ID = "MinutesDDL";
					listItem = new ListItem();
					listItem.Value = "";
					listItem.Text = "";
					minutesDropDownList.Items.Add(listItem);
					for (int i = 0; i < 61; i++)
					{
						listItem = new ListItem();
						listItem.Value = i.ToString("00");
						listItem.Text = i.ToString("00");
						minutesDropDownList.Items.Add(listItem);
					}
					minutesDropDownList.CssClass = "MinutesDropDownList";
					spanControl.Controls.Add(minutesDropDownList);
					CustomizeControls(hoursDropDownList, minutesDropDownList);
					if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
					{
						hoursDropDownList.Enabled = false;
						minutesDropDownList.Enabled = false;
					}

				}
				else
				{
					timeText = new System.Web.UI.WebControls.TextBox();
					timeText.ID = "Time";
					int timeNumPixels = NorthwindWebEnv.GetNumPixelsFromChars(8, false);
					timeText.Attributes["style"] = "width:" + timeNumPixels + "px";
					timeText.CssClass = "TextBoxCss TimeTextBox";
					spanControl.Controls.Add(timeText);
					CustomizeControls(dateText, timeText);
				}
			}

		}

		protected virtual void CustomizeControls(DropDownList hoursDropDownList, DropDownList minutesDropDownList)
		{
		}

		protected virtual void CustomizeControls(TextBox dateText, TextBox timeText)
		{
		}					 

		protected override string GetCurrentControlValue()
		{
			
			string currentCode = string.Empty;

			currentCode = DateControl.Text;
			if (ShowTime)
			{
				if (ShowTimeAsDropDownLists)
				{
					if (HoursDropDownList.SelectedValue != "" && MinutesDropDownList.SelectedValue != "")
					{
						currentCode += " " + HoursDropDownList.SelectedValue;
						currentCode += ":" + MinutesDropDownList.SelectedValue;
					}
					else
						currentCode += " 12:00"; ;

				}
				else
				{
					if (TimeControl.Text.Length > 0)
						currentCode += " " + TimeControl.Text;

				}
			}
			return currentCode;
		}

		protected override void SetCurrentControlValue(string value)
		{
			DateTime dateTime;

			if (value.Length > 0)
			{
				dateTime = NorthwindGeneral.ConvertToDateTime(value);
				char[] separators = { ' ' };
				string[] parts = value.Split(separators, 2);
				DateControl.Text = parts[0];
				if (ShowTimeAsDropDownLists)
				{
					if (dateTime.Hour > 0)
					{
						HoursDropDownList.SelectedValue = dateTime.Hour.ToString("00");
						MinutesDropDownList.SelectedValue = dateTime.Minute.ToString("00");
					}
					else
					{
						HoursDropDownList.SelectedValue = "";
						MinutesDropDownList.SelectedValue = "";
					}
					if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
					{
						if (dateTime.Hour == 12 && dateTime.Minute == 0)
						{
							HoursDropDownList.Visible = false;
							MinutesDropDownList.Visible = false;
						}
					}
				}
				else
				{
					TimeControl.Text = parts[1];
					if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
					{
						if (dateTime.Hour == 12 && dateTime.Minute == 0)
						{
							TimeControl.Visible = false;
						}
					}
				}
			}
			else
			{
				if (ShowTimeAsDropDownLists)
				{
					HoursDropDownList.SelectedValue = "";
					MinutesDropDownList.SelectedValue = "";
					if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
					{
						HoursDropDownList.Visible = false;
						MinutesDropDownList.Visible = false;
					}
				}
				else
				{
					DateControl.Text = "";
					TimeControl.Text = "";
					if (FieldShowMode == FieldShowModeEnum.SHOW_READ_ONLY)
					{
						TimeControl.Visible = false;
					}

				}
			}

		}

		public TextBox DateControl
		{
			get
			{
				EnsureChildControls();
				return (TextBox)this.FindControl("Date");
			}
		}

		public TextBox TimeControl
		{
			get
			{
				EnsureChildControls();
				return (TextBox)this.FindControl("Time");
			}
		}

		public DropDownList HoursDropDownList
		{
			get
			{
				EnsureChildControls();
				return (DropDownList)this.FindControl("HoursDDL");
			}
		}

		public DropDownList MinutesDropDownList
		{
			get
			{
				EnsureChildControls();
				return (DropDownList)this.FindControl("MinutesDDL");
			}
		}

		protected override HtmlTextWriterTag TagKey
		{
			get
			{
				return HtmlTextWriterTag.Div;
			}
		}

	}
}








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