Database Time Sheet

Introduction

 This exercise assumes that you have created the timesheet table that uses double shifts.

Setting Up the Database

Since we will be using a table that is located anywhere, you should know where the table used is located. Mine is located at C:\Program Files\Borland\Database Desktop\WorkDir folder

  1. Start Borland C++ Builder with the startup form.

  2. Change the caption of the form to Employees Time Sheet

  3. Set the BorderIcons: biMaximize to false.

  4. Change the name to frmTimeSheet

  5. On the Component Palette, click BDE

  6. Double-click Table

  7. While the newly added table is still selected, on the Object Inspector, click the Database Name field and fill its field value with the complete location of the database. For mine, I type:
    C:\Program Files\Borland\Database Desktop\WorkDir
     
    Setting the path for the database table

  8. If you are using Borland C++ Builder 6, notice that the table name in the Object TreeView window is specified with a question mark (?):
     
    The TreeView window when the table of the database is not yet specified
     
    In the Object Inspector, click the arrow of the Table Name field and select the table you will use. For this exercise, select the tblTimeSheet table.

  9. On the Object Inspector, click the arrow of the TableName field and select tblTimeSheet

  10. On the Component Palette, click the Data Access tab.

  11. Double-click DataSource

  12. On the Object Inspector, click the arrow of the DataSet field and select Table1.

  13. To save everything, on the Standard toolbar, click the Save All button.

  14. Click the Create New Folder button, type TimeSheet1 and press Enter twice. After a while, the new folder should be positioned in the Save In combo box.

  15. Change the name of the file to TimeSheet and click Save.

  16. Change the name of your project to DoubleShifts and click Save. 

 

Designing the Form

  1. On the Component Palette, click the Standard tab.
  2. Double-click the GroupBox control
  3. Change its caption to Time Sheet Identification and move it to the top left section of the form.
  4. Still on the Standard tab, click the Label control and click inside of the Time Sheet Identification group box on the form.
  5. Change its caption to Time Sheet ID:
  6. On the Standard tab again, click the GroupBox and click an empty area on the form.
  7. Change its caption to Shifts Values
  8. Press and hold Shift.
  9. On the Component Palette, click the Label control.
  10. Click on the lower group box on the form and type Monday:
  11. Click under Monday and type Tuesday:
  12. Add the following labels one under the previous one: Wednesday:, Thursday:, Friday:, Saturday:, Sunday:
  13. Click on the right side of Monday and type Time In
  14. Click on the right side of Time In and type Time Out
  15. Click on the right side of Time Out and type Time In
  16. Click on the right side of the previous Time In and type Time Out
  17. Click on the right side of the previous Time Out and type Total
  18. On the Component Palette, click the arrow button
     
  19. To save your project, on the Standard toolbar, click the Save All button
  20. On the Component Palette, click the Data Controls tab.
  21. Click DBEdit
  22. On the form, click on the right side of the Time Sheet ID label
  23. Change its name to edtTimeSheetID
  24. Change its DataSource property to DataSource1
  25. Change its DataField to TimeSheetID
  26. On the Data Controls tab of the Component Palette, click DBComboBox
  27. On the form, click on the right side of Monday and under Time In
  28. Set the DataSource property of the new combo box to DataSource1
  29. Set the DataField to MondayIn1
  30. Change the Name of the new combo box to cbxMondayIn1
  31. Set the Style to csOwnerDrawFixed
  32. Change the Width value of the new combo box to 75
  33. Click Items and click its ellipsis button to call the String List Editor
  34. On the String List Editor, type 00:00 AM and press Enter
  35. Complete the list as follows:
     
  36. Click OK
  37. Save your project.
  38. On the Component Palette, click the Standard tab.
  39. Click the Edit control and click under Total
  40. Change the content of the Text field to 0.00
  41. Change its name to edtMonday
  42. Set the ReadOnly property to true
  43. On the form, click the combo box to select it.
  44. Press Ctrl + C to copy the combo box.
  45. Press Ctrl + V to paste the control
  46. Change the name of the new combo box to cbxMondayOut1
  47. Move the selected combo box to the right of the first one.
  48. Press and hold Shift, then click the other combo box to select it.
  49. Press Ctrl + C and press Ctrl + V. Continue pressing Ctrl + V to complete the time sheet form as follows:
     
  50. Select each combo box and verify that its DataSource property is set to DataSource1.
  51. Make sure that the name of each combo box is appropriate to the corresponding day and shift.
  52. Save your project.
  53. On the Standard tab of the Component Palette, click the GroupBox control
  54. Click in the lower empty section of the form.
  55. On the Standard tab of the Component Palette, click the Label control.
  56. Click in the lower Group Box and change its Caption to Weekly Total:
  57. On the Standard tab, click the Edit control and click in the new GroupBox on the form.
  58. Change its Name to edtWeeklyTotal and its Text to 0.00
  59. On the Component Palette, click the Additional tab and click the BitBtn control.
  60. Click in the lower GroupBox
  61. Change the Kind property to bkOK
  62. Add another BitBtn control to the right of the OK button.
  63. Change its Kind property to bkNo
  64. Change its Name property to btnReset
  65. Change its Caption to &Reset
  66. On the Standard tab of the Component Palette, click the GroupBox control
  67. Click in the lower empty section of the form.
  68. On the Component Palette, click the Data Controls tab.
  69. Click the DBNavigator control and click in the lower empty GroupBox.
  70. Set its DataSource property to DataSource1
  71. On the Component Palette, click the Standard tab and click the Edit control
  72. Click an empty area in the lower GroupBox.
  73. Change its name to edtCurRecord and change its Text to Record 1 of 100
     
  74. Save your project.

 

 

