#!wish8.2 -f
#
# Pop-up a dialog box from with the Perl engine of CBB
# to query the user as to what to do with a duplicate
# transaction.
#
# Adam Stein (12/10/98)

# Make sure we have only arguments
if {$argc != 12} {
  puts stderr "usage: cbb_dialog transaction1... transaction2..."
  exit 1
}

# Set default answer
set choice 0

# Set window title
wm title . "Duplicate Transaction"

# Create overall and message frames
set f [frame .dialog -borderwidth 10]
bind $f <Destroy> {exit $choice}

set mf [frame $f.messageframe -borderwidth 2 -relief groove]

# Create messages
set message1 [lindex $argv 0]
set message2 [lindex $argv 6]

for {set loop 1} {$loop < 6} {incr loop 1} {
  set message1 "$message1\n[lindex $argv $loop]"
}

for {set loop 7} {$loop < $argc} {incr loop 1} {
  set message2 "$message2\n[lindex $argv $loop]"
}

label $mf.lb1 -text "The following transaction is a duplicate:" \
	      -font -Adobe-Helvetica-Bold-R-Normal-*-*-180-*-*-*-*-*-*

label $mf.lb2 -text "(the * denotes the fields that were compared)" \
	      -font -Adobe-Helvetica-Medium-I-Normal-*-*-140-*-*-*-*-*-*

message $mf.msg1 -text $message1 -aspect 1000

label $mf.lb3 -text "as compared to:" \
	      -font -Adobe-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*

message $mf.msg2 -text $message2 -aspect 1000

label $mf.lb4 -text "How should I proceed?" \
	      -font -Adobe-Helvetica-Bold-R-Normal-*-*-140-*-*-*-*-*-*

pack $mf.lb1 -anchor w
pack $mf.lb2 -anchor w
pack $mf.msg1 -anchor w
pack $mf.lb3 -anchor w
pack $mf.msg2 -anchor w
pack $mf.lb4 -anchor w

# Create filler to separate the message from the buttons
frame $f.filler -width 10 -height 30

# Create the buttons
set b [frame $f.buttons -borderwidth 10]

button $b.ok -text "Don't Insert" -command {set choice 1}
button $b.cancel -text "Insert" -command {set choice 0}
pack $b.ok $b.cancel -padx 5 -pady 5 -side left -expand true

pack $f.messageframe $f.filler $f.buttons -side top -fill x
pack $f -expand true

# Wait til the user made a choice
tkwait variable choice

exit $choice

