CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2009
    Posts
    12

    validate between time start and time end

    I have this class and I need to add an alert in case inspStartTime.TimeID is greater than inspEndTime.TimeID

    Each value represents a time e.g. 16:30 if inspStartTime.TimeID = 16:30 and inspEndTime.TimeID = 15.30 then throw exception.

    Code:
             private bool EnumVisual(Visual myVisual)
            {
                 InspectionTime inspStartTime;
                 InspectionTime inspEndTime;
                 
                for (int i = 0; i < VisualTreeHelper.GetChildrenCount(myVisual); i++)
                {
                    // Retrieve child visual at specified index value.
                    Visual childVisual = (Visual)VisualTreeHelper.GetChild(myVisual, i);
    
    
                    // Do processing of the child visual object.
                    if (childVisual is TextBox)
                    {
                        MaskedTextBox btn = (MaskedTextBox)childVisual;
                        //Check first to see if the element is null
                        if (btn.Tag != null)
                        {
                            //Check to see if it is the start time textbox i=on the screen
                            if (btn.Tag.ToString().ToLower()=="starttime")
                            {
                                //Fillthe inspection time data
                                inspStartTime = new InspectionTime();
                                inspStartTime.TimeID = Convert.ToInt32(btn.Uid);
                                inspStartTime.StartTime = btn.Text;
    
                                //Check to see if it is a valid time
                                if (IsValidTime(btn.Text))
                                {
                                    //Update the starttime for the UID TimeID
                                    if (timeManager.UpdateStartTime(inspStartTime, timeManager.GetJobIDViaTimeID(inspStartTime.TimeID)))
                                    {
                                        saveedChanges = false;
                                        //Throw an exception to be handled
                                        throw new Exception("Invalid Time Entry");
                                    }
                                    else //If everything is ok make it so.
                                    {
                                        btn.Background = System.Windows.Media.Brushes.White;
                                        saveedChanges = true;
                                    }
                                }
                                else //The invalid time status entry
                                {
                                    btn.Background = System.Windows.Media.Brushes.Red ;
                                    saveedChanges =  false;
                                    //Throw an exception to be handled
                                    throw new Exception("Invalid Time Entry");
                                }
    
                            }
                            else if (btn.Tag.ToString().ToLower() == "endtime") //The textbox is the end time textbox
                            {
                                //Fillthe inspection time data
                                inspEndTime = new InspectionTime();
                                inspEndTime.TimeID = Convert.ToInt32(btn.Uid);
                                inspEndTime.EndTime  = btn.Text;
    
                                //Check to see if it is a valid time
                                if (IsValidTime(btn.Text))
                                {
                                    //Do the update in the Database
                                    if (timeManager.UpdateEndTime(inspEndTime, timeManager.GetJobIDViaTimeID(inspEndTime.TimeID)))
                                    {
                                        saveedChanges = false;
                                        //Throw an exception to be handled
                                        throw new Exception("Invalid Time Entry");
                                    }
                                    else
                                    {
                                        btn.Background = System.Windows.Media.Brushes.White;
                                        saveedChanges = true;
                                    }
                                }
                                else
                                {
                                    btn.Background = System.Windows.Media.Brushes.Red;
                                    saveedChanges = false;
                                    //Throw an exception to be handled
                                    throw new Exception("Invalid Time Entry");
                                }
                            }
    
                        }
                       
                    }
    
                    // Enumerate children of the child visual object.
                    EnumVisual(childVisual);
                }
    
                return saveedChanges;
    
            }

  2. #2
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815

    Re: validate between time start and time end

    Hm... And what exactly is your question?

  3. #3
    Join Date
    Apr 2009
    Posts
    12

    Re: validate between time start and time end

    Never mind I found the answer. Txs

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured