//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop
#include "mainframeUnit.h"
#include "SkemaFrameUnit.h"
#include "Edderkop.h"
#include "PlanListeUnit.h"
#include "OutputForm.h"
#include "GenererUnit.h"
#include "AboutUnit.h"
//---------------------------------------------------------------------------
#pragma resource "*.dfm"
TMainFrame *MainFrame;
//---------------------------------------------------------------------------
///Konstruktør
__fastcall TMainFrame::TMainFrame(TComponent* Owner)
	: TForm(Owner)
{
   Caption = "SkemaSuper++ v1.0 beta - <tom>";

   //default tilstande sættes.
   TidsSpecifikationer = false;
   Skrivebeskyttet = true;
   Genereret = false;
   PlanListeHentet = false;

   //Listerne nulstilles.
   AntalLokaler = 0;
   AntalHold = 0;
   AntalLaerer = 0;
   dage[0] = "Mandag"; dage[1] = "Tirsdag"; dage[2] = "Onsdag";
   dage[3] = "Torsdag"; dage[4] = "Fredag";
   tider[0] = "08.00 - 09.00"; tider[1] = "09.00 - 10.00";
   tider[2] = "10.00 - 11.00"; tider[3] = "11.00 - 12.00";
   tider[4] = "12.00 - 13.00"; tider[5] = "13.00 - 14.00";
   tider[6] = "14.00 - 15.00"; tider[7] = "15.00 - 16.00";
   tider[8] = "16.00 - 17.00";

   //objekt af edderkoppen oprettes.
   e = new Edderkop('d');

   Application->OnHint = VisHint; // Viser hints
   MainFrame->NulstilStatusBar();
}//
void __fastcall TMainFrame::VisHint(TObject* Sender)
{
	StatusBar->Panels->Items[8]->Text = Application->Hint;
}
//---------------------------------------------------------------------------
void TMainFrame::NulstilStatusBar()
{
	StatusBar->Panels->Items[1]->Text = 0;
    StatusBar->Panels->Items[3]->Text = 0;
    StatusBar->Panels->Items[5]->Text = 0.0;
    StatusBar->Panels->Items[7]->Text = 0;
}
///Funktionen beregner de forskellige indekser som skal fremgå af baren.
void TMainFrame::UpdateStatusBar()
{
    double Procent(0);
    double CV(0);

    //indekserne beregnes.
    int LL = e->BeregnTotaleLagteLektioner();
    int PL = e->BeregnTotalePlanlagteLektioner();

    if(PL > 0)
      Procent = (double(LL)/double(PL)) * 100;

    int ML = e->AntalMellemLektioner();

    //indekserne indsættes
	StatusBar->Panels->Items[1]->Text = PL;
    StatusBar->Panels->Items[3]->Text = LL;
    StatusBar->Panels->Items[5]->Text = FloatToStrF(Procent, ffNumber, 3, 2);
    StatusBar->Panels->Items[7]->Text = ML;
}
void TMainFrame::NyEdderkop()
{
	e = new Edderkop('d');
}
void TMainFrame::SletEdderkop()
{
}
//---------------------------Fil menu funktioner------------------------------//
///Hent en plan ind i programmet.
void __fastcall TMainFrame::MFPanel2Click(TObject *Sender)
{
   Out->Show();
   MainFrame->StatusBar->Panels->Items[8]->Text = "Kontakter Databasen. Kan godt tage noget tid!";
   PlanListeForm->ShowModal();
}//
///Exit.
void __fastcall TMainFrame::Exit1Click(TObject *Sender)
{
	MainFrame->Close();
}//
///Gem projekt til databasen.
void __fastcall TMainFrame::Gemprojekt1Click(TObject *Sender)
{
	if(!Skrivebeskyttet)
    {
      e->Gem();
      comm.MeddelelseBox("Skemaerne er gemt i databasen!");
    }
    else
      comm.FejlBox("Programmet er sat op til ikke at skrive til databasen!");
}//
///Printer skemaet på den aktive skema frame.
void __fastcall TMainFrame::Printskema1Click(TObject *Sender)
{
   char type;
   char* ID;
	TSkemaFrame* skemaframe = dynamic_cast<TSkemaFrame*>(ActiveMDIChild);
   if(skemaframe)
   {
		skemaframe->Print();
   }
   else
      comm.FejlBox("Intet at printe");
}//
///Sletter alt gammelt data i det indlæste projekt.
void __fastcall TMainFrame::NytSkemaprojekt1Click(TObject *Sender)
{
	e->Slet();
    Genereret = false;
    MainFrame->UpdateStatusBar();
    comm.MeddelelseBox("Skemaerne i projektet er nu slettet!");
}//
///Henter et nyt projekt.
void __fastcall TMainFrame::Hentprojekt1Click(TObject *Sender)
{
   comm.NulstilSpecifikation("Hentning");
   if(TidsSpecifikationer)
     GenSpe->Show();
   PlanListeForm->ShowModal();
}//
///exportere projektet til 3 filer...!!
void __fastcall TMainFrame::ExportProjectClick(TObject *Sender)
{
    if(PlanListeHentet)
    {
      e->GemTilFil();
      comm.MeddelelseBox("Skemaerne er nu exporteret til 3 filer.!\n'HoldSkemaer.txt', 'LaererSkemaer.txt' og 'LokaleSkemaer.txt'");
    }
    else
      comm.FejlBox("Der er ikke åbnet nogen plan!");
}//
//----------------------------Skema menu--------------------------------------//
///åbner en blank skema frame.
void __fastcall TMainFrame::MFPanel8Click(TObject *Sender)
{
   TSkemaFrame* SkemaFrame = new TSkemaFrame(this);

   SkemaFrame->SFStringGrid1->Cells[1][0] = dage[0];
   SkemaFrame->SFStringGrid1->Cells[2][0] = dage[1];
   SkemaFrame->SFStringGrid1->Cells[3][0] = dage[2];
   SkemaFrame->SFStringGrid1->Cells[4][0] = dage[3];
   SkemaFrame->SFStringGrid1->Cells[5][0] = dage[4];

   for(int i=1; i<9; i++)
	   SkemaFrame->SFStringGrid1->Cells[0][i] = i;
	SkemaFrame->Show();
}//
///Åbner et skema frame initialiseret til Hold.
void __fastcall TMainFrame::MFPanel10Click(TObject *Sender)
{
	TSkemaFrame* SkemaFrame = new TSkemaFrame(this);

   SkemaFrame->SFComboBox1->Text = "Hold";
   SkemaFrame->SFComboBox2->Enabled = true;
}//
///Åbner et skema frame initialiseret til Laerer.
void __fastcall TMainFrame::MFPanel11Click(TObject *Sender)
{
	TSkemaFrame* SkemaFrame = new TSkemaFrame(this);

   SkemaFrame->SFComboBox1->Text = "Laerer";
   SkemaFrame->SFComboBox2->Enabled = true;
}//
///Åbner et skema frame initialiseret til LOkaler.
void __fastcall TMainFrame::MFPanel12Click(TObject *Sender)
{
	TSkemaFrame* SkemaFrame = new TSkemaFrame(this);

   SkemaFrame->SFComboBox1->Text = "Lokale";
   SkemaFrame->SFComboBox2->Enabled = true;
}//
///Hjælpe funktion til at lukke en skema frame.
void TMainFrame::luk(int type)
{
   switch(type)
   {
      case 1:
      {
      	TSkemaFrame* skemaframe = dynamic_cast<TSkemaFrame*>(ActiveMDIChild);
        if(skemaframe)
          skemaframe->Close();
   	  }
   }
}//
///Minimere alle åbnede skemaframe vinduer -1.
void __fastcall TMainFrame::MFPanel7Click(TObject *Sender)
{
	for(int i = 0; i < MDIChildCount; i++)
   	MDIChildren[i]->WindowState = wsMinimized;
}//
///Lukker alle åbnede skemaframe vinduer.
void __fastcall TMainFrame::MFPanel6Click(TObject *Sender)
{
	for(int i = 0; i < MDIChildCount; i++)
		MDIChildren[i]->Close();
}//
//----------------------------Genererings menu--------------------------------//
void __fastcall TMainFrame::MFPanel9Click(TObject *Sender)
{
	GenereringsFrame->ShowModal();
}
void __fastcall TMainFrame::Beregnskemaer1Click(TObject *Sender)
{
	GenereringsFrame->ShowModal();
}
void __fastcall TMainFrame::AutoGenererClick(TObject *Sender)
{
	GenereringsFrame->AutoGenerering();
}//--------------------------Opsætnings menu-----------------------------------//
void __fastcall TMainFrame::Cascade1Click(TObject *Sender)
{
    Cascade();
}
void __fastcall TMainFrame::Tile1Click(TObject *Sender)
{
    Tile();
}
///viser de forskellige operationers løbetid i speciel form.
void __fastcall TMainFrame::SpecifikationerClick(TObject *Sender)
{
    Specifikationer->Checked = !Specifikationer->Checked;
    if(Specifikationer->Checked)
    {
      GenSpe->Show();
      TidsSpecifikationer = true;
    }
    else
    {
      GenSpe->Close();
      TidsSpecifikationer = false;
    }
}//
void __fastcall TMainFrame::SkrivebeskytDBClick(TObject *Sender)
{
    SkrivebeskytDB->Checked = !SkrivebeskytDB->Checked;
    if(SkrivebeskytDB->Checked)
      Skrivebeskyttet = true;
    else
      Skrivebeskyttet = false;
}
///VIser en kommunikations klasse hvorpå resten af komponenterne kan skrive på.
void __fastcall TMainFrame::CommBoxClick(TObject *Sender)
{
	CommBox->Checked = !CommBox->Checked;
    if(CommBox->Checked)
      Out->Show();
    else
      Out->Close();
}//
//-----------------------------Hjælp menu-------------------------------------//
void __fastcall TMainFrame::About2Click(TObject *Sender)
{
	About->ShowModal();
}
//--------------------------Panel popnings funktioner-------------------------//
//Følgende funktioner får panelerne, på toolbaren til at hoppe op og ned når
//man kører hen over dem.
void __fastcall TMainFrame::ToolbarPanelMouseMove(TObject *Sender,
	TShiftState Shift, int X, int Y)
{
   if(Panel1->BevelOuter != bvNone)		Panel1->BevelOuter = bvNone;
   if(MFPanel1->BevelOuter != bvNone)		MFPanel1->BevelOuter = bvNone;
   if(MFPanel2->BevelOuter != bvNone)		MFPanel2->BevelOuter = bvNone;
   if(MFPanel4->BevelOuter != bvNone)		MFPanel4->BevelOuter = bvNone;
   if(MFPanel5->BevelOuter != bvNone)		MFPanel5->BevelOuter = bvNone;
   if(MFPanel6->BevelOuter != bvNone)		MFPanel6->BevelOuter = bvNone;
   if(MFPanel7->BevelOuter != bvNone)		MFPanel7->BevelOuter = bvNone;
   if(MFPanel8->BevelOuter != bvNone)		MFPanel8->BevelOuter = bvNone;
   if(MFPanel9->BevelOuter != bvNone)		MFPanel9->BevelOuter = bvNone;
   if(Image1->Visible == false)
     Image1->Visible = true;
   if(Image13->Visible == true)
     Image13->Visible = false;

   if(MFPanel10->BevelOuter != bvNone)		MFPanel10->BevelOuter = bvNone;
   if(MFPanel11->BevelOuter != bvNone)		MFPanel11->BevelOuter = bvNone;
   if(MFPanel12->BevelOuter != bvNone)		MFPanel12->BevelOuter = bvNone;
}  // rækkefølge 1 2 4 5 6 7 8 10 11 12 9
void __fastcall TMainFrame::MFPanel1MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
	if(MFPanel1->BevelOuter != bvRaised)		MFPanel1->BevelOuter = bvRaised;
   if(MFPanel2->BevelOuter != bvNone)		MFPanel2->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel2MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel1->BevelOuter != bvNone)		MFPanel1->BevelOuter = bvNone;
   if(MFPanel2->BevelOuter != bvRaised)		MFPanel2->BevelOuter = bvRaised;
   if(MFPanel4->BevelOuter != bvNone)		MFPanel4->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel4MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel2->BevelOuter != bvNone)		MFPanel2->BevelOuter = bvNone;
   if(MFPanel4->BevelOuter != bvRaised)		MFPanel4->BevelOuter = bvRaised;
   if(MFPanel5->BevelOuter != bvNone)		MFPanel5->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel5MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel4->BevelOuter != bvNone)		MFPanel4->BevelOuter = bvNone;
   if(MFPanel5->BevelOuter != bvRaised)		MFPanel5->BevelOuter = bvRaised;
   if(MFPanel6->BevelOuter != bvNone)		MFPanel6->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel6MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel5->BevelOuter != bvNone)		MFPanel5->BevelOuter = bvNone;
	if(MFPanel6->BevelOuter != bvRaised)		MFPanel6->BevelOuter = bvRaised;
   if(MFPanel7->BevelOuter != bvNone)		MFPanel7->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel7MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel6->BevelOuter != bvNone)		MFPanel6->BevelOuter = bvNone;
   if(MFPanel7->BevelOuter != bvRaised)		MFPanel7->BevelOuter = bvRaised;
   if(MFPanel8->BevelOuter != bvNone)		MFPanel8->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel8MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel7->BevelOuter != bvNone)		MFPanel7->BevelOuter = bvNone;
   if(MFPanel8->BevelOuter != bvRaised)		MFPanel8->BevelOuter = bvRaised;
   if(MFPanel10->BevelOuter != bvNone)		MFPanel10->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel9MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel12->BevelOuter != bvNone)		MFPanel12->BevelOuter = bvNone;
   if(MFPanel9->BevelOuter != bvRaised)		MFPanel9->BevelOuter = bvRaised;
   if(Image1->Visible == true)
     Image1->Visible = false;
   if(Image13->Visible == false)
     Image13->Visible = true;

}
void __fastcall TMainFrame::MFPanel10MouseMove(TObject *Sender,
	TShiftState Shift, int X, int Y)
{
   if(MFPanel8->BevelOuter != bvNone)		MFPanel8->BevelOuter = bvNone;
   if(MFPanel10->BevelOuter != bvRaised)		MFPanel10->BevelOuter = bvRaised;
   if(MFPanel11->BevelOuter != bvNone)		MFPanel11->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel11MouseMove(TObject *Sender,
	TShiftState Shift, int X, int Y)
{
   if(MFPanel10->BevelOuter != bvNone)		MFPanel10->BevelOuter = bvNone;
   if(MFPanel11->BevelOuter != bvRaised)		MFPanel11->BevelOuter = bvRaised;
   if(MFPanel12->BevelOuter != bvNone)		MFPanel12->BevelOuter = bvNone;
}
void __fastcall TMainFrame::MFPanel12MouseMove(TObject *Sender,
	TShiftState Shift, int X, int Y)
{
   if(MFPanel11->BevelOuter != bvNone)		MFPanel11->BevelOuter = bvNone;
   if(MFPanel12->BevelOuter != bvRaised)		MFPanel12->BevelOuter = bvRaised;
   if(MFPanel9->BevelOuter != bvNone)		MFPanel9->BevelOuter = bvNone;
   if(Image1->Visible == false)
     Image1->Visible = true;
   if(Image13->Visible == true)
     Image13->Visible = false;
}
void __fastcall TMainFrame::FormMouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(Panel1->BevelOuter != bvNone)         Panel1->BevelOuter = bvNone;
   if(MFPanel1->BevelOuter != bvNone)		MFPanel1->BevelOuter = bvNone;
   if(MFPanel2->BevelOuter != bvNone)		MFPanel2->BevelOuter = bvNone;
   if(MFPanel4->BevelOuter != bvNone)		MFPanel4->BevelOuter = bvNone;
   if(MFPanel5->BevelOuter != bvNone)		MFPanel5->BevelOuter = bvNone;
   if(MFPanel6->BevelOuter != bvNone)		MFPanel6->BevelOuter = bvNone;
   if(MFPanel7->BevelOuter != bvNone)		MFPanel7->BevelOuter = bvNone;
   if(MFPanel8->BevelOuter != bvNone)		MFPanel8->BevelOuter = bvNone;
   if(MFPanel9->BevelOuter != bvNone)		MFPanel9->BevelOuter = bvNone;
   if(Image1->Visible == false)
     Image1->Visible = true;
   if(Image13->Visible == true)
     Image13->Visible = false;

   if(MFPanel10->BevelOuter != bvNone)		MFPanel10->BevelOuter = bvNone;
   if(MFPanel11->BevelOuter != bvNone)		MFPanel11->BevelOuter = bvNone;
   if(MFPanel12->BevelOuter != bvNone)		MFPanel12->BevelOuter = bvNone;
}
void __fastcall TMainFrame::Panel1MouseMove(TObject *Sender, TShiftState Shift,
	int X, int Y)
{
   if(MFPanel4->BevelOuter != bvNone)		MFPanel4->BevelOuter = bvNone;
   if(Panel1->BevelOuter != bvRaised)		Panel1->BevelOuter = bvRaised;
   if(MFPanel5->BevelOuter != bvNone)		MFPanel5->BevelOuter = bvNone;
}
//----------------------------------------------------------------------------//

