PageRenderTime 89ms CodeModel.GetById 18ms app.highlight 65ms RepoModel.GetById 1ms app.codeStats 0ms

/pruefungskonfig.cpp

http://abicalc.googlecode.com/
C++ | 598 lines | 472 code | 57 blank | 69 comment | 191 complexity | 5562a9dbc7c9947e5993228e1c69ab26 MD5 | raw file
  1//---------------------------------------------------------------------------
  2
  3#include <vcl.h>
  4#include <shellapi.h>
  5#pragma hdrstop
  6
  7
  8#include "pruefungskonfig.h"
  9#include "kursconfiguration.h"
 10#include "noteneing.h"
 11#include "pruefungen.h"
 12#include "start.h"
 13#include "info.h"
 14//---------------------------------------------------------------------------
 15#pragma package(smart_init)
 16#pragma resource "*.dfm"
 17Tpruefungskonfiguration *pruefungskonfiguration;
 18//---------------------------------------------------------------------------
 19__fastcall Tpruefungskonfiguration::Tpruefungskonfiguration(TComponent* Owner)
 20	: TForm(Owner)
 21{
 22
 23}
 24//---------------------------------------------------------------------------
 25
 26void __fastcall Tpruefungskonfiguration::CBBellClick(TObject *Sender)
 27{
 28	String P5 = this->CoBoP5->Items->Strings[this->CoBoP5->ItemIndex];
 29	if(this->LP1->Caption == "En"&& (this->CoBoP5->Items->Strings[this->CoBoP5->ItemIndex] == "Ma")){
 30		ShowMessage("Leider keine BELL möglich");
 31		this->CBBell->Enabled = false;
 32		this->CBBell->Checked = false;
 33		return;
 34	}
 35	if(this->CBBell->Checked){
 36		this->CoBoP5->Enabled = false;
 37	}else{
 38        this->CoBoP5->Enabled = true;
 39	}
 40	this->aenderungSpeichern();
 41}
 42//---------------------------------------------------------------------------
 43
 44void __fastcall Tpruefungskonfiguration::Button1_Click(TObject *Sender)
 45{
 46	//Core-Objekt wieder erneuern
 47	kurskonfiguration->core = this->core ;
 48	kurskonfiguration->Show();
 49	this->Close();
 50}
 51//---------------------------------------------------------------------------
 52
 53
 54void __fastcall Tpruefungskonfiguration::FormShow(TObject *Sender)
 55{
 56	if(this->core != NULL){
 57		Kurs *lk1 = this->core->getLKByPosition(1); //LK 1
 58		this->LP1->Caption = lk1->getName();
 59		Kurs *lk2 = this->core->getLKByPosition(2); //LK2
 60		this->LP2->Caption = lk2->getName();
 61
 62		String currP3 = NULL;
 63		String currP4 = NULL;
 64		String currP5 = NULL;
 65
 66		Pruefungen *p =this->core->getPruefungen() ;
 67
 68		if(p != NULL){
 69			currP3 = p->get(3)->getName();
 70			currP4 = p->get(4)->getName();
 71			currP5 = p->get(5)->getName();
 72
 73		}
 74
 75		this->CoBoP4->Enabled = false;
 76		this->CoBoP5->Enabled = false;
 77
 78		this->initP3(lk1, currP3); //Prüfungsfach 3 init
 79		this->initP4(lk1, currP4); //Prüfungsfach 4 init
 80		this->initP5(lk1, currP5); //Prüfungsfach 5 init
 81        if(p != NULL && p->get(5)->isBell()){
 82				this->CBBell->Checked = true;
 83		}
 84		this->aenderungSpeichern();
 85
 86    }else{
 87		throw new Exception("Keine Daten");
 88	}
 89}
 90//---------------------------------------------------------------------------
 91
 92void __fastcall Tpruefungskonfiguration::CoBoP3Change(TObject *Sender)
 93{
 94	this->CoBoP4->Enabled = true; // P3 gewählt, nun darf man auch P4 wählen
 95	int cCoBoP4 = this->CoBoP4->Items->Count;
 96	//Änderungen an P3
 97	if(this->LP1->Caption == "Ma"){
 98		/**
 99		 * Deutsch als P3
100		 **/
101
102		if(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex] == "De"){
103			this->initP4(this->core->getLKByPosition(1), NULL); //LK zur Identifikation
104            cCoBoP4 =  this->CoBoP4->Items->Count;
105			for(int i =0; i<cCoBoP4; i++){
106				if(this->CoBoP4->Items->Strings[i] == "De"){
107					this->CoBoP4->Items->Delete(i);
108					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
109				}
110				if(this->CoBoP4->Items->Strings[i] == "En"){
111					this->CoBoP4->Items->Delete(i);
112					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
113				}
114				if(this->CoBoP4->Items->Strings[i] == this->core->getFS()->getName()){
115					this->CoBoP4->Items->Delete(i);
116					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
117				}
118
119			}
120		}
121		/**
122		 * Ge als P3
123		 **/
124		 if(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex] == "Ge"){
125			this->initP4(this->core->getLKByPosition(1), NULL); //LK zur Identifikation
126			cCoBoP4 =  this->CoBoP4->Items->Count;
127			for(int i =0; i<cCoBoP4; i++){
128				if(this->CoBoP4->Items->Strings[i] == "Ge"){
129					this->CoBoP4->Items->Delete(i);
130					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
131				}
132				if(this->CoBoP4->Items->Strings[i] == "Wi"){
133					this->CoBoP4->Items->Delete(i);
134					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
135				}
136			}
137			
138
139
140		 }
141	}else if (this->LP1->Caption == "En"){
142		/**
143		 * Ma als P3
144		 **/
145		 if(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex] == "Ma"){
146			this->initP4(this->core->getLKByPosition(1), NULL); //LK zur Identifikation
147			cCoBoP4 =  this->CoBoP4->Items->Count;
148			for(int i =0; i<cCoBoP4; i++){
149				if(this->CoBoP4->Items->Strings[i] == "De"){
150					this->CoBoP4->Items->Delete(i);
151					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
152				}
153				if(this->CoBoP4->Items->Strings[i] == "Ma"){
154					this->CoBoP4->Items->Delete(i);
155					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
156				}
157			}
158		 }
159		 /**
160		 * De als P3
161		 **/
162		 if(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex] == "De"){
163			this->initP4(this->core->getLKByPosition(1), NULL); //LK zur Identifikation
164			cCoBoP4 =  this->CoBoP4->Items->Count;
165			for(int i =0; i<cCoBoP4; i++){
166				if(this->CoBoP4->Items->Strings[i] == "De"){
167					this->CoBoP4->Items->Delete(i);
168					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
169				}
170				if(this->CoBoP4->Items->Strings[i] == "Ma"){
171					this->CoBoP4->Items->Delete(i);
172					i--; //i um 1 verringern, da Liste bei löschung 1 kürzer
173				}
174			}
175		 }
176		 /**
177		 * Ge als P3
178		 **/
179		 if(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex] == "Ge"){
180			this->initP4(this->core->getLKByPosition(1), NULL); //LK zur Identifikation
181			cCoBoP4 =  this->CoBoP4->Items->Count;
182			for(int i =0; i<cCoBoP4; i++){
183				if(this->CoBoP4->Items->Strings[i] == "Wi"){
184					this->CoBoP4->Items->Delete(i);
185					i--;
186				}
187				if(this->CoBoP4->Items->Strings[i] == "Ge"){
188					this->CoBoP4->Items->Delete(i);
189					i--;
190				}
191			}
192		 }
193		 
194	}
195	this->CoBoP4->ItemIndex = 0;
196	this->CoBoP5->ItemIndex = 0;
197
198	this->CoBoP4Change(Sender);
199
200	this->aenderungSpeichern();
201}
202//---------------------------------------------------------------------------
203void __fastcall Tpruefungskonfiguration::CoBoP4Change(TObject *Sender)
204{
205	this->CoBoP5->Enabled = true; // P3 gewählt, nun darf man auch P4 wählen
206	String currP3 = this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex];
207	//
208    if(this->LP1->Caption == "De"){
209		this->initP5(this->core->getLKByPosition(1), NULL);
210		int cCoBoP5 =  this->CoBoP5->Items->Count;
211		for(int i =0; i<cCoBoP5; i++){
212			if(this->CoBoP5->Items->Strings[i] == "De"){
213			this->CoBoP5->Items->Delete(i);
214			}
215		}
216	}
217
218	if(this->LP1->Caption == "Ma"){
219			/**
220			 * P5
221			 **/
222			 this->initP5(this->core->getLKByPosition(1), NULL);
223
224			//aktuell ausgewähltes P4
225			String currP4 = this->CoBoP4->Items->Strings[this->CoBoP4->ItemIndex];
226			if(currP4 == "De"){
227				int cCoBoP5 =  this->CoBoP5->Items->Count;
228				for(int i =0; i<cCoBoP5; i++){
229					if(this->CoBoP5->Items->Strings[i] == "De"){
230						this->CoBoP5->Items->Delete(i);
231						i--;
232					}
233					if(this->CoBoP5->Items->Strings[i] == "Ma"){
234						this->CoBoP5->Items->Delete(i);
235						i--;
236					}
237					/**
238					 * drittes Prüfungsfach entfernen
239					 **/
240                    if(this->CoBoP5->Items->Strings[i] == currP3){
241						this->CoBoP5->Items->Delete(i);
242						i--;
243					}
244				}
245			}
246			if(currP4 == "En" || currP4 == this->core->getFS()->getName()){
247				int cCoBoP5 =  this->CoBoP5->Items->Count;
248				for(int i =0; i<cCoBoP5; i++){
249					if(this->CoBoP5->Items->Strings[i] == "Ma"){
250						this->CoBoP5->Items->Delete(i);
251						i--;
252					}
253					if(this->CoBoP5->Items->Strings[i] == "En"){
254						this->CoBoP5->Items->Delete(i);
255						i--;
256					}
257					if(this->CoBoP5->Items->Strings[i] == this->core->getFS()->getName()){
258						this->CoBoP5->Items->Delete(i);
259						i--;
260					}
261					/**
262					 * drittes Prüfungsfach entfernen
263					 **/
264					if(this->CoBoP5->Items->Strings[i] == currP3){
265						this->CoBoP5->Items->Delete(i);
266						i--;
267					}
268				}
269			}
270			if(currP4 == "Ge" || currP4 == "Wi"){
271				int cCoBoP5 =  this->CoBoP5->Items->Count;
272				for(int i =0; i<cCoBoP5; i++){
273					if(this->CoBoP5->Items->Strings[i] == "De"){
274						this->CoBoP5->Items->Delete(i);
275						i--;
276					}
277				}
278
279			}
280	}else if(this->LP1->Caption == "En"){
281    		/**
282			 * P5
283			 **/
284			this->initP5(this->core->getLKByPosition(1), NULL);
285			//aktuell ausgewähltes P4
286			String currP4 = this->CoBoP4->Items->Strings[this->CoBoP4->ItemIndex];
287			if(currP4 == "De"){
288				int cCoBoP5 =  this->CoBoP5->Items->Count;
289				for(int i =0; i<cCoBoP5; i++){
290					if(this->CoBoP5->Items->Strings[i] == "En"){
291						this->CoBoP5->Items->Delete(i);
292						i--;
293					}
294					if(this->CoBoP5->Items->Strings[i] == "De"){
295						this->CoBoP5->Items->Delete(i);
296						i--;
297					}
298					if(this->CoBoP5->Items->Strings[i] == "Wi"){
299						this->CoBoP5->Items->Delete(i);
300						i-- ;
301					}
302					if(this->CoBoP5->Items->Strings[i] == "Ge"){
303						this->CoBoP5->Items->Delete(i);
304						i-- ;
305					}
306					/**
307					 * drittes Prüfungsfach entfernen
308					 **/
309                    if(this->CoBoP5->Items->Strings[i] == currP3){
310						this->CoBoP5->Items->Delete(i);
311						i--;
312					}
313				}
314			}
315			if(currP4 == "Ma"){
316				int cCoBoP5 =  this->CoBoP5->Items->Count;
317				for(int i =0; i<cCoBoP5; i++){
318					if(this->CoBoP5->Items->Strings[i] == "Ma"){
319						this->CoBoP5->Items->Delete(i);
320						i-- ;
321					}
322					if(this->CoBoP5->Items->Strings[i] == "Wi"){
323						this->CoBoP5->Items->Delete(i);
324						i-- ;
325					}
326					if(this->CoBoP5->Items->Strings[i] == "Ge"){
327						this->CoBoP5->Items->Delete(i);
328						i-- ;
329					}
330					/**
331					 * drittes Prüfungsfach entfernen
332					 **/
333                    if(this->CoBoP5->Items->Strings[i] == currP3){
334						this->CoBoP5->Items->Delete(i);
335						i--;
336					}
337				}
338			}
339			if(currP4 == "Ge" || currP4 == "Wi"){
340				int cCoBoP5 =  this->CoBoP5->Items->Count;
341				for(int i =0; i<cCoBoP5; i++){
342					/**
343					 * drittes Prüfungsfach entfernen
344					 **/
345                    if(this->CoBoP5->Items->Strings[i] == currP3){
346						this->CoBoP5->Items->Delete(i);
347						i--;
348						this->CoBoP5->ItemIndex = 0;
349						this->CoBoP5->Enabled = false; //Gibt nur 1 Möglichkeit
350					}
351				}
352			}
353	}
354	this->CoBoP5->ItemIndex = 0;
355	this->aenderungSpeichern();
356}
357//---------------------------------------------------------------------------
358
359void Tpruefungskonfiguration::initP3(Kurs *lk1, String checked){
360	this->CoBoP3->Items->Clear();
361	if(lk1->getName() == "De"){
362				this->CoBoP3->Items->Add("Ma");
363				this->CoBoP3->ItemIndex = 0;
364				this->CoBoP3->Enabled = false;
365				this->CoBoP4->Enabled = true; //Sonst ist gar keine Auswahl möglich
366	}
367	if(lk1->getName() == "Ma"){
368				this->CoBoP3->Items->Add("De");
369				this->CoBoP3->Items->Add("Ge");
370				//this->CoBoP3->ItemIndex = 0;
371	}
372	if(lk1->getName() == "En"){
373				this->CoBoP3->Items->Add("Ma");
374				this->CoBoP3->Items->Add("De");
375				this->CoBoP3->Items->Add("Ge");
376				//this->CoBoP3->ItemIndex = 0;
377	}
378	if(checked != NULL){
379		for (int i =0; i < this->CoBoP3->Items->Count; i++) {
380        	if(this->CoBoP3->Items->Strings[i] == checked){
381				this->CoBoP3->ItemIndex = i;
382				this->CoBoP3->Enabled = true;
383			}
384		}
385	}
386}
387void Tpruefungskonfiguration::initP4(Kurs *lk1, String checked){
388	this->CoBoP4->Items->Clear();
389	if(lk1->getName() == "De"){
390		this->CoBoP4->Items->Add("Ge");
391		//this->CoBoP4->ItemIndex = 0;
392		Kurs *wi = this->core->getKursByName("Wi");
393		if(wi != NULL){
394			if(!wi->isAbg()){
395				this->CoBoP4->Items->Add("Wi");
396				this->CoBoP4->ItemIndex = -1;
397			}else{
398					  this->CoBoP4->Enabled = false;
399					  this->CoBoP5->Enabled = true;
400					  this->CoBoP4->ItemIndex = 0;
401			}
402		}
403
404	}
405	if(lk1->getName() == "Ma"){
406				Kurs *fs = this->core->getFS();
407				this->CoBoP4->Items->Add("Ge");
408				this->CoBoP4->Items->Add("En");
409				this->CoBoP4->Items->Add(fs->getName());
410			   //	this->CoBoP4->ItemIndex = 0;
411				Kurs *wi = this->core->getKursByName("Wi");
412				if(wi != NULL){
413					if(!wi->isAbg()){
414						this->CoBoP4->Items->Add("Wi");
415					}
416				}
417				this->CoBoP4->Items->Add("De");
418	}
419	if(lk1->getName() == "En"){
420				this->CoBoP4->Items->Add("Ge");
421				this->CoBoP4->Items->Add("De");
422				this->CoBoP4->Items->Add("Ma");
423				Kurs *wi = this->core->getKursByName("Wi");
424				if(wi != NULL){
425					if(!wi->isAbg()){
426						this->CoBoP4->Items->Add("Wi");
427					}
428				}
429				//this->CoBoP4->ItemIndex = 0;
430
431	}
432
433	if(checked != NULL){
434		for (int i =0; i < this->CoBoP4->Items->Count; i++) {
435			if(this->CoBoP4->Items->Strings[i] == checked){
436				this->CoBoP4->ItemIndex = i;
437				this->CoBoP4->Enabled = true;
438			}
439		}
440	}
441
442
443}
444void Tpruefungskonfiguration::initP5(Kurs *lk1, String checked){
445	this->CoBoP5->Items->Clear();
446	if(lk1->getName() == "De"){
447		this->CoBoP5->Items->Add("En");
448		this->CoBoP5->Items->Add(this->core->getFS()->getName());
449		//this->CoBoP5->ItemIndex = 0;
450	}
451	if(lk1->getName() == "Ma"){
452    	Kurs *fs = this->core->getFS();
453		this->CoBoP5->Items->Add(fs->getName());
454		this->CoBoP5->Items->Add("En");
455		this->CoBoP5->Items->Add("De");
456		//this->CoBoP5->ItemIndex = 0;
457	}
458	if(lk1->getName() == "En"){
459		this->CoBoP5->Items->Add("Ma");
460		this->CoBoP5->Items->Add("De");
461		//this->CoBoP5->ItemIndex =0;
462	}
463
464	for (int i =0; i < this->CoBoP5->Items->Count; i++) {
465		String tmp = this->CoBoP5->Items->Strings[i];
466		if(tmp==checked){
467			this->CoBoP5->ItemIndex = i;
468			this->CoBoP5->Enabled = true;
469		}
470	}
471
472}
473
474void __fastcall Tpruefungskonfiguration::CoBoP5Change(TObject *Sender)
475{
476	if(this->CoBoP5->Items->Strings[this->CoBoP5->ItemIndex] != "Ma"){
477		this->CBBell->Enabled = true;
478	}else {
479    	this->CBBell->Enabled = false;
480	}
481	this->aenderungSpeichern();
482}
483//---------------------------------------------------------------------------
484
485void __fastcall Tpruefungskonfiguration::Button2_Click(TObject *Sender)
486{
487  this->aenderungSpeichern();
488
489   if(this->core->getPruefungen()->get(1) != NULL && this->core->getPruefungen()->get(2) != NULL && this->core->getPruefungen()->get(3) != NULL && this->core->getPruefungen()->get(4) != NULL && this->core->getPruefungen()->get(5) != NULL){
490
491   //if(this->CoBoP3->ItemIndex != -1 && this->CoBoP4->ItemIndex != -1 && this->CoBoP5->ItemIndex != -1){
492
493		noteneingabe->core = this->core;
494		noteneingabe->Show();
495   		this->Close();
496   }else{
497       ShowMessage("Bitte Prüfungen wählen");
498   }
499
500}
501//---------------------------------------------------------------------------
502
503void Tpruefungskonfiguration::aenderungSpeichern(){
504	this->core->isChanged = true;
505	Pruefungen *p = new Pruefungen();
506	Kurse_Pruefung *p1 = new Kurse_Pruefung(this->LP1->Caption);
507	if(this->CBNP1->Checked)
508    	p1->setNachpruefung(true);
509	p->add(p1, 1);
510	Kurse_Pruefung *p2 = new Kurse_Pruefung(this->LP2->Caption);
511	if(this->CBNP2->Checked)
512		p2->setNachpruefung(true);
513	p->add(p2, 2);
514	Kurse_Pruefung *p3 = new Kurse_Pruefung(this->CoBoP3->Items->Strings[this->CoBoP3->ItemIndex]);
515	if(this->CBNP3->Checked)
516		p3->setNachpruefung(true);
517	p->add(p3, 3);
518	Kurse_Pruefung *p4 = new Kurse_Pruefung(this->CoBoP4->Items->Strings[this->CoBoP4->ItemIndex]);
519	p->add(p4, 4);
520	Kurse_Pruefung *p5 = new Kurse_Pruefung(this->CoBoP5->Items->Strings[this->CoBoP5->ItemIndex]);
521	if(this->CBBell->Checked){
522    	p5->setBell(true);
523	}
524	p->add(p5, 5);
525
526	this->core->clearPruefungen();
527	this->core->setPruefungen(p);
528
529
530}
531
532void __fastcall Tpruefungskonfiguration::CBNP1Click(TObject *Sender)
533{
534	TCheckBox *sender = dynamic_cast<TCheckBox*>(Sender);
535	if(sender->Name == "CBNP1" && sender->Checked){
536    	this->core->getPruefungen()->get(1)->setNachpruefung(true);
537	}
538	if(sender->Name == "CBNP2" && sender->Checked){
539		this->core->getPruefungen()->get(2)->setNachpruefung(true);
540	}
541	if(sender->Name == "CBNP3" && sender->Checked){
542		this->core->getPruefungen()->get(3)->setNachpruefung(true);
543	}
544
545}
546//---------------------------------------------------------------------------
547
548
549
550void __fastcall Tpruefungskonfiguration::Beenden1Click(TObject *Sender)
551{
552	Application->Terminate();
553}
554//---------------------------------------------------------------------------
555
556//---------------------------------------------------------------------------
557
558void __fastcall Tpruefungskonfiguration::Speichern1Click(TObject *Sender)
559{
560	if(this->core->savePath == ""){
561		if(this->SaveDialog1->Execute()){
562			this->core->savePath = this->SaveDialog1->FileName;
563        }
564	}
565	this->core->saveToFile(this->core->savePath);
566}
567//---------------------------------------------------------------------------
568
569void __fastcall Tpruefungskonfiguration::Speichernunter1Click(TObject *Sender)
570{
571	if(this->SaveDialog1->Execute()){
572			this->core->savePath = this->SaveDialog1->FileName;
573			this->core->saveToFile(this->core->savePath);
574	}
575}
576//---------------------------------------------------------------------------
577
578void __fastcall Tpruefungskonfiguration::Drucken1Click(TObject *Sender)
579{
580	String name = InputBox("Name des Schülers", "Bitte den Namen des Schülers eingeben!", "");
581	if(name != "")
582		this->core->print(name);
583}
584//---------------------------------------------------------------------------
585
586void __fastcall Tpruefungskonfiguration::Info1Click(TObject *Sender)
587{
588	infoform->Show();
589}
590//---------------------------------------------------------------------------
591
592void __fastcall Tpruefungskonfiguration::Hilfebenutzen1Click(TObject *Sender)
593{
594	ShellExecute(Handle, "open", "http://redmine.vadaru.com/projects/abicalc/wiki/Benutzerhandbuch",
595	NULL,NULL,SW_SHOWDEFAULT);
596}
597//---------------------------------------------------------------------------
598