WITH Cars;
WITH Screen;
WITH Ada.Text_IO;
WITH Simple_Dates;
WITH Ada.Integer_Text_IO;
PROCEDURE proj_09ui IS
------------------------------------------------------------------
--| Shell of menu-driven user interface for car "database"
--| when correct input is entered, a message is displayed
--| instead of actually executing the command .
--|
--| Author  : Michael B. Feldman, The George Washington University
--| Changed : Chester B. Lund, The George Washington University
--|
--| Last Modified: September 1998
------------------------------------------------------------------

     TASK synchronize_commit IS
     --
     --   Place your source code here
     --
     END  synchronize_commit;

     TASK BODY synchronize_commit IS
     BEGIN
     --
     --   Place your source code here
     --
          Ada.Text_IO.put_line (Item => "TASK synchronize_commit just ran!");
     END synchronize_commit;

     TASK TYPE database_writer IS
     --   ENTRY start (period_setting : IN Duration);
     --
     --   Place your source code here
     --
     END database_writer;

     TASK BODY database_writer IS
          write_period : Duration;
     BEGIN
     --
     --   Place your source code here
     --
          Ada.Text_IO.put_line (Item => "TASK database_writer just ran!");
     END database_writer;

     DB_Writer : database_writer;

     SUBTYPE text_string IS String (1..30);

     TYPE MenuValues IS (A,        --  Add one record (pending)
                         C,        --  Commit changes in DB
                         D,        --  Delete one record (pending)
                         F,        --  Find and display a record
                         S,        --  Select all records (display)
                         R,        --  Rollback pending changes
                         T,        --  Truncate the database
                         U,        --  Update one record (pending)
                         Q);       --  Quit the program

     PACKAGE Menu_IO IS NEW Ada.Text_IO.Enumeration_IO (Enum => MenuValues);

     MenuSelection : MenuValues;

     PROCEDURE show (row : IN screen.depth;
                     col : IN screen.width;
                     txt : IN text_string) IS
     BEGIN
          screen.movecursor (row  => row, column => col);
          Ada.Text_IO.put   (Item => txt);
     END show;

BEGIN -- user_interface

     --   Place your source code here

     Screen.ClearScreen;

     LOOP -- main program loop
          --                            123456789012345678901234567890
          show (row=> 5, col=>20, txt=>"Select one operation below:   ");
          --
          show (row=> 7, col=>20, txt=>"C -> Table, Commit Table      ");
          show (row=> 8, col=>20, txt=>"R -> Table, Rollback Table    ");
          show (row=> 9, col=>20, txt=>"S -> Table, Select all Rows   ");
          show (row=>10, col=>20, txt=>"T -> Table, Truncate Table    ");
          show (row=>11, col=>20, txt=>"A -> Row, Add One Row         ");
          show (row=>12, col=>20, txt=>"D -> Row, Delete One Row      ");
          show (row=>13, col=>20, txt=>"F -> Row, Find a Row          ");
          show (row=>14, col=>20, txt=>"U -> Row, Update One Row      ");
          show (row=>15, col=>20, txt=>"Q -> Quit the Program         ");

          LOOP
               BEGIN -- EXCEPTION handler block

                    Screen.MoveCursor (Row => 17, Column => 20);
                    Ada.Text_IO.Put
                         ("Please type a command, then press Enter > ");

                    -- this statement will raise Data_Error if input is invalid
                    Menu_IO.Get (Item => MenuSelection);

                    -- these statements will be executed for correct input only
                    -- otherwise, control passes to exception handler
                    Screen.MoveCursor (Row => 18, Column => 20);
                    Ada.Text_IO.put_line ("Thank you for correct input.");
                    EXIT;   -- valid data; go ahead to process it
               EXCEPTION    -- invalid data
              WHEN Ada.Text_IO.Data_Error =>
                screen.Beep;                                              --|
                show (row=>22, col=>20, txt=>"                              ");
                show (row=>22, col=>20, txt=>"**Invalid command; Try again  ");
                Ada.Text_IO.Skip_Line;
             WHEN OTHERS =>
                screen.Beep;                                              --|
                show (row=>22, col=>20, txt=>"                              ");
                show (row=>22, col=>20, txt=>"**Unknown error; Try again    ");
                Ada.Text_IO.Skip_Line;                   Screen.Beep;
            END;  --  EXCEPTION handler block

          END LOOP;

          Screen.MoveCursor (Row => 22, Column => 20);
          Ada.Text_IO.Put   (Item => "                                    ");
          Screen.MoveCursor (Row => 22, Column => 20);
          CASE MenuSelection IS
              WHEN C =>
                  Ada.Text_IO.Put (Item => "C entered:  Commit Table      ");
              WHEN R =>
                  Ada.Text_IO.Put (Item => "R entered:  Rollback Table    ");
              WHEN S =>
                  Ada.Text_IO.Put (Item => "S entered:  Select All Rows   ");
              WHEN T =>
                  Ada.Text_IO.Put (Item => "T entered:  Truncate Table    ");
              WHEN A =>
                  Ada.Text_IO.Put (Item => "A entered:  Add One Row       ");
              WHEN D =>
                  Ada.Text_IO.Put (Item => "D entered:  Delete One Row    ");
              WHEN F =>
                  Ada.Text_IO.Put (Item => "F entered:  Find a Row        ");
              WHEN U =>
                  Ada.Text_IO.Put (Item => "U entered:  Update One Row    ");
              WHEN Q =>
                  Ada.Text_IO.Put (Item => "Q entered:  Quit the Program  ");
                  EXIT;                -- the main loop and quit the program
          END CASE;
          Ada.Text_IO.New_Line;

     END LOOP;

     --   Place your source code here

END proj_09ui;