<%	EntityDefinition currentEntity = (EntityDefinition)_activeObject;
	bool generateGuiControls = currentEntity.OutputSettingValues.GetRealBoolSettingValue("GenerateGuiControls", _executingGenerator.ProjectDefinition);
	if (!generateGuiControls)
		return; // DO NOT GENERATE

	Project currentProject = _executingGenerator.ProjectDefinition;
	bool isProfileEntity = SDE_GeneralUtils.IsProfileEntity(_executingGenerator, currentEntity);
	var pkFields = SDE_GeneralUtils.GetIdentifyingFields(currentEntity);

	// get the gui information for this entity
	XElement entityGuiInfo = SDE_GeneralUtilsGuiFiles.GetGuiInfoAsXElement(currentProject, currentEntity.Name);
	string entityLabel = string.Format("<{1}$ Resources:Entities, {0} {1}>", currentEntity.Name, '%');
	if (string.IsNullOrEmpty(entityLabel)) entityLabel = currentEntity.Name;

%><%%@ Control Language="C#" AutoEventWireup="True" Codebehind="Search<%=currentEntity.Name%>.ascx.cs" Inherits="Controls_Search<%=currentEntity.Name%>" %%>
<asp:Panel id="panSingleInstance" runat="server" visible="true">
<%
	bool emitPkSearchButton = true;
	if(!pkFields.Any())
	{
%>	<div class="formHelp">
			<hr />
			<asp:Localize runat="server" Text="<%%$ Resources:Global, SearchPkUndefined %%>" /><br/><br/>
		</div>
<table class="searchSingleForm" title="Campos de busqueda de <%=entityLabel%>">
<%		emitPkSearchButton = false;
	}
	else
	{
%>	<div class="formHelp">
			<b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchPkHeader %%>" /></b><br/><br/>
			<br/><br/>
		</div>
<table class="searchSingleForm">
<%		foreach(FieldElement field in pkFields)
		{
			bool vAlignLabel = false;
			string tagString = SDE_GeneralUtils.ProduceEditControlTagForField(field, false, false, "PkSearchValidation", false, false, out vAlignLabel);
%>	<tr>
		<td>&nbsp;</td>
		<td class="searchTableLabel"<% if(vAlignLabel) {%> style="vertical-align:text-top;" <% } %>>
			<asp:Localize runat="server" Text="<%=SDE_GeneralUtils.GetFieldLabel(currentProject, field)%>" />:
		</td>
		<td>
			<%=tagString%>
		</td>
		<td style="width:20px; white-space:nowrap;">&nbsp;</td>
	</tr>
<%		}
	}
%>	<tr>
		<td colspan="2" style="white-space:nowrap;">&nbsp;</td>
		<td>
			<br/>
<%	if(emitPkSearchButton)
	{
%>			<asp:Button ID="btnSearchPk" runat="server" CausesValidation="True" ValidationGroup="PkSearchValidation"
				Text="<%%$ Resources:Global, SearchBtn %%>" SkinId="ButtonSkin" OnClick="btnSearchPk_Click"/>
			&nbsp;&nbsp;&nbsp;
<%	}
%>			<asp:Button ID="btnCancelSearchPK" runat="server" Text="Volver" SkinId="ButtonSkin" OnClick="btnCancel_Click" CausesValidation="false"/>
			<br/><br/>
		</td>
		<td style="width:20px; white-space:nowrap;">&nbsp;</td>
	</tr>
<%
	// Search by Unique Constraints. Create the btnSearch_ucName and related form fields
	// Search the entities hierarchy upwards starting by the currentEntity type
	EntityDefinition rootEntity = currentEntity;
	do
	{
		UniqueConstraintList allUCs =rootEntity.UniqueConstraints;
		if(allUCs.Any())
		{
			// UC's defined. For each UC defined, emit a section to search on that UC.
			foreach(var ucSet in allUCs)
			{
%>
	<tr>
		<td colspan="4">
			<hr />
			<b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchUcHeader %%>" /></b><br/><br/>
		</td>
	</tr>
<%			string ucName = ucSet.Name.Replace(" ", "_");
			foreach(var field in ucSet)
			{
				bool vAlignLabel = false;
				string tagString = SDE_GeneralUtils.ProduceEditControlTagForField(field, false, false, ucName + "Validation", false, false, out vAlignLabel);
%>	<tr>
		<td style="width:20px; white-space:nowrap;">&nbsp;</td>
		<td class="searchTableLabel"<% if(vAlignLabel) {%> style="vertical-align:text-top;" <% } %>>
			<asp:Localize runat="server" Text="<%=SDE_GeneralUtils.GetFieldLabel(currentProject, field)%>" />:
		</td>
		<td>
			<%=tagString%>
		</td>
		<td style="width:20px; white-space:nowrap;">&nbsp;</td>
	</tr>
<%			}
%>	<tr>
		<td colspan="2" style="width:20px; white-space:nowrap;">&nbsp;</td>
		<td>
			<br />
			<asp:Button ID="btnSearch<%=ucName%>" runat="server" CausesValidation="True" ValidationGroup="<%=ucName + "Validation"%>" 
				Text="<%%$ Resources:Global, SearchBtn %%>" SkinId="ButtonSkin" OnClick="btnSearch<%=ucName%>_Click"/>
			&nbsp;&nbsp;&nbsp;
			<asp:Button ID="btnCancelSearch<%=ucName%>" runat="server" Text="<%%$ Resources:Global, Cancel %%>" SkinId="ButtonSkin" OnClick="btnCancel_Click" CausesValidation="false"/>
			<br /><br />
		</td>
		<td style="width:20px; white-space:nowrap;">&nbsp;</td>
	</tr>
<%			} // foreach
		}
		if (rootEntity.IsSubType)
		{
			rootEntity = rootEntity.GetSuperType();
		}
		else
		{
			break;
		}
	} // do
	while (true);


