399 lines
No EOL
8.3 KiB
C
399 lines
No EOL
8.3 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 tasse() {
|
|
printf(" ( ) ( ) )\n ) ( ) ( (\n ( ) ( ) )\n _____________\n <_____________> ___\n | |/ _ \\\n | | | |\n | |_| |\n ___| |\\___/\n/ \\___________/ \\\n\\_____________________/\n");
|
|
}
|
|
|
|
void menuConf(ptConf confChain, ptListener listenerChain) {
|
|
char *options[] = {"1/ Voir la liste des conferences", "2/ Ajouter une conference", "3/ Supprimer une conference", "4/ Supprimer les conferences inferieures a une date", "5/ Retour"};
|
|
system("cls");
|
|
drawMenu(options, 5);
|
|
goToCoords(0, 13);
|
|
tasse();
|
|
printf("\n");
|
|
printf("Que voulez-vous faire ? : ");
|
|
int choice;
|
|
scanf("%d", &choice);
|
|
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
{
|
|
ptConf px = confChain -> next;
|
|
|
|
while (px -> next != NULL) {
|
|
printf("Id : %d\nTitre : %s\nConferencier : %s\n", px -> id, px -> title, px -> speaker);
|
|
printf("Date : %d/%d/%d\n",px -> day, px -> month, px -> year);
|
|
printf("Nombre de participants : %d\n", confParticipations(px));
|
|
if (px -> listeners -> next != NULL ) {
|
|
printListenerList(px -> listeners -> next);
|
|
}
|
|
int avg;
|
|
if ((avg = confGradeAvg(px) != -1)) {
|
|
printf("Moyenne des notes : %d\n", confGradeAvg(px));
|
|
}
|
|
printf("\n");
|
|
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("Annee : ");
|
|
scanf("%d", &year);
|
|
|
|
addConf(confChain, id, title, speaker, day, month, year);
|
|
saveConf(confChain -> next);
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
{
|
|
ptConf px = confChain -> next;
|
|
|
|
printf("\n");
|
|
while (px -> next != NULL) {
|
|
printf("%d : %s\n", px -> id, px -> title);
|
|
px = px -> next;
|
|
}
|
|
printf("\n");
|
|
|
|
int id;
|
|
|
|
printf("Id de la conference a supprimer : ");
|
|
scanf("%d", &id);
|
|
|
|
removeConf(confChain, id);
|
|
saveConf(confChain -> next);
|
|
saveRelations(confChain -> next);
|
|
menuConf(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
{
|
|
int day, month, year, time;
|
|
printf("Jour : ");
|
|
scanf("%d", &day);
|
|
printf("Mois : ");
|
|
scanf("%d", &month);
|
|
printf("Annee : ");
|
|
scanf("%d", &year);
|
|
|
|
time = day + 31 * month + 365 * year;
|
|
|
|
ptConf px = confChain;
|
|
|
|
while(px -> next != NULL) {
|
|
if ((px -> day + px -> month * 31 + px -> year * 365) < time && px != confChain) {
|
|
ptConf py = px -> next;
|
|
removeConf(confChain, px -> id);
|
|
px = py;
|
|
} else if ((px -> day + px -> month * 31 + px -> year * 365) < time && px == confChain) {
|
|
removeConf(confChain, px -> id);
|
|
} else {
|
|
px = px -> next;
|
|
}
|
|
}
|
|
|
|
saveConf(confChain -> next);
|
|
|
|
menuConf(confChain, listenerChain);
|
|
}
|
|
|
|
case 5:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
|
|
default:
|
|
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);
|
|
tasse();
|
|
printf("\n");
|
|
printf("Que voulez-vous faire ? : ");
|
|
int choice;
|
|
scanf("%d", &choice);
|
|
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
{
|
|
ptListener py = listenerChain -> next;
|
|
|
|
while (py -> next != NULL) {
|
|
printf("Id : %d\nNom: %s\nAge: %d\nNiveau: %d\n", py -> id, py -> name, py -> age, py -> level);
|
|
if (py -> confs -> next != NULL) {
|
|
printConfList(py -> confs -> next);
|
|
}
|
|
printf("\n");
|
|
py = py -> next;
|
|
}
|
|
system("pause");
|
|
menuAbo(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);
|
|
|
|
if (addListener(listenerChain, id, name, age, level) != -1) {
|
|
saveListeners(listenerChain -> next);
|
|
} else {
|
|
printf("Le niveau de l'abonne doit etre compris entre 0 et 5.\n\n");
|
|
system("pause");
|
|
}
|
|
menuAbo(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 3:
|
|
{
|
|
ptListener px = listenerChain -> next;
|
|
|
|
printf("\n");
|
|
while (px -> next != NULL) {
|
|
printf("%d : %s\n", px -> id, px -> name);
|
|
px = px -> next;
|
|
}
|
|
printf("\n");
|
|
|
|
int id;
|
|
|
|
printf("Id de l'abonne a supprimer : ");
|
|
scanf("%d", &id);
|
|
|
|
removeListener(listenerChain, id);
|
|
saveListeners(listenerChain -> next);
|
|
saveRelations(confChain -> next);
|
|
menuAbo(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
|
|
default:
|
|
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/ Quitter"};
|
|
system("cls");
|
|
drawMenu(options, 5);
|
|
goToCoords(0, 13);
|
|
tasse();
|
|
printf("\n");
|
|
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:
|
|
{
|
|
ptConf px = confChain -> next;
|
|
ptListener py = listenerChain -> next;
|
|
|
|
printf("\n");
|
|
while (px -> next != NULL) {
|
|
printf("%d : %s\n", px -> id, px -> title);
|
|
px = px -> next;
|
|
}
|
|
printf("\n");
|
|
while (py -> next != NULL) {
|
|
printf("%d : %s\n", py -> id, py -> name);
|
|
py = py -> next;
|
|
}
|
|
printf("\n");
|
|
|
|
int confId, listenerId, grade;
|
|
printf("Entrez l'ID de la conference : ");
|
|
scanf("%d", &confId);
|
|
printf("Entrez l'ID du participant : ");
|
|
scanf("%d", &listenerId);
|
|
printf("Entrez la note attribuee par le participant : ");
|
|
scanf("%d", &grade);
|
|
|
|
if (participateToConf(confChain, listenerChain, confId, listenerId, grade) != -1) {
|
|
saveRelations(confChain -> next);
|
|
} else {
|
|
printf("La note doit etre comprise entre 0 et 5 et l'abonne ne doit pas avoir deja participe a la conference\n\n");
|
|
system("pause");
|
|
}
|
|
|
|
menu(confChain, listenerChain);
|
|
break;
|
|
}
|
|
|
|
case 4:
|
|
{
|
|
ptConf px = confChain;
|
|
int max = confGradeAvg(px);
|
|
ptConf confMax = px;
|
|
|
|
while (px -> next != NULL) {
|
|
int tmp = confGradeAvg(px);
|
|
if (tmp > max) {
|
|
confMax = px;
|
|
max = tmp;
|
|
}
|
|
|
|
px = px -> next;
|
|
}
|
|
|
|
printf("La conférence la mieux notee est : %s\n\n", confMax -> title);
|
|
|
|
system("pause");
|
|
menu(confChain, listenerChain);
|
|
|
|
break;
|
|
}
|
|
|
|
case 5:
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
} |