Click here to Skip to main content
15,923,051 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to format a number with an implied decimal Pin
Steve Messer19-Jul-08 13:49
Steve Messer19-Jul-08 13:49 
AnswerRe: How to format a number with an implied decimal Pin
SilimSayo17-Jul-08 9:26
SilimSayo17-Jul-08 9:26 
GeneralRe: How to format a number with an implied decimal Pin
Steve Messer17-Jul-08 9:43
Steve Messer17-Jul-08 9:43 
GeneralRe: How to format a number with an implied decimal Pin
darkelv17-Jul-08 17:08
darkelv17-Jul-08 17:08 
GeneralRe: How to format a number with an implied decimal Pin
Steve Messer17-Jul-08 18:12
Steve Messer17-Jul-08 18:12 
GeneralRe: How to format a number with an implied decimal Pin
darkelv17-Jul-08 19:23
darkelv17-Jul-08 19:23 
GeneralRe: How to format a number with an implied decimal Pin
Steve Messer18-Jul-08 3:35
Steve Messer18-Jul-08 3:35 
QuestionDragging and dropping a TreeNode onto a ListBox Pin
Jordanwb17-Jul-08 8:29
Jordanwb17-Jul-08 8:29 
AnswerRe: Dragging and dropping a TreeNode onto a ListBox Pin
TheFM23417-Jul-08 8:45
TheFM23417-Jul-08 8:45 
GeneralRe: Dragging and dropping a TreeNode onto a ListBox Pin
Jordanwb17-Jul-08 9:18
Jordanwb17-Jul-08 9:18 
QuestionMail attachments Pin
damianrda17-Jul-08 8:05
damianrda17-Jul-08 8:05 
QuestionWMI Question Pin
#realJSOP17-Jul-08 6:11
professional#realJSOP17-Jul-08 6:11 
AnswerRe: WMI Question Pin
half-life17-Jul-08 6:21
half-life17-Jul-08 6:21 
AnswerRe: WMI Question Pin
Uros Calakovic17-Jul-08 6:35
Uros Calakovic17-Jul-08 6:35 
AnswerRe: WMI Question Pin
Luc Pattyn17-Jul-08 8:33
sitebuilderLuc Pattyn17-Jul-08 8:33 
GeneralRe: WMI Question Pin
#realJSOP17-Jul-08 8:53
professional#realJSOP17-Jul-08 8:53 
QuestionWhat does @ mean now? Pin
Dirso17-Jul-08 5:38
Dirso17-Jul-08 5:38 
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)

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.