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;

namespace edu.jhu.Cas.Web
{
	/// <summary>
	/// Summary description for cancelJob.
	/// </summary>
	public class cancelJob : System.Web.UI.Page
	{
		protected long wsid = 1000001;
		protected long jobid = 0;
		protected string lmessage;

		private void Page_Load(object sender, System.EventArgs e)
		{
			WebUtils.CheckLoggedIn(Session,Response,Request);
			wsid = (long)Session["USER"];
			string sjobid = Request.Params["id"];
            try {
                if (null != sjobid && sjobid.Length > 0) jobid = Convert.ToInt64(sjobid);
            } catch (Exception ex) {
                lmessage = ex.Message;
            }
			string docancel = Request.Params["CancelJob"];
			if (null != docancel && docancel.Length > 0 ) 
			{// actually cancel the job
				if (jobid > 0) 
				{
					try 
					{
						edu.jhu.Cas.Jobs.CasJobs cj = new edu.jhu.Cas.Jobs.CasJobs();
						cj.CancelJob(wsid,jobid);
						Response.Redirect("ViewJobs.aspx?lmessage=Cancel initiated for job "+jobid+".");
					} 
					catch (Exception ex) 
					{
						lmessage = ex.Message;
					}
				} 
				else 
				{
					lmessage = "You must specify a Jobid ";
				}
			}

		}

		#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
	}
}
