<%@ Page Language="vb" AutoEventWireup="false" Codebehind="ProjectSample.aspx.vb" Inherits="TestProjectVB.ProjectSample"%>
<!DOCTYPE HTML PUBLIC "-'W3C'DTD HTML 4.0 Transitional'EN" >
<html>
	<head>
		<title>WebForm1</title>
		<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
		<meta name="CODE_LANGUAGE" Content="C#">
		<meta name="vs_defaultClientScript" content="JavaScript">
		<meta name="vs_targetSchema" content="http:'schemas.microsoft.com/intellisense/ie5">
	</head>
	<body MS_POSITIONING="GridLayout">
<table>
<form name="selectForm" method="POST" action="ProjectSample.aspx">
<tr>
<td>
<!--select for create, remove, search-->
<select name="projectMethod">
<option value="create" <% 
						if create then
						Response.Write(" SELECTED ")
						end if
						%>>create</option>
<option value="remove" <% if remove then 
						Response.Write(" SELECTED ")
						end if
						%>>remove</option>
<option value="search" <% if search then
						Response.Write(" SELECTED ")
						end if
						%>>search</option>
</select>
<input type="submit" name="selectGo" value="go"/>

</td>
</tr>


<!--show a search box for search, and a box to box to enter the project id if remove-->
<% 
if  create then
  'if no name or description, show text boxes for name and description, and a submit button
  if name is nothing  or  description is nothing then
   'set default values
   if name is nothing then
      name = ""
   end if
   if description is nothing then
      description = ""
   end if      
    %>
	<tr>
	 <td>
	   Project Name:
	 </td>
	 <td>
	   <input type="text" name="name" value="<%=name%>"/>
	 </td>
	</tr>
	<tr>
	 <td>
	   Project Description:
	 </td>
	 <td>
	   <input type="text" name="description" value="<%=description%>"/>
	 </td>
	</tr>	
	<tr>
	 <td>
	   <input type="submit" name="createSubmit" value="submit"/>
	 </td>
	</tr>		
   <%
  else
  'create a project and print out the project id
		if name is nothing then
		   name = "ExampleProject"
		end if
		if description is nothing then
		   description = "ExampleProjectDescription"
		end if      
	    'create the project
		dim projectManager as Plumtree.Remote.PRC.Collaboration.Project.IProjectManager  = GetProjectManager(Request, Response)
		dim project as Plumtree.Remote.PRC.Collaboration.Project.IProject  = projectManager.CreateProject(name, description)

		'if you want to set additional properties, make sure that store() is called or the changes will not be persisted.
		'for example:
		
		'project.setStatus(ProjectStatus.NOT_STARTED)
		'project.setStartDate(new Date())
		'
		'call store before asking for the id. 
		project.Store()

		%>
		<tr>
			<td>
			<%
				Response.Write("ID of newly created project is " + Cstr(project.ID)) 
			%>
			</td>
		</tr>
        
  <%
  end if
end if
if remove then
	'if no project ID, add a text box for projectID, and a submit button
	if projectID = -1 then
      if strProjectID is nothing then
         strProjectID = ""
      end if   
		%>
		<tr>
			<td>
				Project ID:
			</td>
			<td>
				<input type="text" name="projectID" value="<%=strProjectID%>"/>
			</td>
		</tr>	
		<tr>
			<td>
				<input type="submit" name="removeSubmit" value="submit"/>
			</td>
		</tr>
		<%
		else
		'remove the project
		dim projectManager as Plumtree.Remote.PRC.Collaboration.Project.IProjectManager  = GetProjectManager(Request, Response)
		dim project as Plumtree.Remote.PRC.Collaboration.Project.IProject  = projectManager.GetProject(projectID)
		'squawk if the project could not be retrieved
		if project is  nothing then
			%>
			<tr>
				<td>
					<%Response.Write("Unable to retrieve project with ID of " + Cstr(projectID))%>
				</td>
			</tr>

			<%
		else
			'remove
			projectManager.RemoveProject(project) 
			%>
			<tr>
				<td>
					<%Response.Write("Project with id of " + Cstr(projectID) + " removed.") %>
				</td>
			</tr>

		<%
		end if
	end if
end if

if search then
   
    
	'if no search text, add a text box for search text, and a submit button
	if  searchText is nothing then
		%>
		<tr>
			<td>
				Search Text:
			</td>
			<td>
				<input type="text" name="searchText" />
			</td>
		</tr>	
		<tr>
			<td>
				<input type="submit" name="searchSubmit" value="submit"/>
			</td>
		</tr>
		<%
	else
		'perform the search
		dim  projectManager as Plumtree.Remote.PRC.Collaboration.Project.IProjectManager  = GetProjectManager(Request, Response) 
		dim projectFilter as Plumtree.Remote.PRC.Collaboration.Project.IProjectFilter  = projectManager.CreateProjectFilter() 

		'hard-code the max results to 10
		projectFilter.MaximumResults = 10 

		'set the query
		projectFilter.NameSearchText = searchText 

		'execute the search and print out the results
		dim projects() as Plumtree.Remote.PRC.Collaboration.Project.IProject  = projectManager.QueryProjects(projectFilter) 
		if  projects.Length > 0 then
			%>
			<tr>
				<td>
					Search Results
				</td>

			</tr>
			<tr>
				<td>
					Project Name
				</td>
				<td>
					Project ID
				</td>
			</tr>
			<%
			dim i as Integer
			for i = 0 to projects.Length -1
				dim project as Plumtree.Remote.PRC.Collaboration.Project.IProject  = projects(i) 
				%>
				<tr>
				<td>
			  	<%Response.Write(project.Name) %>
				</td>
				<td>
					<%Response.Write(Cstr(project.ID)) %>
				</td>
				</tr>
			<%	
			next
		else
			Response.Write("No projects found using search query of " + searchText) 
       end if
	end if

end if
%>
</form>
</table>
	</body>
</html>
