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 edu.jhu.Cas.Jobs;
namespace edu.jhu.QueryStats {
	/// <summary>
	/// Summary description for viewplan.
	/// </summary>
	public class ViewPlan: System.Web.UI.Page {
		public const string PLAN = "SESSION_QRY_PLAN";
		private void Page_Load(object sender, System.EventArgs e) {
			//string qry = Request.Params["sql"].Replace("P_L_U_S","+");
			string qry = Request.Params["sql"];
			long wsid = long.Parse(Request.Params["wsid"]);
			string target = Request.Params["target"];
			try{
				if(qry == null || qry == "") throw new Exception("Please enter a query first.");
				DataSet ds = (new CasJobs()).GetPlan(wsid,target,qry);
				PlanMaker pm = new PlanMaker(ds.Tables[1]);
				Session[PLAN] = pm;
				Response.Write(pm.GetHtml("viewimage.aspx",qry));
			}catch(Exception ee){
				Response.Redirect("../submitjob.aspx?lmessage=" + ee.Message.Replace("\n", "<br/>").Replace("\r"," "));
			}
		}
		#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
	}
}
