using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
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;
using edu.jhu.Cas.Util;
using System.IO;

namespace edu.jhu.Cas {
	/// <summary>
	/// Summary description for DropTable.
	/// </summary>
	public class DropTable : System.Web.UI.Page {
        protected long wsid;
		protected System.Web.UI.WebControls.Button yesButton;
		protected System.Web.UI.WebControls.Button noButton;
		protected string tableName,procedureName,functionName,dummy;
		bool isview;
		
		private void Page_Load(object sender, System.EventArgs e) {
			bool loggedin;
			loggedin = Session["USER"] != null;
			 isview=Request.Params["isview"]!=null&&Request.Params["isview"].Length > 1;
			tableName = Request.Params["tableName"];
			procedureName = Request.Params["procedureName"];
			functionName = Request.Params["functionName"];
			dummy=tableName != null?tableName:procedureName != null?procedureName:functionName!= null?
			functionName:null;
						
			if (loggedin) 
				wsid = (long)Session["USER"];
			if(dummy== null )
				Response.Redirect("MyDB.aspx");
		}
		
		protected void Yes(object source, EventArgs E) {
			string lmessage = dummy+" was dropped.";
			try {
				MyDBJobs jobs = new MyDBJobs();
				if(tableName != null){
					if(isview) 
					{
						(new CasJobs()).SubmitShortJob(wsid,"drop view "+tableName,"MYDB",
							SYSTEM.TASKNAME+" DROP view",0);
					}
					else 
						jobs.DeleteTable(wsid,tableName);
				}else if(procedureName != null){
					(new CasJobs()).SubmitShortJob(wsid,"drop procedure "+procedureName,"MYDB",
						SYSTEM.TASKNAME+" DROP PROCEDURE",0);
				}else if(functionName != null){
					(new CasJobs()).SubmitShortJob(wsid,"drop function "+functionName,"MYDB",
						SYSTEM.TASKNAME+" DROP FUNCTION",0);
				}
			}catch(Exception e) {
				lmessage = e.ToString();
				lmessage = lmessage.Replace("\n"," ");
			}
			Response.Redirect("MyDB.aspx?lmessage="+lmessage);
		}
		
		protected void No(object source, EventArgs e) {
			Response.Redirect("MyDB.aspx");
		}
		#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
	}
}
