Click here to Skip to main content
15,899,475 members
Home / Discussions / C#
   

C#

 
AnswerRe: What does @ mean now? Pin
Luc Pattyn17-Jul-08 5:47
sitebuilderLuc Pattyn17-Jul-08 5:47 
AnswerRe: What does @ mean now? Pin
originSH17-Jul-08 5:47
originSH17-Jul-08 5:47 
GeneralRe: What does @ mean now? Pin
Luc Pattyn17-Jul-08 5:59
sitebuilderLuc Pattyn17-Jul-08 5:59 
GeneralRe: What does @ mean now? Pin
originSH17-Jul-08 6:14
originSH17-Jul-08 6:14 
GeneralRe: What does @ mean now? Pin
Luc Pattyn17-Jul-08 6:38
sitebuilderLuc Pattyn17-Jul-08 6:38 
AnswerRe: What does @ mean now? Pin
Dirso17-Jul-08 5:52
Dirso17-Jul-08 5:52 
AnswerRe: What does @ mean now? Pin
Giorgi Dalakishvili17-Jul-08 5:56
mentorGiorgi Dalakishvili17-Jul-08 5:56 
QuestionData Validation Question Pin
Harvey Saayman17-Jul-08 5:11
Harvey Saayman17-Jul-08 5:11 
Ive got a form that the user can enter information on, when clicking the "SAVE" button the general proccess is the following...

private void SaveData()
{
    if(dataIsValid())
    {
        //
        // Create db objects and insert into db
        //
    }
}


lets say the form has a TextBox and a ComboBox

the dataIsValid() method will look something like this

private bool dataIsValid()
{
    if (textBox1.Text = "")
    {
        MessageBox.Show("Please Enter A Name");
        textBox1.Focus();
        return false;
    }
    else if (comboBox1.SelectedValue == null)
    {
        MessageBox.Show("Please Select An Age Group");
        comboBox1.Focus();
        return false;
    }
return true;
}


The idea is to one by one check that the fields have data... But now lets add 3 maskedTextBoxes with mask "##:##" for a time span value. Now the data doesn't just have to be there, but valid as well.

the solution i came up with looks dodgy and can be a nightmare to maintain... its as follows

private bool dataIsValid()
{
    if (textBox1.Text = "")
    {
        MessageBox.Show("Please Enter A Name");
        textBox1.Focus();
        return false;
    }
    else if (comboBox1.SelectedValue == null)
    {
        MessageBox.Show("Please Select An Age Group");
        comboBox1.Focus();
        return false;
    }

    try
    {
        TimeSpan.Parse(maskedTextBox1.Text);
        
        try
        {
            TimeSpan.Parse(maskedTextBox2.Text);
            
            try
            {
                TimeSpan.Parse(maskedTextBox3.Text);
            }
            catch
            {
                MessageBox.Show("Please Enter A Duration");
                maskedTextBox3.Focus();
                return false;
            }
        }
        catch
        {
            MessageBox.Show("Please Enter A Duration");
            maskedTextBox2.Focus();
            return false;
        }
    }
    catch
    {
        MessageBox.Show("Please Enter A Duration");
        maskedTextBox1.Focus();
        return false;
    }
return true;
}


Does anyone have any better ideas cuz im all out? Cry | :((
Im sure there has to be a better way of doing this...

Thanx

Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL

you.suck = (you.passion != Programming)

AnswerRe: Data Validation Question Pin
half-life17-Jul-08 5:49
half-life17-Jul-08 5:49 
AnswerRe: Data Validation Question Pin
Alan Balkany17-Jul-08 7:35
Alan Balkany17-Jul-08 7:35 
AnswerRe: Data Validation Question Pin
Garrett Pauls17-Jul-08 7:42
Garrett Pauls17-Jul-08 7:42 
GeneralRe: Data Validation Question Pin
Harvey Saayman17-Jul-08 20:07
Harvey Saayman17-Jul-08 20:07 
AnswerRe: Data Validation Question Pin
Green Fuze18-Jul-08 2:33
Green Fuze18-Jul-08 2:33 
GeneralRe: Data Validation Question Pin
Harvey Saayman18-Jul-08 4:54
Harvey Saayman18-Jul-08 4:54 
Questioncreate your own version of arraylist in c#?? Pin
lolla200617-Jul-08 4:42
lolla200617-Jul-08 4:42 
AnswerRe: create your own version of arraylist in c#?? Pin
Christian Graus17-Jul-08 4:58
protectorChristian Graus17-Jul-08 4:58 
GeneralRe: create your own version of arraylist in c#?? Pin
lolla200617-Jul-08 9:39
lolla200617-Jul-08 9:39 
GeneralRe: create your own version of arraylist in c#?? Pin
z3irr19-Jul-08 0:56
z3irr19-Jul-08 0:56 
AnswerRe: create your own version of arraylist in c#?? Pin
Dan Neely17-Jul-08 5:05
Dan Neely17-Jul-08 5:05 
AnswerRe: create your own version of arraylist in c#?? Pin
Dan Neely17-Jul-08 5:07
Dan Neely17-Jul-08 5:07 
JokeRe: create your own version of arraylist in c#?? Pin
Luc Pattyn17-Jul-08 6:02
sitebuilderLuc Pattyn17-Jul-08 6:02 
GeneralRe: create your own version of arraylist in c#?? Pin
Dan Neely17-Jul-08 6:48
Dan Neely17-Jul-08 6:48 
GeneralRe: create your own version of arraylist in c#?? Pin
DaveyM6917-Jul-08 10:04
professionalDaveyM6917-Jul-08 10:04 
GeneralRe: create your own version of arraylist in c#?? Pin
lolla200617-Jul-08 9:59
lolla200617-Jul-08 9:59 
GeneralRe: create your own version of arraylist in c#?? [modified] Pin
lolla200617-Jul-08 9:51
lolla200617-Jul-08 9:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.