
<UserControl x:Class="StandaloneTableEditing.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:esri="http://schemas.esri.com/arcgis/client/2009" xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit" mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="400"> �??- note the SL toolkit package is used here �?� <Grid x:Name="LayoutRoot" Background="White"> <Grid x:Name="MyForm"> <Grid.RowDefinitions> <RowDefinition Height="40" ></RowDefinition> <RowDefinition></RowDefinition> </Grid.RowDefinitions> <TextBlock Text="Silverlight Standalone Table Editing" Margin="10" FontSize="14" > </TextBlock> <df:DataForm x:Name="myDataForm" AutoEdit="False" CommandButtonsVisibility="All" Grid.Row="1" Width="400" Height="300" Margin="10" HorizontalAlignment="Left" VerticalAlignment="Top" > </df:DataForm> </Grid> </Grid> </UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using System.ComponentModel;
//Check to aake sure the System.ComponentModel reference has been added
namespace StandaloneTableEditing
{
public partial class MainPage : UserControl
{
public string Owner { get; set; }
public int Value { get; set; }
public string Approved { get; set; }
public int Lastupdate { get; set; }
public Inspection inspection { get; set; }
public FeatureLayer featurelayer { get; set; }
public MainPage()
{
InitializeComponent();
InitializeFeatureService();
InitializeInspection();
myDataForm.CurrentItem = inspection; // Set up data form with data using the set Inspection Class below
}
private void InitializeInspection()
{
//Set up default values
inspection = new Inspection()
{
Owner = "David Hasselhoff ",
Value = 100,
Approved = "Bay Watch",
Lastupdate = 1111,
InspectionFeatureLayer = featurelayer
};
}
public void InitializeFeatureService()
{
featurelayer = new FeatureLayer();
featurelayer.Url = "http://serverbox/ArcGIS/rest/services/EditingTables/FeatureServer/1";
featurelayer.AutoSave = false;
featurelayer.Mode = FeatureLayer.QueryMode.OnDemand;
featurelayer.Initialized += Table_IsInitialized;
featurelayer.Initialize();
featurelayer.EndSaveEdits += Insert_EndSaveEdits;
featurelayer.SaveEditsFailed += Insert_SaveEditsFailed;
}
public void Table_IsInitialized(object sender, EventArgs e)
{
System.Diagnostics.Debug.WriteLine("it's initialized...");
}
public void Insert_SaveEditsFailed(object sender, EventArgs e)
{
string mes = e.ToString(); // For debugging
System.Diagnostics.Debug.WriteLine(mes);
}
public void Insert_EndSaveEdits(object sender, EventArgs e)
{
string mes = e.ToString(); // For debugging
System.Diagnostics.Debug.WriteLine(mes);
}
}
public class Inspection : IEditableObject
{
public string Owner { get; set; }
public int Value { get; set; }
public string Approved { get; set; }
public int Lastupdate { get; set; }
public Inspection TempInspection { get; set; }
public FeatureLayer InspectionFeatureLayer;
public void BeginEdit()
{
// Save current Values
TempInspection = new Inspection()
{
Owner = this.Owner,
Value = this.Value,
Approved = this.Approved,
Lastupdate = this.Lastupdate
};
}
public void CancelEdit()
{
// Reset Values
Owner = TempInspection.Owner;
Value = TempInspection.Value;
Approved = TempInspection.Approved;
Lastupdate = TempInspection.Lastupdate;
}
public void EndEdit()
{
ESRI.ArcGIS.Client.Graphic graphicAttribute = new ESRI.ArcGIS.Client.Graphic();
graphicAttribute.Attributes.Add("OWNER", this.Owner);
graphicAttribute.Attributes.Add("VALUE", this.Value);
graphicAttribute.Attributes.Add("APPROVED", this.Approved);
graphicAttribute.Attributes.Add("LASTUPDATE", this.Lastupdate);
InspectionFeatureLayer.Graphics.Add(graphicAttribute);
InspectionFeatureLayer.SaveEdits();
}
}
}
l.Initialized += new EventHandler<EventArgs>(l_Initialized);
}
void l_Initialized(object sender, EventArgs e)
{
var l = sender as FeatureLayer;
l.Update();
}
l.Initialized += (s, e) => { l.Update(); };
<UserControl x:Class="SilverlightApplication1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:esri="http://schemas.esri.com/arcgis/client/2009">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.Resources>
<esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" />
<esri:SimpleMarkerSymbol x:Key="BlackMarkerSymbol" Color="Black" Size="14" Style="Diamond" />
<esri:PictureMarkerSymbol x:Key="GlobePictureSymbol" OffsetX="8" OffsetY="8"
Source="/Assets/images/globe-16x16.png" />
<esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Green" Style="DashDot" Width="4" />
<esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="Green" BorderBrush="Blue"
BorderThickness="3" />
</Grid.Resources>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="5" />
<RowDefinition Height="150" />
</Grid.RowDefinitions>
<esri:Map x:Name="MyMap" WrapAround="True">
<esri:FeatureLayer ID="IncidentsLayer"
Url="http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
DisableClientCaching="True"
Mode="OnDemand"
AutoSave="True"
OnDemandCacheSize="0"
OutFields="*">
</esri:FeatureLayer>
<esri:GraphicsLayer ID="MySelectionGraphicsLayer"/>
</esri:Map>
<basics:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" />
<esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"
Map="{Binding ElementName=MyMap}"
GraphicsLayer="{Binding ElementName=MyMap, Path=Layers.[IncidentsLayer]}"/>
<Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,0" >
<Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
<Rectangle.Effect>
<DropShadowEffect/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
<!--<TextBlock x:Name="ResponseTextBlock" Text="Edit values in the data grid. When finished, click the Commit button to save to the database."
Width="200" TextAlignment="Left" Margin="30,20,20,30" TextWrapping="Wrap" />-->
</Grid>
<Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin=" 10,10,10,0">
<StackPanel Orientation="Horizontal" Margin="5,0,15,0" Canvas.Top="25" >
<TextBlock Text="US State Name contains:" Margin="10,0,0,0" VerticalAlignment="Center"/>
<TextBox x:Name="StateNameTextBox" Text="New" Height="23" HorizontalAlignment="Left" VerticalAlignment="Center" Width="125" TextWrapping="NoWrap"
Margin="10,0,10,0" FontSize="12" Background="White" AcceptsReturn="False" />
<Button Content="Do Query" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="QueryButton_Click" Margin="0,0,10,0" Cursor="Hand" />
<Button Content="Commit" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="Button_Click" Margin="0,0,10,0" Cursor="Hand" />
</StackPanel>
</Grid>
<Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,10,10,0" >
<Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" >
<Rectangle.Effect>
<DropShadowEffect/>
</Rectangle.Effect>
</Rectangle>
<Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" />
</Grid>
</Grid>
</UserControl>
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Symbols
Imports ESRI.ArcGIS.Client.Toolkit
Imports ESRI.ArcGIS.Client.Geometry
Partial Public Class MainPage
Inherits UserControl
Private Property featurelayer() As FeatureLayer
Get
Return m_featurelayer
End Get
Set(ByVal value As FeatureLayer)
m_featurelayer = value
End Set
End Property
Private m_featurelayer As FeatureLayer
Public Sub New()
InitializeComponent()
initializefeatureservice()
End Sub
Public Sub initializefeatureservice()
Dim featurelayer As New FeatureLayer()
featurelayer.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
featurelayer.AutoSave = True
featurelayer.Mode = featurelayer.QueryMode.OnDemand
featurelayer.Update()
featurelayer.Initialize()
End Sub
Private Sub LoadFeatureLayer()
Dim l As ESRI.ArcGIS.Client.FeatureLayer
l = New ESRI.ArcGIS.Client.FeatureLayer
l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
Dim s As String
s = StateNameTextBox.Text
l.Where = "REL_FACILITYID = '" & s & "'"
l.OutFields.Add("*")
l.AutoSave = False
AddHandler l.Initialized, AddressOf layerInit
l.Initialize()
End Sub
Private Sub layerInit(ByVal sender As Object, ByVal args As EventArgs)
'Load layer information class.
If (sender.GetType Is GetType(FeatureLayer)) Then
Dim Lay As FeatureLayer = CType(sender, FeatureLayer)
Lay.Update()
End If
End Sub
Private Sub QueryButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim queryTask As New QueryTask("http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1")
AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
AddHandler queryTask.Failed, AddressOf QueryTask_Failed
Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
'query.Text = StateNameTextBox.Text
query.ReturnGeometry = False
Dim s As String
s = StateNameTextBox.Text
'MessageBox.Show(s)
query.Where = "REL_FACILITYID = '" & s & "'"
' query.Where = StateNameTextBox.Text
query.OutFields.Add("*")
queryTask.ExecuteAsync(query)
End Sub
Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
Dim featureSet As FeatureSet = args.FeatureSet
featureSet.SpatialReference = MyMap.SpatialReference()
If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
MyDataGrid.ItemsSource = featureSet.Features
Else
MessageBox.Show("No features returned from query")
End If
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MySelectionGraphicsLayer"), GraphicsLayer)
graphicsLayer.ClearGraphics()
If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
For Each feature As Graphic In featureSet.Features
feature.Symbol = TryCast(LayoutRoot.Resources("RedMarkerSymbol"), SimpleMarkerSymbol)
graphicsLayer.Graphics.Add(feature)
Next feature
End If
Dim bind As System.Windows.Data.Binding = New System.Windows.Data.Binding()
bind.ElementName = "MyMap"
bind.Path = New PropertyPath("Layers.[MySelectionGraphicsLayer]")
MyDataGrid.SetBinding(FeatureDataGrid.GraphicsLayerProperty, bind)
MyDataGrid.UpdateLayout()
End Sub
Private Sub QueryTask_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs)
MessageBox.Show("Query execute error: " & args.Error.Message)
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)
m_featurelayer.Update()
End Sub
End Class<UserControl x:Class="SilverlightApplication1.MainPage" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:esri="http://schemas.esri.com/arcgis/client/2009"> <Grid x:Name="LayoutRoot" Background="White"> <Grid.Resources> <esri:SimpleMarkerSymbol x:Key="RedMarkerSymbol" Color="Red" Size="12" Style="Circle" /> <esri:SimpleMarkerSymbol x:Key="BlackMarkerSymbol" Color="Black" Size="14" Style="Diamond" /> <esri:PictureMarkerSymbol x:Key="GlobePictureSymbol" OffsetX="8" OffsetY="8" Source="/Assets/images/globe-16x16.png" /> <esri:SimpleLineSymbol x:Key="DefaultLineSymbol" Color="Green" Style="DashDot" Width="4" /> <esri:SimpleFillSymbol x:Key="DefaultFillSymbol" Fill="Green" BorderBrush="Blue" BorderThickness="3" /> </Grid.Resources> <Grid.RowDefinitions> <RowDefinition Height="*" /> <RowDefinition Height="5" /> <RowDefinition Height="150" /> </Grid.RowDefinitions> <basics:GridSplitter Grid.Row="1" HorizontalAlignment="Stretch" /> <esri:FeatureDataGrid Grid.Row="2" x:Name="MyDataGrid"/> <Grid HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,10,0" > <Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" > <Rectangle.Effect> <DropShadowEffect/> </Rectangle.Effect> </Rectangle> <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" /> <!--<TextBlock x:Name="ResponseTextBlock" Text="Edit values in the data grid. When finished, click the Commit button to save to the database." Width="200" TextAlignment="Left" Margin="30,20,20,30" TextWrapping="Wrap" />--> </Grid> <Grid HorizontalAlignment="Center" VerticalAlignment="Top" Margin=" 10,10,10,0"> <StackPanel Orientation="Horizontal" Margin="5,0,15,0" Canvas.Top="25" > <TextBlock Text="US State Name contains:" Margin="10,0,0,0" VerticalAlignment="Center"/> <TextBox x:Name="StateNameTextBox" Text="New" Height="23" HorizontalAlignment="Left" VerticalAlignment="Center" Width="125" TextWrapping="NoWrap" Margin="10,0,10,0" FontSize="12" Background="White" AcceptsReturn="False" /> <Button Content="Do Query" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="QueryButton_Click" Margin="0,0,10,0" Cursor="Hand" /> <!--><Button Content="Commit" Width="75" VerticalAlignment="Center" HorizontalAlignment="Right" Click="Button_Click" Margin="0,0,10,0" Cursor="Hand" />--> </StackPanel> </Grid> <Grid HorizontalAlignment="Right" VerticalAlignment="Top" Margin="10,10,10,0" > <Rectangle Fill="#77919191" Stroke="Gray" RadiusX="10" RadiusY="10" Margin="0,0,0,5" > <Rectangle.Effect> <DropShadowEffect/> </Rectangle.Effect> </Rectangle> <Rectangle Fill="#FFFFFFFF" Stroke="DarkGray" RadiusX="5" RadiusY="5" Margin="10,10,10,15" /> </Grid> </Grid> </UserControl>
Imports Microsoft.VisualBasic
Imports System.Collections.Generic
Imports System.Windows
Imports System.Windows.Controls
Imports ESRI.ArcGIS.Client
Imports ESRI.ArcGIS.Client.Tasks
Imports ESRI.ArcGIS.Client.Symbols
Imports ESRI.ArcGIS.Client.Toolkit
Imports ESRI.ArcGIS.Client.Geometry
Partial Public Class MainPage
Inherits UserControl
Public Sub New()
InitializeComponent()
End Sub
Private Sub QueryButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim queryTask As New QueryTask("http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1")
AddHandler queryTask.ExecuteCompleted, AddressOf QueryTask_ExecuteCompleted
AddHandler queryTask.Failed, AddressOf QueryTask_Failed
Dim query As New ESRI.ArcGIS.Client.Tasks.Query()
'query.Text = StateNameTextBox.Text
query.ReturnGeometry = False
Dim s As String
s = StateNameTextBox.Text
query.Where = "REL_FACILITYID = '" & s & "'"
query.OutFields.Add("*")
queryTask.ExecuteAsync(query)
End Sub
Private Sub QueryTask_ExecuteCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.QueryEventArgs)
Dim l As ESRI.ArcGIS.Client.FeatureLayer
l = New ESRI.ArcGIS.Client.FeatureLayer
l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
Dim s As String
s = StateNameTextBox.Text
l.Where = "REL_FACILITYID = '" & s & "'"
l.OutFields.Add("*")
l.AutoSave = False
AddHandler l.Initialized, AddressOf layerInit
l.Initialize()
l.ClearGraphics()
Dim featureSet As FeatureSet = args.FeatureSet
If featureSet IsNot Nothing AndAlso featureSet.Features.Count > 0 Then
For Each resultFeature As Graphic In featureSet.Features
l.Graphics.Add(resultFeature)
Next
MyDataGrid.GraphicsLayer = l
Else
MessageBox.Show("No features returned from query")
End If
End Sub
Private Sub LoadFeatureLayer()
Dim l As ESRI.ArcGIS.Client.FeatureLayer
l = New ESRI.ArcGIS.Client.FeatureLayer
l.Url = "http://mcesapp/ArcGIS/rest/services/EditRelTbl/FeatureServer/1"
l.AutoSave = False
Dim s As String
s = StateNameTextBox.Text
l.Where = "REL_FACILITYID = '" & s & "'"
l.OutFields.Add("*")
AddHandler l.Initialized, AddressOf layerInit
l.Initialize()
End Sub
Private Sub layerInit(ByVal sender As Object, ByVal args As EventArgs)
'Load layer information class.
If (sender.GetType Is GetType(FeatureLayer)) Then
Dim Lay As FeatureLayer = CType(sender, FeatureLayer)
Lay.Update()
End If
End Sub
Private Sub QueryTask_Failed(ByVal sender As Object, ByVal args As TaskFailedEventArgs)
MessageBox.Show("Query execute error: " & args.Error.Message)
End Sub
End Class