/*
**  $VER: Fiasco_Start 4.011 (29 Nov 1998) **
**
**        © 1996/98 Gerald Froehlich
**
**  PROGRAMNAME:
**      Fiasco_Start
**
**  FUNCTION:
**      Startet Fiasco mit DB Überweisungen & Vorlage
**
**  $HISTORY:
**
**  29 Nov 1998 : 004.011 :  unverändert
**  29 Jun 1998 : 003.710 :  unverändert
**  08 Jan 1998 : 003.544 :  Limits raus
**  14 Dec 1997 : 003.543 :  .rexx weg
**  23 Nov 1997 : 003.542 :  Versions-Variable
**  12 Nov 1997 : 003.541 :  Versionsprüfung
**  16 Apr 1997 : 003.500 :  Clip Virgin
**  14 Apr 1997 : 003.108 :  wieder ohne run
**  14 Apr 1997 : 003.107 :  im Batch: run Fiasco
**  13 Apr 1997 : 003.106 :  SIGNAL off ...
**  13 Apr 1997 : 003.105 :  mit RAM:-Datei
**  13 Apr 1997 : 003.104 :  Versuch mit run +
**  13 Apr 1997 : 003.103 :  Fehler-Routinen
**  13 Apr 1997 : 003.102 :  stack von Fiasco erhöht
**  14 Jan 1997 : 003.101 :  identisch
**  11 Jan 1997 : 003.031 :  Clips für Limits eingesetzt
**  18 Nov 1996 : 003.003 :  - no comment -
**   24 Mar 1996 : 0.01 : initial release
*/

F_neu = "6.282"


OPTIONS RESULTS

SIGNAL on error
SIGNAL ON break_c
SIGNAL ON break_d
SIGNAL ON break_e
SIGNAL ON break_f
SIGNAL ON failure
SIGNAL ON halt
SIGNAL ON ioerr
SIGNAL ON syntax

IF (~show('l','rexxreqtools.library')) THEN
    call addlib('rexxreqtools.library',0,-30,0)

IF (~show('l','rexxtricks.library')) THEN
    call addlib('rexxtricks.library',0,-30,0)


/*****************************************/

 file = GetClip("FiascoPfad")

a = SetClip("Virgin","0")

IF ~show("P",'FIASCO') THEN DO
  a = Open(B1,"RAM:Command.1","W")
  a = WriteLn(B1,"stack 8192")
  a = WriteLn(B1,file || "Fiasco")
  a = Close(B1)
  ADDRESS command
   'run execute RAM:Command.1'
  
  DO FOREVER
   IF Show("P",'FIASCO') THEN BREAK
  END
END

/* VERSION von FIASCO in CLIP setzten */

ADDRESS command "VERSION >env:FIASCO_V" GetClip("FiascoPfad") || "FIASCO"

a = SetClip("F_Version", Word(RXTR_GETENV('FIASCO_V'),2)  )

SIGNAL off error
SIGNAL off failure

/* Projekte öffnen */

/* noch nicht so weit!

IF GetClip("F_Version") < F_neu THEN DO */

   ADDRESS FIASCO
   F_SelectProj 'Vorlagen.fdb'
   IF rc = 10 THEN DO
     F_OpenProject GetClip("HB_Fiasco") || "Vorlagen.fdb"
     F_OpenList
   END
   F_SelectProj 'Ueberweisungen.fdb'
   IF rc = 10 THEN DO
     F_NewProject
     F_OpenProject GetClip("HB_Fiasco") || "Ueberweisungen.fdb"
   END

/* END    noch nicht! */

/******* jetzt neuen Port init. *************/

IF GetClip("F_Version") ~< F_neu THEN DO

  IF ~abbrev(ADDRESS(), "FIASCO.") THEN DO
      /* Get list of all available ports */

    ports = show("Ports")

    /* Search for a port of Fiasco */

    do i = 1 to words(ports)

        portname = word(ports, i)

        if abbrev(portname, "FIASCO.") then
        do
            if datatype(substr(portname, 8), "Numeric") then
            do
                /* A port of Fiasco has been found.
                 * Now query Fiasco to return the port
                 * name of the active database.
                 */

                Address Value portname

                GetAttr Project Name Active ARexx

                /* This command may fail when
                 * no projects are active. This is
                 * for example the case, when all
                 * projects are hidden.
                 */

                if rc == 0 then
                do
                    Address Value Result
                end
                else
                do
                    RequestChoice '"No active project" "Cancel" Title "' || scriptname || '"'

                    call bail_out
                end

                break
            end
        end
      END
  END

  fiasco_port = ADDRESS()

 /* This script runs WHILE the user cannot DO anything
  * in Fiasco's GUI
  */

 LockGUI
END

waehrung1 = Word(GetClip('Waehrung'),1)
waehrung2 = Word(GetClip('Waehrung'),2)

/* hier noch automatisieren!!!*/

ADDRESS FIASCO F_SelectProj Ueberweisungen.fdb

GetAttr Project Name Active ARexx

ADDRESS VALUE(RESULT)
IF waehrung1 = "DEM" THEN setConstant "W1" 0
ELSE setConstant "W1" 1
IF waehrung2 = "DEM" THEN setConstant "W2" 0
ELSE setConstant "W2" 1
 RecompileFormulas

ADDRESS FIASCO F_SelectProj Vorlagen.fdb

GetAttr Project Name Active ARexx

ADDRESS VALUE(RESULT)
IF waehrung1 = "DEM" THEN setConstant "W1" 0
ELSE setConstant "W1" 1
IF waehrung2 = "DEM" THEN setConstant "W2" 0
ELSE setConstant "W2" 1

 RecompileFormulas



/******************** */

bail_out:

Address Value fiasco_port

UnlockGUI
ResetStatus

EXIT 0





/*###################################
*** Debugging-Fehlerroutinen *******
###################################*/
syntax:
text =  'Syntax-Fehler' rc 'in Zeile' sigl '0A'x ErrorText(rc),
    '0A'x || SourceLine(sigl)
   CALL rtezrequest(text,"Alles klar!", "Fehlermeldung Fiasco",'rt_pubscrname='screen)
  EXIT 10

failure:
ioerr:
ERROR:
text =  'Fehler' rc 'in Zeile' sigl '0A'x ErrorText(rc),
    '0A'x || SourceLine(sigl)
   CALL rtezrequest(text,"Alles klar!", "Fehlermeldung Fiasco",'rt_pubscrname='screen)
  EXIT 10
halT:
break_c:
break_d:
break_e:
break_f:
text =  'User-Abbruch durch Halt!' || '0A'x || 'Wirklich abbrechen ?'
 ab = rtezrequest(text,"_Mach Schluss|_Neeiiin", "Fiasco",'rt_pubscrname='screen)
 IF ab = 1 THEN DO
  EXIT
 END
 ELSE RETURN

