PageRenderTime 113ms CodeModel.GetById 16ms app.highlight 89ms RepoModel.GetById 1ms app.codeStats 0ms

/core.cpp

http://abicalc.googlecode.com/
C++ | 1049 lines | 904 code | 104 blank | 41 comment | 288 complexity | 4345aa11182cd6a8d2a8c43f94dcb4d5 MD5 | raw file
   1//---------------------------------------------------------------------------
   2
   3
   4#pragma hdrstop
   5
   6#include "core.h"
   7
   8//---------------------------------------------------------------------------
   9bool Core::addKurs(Kurs *kurs){
  10	if(this->cKurse>20 || kurs == NULL){
  11		return false;
  12	}
  13	if(kurs->isLK()){
  14    	if(this->cLK >= 2){
  15        	return false;
  16		}
  17		this->lk[this->cLK] = kurs;
  18		this->cLK++;
  19		return true;
  20	}
  21	this->kurse[this->cKurse] = kurs;
  22	this->cKurse++;
  23	return true;
  24}
  25
  26Kurs* Core::getKursByName(String name){
  27	if(this->lk[0] != NULL && this->lk[0]->getName() == name)
  28		return this->lk[0];
  29	if(this->lk[1] != NULL && this->lk[1]->getName() == name)
  30		return this->lk[1];
  31
  32	for(int i =0; i<this->cKurse; i++){
  33		if(this->kurse[i] != NULL){
  34			if(this->kurse[i]->getName() == name){
  35				return  this->kurse[i];
  36			}
  37		}
  38	}
  39
  40	return NULL;
  41}
  42
  43void Core::clearKurse(){
  44	for (int i = 0; i < this->cKurse; i++) {
  45    	this->kurse[i] = NULL;    
  46	}
  47	this->cKurse = 0;
  48	for (int i=0; i< this->cLK; i++) {
  49        this->lk[i] = NULL;
  50	}
  51	this->cLK =0;
  52}
  53
  54Kurs* Core::getLKByPosition(int pos){
  55	if(pos == 1 || pos == 2)
  56		return this->lk[pos-1];
  57	else
  58        return NULL;
  59}
  60
  61Kurs* Core::getFS(){
  62	Kurs *tmp = this->getKursByName("Frz A");
  63	if(tmp != NULL){
  64    	return tmp;
  65	}
  66	tmp = this->getKursByName("Frz B");
  67	if(tmp != NULL){
  68    	return tmp;
  69	}
  70	tmp = this->getKursByName("Ru A");
  71	if(tmp != NULL){
  72    	return tmp;
  73	}
  74	tmp = this->getKursByName("Ru B");
  75	if(tmp != NULL){
  76    	return tmp;
  77	}
  78
  79	return NULL;
  80}
  81
  82int Core::anzahlKurs(){
  83	return this->cKurse+ this->cLK;
  84}
  85
  86double Core::getAverageByYear(int year){
  87	if(year>4 || year < 1){
  88    	return -1;
  89	}
  90	int count =0;
  91	double ret =0;
  92	for(int i =0; i<this->anzahlKurs(); i++){
  93		Kurs *tmp = this->iterateKurse(i);
  94		if(tmp->getNote(year) != -1 && tmp->getNote(year) != -2){
  95			ret += tmp->getNote(year);
  96			count++;
  97		}
  98
  99	}
 100	if(count != 0){
 101    	return ret/count;
 102	}
 103	return -1 ;
 104}
 105
 106
 107/*void Core::orderKurse(){
 108	Kurs *tmp[20];
 109	tmp[0] = this->getLKByPosition(1);
 110	tmp[1] = this->getLKByPosition(2);
 111	for(int i = 0; i<this->cKurse; i++){
 112		Kurs* sTmp  = this->kurse[i];
 113		if(sTmp != NULL && !sTmp->isLK()){
 114        	tmp[2+i] = sTmp;
 115		}
 116	}
 117    for(int i =0; i<20; i++){
 118    	this->kurse[i] = tmp[i];
 119	}
 120
 121}    */
 122
 123Kurs *Core::iterateKurse(int index){
 124    if(index < 2){
 125    	return this->lk[index];
 126	}
 127	if(this->cKurse < index-2){
 128    	return NULL;
 129	}
 130    return this->kurse[index-2];
 131}
 132void Core::setPruefungen(Pruefungen * p){
 133	this->pruefungen = p;
 134}
 135
 136Pruefungen * Core::getPruefungen(){
 137	return this->pruefungen;
 138}
 139
 140void Core::clearPruefungen(){
 141	this->pruefungen = NULL;
 142}
 143
 144
 145void Core::setAbgHalbjahre(int wert){
 146	if(wert<=5 && wert>= 0){
 147    	this->kurse_abg = wert;
 148	}
 149}
 150int Core::getAbgHalbjahre(){
 151	return this->kurse_abg;
 152}
 153
 154int Core::getBlockPunkte(int block){
 155	if(block == 1){
 156		//(Summe Kurshalbjahre)/(Anzahl Kurshalbjahresergebnisse)*40= BLOCK I
 157		int summe = 0;
 158		int summeLK = 0;
 159		int hj = 0;
 160
 161		if(this->lk[0] != NULL){
 162			int note = this->lk[0]->getNote(1);
 163			if(!(note == -1 || note == -2)){
 164				summeLK += note;
 165				hj += 2;
 166			}
 167			note = this->lk[0]->getNote(2);
 168			if(!(note == -1 || note == -2)){
 169				summeLK += note;
 170				hj += 2;
 171			}
 172			note = this->lk[0]->getNote(3);
 173			if(!(note == -1 || note == -2)){
 174				summeLK += note;
 175				hj += 2;
 176			}
 177			note = this->lk[0]->getNote(4);
 178			if(!(note == -1 || note == -2)){
 179				summeLK += note;
 180				hj += 2;
 181			}
 182        }
 183		//LK 2
 184		if(this->lk[1] != NULL){
 185			int note = this->lk[1]->getNote(1);
 186			if(!(note == -1 || note == -2)){
 187				summeLK += note;
 188				hj += 2;
 189			}
 190			note = this->lk[1]->getNote(2);
 191			if(!(note == -1 || note == -2)){
 192				summeLK += note;
 193				hj += 2;
 194			}
 195			note = this->lk[1]->getNote(3);
 196			if(!(note == -1 || note == -2)){
 197				summeLK += note;
 198				hj += 2;
 199			}
 200			note = this->lk[1]->getNote(4);
 201			if(!(note == -1 || note == -2)){
 202				summeLK += note;
 203				hj += 2;
 204			}
 205		}
 206			summe += summeLK*2;
 207
 208		for(int i = 0; i< this->cKurse; i++){
 209			int note1, note2, note3, note4;
 210			if(this->kurse[i] != NULL){
 211				note1 =  this->kurse[i]->getNote(1);
 212				note2 =  this->kurse[i]->getNote(2);
 213				note3 =  this->kurse[i]->getNote(3);
 214				note4 =  this->kurse[i]->getNote(4);
 215				if(note1 != -1 && note1 != -2){
 216					summe += note1;
 217					hj++;
 218				}
 219				if(note2 != -1 && note2 != -2){
 220					summe += note2;
 221					hj++;
 222				}
 223				if(note3!= -1 && note3 != -2){
 224					summe += note3;
 225					hj++;
 226				}
 227				if(note4 != -1 && note4 != -2){
 228					summe += note4;
 229					hj++;
 230				}
 231			}
 232		}
 233		if(hj != 0){
 234			float fSumme = (float)summe;
 235			float fHj = (float)hj;
 236			float t = fSumme/fHj*40.0;
 237            String ret = FormatFloat("##", t);
 238			return ret.ToInt();
 239        }else{
 240            return 0;
 241        }
 242
 243	}else if(block == 2){
 244		//(Prüfung1+Pr2+Pr3+Pr4+Pr5)*4= BlockII
 245		int summe =0;
 246		for(int i =1; i<6; i++){
 247			if(this->pruefungen != NULL){
 248				if(this->pruefungen->get(i) != NULL){
 249					summe += this->pruefungen->get(i)->getNoteGes();
 250				}
 251			}
 252		}
 253		return summe*4;
 254	}else{
 255		return 0;
 256	}
 257}
 258
 259void Core::saveToFile(String path)
 260{
 261	TStringList *file = new TStringList();
 262	//Legacy: abgeschlossene Halbjahre hinzufügen
 263	file->Add("0");
 264	file->Add("//Pruefungen");
 265	if(this->getPruefungen() != NULL){
 266		for(int i = 0; i<5; i++){
 267			Kurse_Pruefung *tmp = this->getPruefungen()->get(i+1);
 268			if(tmp != NULL){
 269            	String bell = "0";
 270				if(tmp->isBell()){
 271                	bell = "1";
 272				}
 273				file->Add("P#"+tmp->getName()+"#"+IntToStr(tmp->getNote())+"#"+IntToStr(tmp->getNachpruefungNote())+"#"+bell+"#");
 274			}else{
 275				//Prüfung[i] nicht vorhanden
 276				file->Add("P#NULL#-1#-1#0#");
 277            }
 278		}
 279	}else{
 280		//Keine Prüfungen vorhanden
 281		file->Add("P#NULL#-1#-1#0#");
 282		file->Add("P#NULL#-1#-1#0#");
 283		file->Add("P#NULL#-1#-1#0#");
 284		file->Add("P#NULL#-1#-1#0#");
 285		file->Add("P#NULL#-1#-1#0#");
 286	}
 287
 288	file->Add("//Kurse");
 289	for(int i = 0; i<this->anzahlKurs(); i++){
 290		Kurs *tmp = this->iterateKurse(i);
 291		if(tmp != NULL){
 292			String kursart = "0";
 293			String abgewaehlt = "0";
 294			if(tmp->isLK()){
 295				kursart = "1";
 296			}
 297			if(tmp->isAbg()){
 298            	abgewaehlt = "1";
 299			}
 300			file->Add("k#"+tmp->getName()+"#"+IntToStr(tmp->getNote(1))+"#"+IntToStr(tmp->getNote(2))+"#"+IntToStr(tmp->getNote(3))+"#"+IntToStr(tmp->getNote(4))+"#"+kursart+"#"+abgewaehlt+"#");
 301        }else{
 302			//Kurs[i] nicht vorhanden
 303		}
 304	}
 305	file->SaveToFile(path);
 306}
 307
 308void Core::loadFromFile(String path)
 309{
 310	int i,h,j;
 311	char *t;
 312	TStringList *ergebnis = new TStringList();
 313	char buffer[6];
 314	String p;
 315	String k;
 316	//TStrings TStg2;
 317	TStrings *Fach;
 318	TStringList *TStg1 = new TStringList();
 319
 320	TStg1->LoadFromFile(path);
 321	if(TStg1->Capacity<9)
 322	{
 323		Application->MessageBoxA(L"Datei unvollständig",L"Fehler",MB_OK);
 324	}else{
 325		this->pruefungen = new Pruefungen();
 326		for(int i = 2; i<7; i++){
 327			Kurse_Pruefung *tmp;
 328			String name;
 329			int countPos = 0; 	//Position im String (Ob Name, Note, etc)
 330			j = 0;          //Zähler des Buffers
 331			t = TStg1->Strings[i].c_str();
 332			for(int k =0; k<TStg1->Strings[i].Length();k++){
 333            	if(t[k] != 'P' && t[k] != '#'){
 334					buffer[j] = t[k];
 335					buffer[j+1] = '\0';
 336					j++;
 337				}else{
 338					if(t[k] != 'P' && j!= 0){
 339                    	switch(countPos){
 340							case 0: //Name
 341								name = buffer;
 342								if(name != "NULL"){
 343									tmp = new Kurse_Pruefung(name);
 344                                }else{
 345                                    tmp = NULL;
 346                                }
 347								buffer[0] = '\0';
 348								buffer[1] = '\0';
 349								buffer[2] = '\0';
 350								buffer[3] = '\0';
 351								buffer[4] = '\0';
 352								countPos++;
 353								j = 0;
 354								break;
 355							case 1: // Note 1 Prüfung
 356								if(tmp != NULL){
 357									String note = buffer;
 358									buffer[0] = '\0';
 359									buffer[1] = '\0';
 360									buffer[2] = '\0';
 361									buffer[3] = '\0';
 362									buffer[4] = '\0';
 363									countPos++;
 364									j = 0;
 365									tmp->setNote(note.ToInt());
 366                                }
 367								break;
 368							case 2:
 369								if(tmp != NULL){
 370									String note = buffer;
 371									buffer[0] = '\0';
 372									buffer[1] = '\0';
 373									buffer[2] = '\0';
 374									buffer[3] = '\0';
 375									buffer[4] = '\0';
 376									countPos++;
 377									j = 0;
 378									int inote = note.ToInt();
 379									if(inote > -2){
 380										tmp->setNachpruefung(true);
 381									}
 382									tmp->setNachpruefungNote(inote);
 383                                }
 384								break;
 385							case 3:
 386								if(tmp != NULL){
 387									String bell = buffer;
 388									buffer[0] = '\0';
 389									buffer[1] = '\0';
 390									buffer[2] = '\0';
 391									buffer[3] = '\0';
 392									buffer[4] = '\0';
 393									countPos++;
 394									j = 0;
 395									if(bell.ToInt() == 1){
 396                                    	tmp->setBell(true);
 397									}
 398
 399									this->getPruefungen()->add(tmp, i-1);
 400								} else{
 401                                	this->getPruefungen()->add(NULL, i-1);
 402                                }
 403								break;
 404						}
 405					}
 406				}
 407				t = TStg1->Strings[i].c_str();
 408			}
 409
 410		}
 411
 412
 413       //Kurse
 414	   //	z=0;
 415	   int lks = 0;
 416	   Kurs *tmp;
 417		for (i = 8; i < TStg1->Count; i++) {
 418			int countPosition = 0;
 419			j = 0;
 420        	p=TStg1->Strings[i];
 421			t=p.c_str();
 422			for (h = 0; h < p.Length(); h++) {
 423				if (t[h] != '#'&& t[h] != 'k') {
 424					buffer[j]=t[h];
 425					buffer[j+1] = '\0';
 426					j++;
 427				}else{
 428                    if(t[h] != 'k' && j != 0){
 429                    	switch(countPosition){
 430							case 0:
 431								tmp = new Kurs(buffer, false);
 432								buffer[0] = '\0';
 433								buffer[1] = '\0';
 434								buffer[2] = '\0';
 435								buffer[3] = '\0';
 436								buffer[4] = '\0';
 437								countPosition++;
 438								j = 0;
 439								break;
 440							case 1:
 441								if(tmp != NULL){
 442									String note = buffer;
 443									buffer[0] = '\0';
 444									buffer[1] = '\0';
 445									buffer[2] = '\0';
 446									buffer[3] = '\0';
 447									buffer[4] = '\0';
 448									countPosition++;
 449									j = 0;
 450									tmp->setNote(note.ToInt(), 1);
 451								}
 452								break;
 453							case 2:
 454								if(tmp != NULL){
 455									String note = buffer;
 456									buffer[0] = '\0';
 457									buffer[1] = '\0';
 458									buffer[2] = '\0';
 459									buffer[3] = '\0';
 460									buffer[4] = '\0';
 461									countPosition++;
 462									j = 0;
 463									tmp->setNote(note.ToInt(), 2);
 464								}
 465								break;
 466							case 3:
 467								if(tmp != NULL){
 468									String note = buffer;
 469									buffer[0] = '\0';
 470									buffer[1] = '\0';
 471									buffer[2] = '\0';
 472									buffer[3] = '\0';
 473									buffer[4] = '\0';
 474									countPosition++;
 475									j = 0;
 476									tmp->setNote(note.ToInt(), 3);
 477								}
 478								break;
 479							case 4:
 480								if(tmp != NULL){
 481									String note = buffer;
 482									buffer[0] = '\0';
 483									buffer[1] = '\0';
 484									buffer[2] = '\0';
 485									buffer[3] = '\0';
 486									buffer[4] = '\0';
 487									countPosition++;
 488									j = 0;
 489									tmp->setNote(note.ToInt(), 4);
 490								}
 491								break;
 492							case 5:
 493								if(tmp != NULL){
 494									String art = buffer;
 495									buffer[0] = '\0';
 496									buffer[1] = '\0';
 497									buffer[2] = '\0';
 498									buffer[3] = '\0';
 499									buffer[4] = '\0';
 500									countPosition++;
 501									j = 0;
 502									if(art.ToInt() == 1){
 503										tmp->setLK(true);
 504									}else if(art.ToInt() == 0){
 505										tmp->setLK(false);
 506									}
 507								}
 508								break;
 509							case 6:
 510                               if(tmp != NULL){
 511									String art = buffer;
 512									buffer[0] = '\0';
 513									buffer[1] = '\0';
 514									buffer[2] = '\0';
 515									buffer[3] = '\0';
 516									buffer[4] = '\0';
 517									countPosition++;
 518									j = 0;
 519									if(art.ToInt() == 1){
 520										tmp->setAbg(true);
 521									}else if(art.ToInt() == 0){
 522										tmp->setAbg(false);
 523									}
 524								}
 525								break;
 526
 527
 528						}
 529					}
 530
 531				}
 532				if(countPosition > 6){
 533					this->addKurs(tmp);
 534
 535					countPosition =0;
 536				}
 537			}
 538		}
 539	}
 540}
 541
 542int Core::getUnterkurse(){
 543	this->unterkurse = 0;
 544	for(int i =0; i<this->anzahlKurs(); i++){
 545		if(this->iterateKurse(i) != NULL){
 546			if(this->iterateKurse(i)->getNote(1) <5 && this->iterateKurse(i)->getNote(1) != -1 && this->iterateKurse(i)->getNote(1) != -2){
 547				if(this->iterateKurse(i)->isLK()){
 548					this->unterkurse++;
 549				}
 550				this->unterkurse++;
 551			}
 552			if(this->iterateKurse(i)->getNote(2) <5 && this->iterateKurse(i)->getNote(2) != -1 && this->iterateKurse(i)->getNote(2) != -2){
 553				if(this->iterateKurse(i)->isLK()){
 554					this->unterkurse++;
 555				}
 556				this->unterkurse++;
 557			}
 558			if(this->iterateKurse(i)->getNote(3) <5 && this->iterateKurse(i)->getNote(3) != -1 && this->iterateKurse(i)->getNote(3) != -2){
 559				if(this->iterateKurse(i)->isLK()){
 560					this->unterkurse++;
 561				}
 562				this->unterkurse++ ;
 563			}
 564			if(this->iterateKurse(i)->getNote(4) <5 && this->iterateKurse(i)->getNote(4) != -1 && this->iterateKurse(i)->getNote(4) != -2){
 565				if(this->iterateKurse(i)->isLK()){
 566					this->unterkurse++;
 567				}
 568				this->unterkurse++;
 569			}
 570		}
 571	}
 572	return this->unterkurse;
 573}
 574
 575void Core::print(String name){
 576	int cm = 118;
 577	int t =0;
 578
 579	TPrinter *print = Printer();
 580	print->BeginDoc();
 581	TCanvas *seite = print->Canvas;
 582	seite->Font->Name = "fnArial";
 583	seite->Brush->Style = bsClear;
 584
 585	seite->Font->Size = 18;
 586	String headline = "Noten für "+name;
 587	seite->TextOutA(3*cm, 1*cm, headline);
 588
 589	seite->Font->Size = 14;
 590	seite->TextOutA(3*cm, 2.5*cm, "Kursnoten");
 591
 592
 593	//Kursnoten
 594	seite->Font->Size = 12;
 595	seite->TextOutA(3*cm, 4*cm, "Fach");
 596	seite->TextOutA(5.5*cm, 4*cm, "12.1");
 597	seite->TextOutA(7.5*cm, 4*cm, "12.2");
 598	seite->TextOutA(9.5*cm, 4*cm, "13.1");
 599	seite->TextOutA(11.5*cm, 4*cm, "13.2");
 600	for(int i =0; i<this->anzahlKurs(); i++){
 601		seite->TextOutA(3*cm, (5+i)*cm, this->iterateKurse(i)->getName());
 602
 603		String n121;
 604		if(this->iterateKurse(i)->getNote(1) <0){
 605			n121 = " - " ;
 606		}else {
 607			n121 = FormatFloat("00", this->iterateKurse(i)->getNote(1));
 608
 609		}
 610		String n122;
 611		if(this->iterateKurse(i)->getNote(2) <0){
 612			n122 = " - " ;
 613		}else {
 614			n122 = FormatFloat("00",this->iterateKurse(i)->getNote(2));
 615		}
 616		String n131;
 617		if(this->iterateKurse(i)->getNote(3) <0){
 618			n131 = " - "  ;
 619		}else {
 620			n131 = FormatFloat("00",this->iterateKurse(i)->getNote(3));
 621		}
 622		String n132;
 623		if(this->iterateKurse(i)->getNote(4) <0){
 624			n132 = " - "  ;
 625		}else {
 626			n132 = FormatFloat("00",this->iterateKurse(i)->getNote(4));
 627		}
 628		seite->TextOutA(5.5*cm, (5+i)*cm, n121);
 629		seite->TextOutA(7.5*cm, (5+i)*cm, n122);
 630		seite->TextOutA(9.5*cm, (5+i)*cm, n131);
 631		seite->TextOutA(11.5*cm, (5+i)*cm, n132);
 632		t++; //Zähler für später erhöhen
 633	}
 634
 635	//Prüfungsnoten
 636	seite->Font->Size = 14;
 637	seite->TextOutA(3*cm, (5.5+t)*cm, "Prüfungsnoten");
 638
 639	seite->Font->Size = 12;
 640	seite->TextOutA(3*cm, (7+t)*cm, "Fach");
 641	seite->TextOutA(5.5*cm, (7+t)*cm, "Prüfung 1");
 642	seite->TextOutA(9.5*cm, (7+t)*cm, "Prüfung 2");
 643	seite->TextOutA(15.5*cm, (7+t)*cm, "Gesamt");
 644	for(int i=1; i<6; i++){
 645		seite->TextOutA(3*cm, (8+t)*cm, this->getPruefungen()->get(i)->getName());
 646	   //	int t = this->getPruefungen()->get(i)->getNote();
 647		if(this->getPruefungen()->get(i)->getNote()>-1){
 648			seite->TextOutA(5.5*cm, (8+t)*cm, FormatFloat("00",this->getPruefungen()->get(i)->getNote()));
 649		}else{
 650			seite->TextOutA(5.5*cm, (8+t)*cm, " - " );
 651		}
 652
 653
 654
 655		if(this->getPruefungen()->get(i)->hasNachpruefung()){
 656			int note =this->getPruefungen()->get(i)->getNachpruefungNote();
 657			if(this->getPruefungen()->get(i)->getNachpruefungNote() >=0){
 658				seite->TextOutA(9.5*cm, (8+t)*cm, FormatFloat("00",this->getPruefungen()->get(i)->getNachpruefungNote()));
 659			}else{
 660				seite->TextOutA(9.5*cm, (8+t)*cm, " - " );
 661			}
 662
 663		}else{
 664			seite->TextOutA(9.5*cm, (8+t)*cm, " - " );
 665		}
 666		int note = this->getPruefungen()->get(i)->getNoteGes()   ;
 667		seite->TextOutA(15.5*cm, (8+t)*cm, FormatFloat("00",note));
 668
 669		t++;
 670	}
 671
 672	//Auswertung
 673	seite->Font->Size = 14;
 674	seite->TextOutA(3*cm, (10+t)*cm, "Auswertung");
 675
 676	seite->Font->Size = 12;
 677	seite->TextOutA(3*cm, (11.5+t)*cm, "Qualifikationsphase:");
 678	seite->TextOutA(12*cm, (11.5+t)*cm, IntToStr(this->getBlockPunkte(1)));
 679
 680	seite->TextOutA(3*cm, (12.5+t)*cm, "Prüfungsphase:");
 681	seite->TextOutA(12*cm, (12.5+t)*cm, IntToStr(this->getBlockPunkte(2)));
 682
 683	double pGes = this->getBlockPunkte(1)+this->getBlockPunkte(2);
 684	double n = (17.0/3.0)-(pGes/180.0) ;
 685	n = (n<1)? 1.00 : n;
 686	String note = n;
 687	//FormatFloat("0.0", t); (t <1) ? 1.0: t;
 688	note = note.SubString(1,3);
 689
 690	seite->TextOutA(3*cm, (15+t)*cm, "Gesamtpunkte:");
 691	seite->TextOutA(10*cm, (15+t)*cm, FloatToStr(pGes));
 692
 693	seite->TextOutA(3*cm, (16+t)*cm, "Abiturnote:");
 694	seite->TextOutA(10*cm, (16+t)*cm, note);
 695
 696
 697	seite->Font->Size = 8;
 698	seite->Font->Style = TFontStyles() << fsItalic;
 699	seite->TextOutA(3*cm, (18+t)*cm, "generiert mit AbiCalc - http://redmine.vadaru.com/projects/abicalc");
 700	print->EndDoc();
 701
 702
 703}
 704
 705int Core::countNaturwissenschaften(){
 706	int c =0;
 707	for (int i = 0; i < this->anzahlKurs(); i++) {
 708		if(this->iterateKurse(i) != NULL){
 709			if(this->iterateKurse(i)->getName() == "Ch"){
 710				c++ ;
 711			}
 712			if(this->iterateKurse(i)->getName() == "Phy"){
 713				c++  ;
 714			}
 715			if(this->iterateKurse(i)->getName() == "Bio"){
 716				c++   ;
 717			}
 718		}
 719	}
 720	return c;
 721}
 722
 723int Core::getPositionOfKursByName(String name){
 724 	for(int i =0; i<this->cKurse; i++){
 725		if(this->kurse[i] != NULL){
 726			if(this->kurse[i]->getName() == name){
 727				return  i;
 728			}
 729		}
 730	}
 731	return -1;
 732}
 733
 734Kurs *Core::getKursByPosition(int pos){
 735	if(0<=pos <20){
 736    	return this->kurse[pos];
 737	}
 738	return NULL;
 739}
 740void Core::setKursInPosition(Kurs* kurs,int pos){
 741	if(0 <= pos < 20){
 742		this->kurse[pos] = kurs;
 743	}
 744}
 745void Core::setLKInPosition(Kurs* kurs,int pos){
 746	if(kurs->isLK()){
 747    	if(this->lk[pos-1] == NULL){
 748        	this->cLK++;
 749		}
 750		if(0<pos<3){
 751			this->lk[pos-1] = kurs;
 752		}
 753	}
 754}
 755void Core::deleteKursOnPosition(int pos){
 756	if(0<=pos<20){
 757		Kurs *tmp;
 758		for(int i = pos; i<this->cKurse; i++){
 759			if((i+1)<this->cKurse){
 760				this->kurse[i] = this->kurse[i+1];
 761            }else{
 762                this->kurse[i] = NULL;
 763            }
 764		}
 765		this->cKurse--;
 766	}
 767}
 768
 769Core::Core(){
 770	this->isChanged = false;
 771	this->cKurse =0; //init - keine Kurse im Array
 772	this->cLK = 0;
 773	this->kurse_abg = 0;
 774	this->pruefungen = NULL;
 775	this->savePath = "";
 776}
 777Core::~Core(){}
 778
 779
 780
 781
 782void Core::parseFile(String path){
 783	TStringList *file = new TStringList();
 784
 785	file->LoadFromFile(path);
 786
 787	bool error = true; //ist ein fehler aufgetreten?
 788	bool isKurse = false; // //Kurse ist aufgetaucht
 789	int cIsKurse =0;      // Zeile an dem cIsKurse true wurde
 790	int countPruefungen =0;
 791
 792	Kurse_Pruefung *tmp[5];
 793	this->pruefungen = new Pruefungen();
 794
 795	for(int i =1; i<file->Count;i++){
 796		char*line = file->Strings[i].c_str(); //Eine Zeile aus der Datei
 797
 798
 799		/**
 800		 * Prüfungen
 801		 **/
 802		if(i == 1 && file->Strings[i].Compare("//Pruefungen") == 0){
 803			error = false;
 804		}
 805
 806		if(i>1 && i<7 && !error){	//Prüfungsfächer
 807			char buffer[6];
 808			buffer[0] = '\0';
 809			buffer[1] = '\0';
 810			buffer[2] = '\0';
 811			buffer[3] = '\0';
 812			buffer[4] = '\0';
 813			buffer[5] = '\0'; //Buffer leeren  */
 814
 815
 816
 817			int countBuffer =0;
 818			int countPosition =0;
 819
 820
 821			for(int j =1; j<file->Strings[i].Length(); j++){
 822				if(line[j] != '#' && !error){
 823					buffer[countBuffer] = line[j];
 824					countBuffer++;
 825				}else{
 826				/*if(countBuffer >= 5 || line[j] == '#' && countPosition < 6 /*&& countBuffer > 1){*/
 827                	if(countBuffer != 0){
 828						switch(countPosition){
 829							case 0: //Name
 830								tmp[countPruefungen] = new Kurse_Pruefung(buffer);
 831								if(tmp[countPruefungen]->getName() ==  "BELL"){
 832                                	tmp[countPruefungen]->setBell(true);
 833								}
 834								buffer[0] = '\0';
 835								buffer[1] = '\0';
 836								buffer[2] = '\0';
 837								buffer[3] = '\0';
 838								buffer[4] = '\0';
 839								buffer[5] = '\0'; //Buffer leeren
 840								countPosition++;
 841								countBuffer =0;
 842								break;
 843							case 1:
 844								if(tmp[countPruefungen] != NULL){
 845									String note = buffer;
 846									buffer[0] = '\0';
 847									buffer[1] = '\0';
 848									buffer[2] = '\0';
 849									buffer[3] = '\0';
 850									buffer[4] = '\0';
 851									buffer[5] = '\0'; //Buffer leeren
 852									countPosition++;
 853									countBuffer =0;
 854
 855									tmp[countPruefungen]->setNote(note.ToInt());
 856								}
 857								break;
 858							case 2:
 859								if(tmp[countPruefungen] != NULL){
 860									String note = buffer;
 861									buffer[0] = '\0';
 862									buffer[1] = '\0';
 863									buffer[2] = '\0';
 864									buffer[3] = '\0';
 865									buffer[4] = '\0';
 866									buffer[5] = '\0'; //Buffer leeren
 867									countPosition++;
 868									countBuffer =0;
 869
 870									if(note.ToInt() == -1){
 871										tmp[countPruefungen]->setNachpruefung(false);
 872									}else{
 873                                    	tmp[countPruefungen]->setNachpruefung(true);
 874										tmp[countPruefungen]->setNachpruefungNote(note.ToInt());
 875                                    }
 876
 877								}
 878								break;
 879						}
 880						if(countPosition == 3){
 881							countPosition = 0;
 882							this->pruefungen->add(tmp[countPruefungen], i-1);
 883							countPruefungen++;
 884						}
 885
 886					}
 887					//fix: Bug das plötzlich line bloß noch 1 buchstabig ist...
 888					line = file->Strings[i].c_str();
 889				}
 890			}
 891
 892
 893		}
 894
 895
 896		/**
 897		 * Kurse
 898		 **/
 899
 900		 if(file->Strings[i].Compare("//Kurse") == 0){
 901			isKurse = true;
 902			cIsKurse = i;
 903		 }
 904
 905		 if(isKurse && cIsKurse < i){
 906         	char buffer[6];
 907			buffer[0] = '\0';
 908			buffer[1] = '\0';
 909			buffer[2] = '\0';
 910			buffer[3] = '\0';
 911			buffer[4] = '\0';
 912			buffer[5] = '\0'; //Buffer leeren  */
 913
 914
 915
 916			int countBuffer =0;
 917			int countPosition =0;
 918
 919			Kurs *tmp;
 920
 921         	for(int j =1; j<file->Strings[i].Length(); j++){
 922				if(line[j] != 'K' && line[j] != '#' && !error){
 923					buffer[countBuffer] = line[j];
 924					countBuffer++;
 925				}else{
 926					if(countBuffer > 0){
 927                    	switch(countPosition){
 928							case 0: // Name
 929								tmp = new Kurs(buffer, false);
 930								buffer[0] = '\0';
 931								buffer[1] = '\0';
 932								buffer[2] = '\0';
 933								buffer[3] = '\0';
 934								buffer[4] = '\0';
 935								buffer[5] = '\0'; //Buffer leeren
 936								countPosition++;
 937								countBuffer =0;
 938								break;
 939							case 1: //12.1
 940                            	if(tmp != NULL){
 941									String note = buffer;
 942									buffer[0] = '\0';
 943									buffer[1] = '\0';
 944									buffer[2] = '\0';
 945									buffer[3] = '\0';
 946									buffer[4] = '\0';
 947									buffer[5] = '\0'; //Buffer leeren
 948									countPosition++;
 949									countBuffer =0;
 950
 951									tmp->setNote(note.ToInt(), 1);
 952								}
 953								break;
 954							case 2: //12.2
 955                            	if(tmp != NULL){
 956									String note = buffer;
 957									buffer[0] = '\0';
 958									buffer[1] = '\0';
 959									buffer[2] = '\0';
 960									buffer[3] = '\0';
 961									buffer[4] = '\0';
 962									buffer[5] = '\0'; //Buffer leeren
 963									countPosition++;
 964									countBuffer =0;
 965
 966									tmp->setNote(note.ToInt(), 2);
 967								}
 968								break;
 969							case 3: //13.1
 970                            	if(tmp != NULL){
 971									String note = buffer;
 972									buffer[0] = '\0';
 973									buffer[1] = '\0';
 974									buffer[2] = '\0';
 975									buffer[3] = '\0';
 976									buffer[4] = '\0';
 977									buffer[5] = '\0'; //Buffer leeren
 978									countPosition++;
 979									countBuffer =0;
 980
 981									tmp->setNote(note.ToInt(), 3);
 982								}
 983								break;
 984							case 4: //13.2
 985                            	if(tmp != NULL){
 986									String note = buffer;
 987									buffer[0] = '\0';
 988									buffer[1] = '\0';
 989									buffer[2] = '\0';
 990									buffer[3] = '\0';
 991									buffer[4] = '\0';
 992									buffer[5] = '\0'; //Buffer leeren
 993									countPosition++;
 994									countBuffer =0;
 995
 996									tmp->setNote(note.ToInt(), 4);
 997								}
 998								break;
 999							case 5: //12.1
1000                            	if(tmp != NULL){
1001									String note = buffer;
1002									buffer[0] = '\0';
1003									buffer[1] = '\0';
1004									buffer[2] = '\0';
1005									buffer[3] = '\0';
1006									buffer[4] = '\0';
1007									buffer[5] = '\0'; //Buffer leeren
1008									countPosition++;
1009									countBuffer =0;
1010
1011									if(note.ToInt() == 0){
1012                                     	tmp->setLK(false);
1013									}else if(note.ToInt() == 1){
1014                                    	tmp->setLK(true);
1015									}
1016								}
1017								break;
1018							case 6: //12.1
1019								if(tmp != NULL){
1020									String note = buffer;
1021									buffer[0] = '\0';
1022									buffer[1] = '\0';
1023									buffer[2] = '\0';
1024									buffer[3] = '\0';
1025									buffer[4] = '\0';
1026									buffer[5] = '\0'; //Buffer leeren
1027									countPosition++;
1028									countBuffer =0;
1029
1030									if(note.ToInt() == 0){
1031										tmp->setAbg(false);
1032									}else if(note.ToInt() == 1){
1033                                    	tmp->setAbg(true);
1034									}
1035								}
1036							break;
1037						}
1038						if(countPosition == 6){
1039							this->addKurs(tmp);
1040							//delete tmp;
1041							countPosition =0;
1042						}
1043					}
1044                }
1045			}
1046		 }
1047	}
1048}
1049#pragma package(smart_init)