237 lines
No EOL
4.6 KiB
C
237 lines
No EOL
4.6 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <windows.h>
|
|
#include "screenManager.h"
|
|
#include "conf.h"
|
|
#include "fileManager.h"
|
|
|
|
void goToCoords(int x, int y)
|
|
{
|
|
COORD coords;
|
|
|
|
coords.X = x;
|
|
coords.Y = y;
|
|
|
|
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coords);
|
|
}
|
|
|
|
void drawHoryLine(char c, int lenght)
|
|
{
|
|
int i = 0;
|
|
|
|
while (i != lenght)
|
|
{
|
|
printf("%c", c);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
void drawVertiLine(char c, int lenght)
|
|
{
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
|
|
int x = info.dwCursorPosition.X;
|
|
int y = info.dwCursorPosition.Y;
|
|
|
|
int i = 0;
|
|
|
|
while (i != lenght) {
|
|
goToCoords(x, y + i);
|
|
printf("%c", c);
|
|
i ++;
|
|
}
|
|
}
|
|
|
|
void drawRectangle(int x, int y, int lenght, int height)
|
|
{
|
|
goToCoords(x, y);
|
|
printf("%c", 201);
|
|
drawHoryLine(205, lenght - 2);
|
|
printf("%c", 187);
|
|
goToCoords(x, y + 1);
|
|
drawVertiLine(186, height - 2);
|
|
goToCoords(x + lenght - 1, y + 1);
|
|
drawVertiLine(186, height - 2);
|
|
goToCoords(x, y + height - 1);
|
|
printf("%c", 200);
|
|
drawHoryLine(205, lenght - 2);
|
|
printf("%c", 188);
|
|
}
|
|
|
|
void drawMenu(char *options[], int lenght) {
|
|
int max = strlen(options[0]);
|
|
int i;
|
|
|
|
for (i = 0; i < lenght; i++) {
|
|
if (strlen(options[i]) > max) {
|
|
max = strlen(options[i]);
|
|
}
|
|
}
|
|
|
|
CONSOLE_SCREEN_BUFFER_INFO info;
|
|
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
|
|
int columns = info.srWindow.Right - info.srWindow.Left + 1;
|
|
int rows = info.srWindow.Bottom - info.srWindow.Top + 1;
|
|
|
|
drawRectangle((columns - max - 4) / 2, 2, max + 4, lenght + 4);
|
|
|
|
for (i = 0; i < lenght; i++) {
|
|
goToCoords((columns - max - 4) / 2 + 2, 4 + i);
|
|
printf("%s", options[i]);
|
|
}
|
|
|
|
}
|
|
|
|
void menuConf(ptConf confChain, ptListener listenerChain) {
|
|
char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Suprimer une conference", "4/ Retour"};
|
|
system("cls");
|
|
drawMenu(options, 4);
|
|
goToCoords(0, 12);
|
|
printf("Que voulez-vous faire ? : ");
|
|
int choice;
|
|
scanf("%d", &choice);
|
|
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
system ("cls");
|
|
ptConf px = confChain;
|
|
|
|
while (px -> next != NULL) {
|
|
printf("id : %d\ntitle : %s\nspeaker : %s\n", px -> id, px -> title, px -> speaker);
|
|
printf("%d/%d/%d\n\n",px -> day, px -> month, px -> year);
|
|
px = px -> next;
|
|
}
|
|
system("pause");
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
|
|
case 2:
|
|
{
|
|
int id, day, month, year;
|
|
char title[30];
|
|
char speaker[20];
|
|
|
|
id = findConfId(confChain);
|
|
printf("Titre de la conference : ");
|
|
scanf("%29s", &title);
|
|
printf("Nom du conferencier : ");
|
|
scanf("%19s", &speaker);
|
|
printf("Jour : ");
|
|
scanf("%d", &day);
|
|
printf("Mois : ");
|
|
scanf("%d", &month);
|
|
printf("Année : ");
|
|
scanf("%d", &year);
|
|
|
|
addConf(confChain, id, title, speaker, day, month, year);
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
break;
|
|
|
|
case 4:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
|
|
default:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void menuAbo(ptConf confChain, ptListener listenerChain) {
|
|
char *options[] = {"1/ Voir la liste des abonnes", "2/ Ajouter un abonne", "3/ Suprimer un abonne", "4/ Retour"};
|
|
system("cls");
|
|
drawMenu(options, 4);
|
|
goToCoords(0, 12);
|
|
printf("Que voulez-vous faire ? : ");
|
|
int choice;
|
|
scanf("%d", &choice);
|
|
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
system ("cls");
|
|
ptListener py = listenerChain;
|
|
|
|
while (py -> next != NULL) {
|
|
printf("name: %s\nage: %d\nlevel: %d", py -> name, py -> age, py -> level);
|
|
py = py -> next;
|
|
}
|
|
system("pause");
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
|
|
case 2:
|
|
{
|
|
int id, age, level;
|
|
char name[20];
|
|
|
|
id = findListenerId(listenerChain);
|
|
printf("Nom : ");
|
|
scanf("%19s", &name);
|
|
printf("Age : ");
|
|
scanf("%d", &age);
|
|
printf("Niveau : ");
|
|
scanf("%d", &level);
|
|
|
|
addListener(listenerChain, id, name, age, level);
|
|
menuAbo(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
break;
|
|
|
|
case 4:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
|
|
default:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
}
|
|
}
|
|
|
|
void menu(ptConf confChain, ptListener listenerChain)
|
|
{
|
|
char *options[] = {"1/ Gestion des conferences", "2/ Gestion des abonnes", "3/ Participer a une conference", "4/ Voir la meilleure conference", "5/ Voir la participation a une conference", "6/ Sauvegarder", "7/ Quitter"};
|
|
system("cls");
|
|
drawMenu(options, 7);
|
|
goToCoords(0, 15);
|
|
printf("Que voulez-vous faire ? : ");
|
|
int choice;
|
|
scanf("%d", &choice);
|
|
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
|
|
case 2:
|
|
menuAbo(confChain, listenerChain);
|
|
break;
|
|
|
|
case 3:
|
|
break;
|
|
|
|
case 4:
|
|
break;
|
|
|
|
case 5:
|
|
break;
|
|
|
|
case 6:
|
|
saveConf(confChain);
|
|
saveListeners(listenerChain);
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
} |