Coding the Application

  1. Double-click the OK button to access its OnClick() event.

  2. Implement the event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::BitBtn1Click(TObject *Sender)
    {
        Close();
    }
    //---------------------------------------------------------------------------

  3. To bring back the form, press F12.

  4. Press Esc a few times to make sure that no control but the form itself is selected.

  5. On the Object Inspector, click the Events tab.

  6. Double-click the empty section on the right side of OnCreate to access the form's to access the form's OnCreate() event.

  7. To make the table available when the form comes up, implement the  event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::FormCreate(TObject *Sender)
    {
        Table1->Open();
    }
    //---------------------------------------------------------------------------

  8. We will use a control-independent function that can reset the values of the combo boxes.
    When a user needs to fill out the time sheet, we will set all times to 0, which would allow the user to proceed step-by-step in selecting the appropriate start and end sections of each shift.
    If the Class Explorer is not visible, on the main menu, click View ClassExplorer.
    On the Class Explorer, expand everything by clicking the + buttons if necessary.
    Right-click frmTimeSheet and click New Method...
  9. Set the Method Name to ResetShifts
  10. Set the Function Result to void
  11. Click the __fastcall check box and click OK.
  12. Implement the method as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::ResetShifts()
    {
        cbxMondayIn1->ItemIndex  = 24;
        cbxMondayOut1->ItemIndex = 24;
        cbxMondayIn2->ItemIndex  = 24;
        cbxMondayOut2->ItemIndex = 24;
    
        cbxTuesdayIn1->ItemIndex = 24;
        cbxTuesdayOut1->ItemIndex  = 24;
        cbxTuesdayIn2->ItemIndex  = 24;
        cbxTuesdayOut2->ItemIndex  = 24;
    
        cbxWednesdayIn1->ItemIndex  = 24;
        cbxWednesdayOut1->ItemIndex  = 24;
        cbxWednesdayIn2->ItemIndex  = 24;
        cbxWednesdayOut2->ItemIndex = 24;
    
        cbxThursdayIn1->ItemIndex = 24;
        cbxThursdayOut1->ItemIndex = 24;
        cbxThursdayIn2->ItemIndex = 24;
        cbxThursdayOut2->ItemIndex = 24;
    
        cbxFridayIn1->ItemIndex = 24;
        cbxFridayOut1->ItemIndex = 24;
        cbxFridayIn2->ItemIndex = 24;
        cbxFridayOut2->ItemIndex = 24;
    
        cbxSaturdayIn1->ItemIndex = 24;
        cbxSaturdayOut1->ItemIndex = 24;
        cbxSaturdayIn2->ItemIndex = 24;
        cbxSaturdayOut2->ItemIndex = 24;
    
        cbxSundayIn1->ItemIndex = 24;
        cbxSundayOut1->ItemIndex = 24;
        cbxSundayIn2->ItemIndex = 24;
        cbxSundayOut2->ItemIndex = 24;
    }
    //---------------------------------------------------------------------------
  13. To make the combo boxes display the reset time values, call the ResetShifts() method from the OnCreate event pf the form as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::FormCreate(TObject *Sender)
    {
        Table1->Open();
        ResetShifts();
    }
    //---------------------------------------------------------------------------
  14. Also call the ResetShifts() method from the btnResetShifts OnClick event. On the form, double-click the Reset button and implement its OnClick event as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::btnResetClick(TObject *Sender)
    {
        ResetShifts();
    }
    //---------------------------------------------------------------------------
  15. To test the form, press F9 and make sure that each combo box displays 12:00 PM
     
    Making sure that each combo box is reset
  16. The first thing we are going to do is to validate the time values that the user selects on a combo box, depending on the combo box. Consider a day like Monday. The starting time that the user selects should not be higher than the end time. This means that a user cannot state that he worked from 12PM to 9AM in one day. Logically, such a sequence doesn't make sense. Therefore, the first time in for Monday must not occur after the first time out for Monday.
    To implement this algorithm, on the form, double-click the combo box at the intersection of Monday and the left Time In label to access its OnChange event.
  17. Implement it as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayIn1Change(TObject *Sender)
    {
        // InSelection is the time that has just been selected
        int In1Selection = cbxMondayIn1->ItemIndex;
        // OutSelection is the time that is displaying the next combo box
        int Out1Selection = cbxMondayOut1->ItemIndex;
    
        // Whenever the user decides to change the time on this one,
        // make sure the new time doesn't occur after the next time value
        // If the user tries this, set the Monday 's first time in to value
        // of the next combo box
        if( Out1Selection < In1Selection )
            cbxMondayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
  18. When it comes to the first time out value, we need to fulfill two conditions: a)the value of the first time out must not be lower than that of the first time in; b) the value of the first time out must not be higher than that of the second time in.
    To implement this behavior, on the form, double-click the combo box at the intersection of Monday and the left Time Out label.

  19. Implement its OnChange() event as follows:
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayOut1Change(TObject *Sender)
    {
        // Get the selected value of the first Time In
        int In1Selection = cbxMondayIn1->ItemIndex;
        // Get the selected value of the first Time Out
        int Out1Selection = cbxMondayOut1->ItemIndex;
        // Get the selected value of the second Time In
        int In2Selection = cbxMondayIn2->ItemIndex;
    
        // Is the new value selected less than that of
        // the first Time In
        if( Out1Selection < In1Selection )
            cbxMondayOut1->ItemIndex = 24; // If so, set it to 12:00 PM
        // If the selected value happens to occur after the second Time In
        if( Out1Selection > In2Selection )
            cbxMondayOut1->ItemIndex = In2Selection; // Set it to that of Time In2
    }
    //---------------------------------------------------------------------------
  20. These two algorithms will be applied to all the other combo boxes. Therefore, implement their OnChange events accordingly. When you have finished, their should look as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayIn1Change(TObject *Sender)
    {
        // InSelection is the time that has just been selected
        int In1Selection = cbxMondayIn1->ItemIndex;
        // OutSelection is the time that is displaying the next combo box
        int Out1Selection = cbxMondayOut1->ItemIndex;
    
        // Whenever the user decides to change the time on this one,
        // make sure the new time doesn't occur after the next time value
        // If the user tries this, set the Monday 's first time in to value
        // of the next combo box
        if( Out1Selection < In1Selection )
            cbxMondayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayOut1Change(TObject *Sender)
    {
        // Get the selected value of the first Time In
        int In1Selection = cbxMondayIn1->ItemIndex;
        // Get the selected value of the first Time Out
        int Out1Selection = cbxMondayOut1->ItemIndex;
        // Get the selected value of the second Time In
        int In2Selection = cbxMondayIn2->ItemIndex;
    
        // Is the new value selected less than that of
        // the first Time In
        if( Out1Selection < In1Selection )
            cbxMondayOut1->ItemIndex = 24; // If so, set it to 12:00 PM
        // If the selected value happens to occur after the second Time In
        if( Out1Selection > In2Selection )
            cbxMondayOut1->ItemIndex = In2Selection; // Set it to that of Time In2
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxMondayIn2->ItemIndex;
        int Out1Selection = cbxMondayOut1->ItemIndex;
        int Out2Selection = cbxMondayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxMondayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxMondayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxMondayOut2->ItemIndex;
        int In2Selection  = cbxMondayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxMondayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxTuesdayIn1->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxTuesdayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxTuesdayIn1->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
        int In2Selection = cbxTuesdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxTuesdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxTuesdayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxTuesdayIn2->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
        int Out2Selection = cbxTuesdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxTuesdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxTuesdayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxTuesdayOut2->ItemIndex;
        int In2Selection  = cbxTuesdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxTuesdayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxWednesdayIn1->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxWednesdayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxWednesdayIn1->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
        int In2Selection = cbxWednesdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxWednesdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxWednesdayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxWednesdayIn2->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
        int Out2Selection = cbxWednesdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxWednesdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxWednesdayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxWednesdayOut2->ItemIndex;
        int In2Selection  = cbxWednesdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxWednesdayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxThursdayIn1->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxThursdayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxThursdayIn1->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
        int In2Selection = cbxThursdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxThursdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxThursdayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxThursdayIn2->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
        int Out2Selection = cbxThursdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxThursdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxThursdayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxThursdayOut2->ItemIndex;
        int In2Selection  = cbxThursdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxThursdayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxFridayIn1->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxFridayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxFridayIn1->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
        int In2Selection  = cbxFridayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxFridayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxFridayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxFridayIn2->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
        int Out2Selection = cbxFridayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxFridayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxFridayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxFridayOut2->ItemIndex;
        int In2Selection  = cbxFridayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxFridayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxSaturdayIn1->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSaturdayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxSaturdayIn1->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
        int In2Selection  = cbxSaturdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSaturdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxSaturdayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxSaturdayIn2->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
        int Out2Selection = cbxSaturdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxSaturdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxSaturdayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxSaturdayOut2->ItemIndex;
        int In2Selection  = cbxSaturdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxSaturdayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxSundayIn1->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSundayIn1->ItemIndex = Out1Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxSundayIn1->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
        int In2Selection  = cbxSundayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSundayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxSundayOut1->ItemIndex = In2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxSundayIn2->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
        int Out2Selection = cbxSundayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxSundayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxSundayIn2->ItemIndex = Out2Selection;
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxSundayOut2->ItemIndex;
        int In2Selection  = cbxSundayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxSundayOut2->ItemIndex = 34;
    }
    //---------------------------------------------------------------------------

  21. Now that we can control the sequence of the time values that the user can select, we can calculate the actual time frames.
     The time values of our time sheet are set as strings. We need a mechanism that can convert such a string to a double-precision number in order to involve such a time value into an arithmetic calculation. To do this, we will get the time value that a user has selected. We will pass that string to a method that would convert it to a double and return that number.
    On the Class Explorer, right-click the frmTimeSheet folder and click Add Method.
  22. Set the name Method Name to ConvertTimeToDouble
  23. In the Arguments edit box, type AnsiString Value
  24. Set the Function Result to double and click the __fastcall check box.
  25. Click OK and implement its method as follows:
     
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::ConvertTimeToDouble(AnsiString Value)
    {
        int     HPortion;   // Hour portion of the string as an integer
        double  MinPortion; // Minute portion of the string as a decimal value
    
        // Remove the empty space on the left of AM/PM
        Value = Value.Delete(6, 1);
    
        // Get the hour portion of the string
        AnsiString ValueHour = Value.SubString(1, 2);
        // Get the minute portion of the string
        AnsiString ValueMin  = Value.SubString(4, 2);
        // Get the AM/PM portion of the string
        AnsiString ValueAMPM = Value.SubString(6, 2);
    
        // Does the time occur in the afternoon?
        if( ValueAMPM == "PM" )
        {
            // Is it at noon = 12 PM?
            if( ValueHour == "12" )
                HPortion = ValueHour.ToInt(); // Convert it to a 12-hour integer
            else
                HPortion = 12 + ValueHour.ToInt(); // Convert it to a 24-hour integer
        }
        // Since the time occured in the morning
        else
            HPortion = ValueHour.ToInt();      // Convert it to a 12-hour integer
    
        // Does the time occur at the exact hour?
        if( ValueMin == "00" )
            MinPortion = 0.00;  // Set the minute to 0
        else // Otherwise
            MinPortion = 0.50;  // set it at half the hour
    
        // Now we have a complete floating number that represents the hour
        return HPortion + MinPortion;
    }
    //---------------------------------------------------------------------------
  26. Whenever the user selects a new or different value on one of the combo box, it is possible that the time frame has changed. We need to get all values of the corresponding day, calculate the equivalent time frame and display its decimal value in the right edit box. To take care of this situation, we will use a particular method for each day.
    In the Class Explorer, right-click frmTimeSheet and click New Method.
  27. Set the Method Name to UpdateMondayTime
  28. Set the Function Result to double and click the __fastcall check box.
  29. Click OK and implement the method as follows:
     
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateMondayTime()
    {
        double Monday, MondayIn1, MondayOut1, MondayIn2, MondayOut2;
    
        // Get the decimal equivalent of the first Time In
        MondayIn1 = ConvertTimeToDouble(cbxMondayIn1->Text);
        // Get the decimal equivalent of the first Time Out
        MondayOut1 = ConvertTimeToDouble(cbxMondayOut1->Text);
        // Get the decimal equivalent of the second Time In
        MondayIn2 = ConvertTimeToDouble(cbxMondayIn2->Text);
        // Get the decimal equivalent of the second Time Out
        MondayOut2 = ConvertTimeToDouble(cbxMondayOut2->Text);
    
        // Calculate the time worked for the first shift
        double FirstShift = MondayOut1 - MondayIn1;
        // Calculate the time worked for the second shift
        double SecondShift = MondayOut2 - MondayIn2;
        // Calculate the total time for the day
        Monday = FirstShift + SecondShift;
    
        // Display the result in the Monday edit box
        edtMonday->Text = FloatToStr(Monday, ffFixed, 4, 2);
        return Monday;
    }
    //---------------------------------------------------------------------------
  30. In the same way, create an update method for each day and implement them as follows:
     
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateTuesdayTime()
    {
        double Tuesday, TuesdayIn1, TuesdayOut1, TuesdayIn2, TuesdayOut2;
    
        TuesdayIn1 = ConvertTimeToDouble(cbxTuesdayIn1->Text);
        TuesdayOut1 = ConvertTimeToDouble(cbxTuesdayOut1->Text);
        TuesdayIn2 = ConvertTimeToDouble(cbxTuesdayIn2->Text);
        TuesdayOut2 = ConvertTimeToDouble(cbxTuesdayOut2->Text);
    
        double FirstShift = TuesdayOut1 - TuesdayIn1;
        double SecondShift = TuesdayOut2 - TuesdayIn2;
    
        Tuesday = FirstShift + SecondShift;
    
        edtTuesday->Text = FloatToStrF(Tuesday, ffFixed, 4, 2);
        return Tuesday;
    }
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateWednesdayTime()
    {
        double Wednesday, WednesdayIn1, WednesdayOut1, WednesdayIn2, WednesdayOut2;
    
        WednesdayIn1 = ConvertTimeToDouble(cbxWednesdayIn1->Text);
        WednesdayOut1 = ConvertTimeToDouble(cbxWednesdayOut1->Text);
        WednesdayIn2 = ConvertTimeToDouble(cbxWednesdayIn2->Text);
        WednesdayOut2 = ConvertTimeToDouble(cbxWednesdayOut2->Text);
    
        double FirstShift = WednesdayOut1 - WednesdayIn1;
        double SecondShift = WednesdayOut2 - WednesdayIn2;
    
        Wednesday = FirstShift + SecondShift;
    
        edtWednesday->Text = FloatToStrF(Wednesday, ffFixed, 4, 2);
        return Wednesday;
    }
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateThursdayTime()
    {
        double Thursday, ThursdayIn1, ThursdayOut1, ThursdayIn2, ThursdayOut2;
    
        ThursdayIn1 = ConvertTimeToDouble(cbxThursdayIn1->Text);
        ThursdayOut1 = ConvertTimeToDouble(cbxThursdayOut1->Text);
        ThursdayIn2 = ConvertTimeToDouble(cbxThursdayIn2->Text);
        ThursdayOut2 = ConvertTimeToDouble(cbxThursdayOut2->Text);
    
        double FirstShift = ThursdayOut1 - ThursdayIn1;
        double SecondShift = ThursdayOut2 - ThursdayIn2;
    
        Thursday = FirstShift + SecondShift;
    
        edtThursday->Text = FloatToStrF(Thursday, ffFixed, 4, 2);
        return Thursday;
    }
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateFridayTime()
    {
        double Friday, FridayIn1, FridayOut1, FridayIn2, FridayOut2;
    
        FridayIn1 = ConvertTimeToDouble(cbxFridayIn1->Text);
        FridayOut1 = ConvertTimeToDouble(cbxFridayOut1->Text);
        FridayIn2 = ConvertTimeToDouble(cbxFridayIn2->Text);
        FridayOut2 = ConvertTimeToDouble(cbxFridayOut2->Text);
    
        double FirstShift = FridayOut1 - FridayIn1;
        double SecondShift = FridayOut2 - FridayIn2;
    
        Friday = FirstShift + SecondShift;
    
        edtFriday->Text = FloatToStrF(Friday, ffFixed, 4, 2);
        return Friday;
    }
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateSaturdayTime()
    {
        double Saturday, SaturdayIn1, SaturdayOut1, SaturdayIn2, SaturdayOut2;
    
        SaturdayIn1 = ConvertTimeToDouble(cbxSaturdayIn1->Text);
        SaturdayOut1 = ConvertTimeToDouble(cbxSaturdayOut1->Text);
        SaturdayIn2 = ConvertTimeToDouble(cbxSaturdayIn2->Text);
        SaturdayOut2 = ConvertTimeToDouble(cbxSaturdayOut2->Text);
    
        double FirstShift = SaturdayOut1 - SaturdayIn1;
        double SecondShift = SaturdayOut2 - SaturdayIn2;
    
        Saturday = FirstShift + SecondShift;
    
        edtSaturday->Text = FloatToStrF(Saturday, ffFixed, 4, 2);
        return Saturday;
    }
    //---------------------------------------------------------------------------
    double __fastcall TfrmTimeSheet::UpdateSundayTime()
    {
        double Sunday, SundayIn1, SundayOut1, SundayIn2, SundayOut2;
    
        SundayIn1 = ConvertTimeToDouble(cbxSundayIn1->Text);
        SundayOut1 = ConvertTimeToDouble(cbxSundayOut1->Text);
        SundayIn2 = ConvertTimeToDouble(cbxSundayIn2->Text);
        SundayOut2 = ConvertTimeToDouble(cbxSundayOut2->Text);
    
        double FirstShift = SundayOut1 - SundayIn1;
        double SecondShift = SundayOut2 - SundayIn2;
    
        Sunday = FirstShift + SecondShift;
    
        edtSunday->Text = FloatToStrF(Sunday, ffFixed, 4, 2);
        return Sunday;
    }
    //---------------------------------------------------------------------------
  31. Now that we can find out how much time the employee worked for a day, we can calculate the total weekly hours and display its value in the Total Weekly Hour edit box. To perform this calculation, we will retrieve the value that each Update...Time method can produce, add the resulting values to obtain a total, format and display that total.
    In the Class Explorer, right-click frmTimeSheet and click Add Method
  32. Set the Method Name to CalcTotalTime
  33. Set its Function Result to void and click the __fastcall check button.
  34. Click OK and implemented the method as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::CalcTotalTime()
    {
        double Mon = UpdateMondayTime();
        double Tue = UpdateTuesdayTime();
        double Wed = UpdateWednesdayTime();
        double Thu = UpdateThursdayTime();
        double Fri = UpdateFridayTime();
        double Sat = UpdateSaturdayTime();
        double Sun = UpdateSundayTime();
    
        double Total = Mon + Tue + Wed + Thu + Fri + Sat + Sun;
        edtWeeklyTotal->Text = FloatToStrF(Total, ffFixed, 4, 2);
    }
    //---------------------------------------------------------------------------
  35. We could have called this method using a button. To make the employees job easier, we want the time sheet to update itself. Whenever the user has changed the value of one of the combo boxes, we will call the CalcTotalTime() method to recalculate things, update the total time for each day, and update the total time for the week.
    At the end of the OnChange event of each combo box, call the CalcTotalTime() method as follows:
     
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayIn1Change(TObject *Sender)
    {
        // InSelection is the time that has just been selected
        int In1Selection = cbxMondayIn1->ItemIndex;
        // OutSelection is the time that is displaying the next combo box
        int Out1Selection = cbxMondayOut1->ItemIndex;
    
        // Whenever the user decides to change the time on this one,
        // make sure the new time doesn't occur after the next time value
        // If the user tries this, set the Monday 's first time in to value
        // of the next combo box
        if( Out1Selection < In1Selection )
            cbxMondayIn1->ItemIndex = Out1Selection;
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayOut1Change(TObject *Sender)
    {
        // Get the selected value of the first Time In
        int In1Selection = cbxMondayIn1->ItemIndex;
        // Get the selected value of the first Time Out
        int Out1Selection = cbxMondayOut1->ItemIndex;
        // Get the selected value of the second Time In
        int In2Selection = cbxMondayIn2->ItemIndex;
    
        // Is the new value selected less than that of
        // the first Time In
        if( Out1Selection < In1Selection )
            cbxMondayOut1->ItemIndex = 24; // If so, set it to 12:00 PM
        // If the selected value happens to occur after the second Time In
        if( Out1Selection > In2Selection )
            cbxMondayOut1->ItemIndex = In2Selection; // Set it to that of Time In2               
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxMondayIn2->ItemIndex;
        int Out1Selection = cbxMondayOut1->ItemIndex;
        int Out2Selection = cbxMondayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxMondayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxMondayIn2->ItemIndex = Out2Selection;
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxMondayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxMondayOut2->ItemIndex;
        int In2Selection  = cbxMondayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxMondayOut2->ItemIndex = 34; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxTuesdayIn1->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxTuesdayIn1->ItemIndex = Out1Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxTuesdayIn1->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
        int In2Selection = cbxTuesdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxTuesdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxTuesdayOut1->ItemIndex = In2Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxTuesdayIn2->ItemIndex;
        int Out1Selection = cbxTuesdayOut1->ItemIndex;
        int Out2Selection = cbxTuesdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxTuesdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxTuesdayIn2->ItemIndex = Out2Selection;
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxTuesdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxTuesdayOut2->ItemIndex;
        int In2Selection  = cbxTuesdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxTuesdayOut2->ItemIndex = 34;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxWednesdayIn1->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxWednesdayIn1->ItemIndex = Out1Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxWednesdayIn1->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
        int In2Selection = cbxWednesdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxWednesdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxWednesdayOut1->ItemIndex = In2Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxWednesdayIn2->ItemIndex;
        int Out1Selection = cbxWednesdayOut1->ItemIndex;
        int Out2Selection = cbxWednesdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxWednesdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxWednesdayIn2->ItemIndex = Out2Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxWednesdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxWednesdayOut2->ItemIndex;
        int In2Selection  = cbxWednesdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxWednesdayOut2->ItemIndex = 34;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxThursdayIn1->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxThursdayIn1->ItemIndex = Out1Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayOut1Change(TObject *Sender)
    {
        int In1Selection = cbxThursdayIn1->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
        int In2Selection = cbxThursdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxThursdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxThursdayOut1->ItemIndex = In2Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxThursdayIn2->ItemIndex;
        int Out1Selection = cbxThursdayOut1->ItemIndex;
        int Out2Selection = cbxThursdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxThursdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxThursdayIn2->ItemIndex = Out2Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxThursdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxThursdayOut2->ItemIndex;
        int In2Selection  = cbxThursdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxThursdayOut2->ItemIndex = 34;     
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxFridayIn1->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxFridayIn1->ItemIndex = Out1Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxFridayIn1->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
        int In2Selection  = cbxFridayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxFridayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxFridayOut1->ItemIndex = In2Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxFridayIn2->ItemIndex;
        int Out1Selection = cbxFridayOut1->ItemIndex;
        int Out2Selection = cbxFridayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxFridayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxFridayIn2->ItemIndex = Out2Selection; 
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxFridayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxFridayOut2->ItemIndex;
        int In2Selection  = cbxFridayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxFridayOut2->ItemIndex = 34;      
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxSaturdayIn1->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSaturdayIn1->ItemIndex = Out1Selection;   
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxSaturdayIn1->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
        int In2Selection  = cbxSaturdayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSaturdayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxSaturdayOut1->ItemIndex = In2Selection;   
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxSaturdayIn2->ItemIndex;
        int Out1Selection = cbxSaturdayOut1->ItemIndex;
        int Out2Selection = cbxSaturdayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxSaturdayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxSaturdayIn2->ItemIndex = Out2Selection;   
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSaturdayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxSaturdayOut2->ItemIndex;
        int In2Selection  = cbxSaturdayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxSaturdayOut2->ItemIndex = 34;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayIn1Change(TObject *Sender)
    {
        int In1Selection = cbxSundayIn1->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSundayIn1->ItemIndex = Out1Selection;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayOut1Change(TObject *Sender)
    {
        int In1Selection  = cbxSundayIn1->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
        int In2Selection  = cbxSundayIn2->ItemIndex;
    
        if( Out1Selection < In1Selection )
            cbxSundayOut1->ItemIndex = 24;
        if( Out1Selection > In2Selection )
            cbxSundayOut1->ItemIndex = In2Selection;   
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayIn2Change(TObject *Sender)
    {
        int In2Selection = cbxSundayIn2->ItemIndex;
        int Out1Selection = cbxSundayOut1->ItemIndex;
        int Out2Selection = cbxSundayOut2->ItemIndex;
    
        if( In2Selection < Out1Selection )
            cbxSundayIn2->ItemIndex = 24;
        if( In2Selection > Out2Selection )
            cbxSundayIn2->ItemIndex = Out2Selection;     
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
    void __fastcall TfrmTimeSheet::cbxSundayOut2Change(TObject *Sender)
    {
        int Out2Selection = cbxSundayOut2->ItemIndex;
        int In2Selection  = cbxSundayIn2->ItemIndex;
    
        if( Out2Selection < In2Selection )
            cbxSundayOut2->ItemIndex = 34;  
    
        CalcTotalTime();
    }
    //---------------------------------------------------------------------------
  36. Test your program.
 

Copyright © 2005-2014, FunctionX, Inc.