using System;
using System.Collections;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace Telerik.Web.Examples.Controls.Integration.DragDropTab
{
    public partial class DefaultCS : System.Web.UI.Page
	{
		
		protected System.Web.UI.WebControls.Panel panelLoadingImage;
		
		private ArrayList GridData
		{
			get 
			{
				return (ArrayList)ViewState["GridDataArray"];
			}
			set
			{
				ViewState["GridDataArray"] = value;
			}
		}
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				RadTreeView1.LoadContentFile("RadTreeView.xml");
				RadTreeView2.LoadContentFile("SourceSafe.xml");
				GridData = new ArrayList();
				GridData.Add("App_Themes");
				GridData.Add("bin");
				GridData.Add("RadControls");
				DataGrid1.DataSource = GridData;
				DataGrid1.DataBind();
			}
		}

		protected void SendEmail_Click(object sender, System.EventArgs e)
		{
			TextBoxTo.Text = String.Empty;
			TextBoxCc.Text = String.Empty;
			TextBoxSubject.Text = String.Empty;
			Attachments.Text = String.Empty;
		}

        protected void RadAjaxManager1_AjaxRequest(object sender, Web.UI.AjaxRequestEventArgs e)
		{
			string [] args = e.Argument.Split('?')[1].Split('!');
			RadTreeNode sourceNode = null, destNode = null;
			if (args.Length>0)
				sourceNode = RadTreeView1.FindNodeByText(args[0]);
			else
				return;
			
			switch (e.Argument.Split('?')[0])
			{
				case "Page1":
					Attachments.Text += sourceNode.Text + "<br />";
					break;
				case "Page2":
					if (args.Length>1)
					{
						destNode = RadTreeView2.FindNodeByText(args[1]);
                        if (!Object.Equals(destNode, null))
						{
                            RadTreeNode newNode = new RadTreeNode(sourceNode.Text);
							newNode.ImageUrl = "Images/SSFolder.gif";
							destNode.Nodes.Add(newNode);
							destNode.Expanded = true;
						}
					}
					else
					{
                        RadTreeNode newNode = new RadTreeNode(sourceNode.Text);
						newNode.ImageUrl = "Images/SSFolder.gif";
						RadTreeView2.Nodes[0].Nodes.Add(newNode);
					}
					break;
				case "Page3":
					GridData.Add(sourceNode.Text);
					DataGrid1.DataSource = GridData;
					DataGrid1.DataBind();
					break;
				default:
					break;
			}
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    
			this.Load += new System.EventHandler(this.Page_Load);
		}
		#endregion
	}
}
