Uso de scrollbar para HLIST.
Frames y Toplevels.
Dialog WIDGET (para mensajes e información).
Son algunas lib y widget usados.
Tabla en la base de datos [b]test:[/b]
Using sql Syntax Highlighting
- CREATE TABLE `productos` (
- `ID` int(11) NOT NULL AUTO_INCREMENT,
- `Precio` double(9,3) DEFAULT NULL,
- `Nombre` varchar(50) DEFAULT NULL,
- `URL` varchar(121) DEFAULT NULL,
- PRIMARY KEY (`ID`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=15 ;
- --
- -- Volcar la base de datos para la tabla `productos`
- --
- INSERT INTO `productos` VALUES (1, 9.600, 'P1', 'crm.jpg');
- INSERT INTO `productos` VALUES (2, 9.600, 'P2', 'shamp.png');
- INSERT INTO `productos` VALUES (3, 12.600, 'P3', 'makaf.jpg');
- INSERT INTO `productos` VALUES (4, 9.600, 'P3', '');
- INSERT INTO `productos` VALUES (12, 9.600, 'er', NULL);
- INSERT INTO `productos` VALUES (7, 9.600, 'P4', '');
- INSERT INTO `productos` VALUES (8, 9.600, 'sa', '');
- INSERT INTO `productos` VALUES (9, 9.600, 'p6', '');
- INSERT INTO `productos` VALUES (10, 9.600, 'P7', '');
- INSERT INTO `productos` VALUES (13, 11.000, 'oli', NULL);
- INSERT INTO `productos` VALUES (14, 44.000, 'edff', NULL);
Coloreado en 0.002 segundos, usando GeSHi 1.0.8.4
Código Perl :
Using perl Syntax Highlighting
- #!/usr/bin/perl
- use strict;
- use Tk;
- use Tk::HList;
- require Tk::LabEntry;
- require Tk::Dialog;
- use DBI;
- my $host = "localhost";
- my $database="test";
- my $user = "root";
- my $pw = "28alonso28";
- my $tl;
- my $oConexInf="DBI:mysql:database=$database;$host:3306";
- my $connect=DBI->connect($oConexInf,$user,$pw);
- #declare vars "glob"
- my $e;
- my $e2;
- #end
- my $mw = MainWindow->new;
- $mw->title("Admin Mysql By TKZeXe");
- $mw->geometry('500x400');
- $mw->resizable(0,0);
- my $frame = $mw->Frame(-borderwidth => 2, -relief => 'groove');
- my $frame2 = $mw->Frame(-borderwidth => 2,-relief => 'groove');
- my $scroll = $frame->Scrollbar( );
- my $hlist = $frame->HList(-command=>[\&oEditReg],-columns => 3,-width=>"50",-height=>"10",-background=>"white", -header => 1,
- -selectbackground=>"#CCCCCC", -selectborderwidth=>0);
- my $title=$frame->Label(-text => "Productos :\n");
- my $title_h1=$mw->Label(-text => "Edita,Borra y revisa tus Productos.\n\n",
- -foreground =>"Blue");
- #header (cabeceras)
- $hlist->headerCreate(0, -text => "ID");
- $hlist->headerCreate(1, -text => "Precio");
- $hlist->headerCreate(2, -text => "Nombre");
- my $query="SELECT ID,Precio,Nombre from Productos ORDER BY ID ASC ";
- my $i=0;
- my $id;
- my $price;
- my $name;
- my $sth = $connect->prepare($query);
- $sth->execute();
- while(my @result = $sth->fetchrow_array())
- {
- $hlist->add($i);
- $hlist->itemCreate($i, 0, -text => $result[0]);
- $hlist->itemCreate($i, 1, -text => $result[1]);
- $hlist->itemCreate($i, 2, -text => $result[2]);
- $i++;
- }
- $hlist->configure(-yscrollcommand => [\&scroll_listboxes],-height=>"10");
- $scroll->configure(-command =>['yview' => $hlist]);
- my $Bdelete=$frame2->Button(-text => "Delete",-width=>"10");
- my $Badd=$frame2->Button(-text => "Add",-width=>"10");
- my $Bedit=$frame2->Button(-text => "Edit",-width=>"10");
- #packs
- $title_h1->pack(-anchor => 'n');
- $frame->pack(-side => "top",-anchor=>"n");
- $title->pack();
- $hlist->pack(-expand => 0, -fill => 'both',-side => 'left');
- $scroll->pack(-side => 'left', -fill => 'y');
- $frame2->pack(-side => 'bottom',-fill=>'x');
- $Bdelete->pack(-side => 'left',-expand => 1,-padx=>10);
- $Bedit->pack(-side => 'left',-expand => 1,-padx=>10);
- $Badd->pack(-side => 'left',-expand => 1,-padx=>10);
- #end
- $Bdelete->bind('<Button-1>',\&oDeleteReg );
- $Bedit->bind('<Button-1>',\&oEditReg);
- $Badd->bind('<Button-1>',\&oAddReg );
- sub oDeleteReg{
- my $path=@_;
- my $Item = $hlist->selectionGet();
- my $data=$hlist->itemCget($Item, 0, -text);
- my $answer = $mw->Dialog(-title => 'Informacion!',
- -text => 'Deseas borrar definitivamente el registro seleccionado?',
- -default_button => 'no', -buttons => [ 'yes', 'no'],
- -bitmap => 'question' )->Show( );
- if ($answer eq 'no') {
- return 0;
- }
- #continue:
- my $query="DELETE from Productos WHERE ID='$data' ";
- my $sth = $connect->prepare($query);
- unless($sth->execute()){
- print "Error en la consulta".$sth->errstr;
- }else{
- $hlist->delete('entry', $Item);
- };
- }
- sub oEditReg{
- my($patt)=@_;
- my $Item = $hlist->selectionGet();
- my $data=$hlist->itemCget($Item, 0, -text);
- my $query="SELECT ID,Precio,Nombre from Productos WHERE ID='$data' LIMIT 1";
- my $sth = $connect->prepare($query);
- $sth->execute();
- my @result = $sth->fetchrow_array();
- if (! Exists($tl)) {
- $tl = $mw->Toplevel(-container => 0);
- $tl->title("Toplevel");
- $tl->geometry('400x300');
- $tl->resizable(0,0);
- $tl->Label(-text => "Edita tu Producto \n")->pack(-side=>'top');
- my $f1=$tl->Frame(-borderwidth => 1, -relief => 'groove')->pack(-side => "top",-anchor=>"nw");
- $f1->Label(-text => "Nombre Producto : ")->grid(-row => 0, -column => 0);
- $e = $f1->Entry()->grid(-row => 0, -column => 1);
- $e->insert('end',$result[1]);
- $f1->Label(-text => "Precio Producto (ej: 12.88) : ")->grid(-row => 1, -column => 0);
- $e2 = $f1->Entry()->grid(-row => 1, -column => 1);
- $e2->insert('end',$result[2]);
- my $f2=$tl->Frame(-borderwidth => 1, -relief => 'groove')->pack(-side => "bottom",-fill=>'x');
- $f2->Button(-text => "Editar Registro",-command => \&UpdateReg)->pack(-side=>'left');
- $f2->Button(-text => "Close",-command => sub { $tl->withdraw })->pack(-side=>'right');
- } else {
- $tl->deiconify( );
- $tl->raise( );
- }
- }
- sub oAddReg{
- if (! Exists($tl)) {
- $tl = $mw->Toplevel(-container => 0);
- $tl->title("Toplevel");
- $tl->geometry('400x300');
- $tl->resizable(0,0);
- $tl->Label(-text => "Ingresa tu Nuevo Producto \n")->pack(-side=>'top');
- my $f1=$tl->Frame(-borderwidth => 1, -relief => 'groove')->pack(-side => "top",-anchor=>"nw");
- $f1->Label(-text => "Nombre Producto : ")->grid(-row => 0, -column => 0);
- $e = $f1->Entry()->grid(-row => 0, -column => 1);
- $f1->Label(-text => "Precio Producto (ej: 12.88) : ")->grid(-row => 1, -column => 0);
- $e2 = $f1->Entry()->grid(-row => 1, -column => 1);
- my $f2=$tl->Frame(-borderwidth => 1, -relief => 'groove')->pack(-side => "bottom",-fill=>'x');
- $f2->Button(-text => "Ingresar Registro",-command => \&InsertInto)->pack(-side=>'left');
- $f2->Button(-text => "Close",-command => sub { $tl->withdraw })->pack(-side=>'right');
- } else {
- $tl->deiconify( );
- $tl->raise( );
- }
- }
- sub UpdateReg{
- my($patt)=@_;
- my $name=$e->get();
- my $price=$e2->get();
- my $Item = $hlist->selectionGet();
- my $ID=$hlist->itemCget($Item, 0, -text);
- my $query="UPDATE Productos SET Precio='$price',Nombre='$name' WHERE ID='$ID'";
- my $sth = $connect->prepare($query);
- unless($sth->execute()){
- my $answer = $mw->Dialog(-title => 'Informacion!',
- -text => "Error en la consulta".$sth->errstr,
- -default_button => 'Aceptar', -buttons => [ 'Aceptar'],
- -bitmap => 'question' )->Show( );
- }else{
- my $answer = $mw->Dialog(-title => 'Informacion!',
- -text => 'Haz Actualizado los datos correctamente!',
- -default_button => 'Aceptar', -buttons => [ 'Aceptar'],
- -bitmap => 'question' )->Show( );
- };
- $tl->withdraw;
- }
- sub InsertInto{
- my($patt)=@_;
- my $name=$e->get();
- my $price=$e2->get();
- my $query="INSERT INTO Productos (ID,Precio,Nombre) VALUES('','$price','$name')";
- my $sth = $connect->prepare($query);
- unless($sth->execute()){
- my $answer = $mw->Dialog(-title => 'Informacion!',
- -text => "Error en la consulta".$sth->errstr,
- -default_button => 'Aceptar', -buttons => [ 'Aceptar'],
- -bitmap => 'question' )->Show( );
- }else{
- my $answer = $mw->Dialog(-title => 'Informacion!',
- -text => 'Haz insertado los datos correctamente!',
- -default_button => 'Aceptar', -buttons => [ 'Aceptar'],
- -bitmap => 'question' )->Show( );
- };
- }
- sub scroll_listboxes {
- my (@args) = @_;
- $scroll->set(@args); # Llama a la barra de desplazamiento
- my ($top, $bottom) = $hlist->yview( );
- }
- MainLoop;
Coloreado en 0.008 segundos, usando GeSHi 1.0.8.4
Ya lo estaré explicando.
¡Saludos!