sub import
{
my $import = $mw->Toplevel();
$import->title("Importieren");
my $auswahl_radio = 1;
my      $windowHeight       = "540";
my      $windowWidth        = "540";
my      $screenHeight       = $import->screenheight;
my      $screenWidth        = $import->screenwidth;
$import->geometry($windowWidth."x".$windowHeight);
$import->geometry("+".int($screenWidth/2 - $windowWidth/2)."+".int($screenHeight/2 - $windowHeight/2));
my $f1 = $import->LabFrame(-label => "Quelle",-labelside => 'acrosstop')->place(-x => 20,
               
                                       -y    => 30,
               
               
            -height => 70, -width => 500
               
                                       ); 
my $Label1 = $import->Label(-text => "Import von Daten:",-anchor => 'w')->place( -x => 21, -y => 10, -height => 21, -width => 493);
my $Label2 = $f1->Label(-text => "Quell-Datei:")->place( -x => 5, -y => 5, -height => 23, -width => 74);
my $ein_entry = $f1->Entry(-width => 50, -relief => "sunken")->place( -x => 79, -y => 5, -height => 24, -width => 224);
my $ein_btn = $f1->Button(-text    => 'Durchsuchen',
                           -relief => "raised",
                         -command =>
                             sub {
                                 my $typen = [
                                     ['Datenbank',  '.dat' ],
                                     ['Alle Dateien', '*'    ],
                                 ];
                                 my $dn = $import->getOpenFile(-filetypes  => $typen,
                                                          );
                                 if (defined $dn and $dn ne '') {
                                     $ein_entry->delete(0, 'end');
                                     $ein_entry->insert('end', $dn);
                                 }
                             },
                        )->place( -x => 308, -y => 5, -height => 24, -width => 152);
my $radioframe = $import->Frame()->place(-x => 40, -y => 100, -height => 60, -width => 480);
my $Radiobutton1 = $radioframe->Radiobutton(
                                     -text => "  (HINZUFÜGEN)  Neue Daten hinzufügen",
               
      -variable => \$auswahl_radio, 
               
      -value => 1,
               
      -anchor => 'w'
                                     )->place( -x => 5, -y => 5, -height => 24, -width => 472);
my $Radiobutton2 = $radioframe->Radiobutton(
                                     -text => "  (ÜBERSCHREIBEN) Lokale Daten durch neue Daten ersatzen",
               
      -variable => \$auswahl_radio, 
               
      -value => 2,
                                     -anchor => 'w'
                                     )->place( -x => 5, -y => 25, -height => 24, -width => 472);
$hlist = $import->Scrolled( "HList",
               
  -header => 1,
               
  -columns => 3,
               
  -scrollbars => 'ose',
                     -width => 70,
                     -selectbackground => '#539FFD',
                       )->place( -x => 24, -y => 200, -height => 312, -width => 488);
$hlist->header('create', 0, -text => 'Nummer');
$hlist->header('create', 1, -text => 'Name');
$hlist->header('create', 2, -text => 'Status');
my $Label4 = $import->Label( -textvariable => \$var_status,
                      -anchor => 'w',
               
   -foreground => 'red'
               
 )->place( -x => 74, -y => 515, -height => 20, -width => 300);
$var_status = "";
my $Button2 = $import->Button(
                           -text => "Vorschau",
                           -relief => "raised",
               -command => sub {
                   
         $hlist->delete('all');
               
         $var_status = "";
               
         $eintragnr = 0;
               
         $Datei_pfad = $ein_entry->get();
               
         if ( not -e $Datei_pfad ) { $var_status = "Die Datei existiert nicht oder kann nicht gelesen werden!"; return; }
                           
     open (EINGABE, "<$Datei_pfad");
               
         @vorschau = <EINGABE>;
               
         close (EINGABE);
               
         print "@vorschau";
               
         foreach $einedatei (@vorschau)
               
         {
               
         @daten = split /->/, $einedatei;        
               
         chop $daten[2];
               
         $hlist->add($eintragnr);
               
         $hlist->itemCreate($eintragnr, 0, -text => "$daten[0]");
               
         $hlist->itemCreate($eintragnr, 1, -text => "$daten[1]");
                   
         $hlist->itemCreate($eintragnr, 2, -text => "$daten[2]");
               
         $eintragnr++;
               
         }
               
        }
                           )->place( -x => 48, -y => 160, -height => 23, -width => 127);
my $Button3 = $import->Button(
                           -text => "Import starten",
                           -relief => "raised",
               -command => sub {
                   
         $Datei_pfad = $ein_entry->get();
               
         if ( not -e $Datei_pfad ) { $var_status = "Die Datei existiert nicht oder kann nicht gelesen werden!"; return; }
                           
     open (EINGABE, "<$Datei_pfad");
               
         @neuedaten = <EINGABE>;
               
         close (EINGABE);
               
         if ( $auswahl_radio == 1 ) #Hinzufügen
               
         {
               
         open (EINGABE, "<daten.dat");
               
         @schuelerdaten = <EINGABE>;
               
         close (EINGABE);
               
         foreach $einedatei (@neuedaten)
               
         {
               
         @list = split /->/, $einedatei;
               
         $test = $list[0];
               
         foreach $einedatei2 (@schuelerdaten)
               
         {
               
         @list2 = split /->/, $einedatei2;
               
         $test2 = $list2[0];
               
         if ($test == $test2)
               
             {
               
             $var_status = "Fehler!! Eine der neuen Schülernummern ist bereits vergeben! ";
               
             $lbl_status->configure(-foreground => 'red');
               
             return;
               
             }
               
         }
               
         }
               
         push @schuelerdaten, @neuedaten;
               
         @schuelerdat = sort @schuelerdaten;
               
         open (AUSGABE, ">daten.dat");
               
         print AUSGABE @schuelerdat;
               
         close (AUSGABE);
               
         $var_status = "Die Daten wurden erfolgreich hinzugefügt!";
                     
         $lbl_status->configure(-foreground => '#008000');
               
         }
               
         if ( $auswahl_radio == 2 ) #Überschreiben
               
         {
               
         open (AUSGABE, ">daten.dat");
               
         print AUSGABE @neuedaten;
               
         close (AUSGABE);
               
         $var_status = "Die Daten wurden erfolgreich ersetzt!";
                     
         $lbl_status->configure(-foreground => '#008000');
               
         }
               
        }
                           )->place( -x => 200, -y => 160, -height => 23, -width => 136);
my $Button4 = $import->Button(
                           -text => "Abbrechen",
                           -relief => "raised",
               -command => sub { $import->destroy() }
                           )->place( -x => 361, -y => 160, -height => 23, -width => 126);
my $Label3 = $import->Label(-text => "Status:",-anchor => 'w')->place( -x => 24, -y => 515, -height => 20, -width => 50);
$ein_btn->focus();
}