How to do validation on both client and server side for a service which is a store procedure(return a complex type)

Posted by Tai on Stack Overflow See other posts from Stack Overflow or by Tai
Published on 2010-09-18T18:46:16Z Indexed on 2010/12/24 16:54 UTC
Read the original article Hit count: 388

Hi

I am doing Silverlight 4

In my database, I have a store procedure(having two parameters) which returns rows (with extra fields). So i have to make a complex type for those rows on my Models. And Making a service to call that function import store procedure.

The RIA will automatically create a matching Entity(to the complex type) and an operation for me.

However, I don't know how to validation the parameters of the operation on both client and server side. For example, the parameter must be an integer only (and greater than 10) or datetime only.

below is my xaml code. I am using DomainDataSource control and don't know how to validate the two field parameter.It has two TextBox to let the user types in the value of parameters. Plz help me, thank you

 <riaControls:DomainDataSource AutoLoad="False" d:DesignData="{d:DesignInstance my1:USPFinancialAccountHistory, CreateList=true}" Height="0" LoadedData="uSPFinancialAccountHistoryDomainDataSource_LoadedData" Name="uSPFinancialAccountHistoryDomainDataSource" QueryName="GetFinancialAccountHistoryQuery" Width="0" Margin="0,0,705,32">
        <riaControls:DomainDataSource.DomainContext>
            <my:USPFinancialAccountHistoryContext />
        </riaControls:DomainDataSource.DomainContext>
        <riaControls:DomainDataSource.QueryParameters>
            <riaControls:Parameter ParameterName="fiscalYear" Value="{Binding ElementName=fiscalYearTextBox, Path=Text}" />
            <riaControls:Parameter ParameterName="fiscalPeriod" Value="{Binding ElementName=fiscalPeriodTextBox, Path=Text}" />
        </riaControls:DomainDataSource.QueryParameters>
    </riaControls:DomainDataSource>
    <StackPanel Height="30" HorizontalAlignment="Left" Orientation="Horizontal" VerticalAlignment="Top">
        <sdk:Label Content="Fiscal Year:" Margin="3" VerticalAlignment="Center" />
        <TextBox Name="fiscalYearTextBox" Width="60" />
        <sdk:Label Content="Fiscal Period:" Margin="3" VerticalAlignment="Center" />
        <TextBox Name="fiscalPeriodTextBox" Width="60" />
        <Button Command="{Binding Path=LoadCommand, ElementName=uSPFinancialAccountHistoryDomainDataSource}" Content="Load" Margin="3" Name="uSPFinancialAccountHistoryDomainDataSourceLoadButton" />
    </StackPanel>
    <telerik:RadGridView ItemsSource="{Binding ElementName=uSPFinancialAccountHistoryDomainDataSource, Path=Data}" Name="uSPFinancialAccountHistoryRadGridView" Grid.Row="1" 
                         IsReadOnly="True"
                         DataLoadMode="Asynchronous"
                         AutoGenerateColumns="False"
                         ShowGroupPanel="False">
        <telerik:RadGridView.Columns>
            <telerik:GridViewDataColumn Header="Account Number" DataMemberBinding="{Binding AccountNumber}"/>
            <telerik:GridViewDataColumn Header="Department Number" DataMemberBinding="{Binding DepartmentNumber}"/>
            <telerik:GridViewDataColumn Header="Period code" DataMemberBinding="{Binding PeriodCode}" />
            <telerik:GridViewDataColumn Header="Total Debit" DataMemberBinding="{Binding TotalDebit}" DataFormatString="{}{0:C2}"/>
            <telerik:GridViewDataColumn Header="Total Credit" DataMemberBinding="{Binding TotalCredit}" DataFormatString="{}{0:C2}"/>
            <telerik:GridViewDataColumn Header="Period Total" DataMemberBinding="{Binding PeriodTotal}" DataFormatString="{}{0:C2}"/>
            <telerik:GridViewDataColumn Header="Year To Date" DataMemberBinding="{Binding YearToDate}" DataFormatString="{}{0:C2}"/>
        </telerik:RadGridView.Columns>
    </telerik:RadGridView>

© Stack Overflow or respective owner

Related posts about Silverlight

Related posts about silverlight-3.0