//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using CommunityServer.Components;
using Telligent.Registration;

namespace CommunityServer.ControlPanel
{
	/// <summary>
	/// Summary description for _Default.
	/// </summary>
	public class _Default2 : System.Web.UI.Page
	{
		protected CommunityServer.Controls.MPContent DescriptionRegion;
		protected System.Web.UI.WebControls.TextBox LicenseText;
		protected System.Web.UI.WebControls.Button UpdateButton;
		protected CommunityServer.Controls.MPContent TaskRegion;
		protected CommunityServer.Controls.MPContainer MPContainer;
		protected System.Web.UI.WebControls.Label Status;
		protected CommunityServer.ControlPanel.Controls.PanelTabControl PanelTabControl1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
		}

		protected virtual void Authorize()
		{
			if(!CSContext.Current.IsAuthenticated)
				Response.Redirect(Globals.GetSiteUrls().Login);
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			this.Response.Cache.SetCacheability(HttpCacheability.NoCache);
			Authorize();	
			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.UpdateButton.Click += new System.EventHandler(this.UpdateButton_Click);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void UpdateButton_Click(object sender, System.EventArgs e)
		{
			try
			{
				Licensing.UpdateLicense(LicenseText.Text);
				Status.Text = "License has been added!";
				Status.ForeColor = Color.Green;
				LicenseText.Text = string.Empty;
			}
			catch(CSException ex)
			{
				Status.Text = "Exception occurred while processing:<br/>" + ex.ToString();
				Status.ForeColor = Color.Red;
			}
		}
	}
}
