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 Microsoft.RFIDLab.EPCISDemo.VerisignEPCIS;

namespace Microsoft.RFIDLab.EPCISDemo
{
	/// <summary>
	/// Summary description for ShowCaseEPCISInformation.
	/// </summary>
	public class ViewCaseEPCISInformation : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
		protected System.Web.UI.WebControls.Label Label1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Request.QueryString["uri"] != null)
			{
				string caseEPCURI = Request.QueryString["uri"];
				Label1.Text = "Event List for EPC " + caseEPCURI + @" from <a href=""http://microsoft.verisignepctest.com/"">Microsoft EPC IS</a>";

				ObservationDataProfile wsObservationDataProfile = new ObservationDataProfile();
				UserTokenType objUserTokenType = new UserTokenType();
				objUserTokenType.UserName = System.Configuration.ConfigurationSettings.AppSettings["VerisignEPCISUserName"];
				objUserTokenType.Password = System.Configuration.ConfigurationSettings.AppSettings["VerisignEPCISPassword"];

				AuthInfoType objAuthInfoType = new AuthInfoType();
				objAuthInfoType.UserToken = objUserTokenType;				
				wsObservationDataProfile.AuthInfo = objAuthInfoType;
				
				getEventsByEPC objParam = new getEventsByEPC();
				IdentifierType objIdentifier = new IdentifierType();
				objIdentifier.Value = caseEPCURI;
				objParam.epc = objIdentifier;
				
				logEvent[] epcEvents1;
				epcEvents1 = wsObservationDataProfile.getEventsByEPC(objParam);

				
				DataTable EPCEventsList = new DataTable("EPCEventsList");
				EPCEventsList.Columns.Add("EPC");
				EPCEventsList.Columns.Add("GLN");
				EPCEventsList.Columns.Add("LocationDescription");
				EPCEventsList.Columns.Add("DateTime");

				foreach (logEvent objEvent in epcEvents1)
				{
					int counter=0;
					object[] rowData = new object[4];
					for (counter=0; counter<objEvent.observation.Tag.Length; counter++)
					{
						if (objEvent.observation.Tag[counter].ID.Value != null)
							rowData[0] = objEvent.observation.Tag[counter].ID.Value;
						else
							rowData[0] = "NA";

						if (objEvent.location.Value != null)
							rowData[1] = objEvent.location.Value;
						else
							rowData[1] = "NA";

						if (objEvent.observation.Command != null)
							rowData[2] = objEvent.observation.Command + " Warehouse";
						else
							rowData[2] = "NA";
					
						rowData[3] = objEvent.observation.DateTime ;
					
						EPCEventsList.Rows.Add(rowData);
					}
				}

				DataGrid1.DataSource = EPCEventsList;
				DataGrid1.DataBind();
			}
			
		}

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