Skip Navigation Links.

Northwind\WebControls\FileBinaryWUCBase.cs

D:\Temp3\TestProjects\CSADO.Net\Northwind\WebControls\FileBinaryWUCBase.cs
/*
 * This file was generated by ProCG version 2.0
 *
 * File name:	Northwind\WebControls\FileBinaryWUCBase.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.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using Northwind.General;
using Northwind.Data;
using Northwind.WebControls;
using System.Web.UI.SilverlightControls;


namespace Northwind.WebControls
{
	[ToolboxData("<{0}:FileBinaryWUC runat=server></{0}:FileBinaryWUC>")]
	public class FileBinaryWUCBase : System.Web.UI.WebControls.CompositeControl
	{
		public FileBinaryWUCBase()
		{
		}

		public FileBinaryWUCBase(FileTypeEnum fileTypeEnum, FieldShowModeEnum showModeEnum)
		{
			FileType = fileTypeEnum;
			ShowMode = showModeEnum;
		}

		public FileTypeEnum FileType
		{
			get
			{
				FileTypeEnum fileType;
				if (ViewState["FileType"] == null)
				{
					fileType = FileTypeEnum.IMAGE;
					return fileType;
				}
				fileType = (FileTypeEnum)ViewState["FileType"];

				return (fileType);
			}

			set
			{
				ViewState["FileType"] = value;
			}
		}

		public FieldShowModeEnum ShowMode
		{
			get
			{
				if (ViewState["ShowMode"] == null)
				{
					ShowMode = FieldShowModeEnum.SHOW_NORMAL;
					return ShowMode;
				}
				FieldShowModeEnum showMode = (FieldShowModeEnum)ViewState["ShowMode"];

				return (showMode);
			}

			set
			{
				ViewState["ShowMode"] = value;
			}
		}

		public override ControlCollection Controls
		{
			get
			{
				EnsureChildControls();
				return base.Controls;
			}
		}

		public override Control FindControl(string id)
		{
			EnsureChildControls();
			return base.FindControl(id);
		}

		protected override void CreateChildControls()
		{
			switch (FileType)
			{
				case FileTypeEnum.IMAGE:
					CreateImageChildControls();
					break;

				case FileTypeEnum.AUDIO:
					CreateAudioChildControls();
					break;

				case FileTypeEnum.VIDEO:
					CreateVideoChildControls();
					break;
			}
		}

		protected virtual void CreateImageChildControls()
		{
			Controls.Clear();
			HtmlTableRow row;
			HtmlTableCell cell;
			HtmlGenericControl content;
			// create <table border=1>
			HtmlTable table = new HtmlTable();
			table.Border = 0;

			// create <tr> - first row
			row = new HtmlTableRow();
			table.Controls.Add(row);

			if (ShowMode == FieldShowModeEnum.SHOW_NORMAL)
			{

				// create <td>
				cell = new HtmlTableCell();
				Image image = new Image();
				image.ID = "Image";
				cell.Controls.Add(image);
				row.Controls.Add(cell);

				// create <td >
				cell = new HtmlTableCell();
				HtmlInputFile inputFile = new HtmlInputFile();
				inputFile.ID = "FileName";
				cell.Controls.Add(inputFile);
				row.Controls.Add(cell);

				// create <td >
				cell = new HtmlTableCell();
				Button uploadButton = new Button();
				uploadButton.ID = "Upload";
				uploadButton.Text = "Upload";
				uploadButton.Click += new EventHandler(uploadButton_Click);
				cell.Controls.Add(uploadButton);
				row.Controls.Add(cell);
			}
			else
			{
				// create <td>
				cell = new HtmlTableCell();
				Image image = new Image();
				image.ID = "Image";
				cell.Controls.Add(image);
				row.Controls.Add(cell);
			}

			this.Controls.Add(table);
		}

		protected virtual void CreateAudioChildControls()
		{
			Controls.Clear();
			HtmlTableRow row;
			HtmlTableCell cell;
			HtmlGenericControl content;
			// create <table border=1>
			HtmlTable table = new HtmlTable();
			table.Border = 0;

			// create <tr> - first row
			row = new HtmlTableRow();
			table.Controls.Add(row);

			if (ShowMode == FieldShowModeEnum.SHOW_NORMAL)
			{

				// create <td>
				cell = new HtmlTableCell();
				MediaPlayer mediaPlayer = new MediaPlayer();
				mediaPlayer.ID = "MediaPlayer";
				mediaPlayer.Width = 300;
				mediaPlayer.Height = 200;
				cell.Controls.Add(mediaPlayer);
				row.Controls.Add(cell);

				// create <td >
				cell = new HtmlTableCell();
				HtmlInputFile inputFile = new HtmlInputFile();
				inputFile.ID = "FileName";
				cell.Controls.Add(inputFile);
				row.Controls.Add(cell);

				// create <td >
				cell = new HtmlTableCell();
				Button uploadButton = new Button();
				uploadButton.ID = "Upload";
				uploadButton.Text = "Upload";
				uploadButton.Click += new EventHandler(uploadButton_Click);
				cell.Controls.Add(uploadButton);
				row.Controls.Add(cell);
			}
			else
			{
				// create <td>
				cell = new HtmlTableCell();
				MediaPlayer mediaPlayer = new MediaPlayer();
				mediaPlayer.ID = "MediaPlayer";
				mediaPlayer.Width = 300;
				mediaPlayer.Height = 200;
				cell.Controls.Add(mediaPlayer);
				row.Controls.Add(cell);
			}

			this.Controls.Add(table);
		}

		protected virtual void CreateVideoChildControls()
		{
			CreateAudioChildControls();
		}

		void uploadButton_Click(object sender, EventArgs e)
		{
			// Get a reference to PostedFile object
			HttpPostedFile myFile = this.FileName.PostedFile;

			// Get size of uploaded file

			int nFileLen = myFile.ContentLength;
			// Allocate a buffer for reading of the file

			byte[] myData = new byte[nFileLen];
			// Read uploaded file from the Stream
			//string strFilename = Path.GetFileName(myFile.FileName);

			myFile.InputStream.Read(myData, 0, nFileLen);

			System.Diagnostics.Debug.Assert(!FileID.Equals(string.Empty));
			this.Context.Session[FileID] = myData;

		}

		public string FileID
		{
			get
			{
				String s = (String)ViewState["FileID"];
				return ((s == null) ? String.Empty : s);
			}

			set
			{
				ViewState["FileID"] = value;
			}
		}

		protected override void OnPreRender(EventArgs e)
		{
			base.OnPreRender(e);
			if (!FileID.Equals(String.Empty))
			{
				switch (FileType)
				{
					case FileTypeEnum.IMAGE:
						ImageControl.ImageUrl = NorthwindGeneral.GetWebServerRootURL() + "ImageHandler.ashx?id=" + FileID;
						break;

					case FileTypeEnum.AUDIO:
						AudioControl.MediaSource = NorthwindGeneral.GetWebServerRootURL() + "ImageHandler.ashx?id=" + FileID;
						break;

					case FileTypeEnum.VIDEO:
						VideoControl.MediaSource = NorthwindGeneral.GetWebServerRootURL() + "ImageHandler.ashx?id=" + FileID;
						break;
				}

			}

		}

		public Image ImageControl
		{
			get
			{
				Image Image = (Image)this.FindControl("Image");
				System.Diagnostics.Debug.Assert(Image != null);
				return Image;
			}
		}

		public MediaPlayer AudioControl
		{
			get
			{
				MediaPlayer mediaPlayer = (MediaPlayer)this.FindControl("MediaPlayer");
				System.Diagnostics.Debug.Assert(mediaPlayer != null);
				return mediaPlayer;
			}
		}

		public MediaPlayer VideoControl
		{
			get
			{
				MediaPlayer mediaPlayer = (MediaPlayer)this.FindControl("MediaPlayer");
				System.Diagnostics.Debug.Assert(mediaPlayer != null);
				return mediaPlayer;
			}
		}

		protected HtmlInputFile FileName
		{
			get
			{
				HtmlInputFile fileName = (HtmlInputFile)this.FindControl("FileName");
				System.Diagnostics.Debug.Assert(fileName != null);
				return fileName;
			}
		}

	}
}


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