1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
| #!/usr/local/bin/perl
use warnings;
use strict;
use Tk;
use Tk::NoteBook;
use Tk::DialogBox;
# ===== Interface graphique =====
my $fenetre_principale = MainWindow->new( -title => 'onglet', -background => 'yellow', );
$fenetre_principale->minsize( 300, 300 );
$fenetre_principale->Label(
-text => "Prêt inter-bibliothèques",
-background => 'yellow',
)->pack();
# blocnote
my $blocnote = $fenetre_principale->NoteBook(
-backpagecolor => 'white',
-inactivebackground => 'pink',
)->pack(qw/-fill both -expand 1/);
# CREATION DES ONGLETS
my $onglet_controle = $blocnote->add( "controle", -label => "Contrôle", );
my $onglet_ajout = $blocnote->add( "ajout", -label => "Ajout", );
# ONGLET CONTROLE
$onglet_controle->Label( -text => "CONTRÔLE\n\nEntrer le code-barre du document :", )->pack();
$onglet_controle->Label( -text => ' Code-barre : ' )->pack(qw/ -side left/);
my $entree_codebarre = $onglet_controle->Entry()->pack(qw/ -side left/);
$onglet_controle->Button(
-text => 'Valider',
-command => [ \&subone, $onglet_controle, $entree_codebarre ],
)->pack(qw/ -side left/);
# ONGLET AJOUT
$onglet_ajout->Label( -text => "AJOUT\n\nEntrer le code-barre du document :", )->pack();
$fenetre_principale->Button(
-text => 'Bouton fermeture',
-command => sub { exit; },
)->pack();
MainLoop;
# ===== Procédures =====
sub subone {
my ( $onglet, $entree_codebarre ) = @_;
open OUT, '>>', 'log.txt' or die("Ecriture impossible : $!");
open IN, '+<', 'liste.txt' or die("Lecture impossible : $!");
my $codebarre_saisie = $entree_codebarre->get;
unless ( defined $codebarre_saisie and $codebarre_saisie =~ /\S+/ ) {
my $popup_erreur = $onglet->DialogBox(
-title => 'ERREUR',
-buttons => ['OK'],
-background => 'white',
);
$popup_erreur->Label(
-text => "Vous n'avez fait aucune saisie",
-background => 'white',
)->pack();
$popup_erreur->Subwidget("B_OK")->configure( -background => 'red', );
$popup_erreur->Show();
return;
}
my $codebarre_trouve = 0;
while ( my $line = <IN> ) {
chomp $line;
# Comparaison des codebarre
if ( $line eq $codebarre_saisie ) {
print OUT "code-barre $codebarre_saisie connu\n"; # Inscription dans le fichier log/data/archive
my $popup_confirmation = $onglet->DialogBox(
-title => 'CONFIRMATION',
-background => 'white',
-buttons => ['OK'],
);
$popup_confirmation->Subwidget("B_OK")->configure( -background => 'green', );
$popup_confirmation->Label(
-text => "Le code-barre $codebarre_saisie, fait bien partie du prêt inter-bibliothèques",
-background => 'white',
)->pack();
$popup_confirmation->Show();
$codebarre_trouve = 1;
last;
}
}
if ( $codebarre_trouve == 0 ) {
my $popup_confirmation = $onglet->DialogBox(
-title => 'N° INCONNU',
-background => 'white',
-buttons => ['OK'],
);
$popup_confirmation->Subwidget("B_OK")->configure( -background => '#00B9FF', );
$popup_confirmation->Label(
-text => "Le code-barre : $codebarre_saisie,\n"
. "ne fait pas encore partie du prêt inter-bibliothèques.\n\n"
. "Il est donc ajouté.\n\n",
-background => 'white',
)->pack();
$popup_confirmation->Show();
print IN $codebarre_saisie, "\n";
}
close(IN);
close(OUT);
return;
} |
Partager