Jackie I've created a monster......

something is wrong with the FeatureReader that is produced from the layer
.... i think?

It seems to be retrieveing all features from the featuresource .... the
layer has a filter assigned that grabs only some features from the
featuresource...
If you or anyone is able to have a looky it would be great ! requires
ajaxcontroltoolkit.
I can zip up the project if required and post it here.


Default.aspx
---------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="Searchtool_Default" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit"
TagPrefix="cc1" %>
<%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
  Namespace="System.Web.UI" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<head runat="server">
  <title>Untitled Page</title>
</head>
<body>
  <form id="form1" runat="server">
  <asp:ScriptManager ID="ScriptManager1" runat="server">
  </asp:ScriptManager>
  <div>
    <cc1:TabContainer ID="SearchContainer" runat="server" ActiveTabIndex="0"
>
      <cc1:TabPanel runat="server" HeaderText="TabPanel1" ID="TabPanel1"
Visible="False">
      </cc1:TabPanel>
    </cc1:TabContainer>
  </div>
  </form>
</body>
</html>

----------
Default.aspx.cs
----------
using System;
using System.Collections.Specialized;
using System.Text;
using System.Globalization;
using OSGeo.MapGuide;
using System.Web;
using System.Data;
using System.Collections;
using System.Web.UI.WebControls;
using System.Web.UI;
using AjaxControlToolkit;

public partial class Searchtool_Default : System.Web.UI.Page
{
  //for testing requires input from session
  //change these to a local map resource
  internal static String mapResLocation =
"Library://Production/PortBris/Maps/PortBris.MapDefinition";
  internal static String mapName = "PortBris";
  
  //define all selections for searches here
  //every search you generate requires a new
  //MGSelection to be defined here.
  internal static MgSelectionBase cadFeatures;
  internal static MgSelectionBase geoFeatures;

  //get selection ready for searching on
  protected MgSelectionBase createSelectionMaster(String[] Layers)
  {
   
MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "../webconfig.ini");
    MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
    MgSite site = new MgSite();
    //connect to site
    site.Open(userInfo);
    String sessionId = site.CreateSession();
    MgSiteConnection siteConnection = new MgSiteConnection();
    //open site connection
    siteConnection.Open(userInfo);
    MgResourceService ResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
    MgFeatureService FeatureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
    MgResourceIdentifier mgResourceID = new
MgResourceIdentifier(mapResLocation);
    //MgMapBase map = new MgMapBase();
    MgMap map = new MgMap(siteConnection);
    map.Create(ResourceService, mgResourceID, mapName);
    MgSelectionBase thisSel = new MgSelectionBase(map);
    foreach (String layer in Layers)
    {
      MgLayer cLayer = map.GetLayers().GetItem(layer) as MgLayer;
      MgFeatureReader cFeatReader = cLayer.SelectFeatures(null);
      thisSel.AddFeatures(cLayer as MgLayerBase, cFeatReader,0);
    }
    return thisSel;
  }
  
  //return an array
  protected String[] StringArray(String CommaSeperatedLayers)
  {
    return CommaSeperatedLayers.Split(",".ToCharArray());
  }
  //add a DDL search type to the TabContainer
  protected DropDownList addSearchDDL(Control controlToAddTo, String
searchDDLId, String labelText)
  {
    Label cLabel = new Label();
    cLabel.Text = labelText + ":";
    controlToAddTo.Controls.Add(new LiteralControl("<BR>"));
    controlToAddTo.Controls.Add(cLabel);

    DropDownList cDDL = new DropDownList();
    cDDL.ID = searchDDLId;
    controlToAddTo.Controls.Add(cDDL);
    controlToAddTo.Controls.Add(new LiteralControl("<BR>"));
    controlToAddTo.Controls.Add(new LiteralControl("<BR>"));
    ListSearchExtender cSrchExt = new ListSearchExtender();
    
    cSrchExt.TargetControlID = searchDDLId;
    cSrchExt.ID = searchDDLId + "SrchExt";
    cSrchExt.IsSorted = true;
    controlToAddTo.Controls.Add(cSrchExt);
    
    return cDDL;
  }
  //add a new Tab to the Ajax TabContainer
  //each tab is a different search type
  protected AjaxControlToolkit.TabPanel
