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 ViewContainmentEPCISDetails.
	/// </summary>
	public class ViewContainmentEPCISDetails : System.Web.UI.Page
	{
		protected System.Web.UI.WebControls.Label Label1;
		protected System.Web.UI.WebControls.DataGrid DataGrid1;
	
		private void Page_Load(object sender, System.EventArgs e)
		{
			if (Request.QueryString["uri"] != null)
			{
				string palletEPCURI = Request.QueryString["uri"];
				Label1.Text = "Containment List for EPC " + palletEPCURI + @" from <a href=""http://microsoft.verisignepctest.com/"">Microsoft EPC IS</a>";

				ContainmentProfileService wsContainmentProfileService = new ContainmentProfileService();
				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;				
				wsContainmentProfileService.AuthInfo = objAuthInfoType;
				
				EPCIn objEPCIn = new EPCIn();
				objEPCIn.epc = palletEPCURI;
				objEPCIn.time = System.DateTime.Now;

				string[] casesEPCList = wsContainmentProfileService.getContents(objEPCIn);				
				
				DataTable EPCContainerList = new DataTable("EPCContainerList");
				EPCContainerList.Columns.Add("CaseEPC");
				
				foreach (string objCaseEPC in casesEPCList)
				{					
					object[] rowData = new object[1];
					
					if (objCaseEPC != null)
						rowData[0] = objCaseEPC;
					else
						rowData[0] = "NA";
						
					EPCContainerList.Rows.Add(rowData);
				}

				DataGrid1.DataSource = EPCContainerList;
				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
	}
}
