using aspPDF;
using System;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Xml.Xsl;
using Microsoft.Win32;
using Microsoft.Web.UI.WebControls;


// Code done by David Schusterman

namespace reportrx
{
	/// <summary>
	/// Summary description for SaveReport.
	/// Save the incoming URl to a PDF file and give the filename used to the controlPlaceHolder.
	/// </summary>
	public class SaveReport : System.Web.UI.Page
	{
		#region Protected Variables
		protected System.Web.UI.WebControls.PlaceHolder controlPlaceHolder;
		#endregion

		#region Private Variables
		private string strConnection;
		#endregion

		#region Constructor, Load, and Init 
		public SaveReport()
		{
			try
			{
				// need to read this from the registry
				RegistryKey key = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Avalon Vision Solutions\\ProcessRx\\7.0\\EventLog");
				strConnection = key.GetValue("ConnectionString").ToString();				
			}
			catch(Exception err)
			{
				err.ToString();
			}
			Page.Init += new System.EventHandler(Page_Init);
		}

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			// Get the query string and parse it into name/value pairs
			NameValueCollection InParams = Request.QueryString;
			
			// Get the input parameters		
			/*
			Response.Write(Request.QueryString + " :Querystring<br>");
			foreach (string key in InParams) 
			{
				Response.Write(key + " : " + InParams[key] + "<br>");
			}
			*/
			string nodetype= InParams.Get("nodetype");
			string levelClause= InParams.Get("levelclause");
			string grain= InParams.Get("grain");
			string txtStartDate= InParams.Get("start");
			string txtEndDate= InParams.Get("end");
			string report= InParams.Get("report");
			string inputpage = "http://localhost/ProcessRx/reportrx/printreport.aspx?start="+txtStartDate+"&end="+txtEndDate+"&grain="+grain+"&report="+report+"&levelClause="+levelClause+"&nodetype="+nodetype;

			aspPDF.EASYPDF pdf = new aspPDF.EASYPDF();
			pdf.Create();
			pdf.AddHTML(inputpage);
			pdf.Save(Server.MapPath("test.pdf"));

			controlPlaceHolder.Controls.Add(new LiteralControl("<a href=\"" + inputpage + "\">link to saved page<br>"));
		}

		private void Page_Init(object sender, EventArgs e)
		{
			// The DataGrid relies on view state info for paging. If I setup the
			// columns after the call to Page_Init the view state info is not
			// included. That is why there are two data grids, one for Usage and 
			// RunState Events with AutoGenerateColumns=true and one for Cycle 
			// Events with AutoGenerateColums=false.
			//
			// This method sets up the columns for the data grid that displays the 
			// cycle events. I manually setup the columns so I can add a hyperlink
			// to the event details page.

			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();			
		}


		#endregion

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