%>
</table>
</asp:Panel>
<asp:Panel id="panMultiInstance" runat="server" visible="true">
	<div class="formHelp">
		<b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchSubsetHelp1 %%>" /></b><br/>
		<asp:Localize runat="server" Text="<%%$ Resources:Global, SearchSubsetHelp2 %%>" />
		<br/><br/>
	</div>
<div class="searchSubSetForm">
  <table class="searchTable">
  <caption><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchCaption %%>" /> <asp:Localize runat="server" Text="<%=entityLabel%>" /></caption>
	<tr>
		<th class="chkEnableSearch">&nbsp;</th>
		<th><b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchFieldHeader %%>" /></b></th>
		<th><b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchNegateHeader %%>" /></b></th>
		<th><b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchOperatorHeader %%>" /></b></th>
		<th><b><asp:Localize runat="server" Text="<%%$ Resources:Global, SearchValueHeader %%>" /></b></th>
	</tr>
<%
		List<KeyValuePair<EntityDefinition, IFieldElementCore>> searchFields =
			SDE_GeneralUtils.GetEntitySearchFields(currentEntity, entityGuiInfo, _executingGenerator);

		// Print all the searchFields
		foreach (var f in searchFields)
		{
			EntityDefinition processEntity = f.Key;
			IFieldElementCore processField = f.Value;
			bool isProfileUserId = isProfileEntity && (processField.Name == SDE_GeneralUtils.PROFILE_USER_ID_FIELD);
			XElement processEntityGuiInfo = SDE_GeneralUtilsGuiFiles.GetGuiInfoAsXElement(currentProject, processEntity.Name);
			string fieldName = processField.Name;

			// Set the label to show (if not current entity, it will be "FieldLabel (EntityLabel)"
			bool fieldInCurrentEntity = (processEntity.Name == currentEntity.Name);
			string processFieldLabel = null;
			if (fieldInCurrentEntity)
			{
				processFieldLabel = SDE_GeneralUtils.GetFieldLabel(currentProject, processField);
			}
			else
			{
				processFieldLabel = String.Format("<{2}$ Resources:Entities, SRF_{0}_{1} {2}>", processEntity.Name, processField.Name, '%');
				fieldName += processEntity.Name;
			}

			// UseLookupDropDownList has been validated in SDE_GeneralUtils.ValidateEntitySettings
			bool useLookupDropDownList = isProfileUserId || processField.OutputSettingValues.GetRealBoolSettingValue("UseLookupDropDownList", currentProject);
			RelationshipInfo relationToUse = SDE_GeneralUtils.FindRelation(processEntity, processField, _executingGenerator);
%>	<asp:Panel ID="pan<%=fieldName%>" runat="server">
	<tr>
		<td class="chkEnableSearch"><asp:CheckBox ID="chkEnable<%=fieldName%>" runat="server" /></td>
		<td class="searchTableLabel">
			<asp:Localize runat="server" Text="<%=processFieldLabel%>" />:
		</td>
		<td>
			<asp:CheckBox ID="chkNot<%=fieldName%>" runat="server" />
		</td>
		<td>
<%			bool emitBetweenBoxes=false;
			string onSelectedIndexChanged = string.Empty;
			string toControlPrefix = "tbx";

			if (!useLookupDropDownList)
			{
				switch(Type.GetTypeCode(processField.FieldType.RepresentedType))
				{
					case TypeCode.DateTime:
						toControlPrefix = "dtx";
						emitBetweenBoxes = true;
						break;
					case TypeCode.Byte:
					case TypeCode.Int16:
					case TypeCode.Int32:
					case TypeCode.Int64:
					case TypeCode.Decimal:
					case TypeCode.Double:
					case TypeCode.Single:
						emitBetweenBoxes = true;
						break;
				}
				if (emitBetweenBoxes)
				{
					onSelectedIndexChanged = string.Format("OnSelectedIndexChanged=\"op{0}_IndexChanged\" AutoPostBack=\"true\"", fieldName);
				}
			}
%>			<asp:DropDownList ID="op<%=fieldName%>" runat="server" <%=onSelectedIndexChanged%>>
				<asp:ListItem Value="0" Selected="True" Text="<%%$ Resources:Global, SearchOpEqual %%>"/>
<%
			if (!useLookupDropDownList)
			{
				if (emitBetweenBoxes)
				{
%>				<asp:ListItem Value="1" Text="<%%$ Resources:Global, SearchOpGreater %%>"/>
				<asp:ListItem Value="2" Text="<%%$ Resources:Global, SearchOpGreaterOrEqual %%>"/>
				<asp:ListItem Value="3" Text="<%%$ Resources:Global, SearchOpLesser %%>"/>
				<asp:ListItem Value="4" Text="<%%$ Resources:Global, SearchOpLesserOrEqual %%>"/>
				<asp:ListItem Value="5" Text="<%%$ Resources:Global, SearchOpBetween %%>"/>
<%				}

				if(processField.IsOptional)
				{
%>				<asp:ListItem Value="6" Text="<%%$ Resources:Global, SearchOpNull %%>"/>
<%				}
				if(processField.FieldType.RepresentedType == typeof(string))
				{
%>				<asp:ListItem Value="7" Text="<%%$ Resources:Global, SearchOpLike %%>"/>
<%				}
			}
%>			</asp:DropDownList>
		</td>
		<td>
<%			if (isProfileUserId)
			{
%>				<gui:_UserDropDown ID="cbx<%=fieldName%>" runat="server" DropdownMode="Search"
						SelectedValue='<%%# Bind("<%=fieldName%>") %%>' >
				</gui:_UserDropDown>			
<%			}
			else if (useLookupDropDownList)
			{
				string relatedEntityName = relationToUse.RelatedEntity.Name;
				string fieldIsOptionalTag = (processField.IsOptional) ? "IsOptional=\"True\" " : string.Empty;

%>			<gui:<%=relatedEntityName%>DropDown ID="cbx<%=fieldName%>" runat="server" DropdownMode="Search" <%=fieldIsOptionalTag%>>
<%				if(processField.IsOptional)
				{
%>				<asp:ListItem Text="<%%$ Resources:Global, SelectOptionalDdlValue %%>" Value="" Enabled="true"/><%
				}%>
			</gui:<%=relatedEntityName%>DropDown>
<%			}
			else
			{
				bool vAlignLabel = false;
				string tagStringFrom = SDE_GeneralUtils.ProduceEditControlTagForField(processField, false, false, "SubSetSearchValidation", false, false, "valMi", "MiFrom", false, false, 25, out vAlignLabel);
%>			<%=tagStringFrom%><%
				if(emitBetweenBoxes)
				{
			string tagStringTo = SDE_GeneralUtils.ProduceEditControlTagForField(processField, false, false, "SubSetSearchValidation", false, false, "valMi", "MiTo", false, false, 25, out vAlignLabel);
%>			<span ID="pan<%=toControlPrefix%><%=fieldName%>MiTo" Visible="false" runat="server">
				<asp:Localize runat="server" Text="<%%$ Resources:Global, And %%>" /> <%=tagStringTo%>
			</span>
<%				}
			}
%>		</td>
	</tr>
	</asp:Panel>
<%
		} // foreach searchFields

%>	<tr id="trPreviousBucket" runat="server" visible="false">
		<td class="chkEnableSearch"><asp:CheckBox ID="chkEnablePreviousBucket" runat="server" Checked="true" /></td>
		<td class="searchTableLabel" colspan="4">
			<asp:Localize runat="server" Text="<%%$ Resources:Global, SearchPreviousFilter %%>" /> (<asp:Label ID="lbPreviousBucketEntityName" runat="server" Text="" />)
		</td>
	</tr>
	<tr>
		<td colspan="2">&nbsp;</td>
		<td colspan="3">
			<br/>
			<asp:Button ID="btnSearchSubSet" runat="server" CausesValidation="True" ValidationGroup="SubSetSearchValidation" Text="<%%$ Resources:Global, SearchBtn %%>" SkinId="ButtonSkin" OnClick="btnSearchSubSet_Click"/>
			&nbsp;&nbsp;&nbsp;
			<asp:Button ID="btnCancelSearchSubSet" runat="server" Text="<%%$ Resources:Global, Cancel %%>" SkinId="ButtonSkin" OnClick="btnCancel_Click" CausesValidation="false"/>
			<br/><br/>
		</td>
	</tr>
</table>
</div>
</asp:Panel>
