Problem with Date attribute field.

1852
9
02-15-2011 09:06 PM
by Anonymous User
Not applicable
Original User: sanjayjadhav

Hi,

I am facing weired problem when querying/identifying a map service layer that has Date field.

When feature is identified (using Identify Task), I get the results in FeatureDataGrid in same format as they are saved in SDE (without time stamp). However, when I spatially select the features from the same layer (using Query Task), I get time stamp (12:00 A.M.) in all values in FeatureDataGrid.

I have attached the screen shots for both of the task results along with this post.Please go through it.

Please have a look at "Lease Applied Date" field in Identify.jpg and LAD (same field) in query.jpg. I do not want to display this time stamp in result FeatureDataGrid.

Can anybody please help me on this issue?

-Sanjay.
0 Kudos
9 Replies
JMcNeil
Occasional Contributor III
Sanjayjadhav

hmmm....not sure the  Identify Task might have "built-in" formatting for date return results and maybe query doesn't or vise versa.  ESRI could shed some light on that. 

When you are asking for the fields back in your query are you stating

query.OutFields.Add("*");

Instead you could ask for each field back and maybe format it as/when you ask for it

query.OutFields.AddRange(new string[] { "Feild", "Feild2", "(To_Date("LAD", 'YYYY-MM-DD')", "Feild3", "Feild4", "Feild7" });


and when you ask for the LAD field or your other fields you would do something like this to convert the format

