Autor Beitrag
Talemantros
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Fr 28.11.14 18:22 
Hallo zusammen,
ich würde gern eine Modellklasse validieren.

Zur Zeit

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
        public bool IsValid
        {
            get
            {
                return !string.IsNullOrWhiteSpace(CompanyName) &&
                        !string.IsNullOrWhiteSpace(InvoiceName) &&
                        !string.IsNullOrWhiteSpace(Charge) &&
                        !string.IsNullOrWhiteSpace(Street) &&
                        !string.IsNullOrWhiteSpace(Postale) &&
                        !string.IsNullOrWhiteSpace(City) &&
                        DocumentPath.HasValue;
            }
        }


Ich würde gern noch hinzufügen, dass Charge genau 3 Zeichen haben muss.

Geht dies, oder soll ich das lieber über die TextChange der TextBox erledigen?

Danke

Gruß
Daniel
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4701
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Fr 28.11.14 18:47 
Kannst du da einfach erledigen. In der UI solltest du das nur machen wenn du direktes Feedback (während der Eingabe) zum User brauchst. Und dann zusätzlich zum Test in der Modelklasse und nicht anstatt.

Auf die Länge solltest du nach dem bereits vorhanden Test auf IsNull machen um nicht nochmal auf Null prüfen zu müssen.
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 29.11.14 00:06 
Hi
danke Ralf.
Wärst du so nett mir noch aufzuführen wie ich das in die Modellklasse einbinde mit welchen Befehl?

Danke

Gruß
Daniel
Th69
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Moderator
Beiträge: 4764
Erhaltene Danke: 1052

Win10
C#, C++ (VS 2017/19/22)
BeitragVerfasst: Sa 29.11.14 10:06 
Das solltest du aber jetzt selber hinbekommen :gruebel:
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 29.11.14 16:13 
Würde ja nicht fragen, wenn ich es wissen würde.
string.textlenght oder so habe ich nicht gefunden
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4701
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Sa 29.11.14 16:20 
Talemantros Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 444
Erhaltene Danke: 2

Win7 Proff 64bit
C# (VS2013)
BeitragVerfasst: Sa 29.11.14 17:09 
Argh

Mich nerven diese Kleinigkeiten :-(

Vielen Dank
Palladin007
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1282
Erhaltene Danke: 182

Windows 11 x64 Pro
C# (Visual Studio Preview)
BeitragVerfasst: So 30.11.14 11:53 
Talemantros, da gibt es einen ganz einfachen Trick: bit.ly/1uYMFno

Das funktioniert fast immer ;)