home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 13 / CDA13.ISO / cdactual / demobin / share / program / C / 50_OW.ZIP / DARTS.CPP next >
Encoding:
C/C++ Source or Header  |  1993-02-02  |  23.8 KB  |  899 lines

  1. #include <owl.h>
  2. #include <window.h>
  3. #include <filedial.h>
  4. #include <string.h>
  5. #include <stdio.h>
  6. #include <mdi.h>
  7. #include <checkbox.h>
  8. #include <static.h>
  9. #include <edit.h>
  10. #include <button.h>
  11. #include <listbox.h>
  12. #include <combobox.h>
  13.  
  14. #include "d4all.h"
  15.  
  16.  
  17. #define CM_COUNTCHILDREN    201
  18. #define ID_CLOSEBOX         101
  19.  
  20. // Team Entry Window constants
  21. const ID_TEAMCOMBO      = 101;
  22. const ID_GAMECOMBO      = 102;
  23. const WORD ID_PLAYR1    = 201;
  24. const WORD ID_PLAYR2    = 202;
  25. const WORD ID_PLAYR3    = 203;
  26. const WORD ID_TEAMNAME  = 204;
  27. const WORD ID_RRPOINTS  = 205;
  28. const WORD ID_DKPOINTS  = 206;
  29. const WORD ID_SCOREFROM = 207;
  30. const WORD ID_SCORETO   = 208;
  31. const ID_ADDTEAM     = 301;
  32. const ID_DELTEAM     = 302;
  33.  
  34. // Round Robin Generation Window constants
  35. const WORD ID_TGROUPS   = 101;
  36. const ID_GROUPSCOMBO    = 201;
  37. const ID_GROUPTEAMCOMBO = 202;
  38. const ID_GENERATERR     = 301;
  39. const ID_CLOSERR        = 302;
  40.  
  41. // Round Robin Game Entry Window constants
  42. const WORD ID_HSCORE    = 101;
  43. const WORD ID_VSCORE    = 102;
  44. const WORD ID_HPOINTS   = 103;
  45. const WORD ID_VPOINTS   = 104;
  46.  
  47.  
  48.  
  49. const WORD MAX_TEXTLEN = 50;
  50.  
  51. extern unsigned _stklen = 15000 ;
  52.  
  53. int teamsWindowOpen;
  54. int rrWindowOpen;
  55. int rgWindowOpen;
  56.  
  57.  
  58.  
  59. FIELD4INFO teamFields[] =
  60. {
  61.    { "TEAM_NUM",  r4num,  6, 0 },
  62.    { "TEAM_NAME", r4str, 10, 0 },
  63.    { "PLAYR1",    r4str, 15, 0 },
  64.    { "PLAYR2",    r4str, 15, 0 },
  65.    { "PLAYR3",    r4str, 15, 0 },
  66.    { "RR_POINTS", r4num,  6, 0 },
  67.    { "DK_POINTS", r4num,  6, 0 },
  68.    { 0, 0, 0, 0 },
  69.  
  70. };
  71.  
  72. TAG4INFO teamTags[] =
  73. {
  74.    { "TEAM_NAME", "TEAM_NAME", ".NOT. DELETED()", 0, 0 },
  75.    { "TEAM_NUM",  "TEAM_NUM",  ".NOT. DELETED()", 0, 0 },
  76.    { 0, 0, 0, 0, 0 },
  77. };
  78.  
  79. FIELD4INFO gameFields[] =
  80. {
  81.    { "TEAM_NUM",     r4num,  4, 0 },
  82.    { "GAME_TYPE",    r4str,  1, 0 },
  83.    { "GROUP_NAME",   r4str, 15, 0 },
  84.    { "GAME_NUM",     r4num,  4, 0 },
  85.    { "VS_TEAM",      r4num,  4, 0 },
  86.    { "HSCORE",       r4num,  6, 0 },
  87.    { "VSCORE",       r4num,  6, 0 },
  88.    { "POINTS",       r4num,  6, 0 },
  89.    { 0, 0, 0, 0 },
  90.  
  91. };
  92.  
  93. TAG4INFO gameTags[] =
  94. {
  95.    { "TEAM_NUM",  "TEAM_NUM",  ".NOT. DELETED()", 0, 0 },
  96.    { "GROUP_NAME", "GROUP_NAME", ".NOT. DELETED()", 0, 0 },
  97.    { 0, 0, 0, 0, 0 },
  98. };
  99.  
  100.  
  101. class DartApplication : public TApplication
  102. {
  103.    public:
  104.    DartApplication(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  105.             LPSTR lpCmdLine, int nCmdShow)
  106.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  107.  
  108.    virtual void InitMainWindow();
  109.  
  110.    CODE4 codeBase ;
  111. };
  112.  
  113.  
  114. ///////////////////////////////////////////////////////////////////////////////////
  115. //
  116. // MDI CHILD WINDOW CLASS / MEMBERS
  117. //
  118.  
  119. class EditTeamWindow : public TWindow
  120. {
  121.    public:
  122.  
  123.       TComboBox *TeamsCombo;
  124.       TComboBox *GamesCombo;
  125.       TEdit *Player1, *Player2, *Player3;
  126.       TEdit *teamName, *rrpoints, *dkpoints;
  127.       TEdit *scoreFrom, *scoreTo;
  128.  
  129.       EditTeamWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *teams, DATA4 *games);
  130.    
  131.       virtual void SetupWindow();
  132.       
  133.       virtual void HandleButton1Msg(RTMessage Msg) = [ID_FIRST + ID_ADDTEAM];
  134.       virtual void HandleButton2Msg(RTMessage Msg) = [ID_FIRST + ID_DELTEAM];
  135.       virtual void HandleListBoxMsg(RTMessage Msg) = [ID_FIRST + ID_TEAMCOMBO];
  136.  
  137.       virtual void WMDestroy( TMessage& )          = [WM_FIRST + WM_DESTROY];
  138.  
  139.       DATA4 *teams;
  140.       DATA4 *games;
  141.  
  142.       CODE4 *cb ;
  143. };
  144.  
  145. void EditTeamWindow::WMDestroy( TMessage& Message )
  146. {
  147.    teamsWindowOpen = 0;
  148.    TWindow::WMDestroy(Message);
  149. }
  150.  
  151.  
  152. EditTeamWindow::EditTeamWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *t, DATA4 *g)
  153.    : TWindow(AParent, ATitle)
  154. {
  155.    Attr.X = 50;
  156.    Attr.Y = 50;
  157.    Attr.W = 530;
  158.    Attr.H = 285;
  159.  
  160.    cb = cbase5;
  161.    teams = t;
  162.    games = g;
  163.  
  164.    new TStatic(this, -1, "Team Name",  10,  10, 85, 20, 0);
  165.    new TStatic(this, -1, "Lookup",    275,  10, 85, 20, 0);
  166.    new TStatic(this, -1, "Players",    10,  40, 85, 20, 0);
  167.    new TStatic(this, -1, "Game",      275,  45, 85, 20, 0);
  168.    new TStatic(this, -1, "RR Points",  10, 130, 85, 20, 0);
  169.    new TStatic(this, -1, "DK Points",  10, 160, 85, 20, 0);
  170.    new TStatic(this, -1, "Score",     275, 100, 85, 20, 0);
  171.    new TStatic(this, -1, "To",        400, 100, 85, 20, 0);
  172.  
  173.    teamName = new TEdit(this, ID_TEAMNAME, "", 100, 10, 150, 27, MAX_TEXTLEN, FALSE);
  174.    teamName->Attr.Style |= ES_UPPERCASE;
  175.    Player1 = new TEdit(this, ID_PLAYR1, "", 100, 40, 150, 27, MAX_TEXTLEN, FALSE);
  176.    Player1->Attr.Style |= ES_UPPERCASE;
  177.    Player2 = new TEdit(this, ID_PLAYR1, "", 100, 70, 150, 27, MAX_TEXTLEN, FALSE);
  178.    Player2->Attr.Style |= ES_UPPERCASE;
  179.    Player3 = new TEdit(this, ID_PLAYR1, "", 100, 100, 150, 27, MAX_TEXTLEN, FALSE);
  180.    Player3->Attr.Style |= ES_UPPERCASE;
  181.    rrpoints = new TEdit(this, ID_RRPOINTS, "", 100, 130, 150, 27, MAX_TEXTLEN, FALSE);
  182.    rrpoints->Attr.Style |= ES_UPPERCASE;
  183.    dkpoints = new TEdit(this, ID_DKPOINTS, "", 100, 160, 150, 27, MAX_TEXTLEN, FALSE);
  184.    dkpoints->Attr.Style |= ES_UPPERCASE;
  185.  
  186.    TeamsCombo = new TComboBox(this, ID_TEAMCOMBO, 340, 10, 170, 300, CBS_DROPDOWNLIST, 0 );
  187.    TeamsCombo->Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST;
  188.    GamesCombo = new TComboBox(this, ID_GAMECOMBO, 340, 45, 170, 400, CBS_DROPDOWNLIST, 1);
  189.    GamesCombo->Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST;
  190.  
  191.    scoreFrom = new TEdit(this, ID_SCOREFROM, "", 340, 100, 50, 27, MAX_TEXTLEN, FALSE);
  192.    scoreFrom->Attr.Style |= ES_UPPERCASE;
  193.    scoreTo = new TEdit(this, ID_SCORETO, "", 440, 100, 50, 27, MAX_TEXTLEN, FALSE);
  194.    scoreTo->Attr.Style |= ES_UPPERCASE;
  195.  
  196.    new TButton(this, ID_ADDTEAM, "New Team", 10, 205, 110, 28, FALSE);
  197.    new TButton(this, ID_DELTEAM, "Delete", 140, 205, 110, 28, FALSE);
  198.    
  199.    EnableKBHandler();
  200.  
  201. }
  202.  
  203.  
  204. void EditTeamWindow::HandleListBoxMsg(RTMessage Msg)
  205. {
  206.    char TheText[MAX_TEXTLEN];
  207.    int  curIndex, rc ;
  208.  
  209.    switch( Msg.LP.Hi )
  210.    {
  211.       case LBN_SELCHANGE:
  212.  
  213.          TeamsCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  214.          d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  215.          rc = d4seek( teams, TheText );
  216.          if( rc == r4after || rc == 0 )
  217.          {
  218.             teamName->SetText( f4str(d4field(teams,"TEAM_NAME")) );
  219.             Player1->SetText( f4str(d4field(teams,"PLAYR1")) );
  220.             Player2->SetText( f4str(d4field(teams,"PLAYR2")) );
  221.             Player3->SetText( f4str(d4field(teams,"PLAYR3")) );
  222.             SetFocus( TeamsCombo->HWindow );
  223.          }
  224.          else
  225.          {
  226.             MessageBox( HWindow, "Problem", "Error in the d4seek()", MB_OK );
  227.          }
  228.          break;
  229.  
  230.       case LBN_DBLCLK:
  231.  
  232.          break;
  233.  
  234.       case LBN_SETFOCUS:
  235.  
  236.          break;
  237.  
  238.    }
  239. }
  240.  
  241.  
  242. void EditTeamWindow::SetupWindow()
  243. {
  244.   int rc;
  245.   FIELD4 *tName;
  246.  
  247.   TWindow::SetupWindow();
  248.  
  249.   d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  250.   tName=d4field(teams,"TEAM_NAME");
  251.   for( rc=d4top(teams); rc==r4success; rc=d4skip(teams,1L) )
  252.   {
  253.      TeamsCombo->AddString( f4str(tName) );
  254.   }
  255.   TeamsCombo->SetSelIndex( 0 ) ;
  256.    d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  257.    d4top( teams );
  258.    teamName->SetText( f4str(d4field(teams,"TEAM_NAME")) );
  259.    Player1->SetText( f4str(d4field(teams,"PLAYR1")) );
  260.    Player2->SetText( f4str(d4field(teams,"PLAYR2")) );
  261.    Player3->SetText( f4str(d4field(teams,"PLAYR3")) );
  262.    SetFocus( TeamsCombo->HWindow );
  263. }
  264.  
  265. void EditTeamWindow::HandleButton1Msg(RTMessage)
  266. {
  267.    // Add a team to the roster
  268.    char TheText[MAX_TEXTLEN];
  269.  
  270.    teamName->GetText(TheText, sizeof(TheText));
  271.    if( TheText[0] <= 32 )
  272.       return;
  273.    TeamsCombo->AddString(TheText);
  274.    TeamsCombo->SetSelIndex(TeamsCombo->FindString(TheText, 0) );
  275.  
  276.    d4append_blank(teams);
  277.    teamName->GetText(TheText, sizeof(TheText));
  278.    f4assign(d4field(teams,"TEAM_NAME"),TheText);
  279.    Player1->GetText(TheText, sizeof(TheText));
  280.    f4assign(d4field(teams,"PLAYR1"),TheText);
  281.    Player2->GetText(TheText, sizeof(TheText));
  282.    f4assign(d4field(teams,"PLAYR2"),TheText);
  283.    Player3->GetText(TheText, sizeof(TheText));
  284.    f4assign(d4field(teams,"PLAYR3"),TheText);
  285.    f4assign_long(d4field(teams,"RR_POINTS"),0L);
  286.    f4assign_long(d4field(teams,"DK_POINTS"),0L);
  287.  
  288.    SetFocus( TeamsCombo->HWindow );
  289. }
  290.  
  291. void EditTeamWindow::HandleButton2Msg(RTMessage)
  292. {
  293.   // Delete a team from the roster
  294.    char TheText[MAX_TEXTLEN];
  295.    int  curIndex, rc ;
  296.  
  297.    TeamsCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  298.    d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  299.    rc = d4seek( teams, TheText );
  300.    if( rc == r4after || rc == 0 )
  301.    {
  302.       d4delete( teams );
  303.    }
  304.    else
  305.    {
  306.       MessageBox( HWindow, "Problem", "Error in the d4seek(), delete failed", MB_OK );
  307.    }
  308.    curIndex = TeamsCombo->GetSelIndex();
  309.    TeamsCombo->DeleteString( curIndex );
  310.    if( TeamsCombo->GetCount() > 0 )
  311.    {
  312.       if( curIndex >= TeamsCombo->GetCount() )
  313.       curIndex--;
  314.       TeamsCombo->SetSelIndex( curIndex ) ;
  315.         TeamsCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  316.       d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  317.       rc = d4seek( teams, TheText );
  318.       if( rc == r4after || rc == 0 )
  319.       {
  320.          teamName->SetText( f4str(d4field(teams,"TEAM_NAME")) );
  321.          Player1->SetText( f4str(d4field(teams,"PLAYR1")) );
  322.          Player2->SetText( f4str(d4field(teams,"PLAYR2")) );
  323.          Player3->SetText( f4str(d4field(teams,"PLAYR3")) );
  324.       }
  325.    }
  326.    SetFocus( TeamsCombo->HWindow );
  327. }
  328.  
  329.  
  330. ///////////////////////////////////////////////////////////////////////////////////
  331. //
  332. // Round Robin Game Entry Window
  333. //
  334.  
  335. class rgWindow : public TWindow
  336. {
  337.    public:
  338.  
  339.       TComboBox *gameCombo;
  340.       TEdit     *hScore, *vScore;
  341.       TEdit     *hPoints, *vPoints;
  342.  
  343.       rgWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *teams, DATA4 *games, char *group, int tNum);
  344.    
  345.       virtual void SetupWindow();
  346.       
  347.       virtual void HandleCloseButtonMsg(RTMessage Msg)   = [ID_FIRST + ID_CLOSERR];
  348.       virtual void HandleCombo1Msg(RTMessage Msg)        = [ID_FIRST + ID_GAMECOMBO];
  349.  
  350.       virtual void WMDestroy( TMessage& )                = [WM_FIRST + WM_DESTROY];
  351.  
  352.       char  *groupName;
  353.       int    teamNum;
  354.       
  355.       DATA4 *teams;
  356.       DATA4 *games;
  357.       CODE4 *cb ;
  358. };
  359.  
  360.  
  361. void rgWindow::WMDestroy( TMessage& Message )
  362. {
  363.    rgWindowOpen = 0;
  364.    TWindow::WMDestroy(Message);
  365. }
  366.  
  367.  
  368. rgWindow::rgWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *t, DATA4 *g, char *group, int tNum)
  369.    : TWindow(AParent, ATitle)
  370. {
  371.    int     rc;
  372.  
  373.    Attr.X = 50;
  374.     Attr.Y = 50;
  375.    Attr.W = 450;
  376.    Attr.H = 250;
  377.  
  378.    cb = cbase5;
  379.    teams = t;
  380.    games = g;
  381.    groupName = group;
  382.    teamNum  = tNum;
  383.  
  384.  
  385.    gameCombo = new TComboBox(this, ID_GAMECOMBO, 100, 40, 250, 200, CBS_DROPDOWNLIST, 0 );
  386.    gameCombo->Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST;
  387.  
  388.     new TStatic(this, -1, "Group",      10,  10, 85, 20, 0);
  389.    new TStatic(this, -1, "Game Type", 200,  10, 85, 20, 0); 
  390.    new TStatic(this, -1, "Game",       10,  40, 85, 20, 0);
  391.     new TStatic(this, -1, "Team",       10,  70, 85, 20, 0);
  392.    new TStatic(this, -1, "vs.",       200,  70, 85, 20, 0);
  393.    new TStatic(this, -1, "Score",      10, 100, 85, 20, 0);
  394.    new TStatic(this, -1, "To",        200, 100, 85, 20, 0);
  395.    new TStatic(this, -1, "Points",     10, 130, 85, 20, 0);
  396.  
  397.     hScore  = new TEdit(this, ID_HSCORE,  "", 100, 100, 50, 27, MAX_TEXTLEN, FALSE);
  398.     vScore  = new TEdit(this, ID_VSCORE,  "", 100, 100, 50, 27, MAX_TEXTLEN, FALSE);
  399.    hPoints = new TEdit(this, ID_HPOINTS, "", 280, 130, 50, 27, MAX_TEXTLEN, FALSE);
  400.    vPoints = new TEdit(this, ID_VPOINTS, "", 280, 130, 50, 27, MAX_TEXTLEN, FALSE);
  401.  
  402.    new TButton(this, ID_CLOSERR,  "Close", 10, 180, 110, 28, FALSE);
  403.    
  404.  
  405.     EnableKBHandler();
  406.  
  407.  
  408. }
  409.  
  410.  
  411. void rgWindow::HandleCombo1Msg(RTMessage Msg)
  412. {
  413.    int     curIndex, rc ;
  414.  
  415.    switch( Msg.LP.Hi )
  416.    {
  417.       case LBN_SELCHANGE:
  418.          break;
  419.  
  420.       case LBN_DBLCLK:
  421.  
  422.          break;
  423.  
  424.       case LBN_SETFOCUS:
  425.  
  426.          break;
  427.  
  428.    }
  429. }
  430.  
  431.  
  432. void rgWindow::SetupWindow()
  433. {
  434.     int     rc;
  435.    FIELD4 *teamName;
  436.    FIELD4 *teamNumber;
  437.    FIELD4 *grpName;
  438.    
  439.    char    comboText[51];
  440.    TWindow::SetupWindow();
  441.  
  442.    SetFocus( gameCombo->HWindow );
  443.  
  444.    // Count the total number of games
  445.    d4tag_select( games, d4tag(games,"GROUP_NAME") );
  446.    teamName=d4field(teams,"TEAM_NAME");
  447.    grpName=d4field(games,"GROUP_NAME");
  448.    teamNumber=d4field(games,"TEAM_NUM");
  449.  
  450.     d4tag_select( games, d4tag(games,"GROUP_NAME") );
  451.     rc = d4seek( games, groupName );
  452.     //if( rc != r4after && rc != 0 ) return;
  453.    rc = r4success;
  454.     gameCombo->ClearList();
  455.  
  456.     while( 1 )
  457.     {
  458.      if( teamNum == f4int(teamNumber) )
  459.          break;
  460.  
  461.         rc=d4skip(games,1L);
  462.         if( rc == r4eof ) break ;
  463.     }
  464.   if( rc==r4eof )
  465.        return;
  466.  
  467.     for( ; rc==r4success; rc=d4skip(games,1L) )
  468.    {
  469.       if( memcmp(groupName,f4str(grpName), 7) )
  470.          break;
  471.       if( teamNum != f4int(teamNumber) )
  472.          break;
  473.       int gameNumber = f4int(d4field(games,"GAME_NUM"));
  474.       int hTeam = f4int(d4field(games,"TEAM_NUM"));
  475.       int vTeam = f4int(d4field(games,"VS_TEAM"));
  476.       sprintf(comboText,"Game: %02d,  Team %02d vs %02d", gameNumber, hTeam, vTeam );
  477.         gameCombo->AddString( comboText );
  478.         gameCombo->SetSelIndex(gameCombo->FindString(comboText, 0) );
  479.     }
  480.  
  481.     gameCombo->SetSelIndex( 0 ) ;
  482.     SetFocus( gameCombo->HWindow );
  483. }
  484.  
  485. void rgWindow::HandleCloseButtonMsg(RTMessage)
  486. {
  487.     CloseWindow();
  488. }
  489.  
  490.  
  491.  
  492. ///////////////////////////////////////////////////////////////////////////////////
  493. //
  494. // Round Robin Generation Window
  495. //
  496.  
  497. class rrWindow : public TWindow
  498. {
  499.    public:
  500.  
  501.       TComboBox *groupsCombo;
  502.       TComboBox *teamGroupCombo;
  503.         TEdit *tGroups;
  504.  
  505.       rrWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *teams, DATA4 *games);
  506.    
  507.       virtual void SetupWindow();
  508.       
  509.       virtual void HandleGenButtonMsg(RTMessage Msg)     = [ID_FIRST + ID_GENERATERR];
  510.       virtual void HandleCloseButtonMsg(RTMessage Msg)   = [ID_FIRST + ID_CLOSERR];
  511.       virtual void HandleCombo1Msg(RTMessage Msg)        = [ID_FIRST + ID_GROUPSCOMBO];
  512.       virtual void HandleCombo2Msg(RTMessage Msg)        = [ID_FIRST + ID_GROUPTEAMCOMBO];
  513.  
  514.       virtual void WMDestroy( TMessage& )                = [WM_FIRST + WM_DESTROY];
  515.  
  516.       long   numGroups;
  517.       char   tTeams[35];
  518.  
  519.       DATA4 *teams;
  520.       DATA4 *games;
  521.  
  522.       CODE4 *cb ;
  523. };
  524.  
  525. void rrWindow::HandleGenButtonMsg(RTMessage)
  526. {
  527.    int      rc;
  528.    long     recNum, teamsPerGroup;
  529.    long     lCntr;
  530.    char     nGroupsText[35];
  531.    char     nText[35];
  532.    ldiv_t   lx;
  533.  
  534.  
  535.    tGroups->GetText(nGroupsText, sizeof(nGroupsText));
  536.    numGroups = atol( nGroupsText );
  537.  
  538.    d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  539.  
  540.    // Assign, in alphabeticle order, a team number to each team
  541.     recNum = 1;
  542.    for( rc=d4top(teams); rc==r4success; rc=d4skip(teams,1L) )
  543.       f4assign_long(d4field(teams,"TEAM_NUM"), recNum++) ;
  544.  
  545.    d4tag_select( teams, d4tag(teams,"TEAM_NUM") );
  546.    long tRecs = d4reccount(teams);
  547.    d4top(teams);
  548.    long groupRecStart = d4recno(teams);
  549.  
  550.    if( numGroups<1 || numGroups>=tRecs )
  551.    {
  552.       MessageBox( HWindow, "Invalid number of groups", "Entry Error", MB_OK );
  553.         return;
  554.    }
  555.  
  556.    lx = ldiv(tRecs, numGroups);
  557.    // lx.quot
  558.    // lx.rem
  559.  
  560.  
  561.    d4zap(games,1L,d4reccount(games));
  562.    d4top(games);
  563.  
  564.    int groupCounter = 1;
  565.    int skipAnother = 0;
  566.  
  567.     groupsCombo->ClearList();
  568.     teamGroupCombo->ClearList();
  569.  
  570.    while( 1 )
  571.    {
  572.       itoa( groupCounter++, nText, 10 );
  573.       strcpy( nGroupsText, "GROUP " );
  574.       strcat( nGroupsText, nText );
  575.       groupsCombo->AddString(nGroupsText);
  576.       groupsCombo->SetSelIndex(groupsCombo->FindString(nGroupsText, 0) );
  577.  
  578.       lCntr = 1;
  579.       int extraTeamSwitch = 1;
  580.       while( 1 )
  581.       {
  582.          long curTeamRec = d4recno(teams);
  583.          long curTeam = f4long(d4field(teams,"TEAM_NUM"));
  584.    
  585.          teamsPerGroup = lx.quot;
  586.          if( lx.rem ) teamsPerGroup++;
  587.          d4go(teams,groupRecStart);
  588.  
  589.          int gameNum = 1;
  590.          while( teamsPerGroup )
  591.          {
  592.             long thisTeam = f4long(d4field(teams,"TEAM_NUM"));
  593.             if( curTeam != thisTeam )
  594.             {
  595.                d4append_blank( games );
  596.                f4assign(d4field(games,"GROUP_NAME"), nGroupsText );
  597.                f4assign_long(d4field(games,"TEAM_NUM"), curTeam );
  598.                f4assign(d4field(games,"GAME_TYPE"), "R" );
  599.                f4assign_int(d4field(games,"GAME_NUM"), gameNum );
  600.                f4assign_long(d4field(games,"VS_TEAM"), thisTeam );
  601.                gameNum++;
  602.             }
  603.             if( d4skip(teams, 1L) == r4eof )
  604.                break;
  605.             teamsPerGroup--;
  606.          }
  607.    
  608.          d4go(teams, curTeamRec);
  609.          if( d4skip(teams, 1L) == r4eof )
  610.             break;
  611.  
  612.          lCntr++;
  613.  
  614.          if( lCntr>lx.quot )
  615.          {
  616.             if( lx.rem && extraTeamSwitch )
  617.             {
  618.                skipAnother = 1 ;
  619.                lx.rem--;
  620.                extraTeamSwitch = 0;
  621.             }
  622.             else
  623.             {
  624.                break;
  625.             }
  626.          }
  627.       }
  628.  
  629.       d4go(teams,groupRecStart);
  630.       if( d4skip( teams, lx.quot ) == r4eof )
  631.          break;
  632.       if( skipAnother )
  633.       {
  634.          skipAnother = 0;
  635.          if( d4skip( teams, 1L ) == r4eof )
  636.             break;
  637.       }
  638.  
  639.       groupRecStart = d4recno(teams);
  640.    }
  641.  
  642.    SetFocus( groupsCombo->HWindow );
  643. }
  644.  
  645.  
  646. void rrWindow::WMDestroy( TMessage& Message )
  647. {
  648.    rrWindowOpen = 0;
  649.    TWindow::WMDestroy(Message);
  650. }
  651.  
  652.  
  653. rrWindow::rrWindow(PTWindowsObject AParent, LPSTR ATitle, CODE4 *cbase5, DATA4 *t, DATA4 *g)
  654.    : TWindow(AParent, ATitle)
  655. {
  656.    int     rc;
  657.    long    tTeamCntr = 0;
  658.    FIELD4 *tName;
  659.  
  660.    Attr.X = 10;
  661.    Attr.Y = 10;
  662.    Attr.W = 450;
  663.    Attr.H = 250;
  664.  
  665.    cb = cbase5;
  666.    teams = t;
  667.    games = g;
  668.  
  669.    // Count the total number of teams
  670.    d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  671.    tName=d4field(teams,"TEAM_NAME");
  672.    d4pack(teams);
  673.    for( rc=d4top(teams); rc==r4success; rc=d4skip(teams,1L) )
  674.    {
  675.       tTeamCntr++;
  676.    }
  677.    ltoa( d4reccount(teams), tTeams, 10);
  678.  
  679.    new TStatic(this, -1, "Total Teams",   10,  10, 85, 20, 0);
  680.    new TStatic(this, -1, tTeams,         100,  10, 85, 20, 0); 
  681.    new TStatic(this, -1, "Groups",       175,  10, 85, 20, 0);
  682.  
  683.    new TStatic(this, -1, "# Groups",      10,  40, 85, 20, 0);
  684.    new TStatic(this, -1, "Group Teams",  175,  45, 85, 20, 0);
  685.  
  686.    tGroups = new TEdit(this, ID_TGROUPS, "", 100, 40, 50, 27, MAX_TEXTLEN, FALSE);
  687.  
  688.    groupsCombo = new TComboBox(this, ID_GROUPSCOMBO, 240, 10, 170, 150, CBS_DROPDOWNLIST, 0 );
  689.    groupsCombo->Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST;
  690.    teamGroupCombo = new TComboBox(this, ID_GROUPTEAMCOMBO, 240, 45, 170, 300, CBS_DROPDOWNLIST, 1);
  691.    teamGroupCombo->Attr.Style = WS_CHILD | WS_VISIBLE | WS_GROUP | WS_TABSTOP | WS_VSCROLL | CBS_DROPDOWNLIST;
  692.  
  693.    new TButton(this, ID_GENERATERR, "Generate", 10, 150, 110, 28, FALSE);
  694.    new TButton(this, ID_CLOSERR,  "Close", 140, 150, 110, 28, FALSE);
  695.    
  696.    EnableKBHandler();
  697.  
  698. }
  699.  
  700.  
  701. void rrWindow::HandleCombo1Msg(RTMessage Msg)
  702. {
  703.    char TheText[MAX_TEXTLEN];
  704.    int  curIndex, rc ;
  705.    long lastNum;
  706.    FIELD4 *teamName;
  707.    FIELD4 *teamNum;
  708.    FIELD4 *groupName;
  709.  
  710.    switch( Msg.LP.Hi )
  711.    {
  712.       case LBN_SELCHANGE:
  713.          teamNum=d4field(games,"TEAM_NUM");
  714.          teamName=d4field(teams,"TEAM_NAME");
  715.          groupName=d4field(games,"GROUP_NAME");
  716.  
  717.          d4tag_select( games, d4tag(games,"GROUP_NAME") );
  718.          d4tag_select( teams, d4tag(teams,"TEAM_NUM") );
  719.  
  720.          teamGroupCombo->ClearList();
  721.          groupsCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  722.  
  723.          rc = d4seek( games, TheText );
  724.          if( rc != r4after && rc != 0 ) break;
  725.  
  726.          while( 1 )
  727.          {
  728.             lastNum = f4long(teamNum);
  729.             rc = d4seek_double( teams, (double)f4long(teamNum) );
  730.             if( rc != r4after && rc != 0 )
  731.                break;
  732.             if( memcmp(TheText,f4str(groupName), 7) )
  733.                break;
  734.             teamGroupCombo->AddString( f4str(teamName) );
  735.  
  736.             while( 1 )
  737.             {
  738.                rc=d4skip(games,1L);
  739.                if( rc != r4success )
  740.                   break;
  741.                if( lastNum != f4long(teamNum) )
  742.                   break;
  743.             }
  744.             if( rc != r4success ) break;
  745.          }
  746.          teamGroupCombo->SetSelIndex( 0 ) ;
  747.          SetFocus( groupsCombo->HWindow );
  748.          break;
  749.  
  750.       case LBN_DBLCLK:
  751.  
  752.          break;
  753.  
  754.       case LBN_SETFOCUS:
  755.  
  756.          break;
  757.  
  758.    }
  759. }
  760.  
  761.  
  762. void rrWindow::HandleCombo2Msg(RTMessage Msg)
  763. {
  764.    char TheText[MAX_TEXTLEN];
  765.    int  curIndex, rc ;
  766.    FIELD4 *teamName;
  767.    FIELD4 *teamNum;
  768.  
  769.    switch( Msg.LP.Hi )
  770.    {
  771.       case LBN_SELCHANGE:
  772.          d4tag_select( teams, d4tag(teams,"TEAM_NAME") );
  773.          teamNum=d4field(teams,"TEAM_NUM");
  774.          teamGroupCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  775.          TheText[10] = 0;
  776.          rc = d4seek( teams, TheText );
  777.          if( rc != r4after && rc != 0 )
  778.          {
  779.             MessageBox( HWindow, "Seek on Team Name didn't work!", "Seeking Error", MB_OK );
  780.             break;
  781.          }
  782.          groupsCombo->GetSelString( TheText, MAX_TEXTLEN-1 );
  783.          GetApplication()->MakeWindow( new rgWindow(this, "Game Entry Window", cb, teams, games,TheText,f4int(teamNum)) );
  784.          break;
  785.  
  786.       case LBN_DBLCLK:
  787.          break;
  788.  
  789.       case LBN_SETFOCUS:
  790.  
  791.          break;
  792.  
  793.    }
  794. }
  795.  
  796.  
  797. void rrWindow::SetupWindow()
  798. {
  799.    TWindow::SetupWindow();
  800.  
  801.    SetFocus( tGroups->HWindow );
  802. }
  803.  
  804. void rrWindow::HandleCloseButtonMsg(RTMessage)
  805. {
  806.     CloseWindow();
  807. }
  808.  
  809.  
  810. ///////////////////////////////////////////////////////////////////////////////////
  811. //
  812. // FRAME WINDOW CLASS / MEMBERS
  813. //
  814.  
  815.  
  816. _CLASSDEF(DartFrame)
  817.  
  818. class DartFrame : public TMDIFrame
  819. {
  820.    public:
  821.    DartFrame(LPSTR ATitle, CODE4 *cbase5);
  822.    void SetupWindow();
  823.  
  824.    virtual void RosterEntryWindow( RTMessage Msg )       = [CM_FIRST+1024];
  825.    virtual void RoundRobinGenerate( RTMessage Msg )      = [CM_FIRST+1025];
  826.  
  827.    DATA4 *teams;
  828.    DATA4 *games;
  829.    CODE4  *cb;
  830. };
  831.  
  832. DartFrame::DartFrame(LPSTR ATitle, CODE4 *cbase5)
  833.    : TMDIFrame(ATitle, "COMMANDS")
  834. {
  835.    ChildMenuPos = 2;
  836.    cb = cbase5;
  837.    teamsWindowOpen = 0;
  838.  
  839.    cb->open_error = 0;
  840.    cb->safety = 0;
  841.    teams = d4open( cb, "TEAMS.DBF" );
  842.    if( teams == NULL )
  843.       teams = d4create( cb, "TEAMS.DBF", teamFields, teamTags );
  844.  
  845.    games = d4open( cb, "GAMES.DBF" );
  846.    if( games == NULL )
  847.       games = d4create( cb, "GAMES.DBF", gameFields, gameTags );
  848.  
  849. };
  850.  
  851.  
  852. // set up the TMDIFrame, creating its first child
  853. void DartFrame::SetupWindow()
  854. {
  855.    TMDIFrame::SetupWindow();
  856. }
  857.  
  858. void DartFrame::RosterEntryWindow( RTMessage Msg )
  859. {
  860.    if( !teamsWindowOpen )
  861.    {
  862.       GetApplication()->MakeWindow( new EditTeamWindow(this, "Team Roster", cb, teams, games) );
  863.       teamsWindowOpen = 1;
  864.    }
  865. }
  866.  
  867. void DartFrame::RoundRobinGenerate( RTMessage Msg )
  868. {
  869.    if( !rrWindowOpen )
  870.    {
  871.       GetApplication()->MakeWindow( new rrWindow(this, "Round Robin Generation", cb, teams, games) );
  872.       rrWindowOpen = 1;
  873.    }
  874. }
  875.  
  876.  
  877.  
  878. ///////////////////////////////////////////////////////////////////////////////////
  879.  
  880.  
  881.  
  882. void DartApplication::InitMainWindow()
  883. {
  884.    d4init( &codeBase ) ;
  885.    MainWindow = new DartFrame( Name, &codeBase);
  886.  
  887. }
  888.  
  889. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  890. {
  891.    DartApplication DartApp("Dart Tounament", hInstance, hPrevInstance, lpCmdLine, nCmdShow);
  892.    DartApp.Run();
  893.  
  894.    d4close_all( &DartApp.codeBase );
  895.  
  896.    return DartApp.Status;
  897. }
  898.  
  899.