/pruefungskonfig.cpp

http://abicalc.googlecode.com/ · C++ · 598 lines · 472 code · 57 blank · 69 comment · 191 complexity · 5562a9dbc7c9947e5993228e1c69ab26 MD5 · raw file

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