//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "PlanListeUnit.h"
#include "mainframeUnit.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TPlanListeForm *PlanListeForm;
//---------------------------------------------------------------------------
__fastcall TPlanListeForm::TPlanListeForm(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TPlanListeForm::PlanValgKnapClick(TObject *Sender)
{
	string temp;
    int i;
    MainFrame->SletEdderkop();
    MainFrame->NyEdderkop();
    Tid t;
    double Tid;
    ++t;
    if(MainFrame->e->VaelgPlan(MainFrame->PlanListeArray[PlanListe->ItemIndex].c_str()))
    {
      //Hold liste hentes.
      MainFrame->e->StartHentningAfListe('h');
      for(i = 0; MainFrame->e->HentNaestePaaListen(temp); i++)
      {
        MainFrame->HoldListe[i] = temp;
        comm << temp;
      }
      MainFrame->AntalHold = i;

      //Lærer liste hentes.
      MainFrame->e->StartHentningAfListe('l');
      for(i = 0; MainFrame->e->HentNaestePaaListen(temp); i++)
      {
        MainFrame->LaererListe[i] = temp;
        comm << temp;
      }
      MainFrame->AntalLaerer = i;

      //Lokale liste hentes.
      MainFrame->e->StartHentningAfListe('k');
      for(i = 0; MainFrame->e->HentNaestePaaListen(temp); i++)
      {
        comm << temp;
        MainFrame->LokaleListe[i] = temp;
      }
      MainFrame->AntalLokaler = i;

      MainFrame->StatusBar->Panels->Items[8]->Text = "Planen er indlæst!";
      MainFrame->Genereret = false;
      MainFrame->UpdateStatusBar();
      PlanListeForm->Close();

      MainFrame->MFPanel9->Enabled = true;
      MainFrame->Beregnskemaer1->Enabled = true;
      MainFrame->AutoGenerer->Enabled = true;
      --t;
      t >> Tid;
      comm.IndsaetISpecifikation(Tid, "Hentning af Plan:", 2);
      string temp = "SkemaSuper++ v1.0 beta - ";
      temp += MainFrame->PlanListeArray[PlanListe->ItemIndex];
      MainFrame->Caption = temp.c_str();
    }
    --t;
}
//---------------------------------------------------------------------------
void __fastcall TPlanListeForm::AnnullerKnapClick(TObject *Sender)
{
    PlanListeForm->Close();
}
//---------------------------------------------------------------------------
void __fastcall TPlanListeForm::FormShow(TObject *Sender)
{
 	string ID;
    int i(0);
    Tid t;
    double Tid(0);
    ++t;
    if(!MainFrame->PlanListeHentet)
    {
      PlanListe->Items->Clear();
      //En plan liste indhentes.
      MainFrame->e->StartHentningAfPlanListe();
      while(MainFrame->e->HentNaestePlanID(ID))
      {
        MainFrame->PlanListeArray[i++] = ID;
        PlanListe->Items->Add(ID.c_str());
      }
      --t;
      t >> Tid;
      comm.IndsaetISpecifikation(Tid, "Indlæsning af Planliste: ", 1);
      MainFrame->PlanListeHentet = true;
    }
    --t;
}
//---------------------------------------------------------------------------
