Click here to Skip to main content
15,895,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
My DomainService_db_SINHVIEN.metadata.cs at Sever side
C#
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
C#
public static ValidationResult CheckMaSV(string description, ValidationContext context)
        {
            //Validation Logic 
            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 Validation Success if dont have error


            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:
C#
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());
            //Bind to dataGrid
            dG_InfoSV.ItemsSource = _SinhViens.Entities;
        }

        private void btn_Sua_Click(object sender, RoutedEventArgs e)
        {
            if (dG_InfoSV.SelectedItem != null)
            {
                //Creating a new object of Popup
                Child_Nhap_SV chldWind = new Child_Nhap_SV();
                //Getting the GridLayout Control of the popUp To Be Shown
                ((Grid)chldWind.FindName("LayoutRoot")).DataContext = dG_InfoSV.SelectedItem;
                //Add a Event Handaler Which will Execute the Submit The Changes  made to entity Assigned
                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:
XML
<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
XML
<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
Posted
Updated 17-Apr-13 17:58pm
v3

1 solution

Anyone help me!!! How can i do to show SummaryValidation???
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900