-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuConfiguracion.cpp
More file actions
258 lines (195 loc) · 7.41 KB
/
Copy pathMenuConfiguracion.cpp
File metadata and controls
258 lines (195 loc) · 7.41 KB
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
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#include <iostream>
#include "ArchivoVenta.h"
#include "ArchivoProducto.h"
#include "MenuConfiguracion.h"
using namespace std;
void MenuConfiguracion:: menu(){
int opc;
while(true){
system("cls");
cout << R"(
_____________________________________________
| |
| MENU CONFIGURACION |
|_____________________________________________|
|_____________________________________________|
| |
| INGRESE UNA OPCION |
|_____________________________________________|
| |
| 1. COPIA DE SEGURIDAD ARCHIVO PRODUCTO |
| 2. COPIA DE SEGURIDAD ARCHIVO VENTAS |
| 3. COPIA DE SEGURIDAD ARCHIVO CLIENTE |
| 4. COPIA DE SEGURIDAD ARCHIVO VENDEDOR |
| 5. RESTAURAR ARCHIVO PRODUCTO |
| 6. RESTAURAR ARCHIVO VENTA |
| 7. RESTAURAR ARCHIVO CLIENTE |
| 8. RESTAURAR ARCHIVO VENDEDOR |
| 0. VOLVER ATRAS |
|_____________________________________________|
OPCION: )";cin>>opc;
/*
cout<<"MENU CONFIGURACION"<<endl;
cout<<"-----------------"<<endl;
cout<<"1) COPIA DE SEGURIDAD ARCHIVO PRODUCTO"<<endl;
cout<<"2) COPIA DE SEGURIDAD ARCHIVO VENTA"<<endl;
cout<<"3) COPIA DE SEGURIDAD ARCHIVO CLIENTE"<<endl;
cout<<"4) COPIA DE SEGURIDAD ARCHIVO VENDEDOR"<<endl;
cout<<"5) RESTAURAR ARCHIVO PRODUCTO"<<endl;
cout<<"6) RESTAURAR ARCHIVO VENTA"<<endl;
cout<<"7) RESTAURAR ARCHIVO CLIENTE"<<endl;
cout<<"8) RESTAURAR ARCHIVO VENDEDOR"<<endl;
cout<<"--------------------------"<<endl;
cout<<"0) VOLVER AL MENU PRINCIPAL"<<endl;
cout<<"OPCION: "<<endl;
*/
system("cls");
switch(opc){
case 1: copiaSeguridadProducto();
break;
case 2: copiaSeguridadVentas();
copiaSeguridadProducto();
break;
case 3: copiaSeguridadCliente();
break;
case 4:
copiaSeguridadVendedor();
break;
case 5: restaurarArchivoProducto();
break;
case 6: restaurarArchivoVentas();
restaurarArchivoProducto();
break;
case 7: restaurarArchivoCliente();
break;
case 8: restaurarArchivoVendedor();
break;
case 0:return ;
default:cout<<"OPCION INCORRECTA"<<endl;
break;
}
system("pause");
}
}
void MenuConfiguracion::copiaSeguridadVentas() {
FILE *origen = fopen("venta.dat", "rb");
FILE *destino = fopen("ventaCopiaSeguridad.bak", "wb");
if (origen == nullptr || destino == nullptr) {
cout << "ERROR AL ABRIR LOS ARCHIVOS" << endl;
return;
}
Venta reg;
while (fread(®, sizeof(reg), 1, origen) == 1) {
if (fwrite(®, sizeof(reg), 1, destino) != 1) {
cout << "ERROR AL ESCRIBIR EN EL ARCHIVO DE COPIA" << endl;
fclose(origen);
fclose(destino);
return;
}
}
fclose(origen);
fclose(destino);
cout << "COPIA GENERADA EXITOSAMENTE" << endl;
}
void MenuConfiguracion::copiaSeguridadProducto() {
FILE *origen = fopen("producto.dat", "rb");
FILE *destino = fopen("productoCopiaSeguridad.bak", "wb");
if (origen == nullptr || destino == nullptr) {
cout << "ERROR AL ABRIR LOS ARCHIVOS" << endl;
return;
}
Producto reg;
while (fread(®, sizeof(reg), 1, origen) == 1) {
if (fwrite(®, sizeof(reg), 1, destino) != 1) {
cout << "ERROR AL ESCRIBIR EN EL ARCHIVO DE COPIA" << endl;
fclose(origen);
fclose(destino);
return;
}
}
fclose(origen);
fclose(destino);
cout << "COPIA GENERADA EXITOSAMENTE" << endl;
}
void MenuConfiguracion::copiaSeguridadVendedor() {
FILE *origen = fopen("vendedor.dat", "rb");
FILE *destino = fopen("vendedorCopiaSeguridad.bak", "wb");
if (origen == nullptr || destino == nullptr) {
cout << "ERROR AL ABRIR LOS ARCHIVOS" << endl;
return;
}
Vendedor reg;
while (fread(®, sizeof(reg), 1, origen) == 1) {
if (fwrite(®, sizeof(reg), 1, destino) != 1) {
cout << "ERROR AL ESCRIBIR EN EL ARCHIVO DE COPIA" << endl;
fclose(origen);
fclose(destino);
return;
}
}
fclose(origen);
fclose(destino);
cout << "COPIA GENERADA EXITOSAMENTE" << endl;
}
void MenuConfiguracion::copiaSeguridadCliente() {
FILE *origen = fopen("cliente.dat", "rb");
FILE *destino = fopen("clienteCopiaSeguridad.bak", "wb");
if (origen == nullptr || destino == nullptr) {
cout << "ERROR AL ABRIR LOS ARCHIVOS" << endl;
return;
}
Cliente reg;
while (fread(®, sizeof(reg), 1, origen) == 1) {
if (fwrite(®, sizeof(reg), 1, destino) != 1) {
cout << "ERROR AL ESCRIBIR EN EL ARCHIVO DE COPIA" << endl;
fclose(origen);
fclose(destino);
return;
}
}
fclose(origen);
fclose(destino);
cout << "COPIA GENERADA EXITOSAMENTE" << endl;
}
///RENAME, funcion de c++. Renombra el archivo NOMBRE COPIA al NOMBRE ORIGINAL. Rename devuelve 0 si es ok de lo contrario devuelve -1.
/// REMOVE, funcion de c++. Elimina el archivo si existe. Se neceista para generar la restauracion sin problema.
void MenuConfiguracion:: restaurarArchivoProducto() {
const char *nombreOriginal = "producto.dat";
const char *nombreCopia = "productoCopiaSeguridad.bak";
remove(nombreOriginal);
if (rename(nombreCopia, nombreOriginal) == 0) {
cout << "RESTAURACION DEL ARCHIVO EXISTOSA" << endl;
} else {
cout << "ERROR AL RESTAURAR EL ARCHIVO" << endl;
}
}
void MenuConfiguracion:: restaurarArchivoVentas() {
const char *nombreOriginal = "venta.dat";
const char *nombreCopia = "ventaCopiaSeguridad.bak";
remove(nombreOriginal);
if (rename(nombreCopia, nombreOriginal) == 0) {
cout << "RESTAURACION DEL ARCHIVO EXISTOSA" << endl;
} else {
cout << "ERROR AL RESTAURAR EL ARCHIVO" << endl;
}
}
void MenuConfiguracion:: restaurarArchivoVendedor() {
const char *nombreOriginal = "vendedor.dat";
const char *nombreCopia = "vendedorCopiaSeguridad.bak";
remove(nombreOriginal);
if (rename(nombreCopia, nombreOriginal) == 0) {
cout << "RESTAURACION DEL ARCHIVO EXISTOSA" << endl;
} else {
cout << "ERROR AL RESTAURAR EL ARCHIVO" << endl;
}
}
void MenuConfiguracion:: restaurarArchivoCliente() {
const char *nombreOriginal = "cliente.dat";
const char *nombreCopia = "clienteCopiaSeguridad.bak";
remove(nombreOriginal);
if (rename(nombreCopia, nombreOriginal) == 0) {
cout << "RESTAURACION DEL ARCHIVO EXISTOSA" << endl;
} else {
cout << "ERROR AL RESTAURAR EL ARCHIVO" << endl;
}
}