My DomainService_db_SINHVIEN.metadata.cs at Sever side
private SINHVIENMetadata()
{
}
public int ID { get; set; }
[CustomValidation(typeof(StudentValidation),"CheckMaSV")]
public string MASV { get; set; }
[Required(ErrorMessage="Please typing here")]
[CustomValidation(typeof(StudentValidation),"CheckTenSV")]
public string TENSV { get; set;
My StudentValidation.shared.cs at Server side
public static ValidationResult CheckMaSV(string description, ValidationContext context)
{
if (String.IsNullOrEmpty(description))
{
ValidationResult ErrorMasv = new ValidationResult("This need some infomation", new string[] { context.MemberName });
return ErrorMasv;
}
if (description == "SVxxx")
{
ValidationResult ErrorMasv = new ValidationResult("Masv can't be SVxxx", new string[] { context.MemberName });
return ErrorMasv;
}
return ValidationResult.Success;
}
public static ValidationResult CheckTenSV(string text, ValidationContext context)
{
if (text == "Tenxxx")
{
ValidationResult ErrorTenSV = new ValidationResult("TenSV can't be Tenxxx",new string[] { context.MemberName });
return ErrorTenSV;
}
return ValidationResult.Success;
}
I have Form InfoSINHVIEN at Client side:
DomainService_db_SINHVIEN _service = new DomainService_db_SINHVIEN();
public InfoSinhVien()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
LoadOperation<SINHVIEN> _SinhViens = _service.Load(_service.GetSINHVIENsQuery());
dG_InfoSV.ItemsSource = _SinhViens.Entities;
}
private void btn_Sua_Click(object sender, RoutedEventArgs e)
{
if (dG_InfoSV.SelectedItem != null)
{
Child_Nhap_SV chldWind = new Child_Nhap_SV();
((Grid)chldWind.FindName("LayoutRoot")).DataContext = dG_InfoSV.SelectedItem;
chldWind.Closed += new EventHandler(chldWind_Closed);
chldWind.Show();
}
else{
MessageBox.Show("Chose item to Update!!!");
}
}
public void chldWind_Closed(object sender, EventArgs e)
{
ChildWindow chldWind = (ChildWindow)sender;
if ((chldWind.DialogResult == true))
{
_service.SubmitChanges
(
result =>
{
MessageBox.Show("Update Successs!!!");
dG_InfoSV.ItemsSource = _service.SINHVIENs;
}, null
);
}
else
_service.RejectChanges();
}
XAML:
<Grid x:Name="LayoutRoot" removed="White">
<sdk:DataGrid AutoGenerateColumns="True" Height="145" HorizontalAlignment="Left" Margin="129,158,0,0" Name="dG_InfoSV" VerticalAlignment="Top" Width="706" />
<Button Content="Sửa" Height="23" HorizontalAlignment="Left" Margin="507,71,0,0" Name="btn_Sua" VerticalAlignment="Top" Width="75" Click="btn_Sua_Click" />
</Grid>
and last i have ChildForm
<Grid x:Name="LayoutRoot" Margin="2" BindingValidationError="LayoutRoot_BindingValidationError" >
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Button x:Name="CancelButton" Content="Cancel" Click="CancelButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,0,0" Grid.Row="1" />
<Button x:Name="OKButton" Content="OK" Click="OKButton_Click" Width="75" Height="23" HorizontalAlignment="Right" Margin="0,12,79,0" Grid.Row="1" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="46,40,0,0" Name="textBlock1" Text="Mã sinh viên:" VerticalAlignment="Top" />
<TextBlock Height="23" HorizontalAlignment="Left" Margin="50,91,0,0" Name="textBlock2" Text="Tên sinh viên:" VerticalAlignment="Top" />
<TextBox Text="{Binding MASV, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,ValidatesOnNotifyDataErrors=True}" Height="23" HorizontalAlignment="Left" Margin="135,36,0,0" Name="txt_MaSV" VerticalAlignment="Top" Width="120" />
<TextBox Text="{Binding TENSV, Mode=TwoWay,ValidatesOnDataErrors=True,ValidatesOnExceptions=True,ValidatesOnNotifyDataErrors=True}" Height="23" HorizontalAlignment="Left" Margin="135,87,0,0" Name="txt_TenSV" VerticalAlignment="Top" Width="120" />
<input:ValidationSummary Name="_ValidationSum" Margin="46,120,0,0" HorizontalAlignment="Left" Width="291" />
</Grid>
When i type something to test at ChildForm, ValidationError is shown at Textbox have Error. But i dont see where's my SummaryValidation. How can i do next? Hope all you help me!! Im new Silverlighter