(To_Date(LAD, 'YYYY-MM-DD')

This probably won't work with my code because it will depend on your underlyinng database and I'm not 100% sure about this....just a suggestion.

J
0 Kudos
by Anonymous User
Not applicable
Original User: sanjayjadhav

J Lennon,

Thanks for the suggestion.But, I cannot hard-code any fields as I cannot know in advance which layer would be identified or queried by the user.

Also,I am curious, why it is happening? You might have noticed one more issue in this. When I was getting results back from Identify Task, the column headings were field aliases and in case of Query task, it was filed name. This is my concern.

Also, few days back, I noticed that using Identify Task, you would get actual domain values (if any set for that field).And for query task, you would get domain codes in the result. Weired, no?

These are the 3 issues I have noticed so far in case of Identify and query task.

Can anybody from ESRI shed some light on this please? These have become key issues for our apps development. I would really appreciate any comment.

-Sanjay.
0 Kudos
AliMirzabeigi
New Contributor
Sanjay,

How are you populating the items in your FeatureDataGrid in these scenarios? The reason I'm asking this is that both the IdentifyTask and QueryTask objects return FeatureSet as their completed event handler arguments and none of them have any information about the field/attribute collection that could be retreived from the service itself (i.e. data types, etc...). FeatureDataGrid gets this field information from its associated layer (GraphicsLayer property) and uses appropriate converters and editing cell templates correspondingly. This is the reason that we always suggest developers NOT to set FeatureDataGrid's ItemsSource property directly as it will be populated by the control automatically with regards to its GraphicsLayer property.
In addition, if you're adding features to a GraphicsLayer and using this layer as the source of your FeatureDataGrid then date fields format won't match the format in SDE because these layers do not have field/attribute information as opposed to feature layers.
It would be also good if you could share some code snippets or explain more how you are showing the results in FeatureDataGrid if the above comments have not addressed your concerns.
0 Kudos
by Anonymous User
Not applicable
Original User: sanjayjadhav

Ali,

Thanks for getting back to me.

I am populating the FDG as mentioned below:

1. Subscribe to completed event of concerned task.
2. Get the result from FeatureSet.
3. Get reference to the predefined graphics layer and add the result graphic object to it.
4. Set GraphicsLayer and Map property of the FDG.

So, you can notice that I am not dealing with ItemSource property and but setting GraphicsLayer property as ESRI suggests.

Please find the code for the IdentifyTask.

void identifyTask_ExecuteCompleted(object sender, IdentifyEventArgs args)
        {
            //if no results are returned from Identify task, exit.
            if (args.IdentifyResults.Count <= 0)
            {
                MessageWindow msgWin = new MessageWindow();
                msgWin.ErrMsg = commonConst.IDENTIFY_NO_RESULTS;
                msgWin.Show();
                return;               
            }

            //get result in identify result list array
            List<IdentifyResult> identifyResult = args.IdentifyResults;

            String layerName = identifyResult[0].LayerName.ToString();

            //graphic that would represent selected feature..
            Graphic graphic = null;

            //If geometry type of the first feature in the identifyresult is Polyline
            if (identifyResult[0].Feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
            {
                graphic = identifyResult[0].Feature;
                graphic.Symbol = currentApps.MapXaml.LayoutRoot.Resources["IdentifyLineSymbol"] as SimpleLineSymbol;
            }

            //If geometry type of the first feature in the identifyresult is Polygon
            if (identifyResult[0].Feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
            {
                graphic = identifyResult[0].Feature;
                graphic.Symbol = currentApps.MapXaml.LayoutRoot.Resources["IdentifyPolygonSymbol"] as SimpleFillSymbol;
            }

            //If geometry type of the first feature in the identifyresult is MapPoint
            if (identifyResult[0].Feature.Geometry is ESRI.ArcGIS.Client.Geometry.MapPoint)
            {
                graphic = identifyResult[0].Feature;
                graphic.Symbol = currentApps.MapXaml.LayoutRoot.Resources["IdentifyPointMarkerSymbol"] as PictureMarkerSymbol;
            }

            //add selected and hilighted Feature to its graphic layer.
            identifyResultGraphicsLayer.Graphics.Insert(0, graphic);

            //Make FeatureDatagrid visible
            if (identifyResultGraphicsLayer.Graphics.Count > 0)
            {
                //Set Relationship Count
                currentApps.RelationshipCount = sel_idntRelationshipCount;
                ResultFeatureDataGrd.Map = currentApps.MapXaml.MyMap;
                ResultFeatureDataGrd.GraphicsLayer = identifyResultGraphicsLayer;
                ResultDataGrdGlssPnl.Visibility = Visibility.Visible;
            }
            else
            {
                //If geometrty types other than point/line/polygon are returned, they cannot be shown.               
                if (ResultDataGrdGlssPnl.Visibility == Visibility.Visible)
                {
                    ResultDataGrdGlssPnl.Visibility = Visibility.Collapsed;
                    MessageWindow msgWin = new MessageWindow();
                    msgWin.ErrMsg = commonConst.ATTRIBUTE_SEARCH_RESULTS_UNHANDLE_GRAPHIC;
                    msgWin.Show();
                    return;                 
                }
            }
            identifyTask.ExecuteCompleted -= identifyTask_ExecuteCompleted;
        }

Code for QueryTask:

private void QueryTask_ExecuteCompleted(object sender, ESRI.ArcGIS.Client.Tasks.QueryEventArgs args)
        {
            try
            {
                if (args.FeatureSet == null)
                {
                    currentApps.progressBar.DialogResult = false;
                    return;
                }

                //get selected features in featureSet
                FeatureSet selectedFeatures = args.FeatureSet;

                //validate selected features
                if (selectedFeatures == null || selectedFeatures.Features.Count < 1)
                {
                    currentApps.progressBar.DialogResult = false;

                    //If no features found then celar all rectngle graphics
                    rectGraphicsLayer.ClearGraphics();

                    MessageWindow msgWin = new MessageWindow();
                    msgWin.ErrMsg = commonConst.SELECT_BY_RECT_NO_RESULTS;
                    msgWin.Show();
                    return;
                }

                if (selectedFeatures != null && selectedFeatures.Features.Count > 0)
                {
                    //loop thru each selected feature, check its geometry type and set its symbol accordingly.
                    foreach (Graphic feature in selectedFeatures.Features)
                    {
                        if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polygon)
                        {
                            feature.Symbol = currentApps.MapXaml.LayoutRoot.Resources["SelectByRectFillSymbol"] as FillSymbol;
                        }

                        else if (feature.Geometry is ESRI.ArcGIS.Client.Geometry.Polyline)
                        {
                            feature.Symbol = currentApps.MapXaml.LayoutRoot.Resources["SelectByRectLineSymbol"] as SimpleLineSymbol;
                        }
                        else
                        {
                            feature.Symbol = currentApps.MapXaml.LayoutRoot.Resources["SelectByRectMrkrSymbol"] as SimpleMarkerSymbol;
                        }

                        selectByRectResultsGraphicsLyr.Graphics.Add(feature);
                    }
                }

                //remove user drawn rectangle from the map
                rectGraphicsLayer.ClearGraphics();

                ResultDataGrdGlssPnl.Visibility = Visibility.Visible;
                ResultFeatureDataGrd.GraphicsLayer = null;
                ResultFeatureDataGrd.ItemsSource = null;

                // ResultDataGrdGlssPnl.IsOpen = true;
               ResultFeatureDataGrd.GraphicsLayer = selectByRectResultsGraphicsLyr;
                ResultFeatureDataGrd.Map = currentApps.MapXaml.MyMap;
                currentApps.RelationshipCount = sel_idntRelationshipCount;

            }
            catch (Exception ex)
            {
                currentApps.progressBar.DialogResult = false;
                MessageWindow msgWin = new MessageWindow();
                msgWin.ErrMsg = ex.Message;
                msgWin.Show();
            }
            currentApps.progressBar.DialogResult = false;
        }

If you need any additional information on this, please let me know.

Thanks and Regards,
Sanjay.
0 Kudos
AliMirzabeigi
New Contributor

3. Get reference to the predefined graphics layer and add the result graphic object to it.
4. Set GraphicsLayer and Map property of the FDG.


Like mentioned in my previous post:

In addition, if you're adding features to a GraphicsLayer and using this  layer as the source of your FeatureDataGrid then date fields format  won't match the format in SDE because these layers do not have  field/attribute information as opposed to feature layers.


Feature layers contain the LayerInfo.Fields object that the FeatureDataGrid control uses to populate its ItemsSource, i.e. some custom converters have been used for date fields, coded value domain fields, etc... Unfortunately, graphics layers do not have any information in regards to this and you have to write your own converters for your attributes.
0 Kudos
by Anonymous User
Not applicable
Original User: sanjayjadhav

Ali,

Thanks for the reply. I really appreciate your help on this issue.

Unfortunately, graphics layers do not have any information in regards to this and you have to write your own converters for your attributes.


But, since Graphic::Attributes returns read-only dictionary object, I would not be able to change any of the values from the result, right? Please correct me if I am wrong.

So, can you please tell me how should I proceed to manually convert the date field value or just lead me in the right direction to write the custom converter?

Thanks and regards,
Sanjay.
0 Kudos
JenniferNery
Esri Regular Contributor
I believe that Ali is saying use FeatureLayer to assign to FeatureDataGrid.GraphicsLayer property if you want to preserve field information, instead of performing a QueryTask and then putting results to a GraphicsLayer. You can still perform queries using FeatureLayer by updating Where clause.

You are correct that GraphicsLayer does not change the Attribute values but it also does not know how DateTime fields should be displayed, they are treated like System.DateTime objects which includes time information.
0 Kudos
by Anonymous User
Not applicable
Original User: ali5110

Sanjay,

If you need to use converters to show DateTime data types in your GraphicsLayer,
1. In your code, implement your date converter. A simple converter could be something like the following:
public class DateConverter : IValueConverter
{
 public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
  return System.Convert.ToDateTime(value, System.Globalization.CultureInfo.CurrentCulture).ToShortDateString();
 }
 public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
 {
  return System.Convert.ToDateTime(value, System.Globalization.CultureInfo.CurrentCulture);
 }
}

2. Define a XML namespace referencing your converter namespace. In this sample I have developed my converter in the same namespace:
xmlns:local="clr-namespace:MySilverlightApplication"

3. Add your converter to your resources:
<local:DateConverter x:Key="DateConverter" />

4. Set FeatureDataGrid AutoGenerateColumns property to FALSE and manually define its columns collection. In this example my GraphicsLayer has STRING_ATTRIBUTE and DATE_ATTRIBUTE attributes where the latter requires conversion for both showing and editing its contents (convert back):
<esri:FeatureDataGrid x:Name="MyDataGrid" AutoGenerateColumns="False" Map="{Binding ElementName=MyMap}" GraphicsLayer="{Binding Layers[MyGraphicsLayer], ElementName=MyMap}">
  <esri:FeatureDataGrid.Columns>
      <data:DataGridTextColumn Binding="{Binding STRING_ATTRIBUTE}" Header="String Attribute" />
      <data:DataGridTextColumn Binding="{Binding DATE_ATTRIBUTE, Converter={StaticResource DateConverter}}" Header="Date Attribute" />
  </esri:FeatureDataGrid.Columns>
</esri:FeatureDataGrid>

Where "data" refers to:
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"


Hope this helps.
0 Kudos
SanajyJadhav
Occasional Contributor II
Ali and Jenn,

Thanks for your continuous help on this issue.

I am gonna try Ali's sample code in my apps and see the result. I would put it here.

Thanks once again for the sample code.

-
Sanjay
0 Kudos