-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
181 lines (156 loc) · 8.41 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#include <stdio.h>
#include <malloc.h>
#include "include/UI.h"
#include "include/Data.h"
#include "include/Debug.h"
#include "include/Storage.h"
#include "include/Scene.h"
#include "include/ErrorList.h"
int main() {
DataSettings dataSettings;
Dosen *dataDosen = initializeEmptyData();
Mahasiswa *dataMahasiswa = initializeEmptyData();
Matkul *dataMatkul = initializeEmptyData();
PesertaKuliah *dataPesertaKuliah = initializeEmptyData();
if (loadSettings("bin/d_settings.dat", &dataSettings) == ERROR_NOFILE) {
dataSettings.structSize_Dosen = 0;
dataSettings.structSize_Mahasiswa = 0;
dataSettings.structSize_Matkul = 0;
dataSettings.structSize_PesertaKuliah = 0;
}
dataDosen = realloc(dataDosen, dataSettings.structSize_Dosen * sizeof(Dosen));
dataMahasiswa = realloc(dataMahasiswa, dataSettings.structSize_Mahasiswa * sizeof(Mahasiswa));
dataMatkul = realloc(dataMatkul, dataSettings.structSize_Matkul * sizeof(Matkul));
dataPesertaKuliah = realloc(dataPesertaKuliah, dataSettings.structSize_PesertaKuliah * sizeof(PesertaKuliah));
loadData("bin/d_dosen.dat", dataDosen, sizeof(Dosen), dataSettings.structSize_Dosen);
loadData("bin/d_mahasiswa.dat", dataMahasiswa, sizeof(Mahasiswa), dataSettings.structSize_Mahasiswa);
loadData("bin/d_matkul.dat", dataMatkul, sizeof(Matkul), dataSettings.structSize_Matkul);
loadData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
forceReadjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
int menuSelection;
int invalidSelection = 0;
while (1) {
printMainMenu();
if (invalidSelection) {
setColor(COLOR_RED);
printf("MOHON HANYA MEMASUKKAN ANGKA YANG VALID!\n");
setColor(COLOR_DEFAULT);
invalidSelection = 0;
}
printf("Silakan pilih angka pada menu: ");
scanf("%d", &menuSelection);
// (1) Lihat Data Dosen
if (menuSelection == 1) {
sceneLihatDataDosen(dataDosen, &dataSettings);
}
// (2) Input Data Dosen
else if (menuSelection == 2) {
sceneInputDataDosen(&dataDosen, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_dosen.dat", dataDosen, sizeof(Dosen), dataSettings.structSize_Dosen);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (3) Hapus Data Dosen
else if (menuSelection == 3) {
sceneDeleteDataDosen(&dataDosen, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_dosen.dat", dataDosen, sizeof(Dosen), dataSettings.structSize_Dosen);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (4) Lihat Data Mahasiswa
else if (menuSelection == 4) {
sceneLihatDataMahasiswa(dataMahasiswa, &dataSettings);
}
// (5) Input Data Mahasiswa
else if (menuSelection == 5) {
sceneInputDataMahasiswa(&dataMahasiswa, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_mahasiswa.dat", dataMahasiswa, sizeof(Mahasiswa), dataSettings.structSize_Mahasiswa);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (6) Hapus Data Mahasiswa
else if (menuSelection == 6) {
sceneDeleteDataMahasiswa(&dataMahasiswa, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_mahasiswa.dat", dataMahasiswa, sizeof(Mahasiswa), dataSettings.structSize_Mahasiswa);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (7) Lihat Data Matkul
else if (menuSelection == 7) {
sceneLihatDataMatkul(dataMatkul, &dataSettings);
}
// (8) Input Data Matkul
else if (menuSelection == 8) {
sceneInputDataMatkul(&dataMatkul, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_matkul.dat", dataMatkul, sizeof(Matkul), dataSettings.structSize_Matkul);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (9) Hapus Data Matkul
else if (menuSelection == 9) {
sceneDeleteDataMatkul(&dataMatkul, &dataSettings);
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_matkul.dat", dataMatkul, sizeof(Matkul), dataSettings.structSize_Matkul);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (10) Lihat Data Peserta Kuliah
else if (menuSelection == 10) {
sceneLihatDataPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
}
// (11) Input Data Peserta Kuliah
else if (menuSelection == 11) {
sceneInputDataPesertaKuliah(&dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (12) Hapus Data Peserta Kuliah
else if (menuSelection == 12) {
sceneDeleteDataPesertaKuliah(&dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (13) Input Nilai Peserta Kuliah
else if (menuSelection == 13) {
sceneInputNilaiPesertaKuliah(&dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
}
// (14) Informasi Data
else if (menuSelection == 14) {
sceneInformasiData(&dataSettings);
}
// (15) Simpan Paksa Data
else if (menuSelection == 15) {
readjustPesertaKuliah(dataPesertaKuliah, &dataSettings, dataMatkul, dataDosen, dataMahasiswa);
saveSettings("bin/d_settings.dat", &dataSettings);
saveData("bin/d_dosen.dat", dataDosen, sizeof(Dosen), dataSettings.structSize_Dosen);
saveData("bin/d_mahasiswa.dat", dataMahasiswa, sizeof(Mahasiswa), dataSettings.structSize_Mahasiswa);
saveData("bin/d_matkul.dat", dataMatkul, sizeof(Matkul), dataSettings.structSize_Matkul);
saveData("bin/d_pesertakuliah.dat", dataPesertaKuliah, sizeof(PesertaKuliah), dataSettings.structSize_PesertaKuliah);
sceneSimpanPaksaData(&dataSettings);
}
// (16) Informasi Perangkat Lunak
else if (menuSelection == 16) {
sceneAppInfo();
}
// (16) Keluar
else if (menuSelection == 17) {
if (sceneExitApp() == PROCCESS_SUCCESS) {
clearScreen();
printf("Terima kasih telah menggunakan aplikasi sistem informasi akademik!\n");
break;
}
}
// Default case
else {
invalidSelection = 1;
}
}
return 0;
}