AddTab(AjaxControlToolkit.TabContainer TabCont, String TabID, String Header)
  {
    AjaxControlToolkit.TabPanel newTab = new AjaxControlToolkit.TabPanel();
    newTab.ID = TabID;
    newTab.HeaderText = Header;
    TabCont.Tabs.Add(newTab);
    TabCont.TabIndex = 1;

    return newTab;
  }

  protected Panel addAdvancedSearch(Control controlToAddTo, String
searchName)
  {
    if (controlToAddTo.FindControl("advSrchPnl" + searchName) == null)
    {
      Panel advSearchPanel = new Panel();
      Panel advSearchPanelToggle = new Panel();
      advSearchPanel.ID = "advSrchPnl" + searchName;
      advSearchPanelToggle.ID = "advSrchPnlToggle" + searchName;

      Label advSearchPanelLbl = new Label();
      advSearchPanelLbl.Text = "Advanced Search";

      CollapsiblePanelExtender advSearchExt = new
CollapsiblePanelExtender();
      advSearchExt.TargetControlID = advSearchPanel.ID;
      advSearchExt.CollapseControlID = advSearchPanelToggle.ID;
      advSearchExt.ExpandControlID = advSearchPanelToggle.ID;
      advSearchExt.Collapsed = true;
      advSearchPanelToggle.Controls.Add(advSearchPanelLbl);
      controlToAddTo.Controls.Add(advSearchPanelToggle);
      controlToAddTo.Controls.Add(advSearchPanel);
      controlToAddTo.Controls.Add(advSearchExt);
      return advSearchPanel;
    }
    else
    {
      return controlToAddTo.FindControl("advSrchPnl" + searchName) as Panel;
    }
  }

  protected DataTable addToDT(DataTable DT, MgFeatureReader featReaderToAdd,
String propToAdd)
  {
    
    while (featReaderToAdd.ReadNext())
    {
      DataRow DR = DT.NewRow();
      if (featReaderToAdd.IsNull(propToAdd) == false)
      {
        DR[propToAdd] = featReaderToAdd.GetString(propToAdd);
        //Response.Write(propToAdd + " = " +
featReaderToAdd.GetString(propToAdd));
        DT.Rows.Add(DR);
      }
    }
    featReaderToAdd.Close();
    //DataTable DT2 = DT.DefaultView.ToTable(true, propToAdd);
    //DataView DV = new DataView(DT2);
    //DV.Sort = propToAdd;
    //DDLToAddTo.DataTextField = propToAdd;
    //DDLToAddTo.DataValueField = propToAdd;
    //DDLToAddTo.DataSource = DV;
    //DDLToAddTo.DataBind();
    return DT;
  }

  protected void createSearch(MgSelectionBase srchOnThisSel, String
srchName, String[] basicProps, String[] advProps, Control controlToAddTo)
  {
    foreach (MgLayerBase cLayer in srchOnThisSel.GetLayers())
    {
      MgFeatureReader featureReader = cLayer.SelectFeatures(null);
      MgClassDefinition cClassDef = featureReader.GetClassDefinition();
      
      //write out each Properties search Drop down List
      foreach (string basicProp in basicProps)
      {
        DataTable DT;
        //something here is grabbing all features from featuresource
        //i think ? it should only grab those in cLayer
        MgFeatureReader featReaderForDT = cLayer.SelectFeatures(null);
        if (controlToAddTo.FindControl(basicProp) == null)
        {
          //ToDo: add Property type selector...
          MgProperty cProp =
featureReader.GetClassDefinition().GetProperties().GetItem(basicProp);
          DropDownList cDDL = addSearchDDL(controlToAddTo, basicProp,
cProp.Name);
          DT = new DataTable();
          DT.Columns.Add(cProp.Name);
          DT = addToDT(DT,featReaderForDT,cProp.Name);
          DropDownList DDLToAddTo = controlToAddTo.FindControl(basicProp) as
DropDownList;
          DataTable DT2 = DT.DefaultView.ToTable(true, basicProp);
          DataView DV = new DataView(DT2);
          DV.Sort = basicProp;
          DDLToAddTo.DataTextField = basicProp;
          DDLToAddTo.DataValueField = basicProp;
          DDLToAddTo.DataSource = DV;
          DDLToAddTo.DataBind();
        }
        else
        {
          //ToDo: add Property type selector...
          DropDownList cDDL = controlToAddTo.FindControl(basicProp) as
DropDownList;
          Response.Write(cDDL.DataSource.GetType().ToString());
          DataView DV1 = cDDL.DataSource as DataView;
          DT = DV1.ToTable();
          DT = addToDT(DT, featReaderForDT, basicProp);
          DataTable DT2 = DT.DefaultView.ToTable(true, basicProp);
          DataView DV = new DataView(DT2);
          DV.Sort = basicProp;
          cDDL.DataTextField = basicProp;
          cDDL.DataValueField = basicProp;
          cDDL.DataSource = DV;
          cDDL.DataBind();

        }


      }
      //write advanced search options
      Panel cSearchPanel = addAdvancedSearch(controlToAddTo, srchName);
      //write other properties as advanced search options
      //Search through defined properties.
      foreach (string advProp in advProps)
      {
        if (cSearchPanel.FindControl(advProp) == null)
        {
          //ToDo: add Property type selector...
          MgProperty cProp =
featureReader.GetClassDefinition().GetProperties().GetItem(advProp);
          DropDownList cDDL = addSearchDDL(cSearchPanel, advProp,
cProp.Name);
        }
      }
    }

  }

  //ToDo: Add more searches

  protected void Page_Load(object sender, EventArgs e)
  {
   
MapGuideApi.MgInitializeWebTier(Request.ServerVariables["APPL_PHYSICAL_PATH"]
+ "../webconfig.ini");
    MgUserInformation userInfo = new MgUserInformation("Anonymous", "");
    MgSite site = new MgSite();
    //connect to site
    site.Open(userInfo);
    String sessionId = site.CreateSession();
    MgSiteConnection siteConnection = new MgSiteConnection();
    //open site connection
    siteConnection.Open(userInfo);
    MgResourceService ResourceService =
siteConnection.CreateService(MgServiceType.ResourceService) as
MgResourceService;
    MgFeatureService FeatureService =
siteConnection.CreateService(MgServiceType.FeatureService) as
MgFeatureService;
    MgResourceIdentifier mgResourceID = new
MgResourceIdentifier(mapResLocation);
    MgMap map = new MgMap(siteConnection);
    map.Create(ResourceService, mgResourceID, mapName);

    //customise these to produce a new tab for your search
    //add tab for cadastre search
    TabPanel cadSearch = AddTab(SearchContainer, "cadSearch", "Cadastre");
    cadFeatures = createSelectionMaster(StringArray("cadFREE,cadPPLE"));
    String[] cadBasicProps = StringArray("PRI_LOT,PRI_PLAN");
    String[] cadAdvProps =
StringArray("LAND_TYPE,UNIQUE_ID,WET_DRY,AREA,COUNTY,PARISH,STRATEGIC,FILE_NO,STATUS,TENURE_TYP");
    createSearch(cadFeatures, "cadastre", cadBasicProps, cadAdvProps,
cadSearch);

    //add tab for geotechnical search
    TabPanel geoSearch = AddTab(SearchContainer, "geotechBoreHole",
"Borehole");
    geoFeatures = createSelectionMaster(StringArray("geotechBorehole"));
    String[] geoBasicProps = StringArray("date,author");
    String[] geoAdvProps = StringArray("ID,plan");
    createSearch(geoFeatures, "cadastre", geoBasicProps, geoAdvProps,
geoSearch);


  }
}


-- 
View this message in context: 
http://n2.nabble.com/Trying-to-create-an-ajax-search-thingo-tp2729762p2738096.html
Sent from the MapGuide Users mailing list archive at Nabble.com.

_______________________________________________
mapguide-users mailing list
mapguide-users@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/mapguide-users

Reply via email to