Академический Документы
Профессиональный Документы
Культура Документы
a = strlen(numero);
for (int i = 0; i < a; i++)
{
b = numero[i];
if ( (b > 47 && b < 58) || (b == '.'))
{
k = true;
}
else
{
return false;
}
}
return(k);
}
//valida que se ingrese un correo con un dominio conocido ej: @gmail.com @hotmai
l.com @hotmail.es @yahoo.com etc.
bool Validar_Correo(char correo[]){
int tam, a, i, j;
bool k = false;
char dominio[30];
tam = strlen(correo);
for (i = 0; i < tam; i++)
{
if (correo[i] == '@')
{
if (i == 0)
{
return(false);
}
for (j = 0; j < tam - i; j++)
{
dominio[j] = correo[j + i + 1];
}
dominio[j] = '\0';
if (strcmp(dominio, "hotmail.com") == 0 || strcmp(domini
o, "gmail.com") == 0 || strcmp(dominio, "yahoo.com") == 0 || strcmp(dominio, "ho
tmail.es") == 0 || strcmp(dominio, "outlook.com") == 0)
{
k = true;
}
else{ return(false); }
k = true;
}
}
return(k);
}
//valida que se ingresen solo numeros
bool Validar_Telefono(char telefono[]){
bool bandera = false;
int i;
for (i = 0; i < strlen(telefono); i++){
if (telefono[i] == '0' || telefono[i] == '1' || telefono[i] == '
2' || telefono[i] == '3' || telefono[i] == '4' ||
telefono[i] == '5' || telefono[i] == '6' || telefono[i]
== '7' || telefono[i] == '8' ||
telefono[i] == '9'){
bandera = true;
}
}
return (bandera);
}
//valida que el precio ingresado este entre los rangos aceptables de la variable
float y que sea mayor o igual a 0
bool validar_precio_aceptable(char precio[])
{
if(validarFlotantePositivo(precio)==false)
{
system("cls");
cout<<"error, ingrese un numero real positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atof(precio)<0)
{
system("cls");
cout<<"error, ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atof(precio)>2147483647)
{
system("cls");
cout<<"error, el numero excede el rango maximo p
ermitido por la variable float \n ingrese un numero menor o igual a 2147483647!"
<<endl;
system("pause");
return false;
}
}
}
return true;
}
///////////////////////////validaciones de fecha////////////////////////////////
//////////
bool validar_fecha(int dia, int mes, int anho)
{
if (mes>12 || mes<0 ||
dia>31 || dia<0 ||
(dia>30 && mes>7 && mes % 2 == 1) ||
(dia>30 && mes<7 && (mes % 2 == 0)) ||
(dia>29 && mes == 2 && ((anho % 4 == 0) || ((anho % 100 > 0) &&
(anho % 400 == 0)))) ||
(dia>28 && mes == 2 && (anho % 4 >0) || ((anho % 100 == 0) && (a
nho % 400 > 0))))
{
return false;
}
else
{
return true;
}
}
bool fechavalida(char fecha[11])
{
gets(fecha);
fecha[10] = '\0';
bool correcto = true;
int dia = (fecha[0] - '0') * 10 + (fecha[1] - '0');
int mes = (fecha[3] - '0') * 10 + (fecha[4] - '0');
int anho = (fecha[6] - '0') * 1000 + (fecha[7] - '0') * 100 + (fecha[8]
- '0') * 10 + (fecha[9] - '0');
correcto = validar_fecha(dia, mes, anho);
//return true;
return correcto;
}
bool fechamenor(char *fechaini, char *fecha)
{
char d[3], m[3], a[5], d2[3], m2[3], a2[5];
bool cumple = false;
d[0] = fechaini[0]; d[1] = fechaini[1]; d[2] = '\0';
m[0] = fechaini[3]; m[1] = fechaini[4]; m[2] = '\0';
a[0] = fechaini[6]; a[1] = fechaini[7]; a[2] = fechaini[8]; a[3] = fecha
ini[9]; a[4] = '\0';
d2[0] = fecha[0]; d2[1] = fecha[1]; d2[2] = '\0';
m2[0] = fecha[3]; m2[1] = fecha[4]; m2[2] = '\0';
a2[0] = fecha[6]; a2[1] = fecha[7]; a2[2] = fecha[8]; a2[3] = fecha[9];
a2[4] = '\0';
if (strcmp(a, a2)<0)
{
cumple = true;
}
if (strcmp(a, a2) == 0)
{
if (strcmp(m, m2)<0)
{
cumple = true;
}
if (strcmp(m, m2) == 0)
{
if (strcmp(d, d2) <= 0)
{
cumple = true;
}
}
}
return cumple;
}
bool estaentrefechas(char *fecha, char *fecha_i, char *fecha_f)
{
return (fechamenor(fecha_i, fecha) && !fechamenor(fecha_f, fecha));
}
DateTime fechaDT(char fecha[])
{
int dia, mes, anho;
sscanf(fecha, "%d/%d/%d", &dia, &mes, &anho);
return DateTime(anho, mes, dia);
}
bool bisiesto(int x)
{
if (x % 100 == 0)
{
if ((x / 100) % 4 == 0)
return true;
else
return false;
}
else
{
if (x % 4 == 0)
return true;
else
return false;
}
}
///valida la fecha
bool esfechacorrecta(char fecha[])
{
int dia, mes, anho;
DateTime fecha1;
try
{
fecha1 = fechaDT(fecha);
}
catch (...)
{
return false;
}
sscanf(fecha, "%d/%d/%d", &dia, &mes, &anho);
bool correcta = false;
if ((dia == 0) || (mes == 0) || (mes > 12))
correcta = false;
else
{
if ((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11))
correcta = (dia <= 30);
else
{
if (mes == 2)
{
if (bisiesto(anho))
correcta = (dia <= 29);
else
correcta = (dia <= 28);
}
else
correcta = (dia <= 31);
}
}
return(correcta);
}
//////////////////////////////////producto//////////////////////////////////////
//////////
//valida que no exista un producto con el mismo id.
bool Validar_Id_Producto(int x)
{
FILE *ptr;
producto reg;
bool bandera = false;
ptr = fopen("producto.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_producto==x) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
//valida que no exista un producto con el mismo id.
bool Existe_Id_Producto(int id_producto)
{
FILE *ptr;
producto reg;
bool bandera = false;
ptr = fopen("producto.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_producto == id_producto ) && (reg.estado =
= 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
//valida queno exista un producto con el mismo nombre
bool Existe_Nombre_Producto(char nombre[])
{
FILE *ptr;
producto reg;
bool bandera = false;
ptr = fopen("producto.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (strcmp(reg.nombre,nombre)==0) && (reg.estado == '
N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
//valida que se ingrese un id producto del archivo binario
bool validar_id_producto_aceptable(char regidproducto[])
{
if( validarEntero(regidproducto) == false)
{
system("cls");
cout<<"ingrese un numero entero!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) <=0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
if(Existe_Id_Producto( (atoi(regidproduc
to))==true))
{
system("cls");
cout<<"el id ya existe, ingrese
otro id!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
}
return false;
}
//valida que no exista un producto con el mismo id
bool validar_nombre_producto_aceptable(char nombre[])
{
if(Existe_Nombre_Producto(nombre)==true)
{
system("cls");
cout<<"El nombre del producto ya existe!"<<endl;
system("pause");
return true;
}
else
{
return false;
}
return false;
}
//valida que el numero ingresado al stack este entre los rangos aceptables por e
l entero y que sea mayor a 0
bool validar_stack_aceptable(char stack[])
{
if( validarEntero(stack) == false)
{
system("cls");
cout<<"ingrese solamente numeros enteros: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(stack) <=0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(stack) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
//valida que se ingrese un id producto existente del archivo binario para poder
proceder con la modificacion del registro.
bool validar_id_producto_aceptable_modificar(char regidproducto[])
{
if( validarEntero(regidproducto) == false)
{
system("cls");
cout<<"ingrese un numero entero!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
// funcion que cuentra el numero de registro
int contar_modificar_producto(int idproducto)
{
FILE *ptr;
producto reg;
//posible error arreglar disminiyendo en -1
int c=0;
bool bandera = false;
ptr = fopen("producto.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_producto == idproducto ) && (reg.estado ==
'N'))
{
return c;
}
fread(®, sizeof(reg), 1, ptr);
c++;
}
}
fclose(ptr);
return(c);
}
//valida que no exista ninguna venta relacionada con ese producto para poder ser
eliminado.
bool Se_Puede_Vender(int id_producto)
{
FILE *ptr;
venta reg;
bool bandera = false;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_producto==id_producto) && (reg.estado == 'N'
))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
///////////////////////////cliente//////////////////////////////////
bool Validar_Id_Cliente(int x)
{
FILE *ptr;
cliente reg;
bool bandera = false;
ptr = fopen("cliente.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_cliente==x) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool Existe_Id_Cliente(int id_cliente)
{
FILE *ptr;
cliente reg;
bool bandera = false;
ptr = fopen("cliente.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_cliente == id_cliente ) && (reg.estado ==
'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool Existe_nit_Cliente(char nit[])
{
FILE *ptr;
cliente reg;
bool bandera = false;
ptr = fopen("cliente.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (strcmp(reg.nit,nit)==0) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool validar_id_cliente_aceptable(char regidcliente[])
{
if( validarEntero(regidcliente) == false)
{
system("cls");
cout<<"Ingrese solamente numeros enteros: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcliente) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcliente) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
if(Existe_Id_Cliente( (atoi(regidcliente
))==true))
{
system("cls");
cout<<"el id ya existe, ingrese
otro id: "<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
}
return false;
}
bool validar_nit_cliente_aceptable(char nit[])
{
if(Existe_nit_Cliente(nit)==true)
{
system("cls");
cout<<"El Nit ya existe!"<<endl;
system("pause");
return true;
}
else
{
if( validarEntero(nit) == false)
{
system("cls");
cout<<"Ingrese solo numeros!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
return false;
}
bool validar_id_cliente_aceptable_modificar(char regidproducto[])
{
if( validarEntero(regidproducto) == false)
{
system("cls");
cout<<"ingrese un numero entero!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidproducto) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
int contar_modificar_cliente(int idcliente)
{
FILE *ptr;
cliente reg;
//posible error arreglar disminiyendo en -1
int c=0;
bool bandera = false;
ptr = fopen("cliente.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_cliente == idcliente) && (reg.estado == 'N
'))
{
return c;
}
fread(®, sizeof(reg), 1, ptr);
c++;
}
}
fclose(ptr);
return(c);
}
////////////////////////vendedor//////////////////////////////////////
bool Existe_Id_Vendedor(int id_vendedor)
{
FILE *ptr;
vendedor reg;
bool bandera = false;
ptr = fopen("vendedor.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_vendedor == id_vendedor ) && (reg.estado =
= 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool Validar_Id_Vendedor(int idvendedor)//completar
{
FILE *ptr;
vendedor reg;
bool bandera = false;
ptr = fopen("vendedor.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_vendedor==idvendedor) && (reg.estado == 'N')
)
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool validar_id_vendedor_aceptable(char idvendedor[])//completar
{
if( validarEntero(idvendedor) == false)
{
system("cls");
cout<<"ingrese un numero entero: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(idvendedor) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(idvendedor) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
if(Existe_Id_Vendedor( (atoi(idvendedor)
)==true))
{
system("cls");
cout<<"el id ya existe, ingrese
otro id!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
}
return false;
}
bool contar_modificar_vendedor(int idvendedor)//completar
{
FILE *ptr;
vendedor reg;
//posible error arreglar disminiyendo en -1
int c=0;
bool bandera = false;
ptr = fopen("vendedor.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_vendedor == idvendedor ) && (reg.estado ==
'N'))
{
return c;
}
fread(®, sizeof(reg), 1, ptr);
c++;
}
}
fclose(ptr);
return(c);
}
bool validar_id_vendedor_aceptable_modificar(char regidvendedor[])
{
if( validarEntero(regidvendedor) == false)
{
system("cls");
cout<<"ingrese un numero entero!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidvendedor) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidvendedor) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
//valida que no exista ninguna venta relacionada con ese vendedor.
bool Se_Puede_Eliminar_Vendedor(int id_vendedor)
{
FILE *ptr;
venta reg;
bool bandera = true;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_vendedor==id_vendedor) && (reg.estado == 'N'
))
{
bandera = false;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
/////////////////////////venta/////////////////////////////////////////
//verifica que no exista el id venta
bool Existe_Id_Venta(int idventa)
{
FILE *ptr;
venta reg;
bool bandera = false;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_venta == idventa ) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool existeVenta(int idprod)
{
FILE *ptr;
venta reg;
bool bandera = false;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((idprod==reg.id_producto) && (reg.estado == 'N'))
{
bandera=true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
//valida que no exista el de la venta en el archivo binario
bool Validar_Id_Venta(int idventa)
{
FILE *ptr;
venta reg;
bool bandera = false;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_venta==idventa) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
//valida que exista almenos un vendedor, cliente y producto para vender
bool se_puede_vender()
{
FILE *ptrcliente,*ptrproducto,*ptrvendedor;
int a=0,b=0,c=0;
ptrcliente=fopen("cliente.dat","rb");
ptrproducto=fopen("producto.dat","rb");
ptrvendedor=fopen("vendedor.dat","rb");
producto regproducto;
cliente regcliente;
vendedor regvendedor;
////////////////////////////////////////////////////////////
if(ptrcliente!=NULL)
{
fread(®cliente, sizeof(cliente), 1, ptrcliente);
while (!feof(ptrcliente))
{
a++;
fread(®cliente, sizeof(cliente), 1, ptrcliente);
}
}
fclose(ptrcliente);
////////////////////////////////////////////////////////////
if(ptrproducto!=NULL)
{
fread(®producto, sizeof(producto), 1, ptrproducto);
while (!feof(ptrproducto))
{
b++;
fread(®producto, sizeof(producto), 1, ptrproducto);
}
}
fclose(ptrproducto);
////////////////////////////////////////////////////////////
if(ptrvendedor!=NULL)
{
fread(®vendedor, sizeof(vendedor), 1, ptrvendedor);
while (!feof(ptrvendedor))
{
c++;
fread(®vendedor, sizeof(vendedor), 1, ptrvendedor);
}
}
fclose(ptrvendedor);
////////////////////////////////////////////////////////////
if( (a<1) || (b<1) || (c<1) )
{ return false; }
return true;
}
//valida que el id venta exista en el archivo venta para proceder con la modific
acion.
bool validar_id_venta_aceptable(char regidventa[])
{
if( validarEntero(regidventa) == false)
{
system("cls");
cout<<"ingrese un numero entero: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidventa) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidventa) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
if(Existe_Id_Venta( (atoi(regidventa))==
true))
{
system("cls");
cout<<"el id ya existe, ingrese
otro id: "<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
}
return false;
}
//valida que exista el idproducto para procecer con la venta.
bool validar_exista_producto_para_venta(char idproducto[])
{
if(validar_id_producto_aceptable_modificar(idproducto)==false)
{
system("cls");
cout<<"Error no se puede registrar una venta, no existen product
os registrados!"<<endl;
system("pause");
}
else
{
return true;
}
return false;
}
//cuenta el numero de registros para proceder a la modificacion del mismo con fs
eek.
bool contar_modificar_venta(int idventa)
{
FILE *ptr;
venta reg;
//posible error arreglar disminiyendo en -1
int c=0;
bool bandera = false;
ptr = fopen("venta.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_venta == idventa) && (reg.estado == 'N'))
{
return c;
}
fread(®, sizeof(reg), 1, ptr);
c++;
}
}
fclose(ptr);
return(c);
}
//valida que el id venta exista en el archivo ventas para proceder con la modifi
cacion del mismo.
bool validar_id_venta_aceptable_modificar(char idventa[])
{
if( validarEntero(idventa) == false)
{
system("cls");
cout<<"ingrese solamente numeros enteros:"<<endl;
system("pause");
return false;
}
else
{
if(atoi(idventa) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(idventa) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
// valida que exista stock para proceceder con la venta.
bool Existe_Stack_Suficiente(int idproducto,int cuanto)
{
FILE *ptr;
producto reg;
ptr = fopen("producto.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_producto==idproducto) && (reg.estado == 'N')
)
{
if( cuanto <= reg.stack)
{
return true;
}
else
{
return false;
}
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(false);
}
// actualiza el valor del stack del producto luego de realizar la venta.
void Actualizar_Stack_Producto(int idprod,int requerimiento)
{
FILE*ptr;
producto reg;
char aux[100];
ptr = fopen("producto.dat", "r+b");
if (ptr == NULL)
{
cout << "El archivo no existe...";
}
else
{
reg.id_producto = idprod;
fseek(ptr, sizeof(reg)*(contar_modificar_producto(reg.id_product
o)-1), SEEK_SET);
fread(®, sizeof(producto), 1, ptr);
if (feof(ptr))
{
cout << "El registro no existe...";
}
else
{
reg.stack -= requerimiento;
int num=reg.id_producto;
fseek(ptr, sizeof(reg)* (contar_modificar_producto(reg.i
d_producto) - 1), SEEK_SET);
fwrite(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
}
//////////////////////////////compra//////////////////////////////////////////
//valida que exista almenos un producto para efectuar la compra
bool se_puede_comprar()
{
FILE *ptr;
int c=0;
producto reg;
ptr=fopen("producto.dat","rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
c++;
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
if(c>0)
{
return true;
}
else
{
return false;
}
}
bool Validar_Id_Compra(int x)
{
FILE *ptr;
compra reg;
bool bandera = false;
ptr = fopen("compra.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ((reg.id_compra==x) && (reg.estado == 'N'))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool Existe_Id_Compra(int id_compra)
{
FILE *ptr;
compra reg;
bool bandera = false;
ptr = fopen("compra.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_compra == id_compra) && (reg.estado == 'N'
))
{
bandera = true;
}
fread(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
return(bandera);
}
bool validar_id_compra_aceptable(char regidcompra[])
{
if( validarEntero(regidcompra) == false)
{
system("cls");
cout<<"ingrese solamente numeros enteros: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcompra) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcompra) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
if(Existe_Id_Compra( (atoi(regidcompra))
==true))
{
system("cls");
cout<<"el id ya existe, ingrese
otro id!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
}
return false;
}
bool validar_id_compra_aceptable_modificar(char regidcompra[])
{
if( validarEntero(regidcompra) == false)
{
system("cls");
cout<<"ingrese solamente numeros enteros: "<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcompra) <0)
{
system("cls");
cout<<"ingrese un numero positivo!"<<endl;
system("pause");
return false;
}
else
{
if(atoi(regidcompra) > Max_int)
{
system("cls");
cout<<"ingrese un numero menor,se excedi
o el rango de int!"<<endl;
system("pause");
return false;
}
else
{
return true;
}
}
}
return false;
}
int contar_modificar_compra(int idcompra)
{
FILE *ptr;
compra reg;
//posible error arreglar disminiyendo en -1
int c=0;
bool bandera = false;
ptr = fopen("compra.dat", "rb");
if (ptr != NULL)
{
fread(®, sizeof(reg), 1, ptr);
while (!feof(ptr))
{
if ( (reg.id_compra== idcompra) && (reg.estado == 'N'))
{
return c;
}
fread(®, sizeof(reg), 1, ptr);
c++;
}
}
fclose(ptr);
return(c);
}
/*void Actualizar_Stack_Producto_Compra(int idprod,int requerimiento)
{
FILE*ptr;
producto reg;
char aux[100];
ptr = fopen("producto.dat", "r+b");
if (ptr == NULL)
{
cout << "El archivo no existe...";
}
else
{
reg.id_producto = idprod;
fseek(ptr, sizeof(reg)*(contar_modificar_producto(reg.id_product
o)-1), SEEK_SET);
fread(®, sizeof(producto), 1, ptr);
if (feof(ptr))
{
cout << "El registro no existe...";
}
else
{
reg.stack += requerimiento;
int num=reg.id_producto;
fseek(ptr, sizeof(reg)* (contar_modificar_producto(reg.i
d_producto) - 1), SEEK_SET);
fwrite(®, sizeof(reg), 1, ptr);
}
}
fclose(ptr);
}*/
////////////////Funciones Producto////////////////////////
void CrearArchivoProducto(){
FILE *ptr;
ptr = fopen("producto.dat", "wb");
fclose(ptr);
}
void addregistroProducto()
{
FILE *ptr;
producto reg;
char aux[100];
////variables para validar la entrada de datos (auxiliares)
aux[0]='\0';
do
{
//limpia el buffer de entrada
fflush(stdin);
cin.clear();
///////////
cout << "Ingrese el ID del Producto: ";
gets(aux);
}
while(validar_id_producto_aceptable(aux)==false); //vali
da el id producto sea entero, este en un rango aceptable y que no exista.
do{
aux[0]='\0';
cout << "Ingrese el ID del Vendedor:";
gets(aux);
}while ( validar_id_vendedor_aceptable(aux) == false );
reg.id_vendedor = atoi(aux);
reg.nombre[0]='\0';
cout << "Ingrese el nombre del vendedor:";
gets (reg.nombre);
do
{
reg.correo[0]='\0';
cout<<"Ingrese el email del vendedor:";
gets(reg.correo);
}while(Validar_Correo(reg.correo)==false);
do
{
reg.telefono[0]='\0';
cout<<"Ingrese el telefono del vendedor: ";
gets(reg.telefono);
}while(Validar_Telefono(reg.telefono) == false);
reg.estado = 'N';
ptr = fopen("vendedor.dat", "ab");
fwrite(®, sizeof(reg), 1, ptr);
fclose(ptr);
}
void mostrarVendedor(){
FILE *ptr;
vendedor reg;
ptr = fopen("vendedor.dat", "rb");
if (ptr != NULL){
cout << endl << "===============================================
=====================================================";
cout << endl << " << ** LISTADO D
E VENDEDORES ** >>";
cout << endl << "-----------------------------------------------
-----------------------------------------------------";
cout << endl << "id Nombre
Correo Telefono ";
cout << endl << "-----------------------------------------------
-----------------------------------------------------";
fread(®, sizeof(vendedor), 1, ptr);
while (feof(ptr) == false){
if (reg.estado == 'N'){
cout << endl << reg.id_vendedor << "|\t\t " ;
cout<<reg.nombre<<"|\t\t";
cout<<reg.correo<<"|\t\t";
cout<<reg.telefono<<"|\t";
}
fread(®, sizeof(reg), 1, ptr);
}
cout << endl << "===============================================
=====================================================";
fclose(ptr);
}
else{
cout << endl << "El archivo no existe...!!";
}
}
void modificar_Registro_Vendedor()
{
FILE*ptr;
vendedor reg;
char aux[100];
ptr = fopen("vendedor.dat", "r+b");
if (ptr == NULL)
{
cout << "El archivo no existe...";
}
else
{
do{
cout << "Ingrese el ID del Vendedor:";
gets(aux);
}while ( validar_id_vendedor_aceptable(aux) == false );
reg.id_vendedor = atoi(aux);
fseek(ptr,sizeof(reg)* (contar_modificar_cliente(reg.id_
vendedor)),SEEK_SET);
fread(®, sizeof(reg),1,ptr);
if(feof(ptr))
{
cout<<"El registro no existe..."<<endl;
}
else
{
if (Validar_Id_Vendedor( atoi(aux) ) == true)
{
do{
fflush(stdin);
cin.clear();
cout << "Ingrese el ID de la Venta: ";
gets(aux);
}while ( validar_id_venta_aceptable_modificar(aux) == fa
lse );
reg.id_venta = atoi(aux);
fseek(ptr,sizeof(reg)* (contar_modificar_venta(reg.id_ve
nta)),SEEK_SET);
fread(®, sizeof(venta),1,ptr);
if(feof(ptr))
{
cout<<"el registro no existe..."<<endl;
}
else
{
if (Validar_Id_Venta( atoi(aux) ) == true)
{
Reporte_Venta(dtInicio,
dtFin);
_getch();
}
else if (opcion6 == '2')
{
system("cls");
//reporte de ventas por
producto entre fechas
//reporte de ventas entr
e fechas
char fecha_inicio[10], f
echa_fin[10];
DateTime dtInicio, dtFin
;
// Fecha Inicio se valid
a
do{
cout << "Fecha I
nicio: ";
fflush(stdin);
gets(fecha_inici
o);
fflush(stdin);
} while (!esfechacorrect
a(fecha_inicio));
//se almacena el valor d
e la fecha inicio en la variable dt
dtInicio = fechaDT(fecha
_inicio);
// Fecha Fin se valida
do{
do{
cout <<
"Fecha Final: ";
fflush(s
tdin);
gets(fec
ha_fin);
fflush(s
tdin);
} while (!esfech
acorrecta(fecha_fin));
//se almacena el
valor de la fecha fin en la variable dt
dtFin = fechaDT(
fecha_fin);
//se valida que
la fecha inicio no sea mayor que la fecha fin
//muestra mensaj
e que la fecha inicio no puede ser mayor que la final
if (dtInicio > d
tFin)
{ cout <<
endl << "La fecha Inicio no puede ser mayor a la Fecha Final" << endl;}
} while (dtInicio > dtFi
n);
int idproducto;
do{
cout <<
"Ingrese el ID del Producto:";
gets(aux
);
}while ( validar_id_prod
ucto_aceptable_modificar(aux) == false ); //valida el id producto sea entero, es
te en un rango aceptable y que no exista.
idproducto=atoi(aux);
system("cls");
Reporte_Venta_Por_Produc
to(dtInicio, dtFin,idproducto);
_getch();
}
else if (opcion6 == '3')
{
system("cls");
//reporte de venta por c
liente entre fechas
//reporte de ventas entr
e fechas
char fecha_inicio[10], f
echa_fin[10];
DateTime dtInicio, dtFin
;
// Fecha Inicio se valid
a
do{
cout << "Fecha I
nicio: ";
gets(fecha_inici
o);
} while (!esfechacorrect
a(fecha_inicio));
//se almacena el valor d
e la fecha inicio en la variable dt
dtInicio = fechaDT(fecha
_inicio);
// Fecha Fin se valida
do{
do{
cout <<
"Fecha Final: ";
gets(fec
ha_fin);
} while (!esfech
acorrecta(fecha_fin));
//se almacena el
valor de la fecha fin en la variable dt
dtFin = fechaDT(
fecha_fin);
//se valida que
la fecha inicio no sea mayor que la fecha fin
//muestra mensaj
e que la fecha inicio no puede ser mayor que la final
if (dtInicio > d
tFin)
{ cout <<
endl << "La fecha Inicio no puede ser mayor a la Fecha Final" << endl;}
} while (dtInicio > dtFi
n);
int idcliente;
do{
cout << "Ingrese
el ID del Cliente:";
gets(aux);
}while ( validar_id_clie
nte_aceptable(aux) == false );
idcliente = atoi(aux);
//validar
Reporte_Venta_Por_Client
e(dtInicio, dtFin,idcliente);
_getch();
}
else if (opcion6 == '4')
{
system("cls");
//reporte de compras ent
re fechas
//reporte de ventas entr
e fechas
char fecha_inicio[10], f
echa_fin[10];
DateTime dtInicio, dtFin
;
// Fecha Inicio se valid
a
do{
cout << "Fecha I
nicio: ";
fflush(stdin);
gets(fecha_inici
o);
fflush(stdin);
} while (!esfechacorrect
a(fecha_inicio));
//se almacena el valor d
e la fecha inicio en la variable dt
dtInicio = fechaDT(fecha
_inicio);
// Fecha Fin se valida
do{
do{
cout <<
"Fecha Final: ";
fflush(s
tdin);
gets(fec
ha_fin);
fflush(s
tdin);
} while (!esfech
acorrecta(fecha_fin));
//se almacena el
valor de la fecha fin en la variable dt
dtFin = fechaDT(
fecha_fin);
//se valida que
la fecha inicio no sea mayor que la fecha fin
//muestra mensaj
e que la fecha inicio no puede ser mayor que la final
if (dtInicio > d
tFin)
{ cout <<
endl << "La fecha Inicio no puede ser mayor a la Fecha Final" << endl;}
} while (dtInicio > dtFi
n);
//validar
Reporte_Compra(dtInicio,
dtFin);
_getch();
}
else if (opcion6 == '5')
{
system("cls");
char fecha_inicio[10], f
echa_fin[10];
DateTime dtInicio, dtFin
;
// Fecha Inicio se valid
a
do{
cout << "Fecha I
nicio: ";
fflush(stdin);
gets(fecha_inici
o);
fflush(stdin);
} while (!esfechacorrect
a(fecha_inicio));
//se almacena el valor d
e la fecha inicio en la variable dt
dtInicio = fechaDT(fecha
_inicio);
// Fecha Fin se valida
do{
do{
cout <<
"Fecha Fin: ";
fflush(s
tdin);
gets(fec
ha_fin);
fflush(s
tdin);
} while (!esfech
acorrecta(fecha_fin));
//se almacena el
valor de la fecha fin en la variable dt
dtFin = fechaDT(
fecha_fin);
//se valida que
la fecha inicio no sea mayor que la fecha fin
//muestra mensaj
e que la fecha inicio no puede ser mayor que la final
if (dtInicio > d
tFin)
{ cout <<
endl << "La fecha Inicio no puede ser mayor a la Fecha Final" << endl;}
}while (dtInicio > dtFin
);
int idproducto5;
do{
cout <<
"Ingrese el ID del Producto:";
gets(aux
);
}while ( validar_id_prod
ucto_aceptable_modificar(aux) == false ); //valida el id producto sea entero, es
te en un rango aceptable y que no exista.
idproducto5=atoi(aux);
//validar
Reporte_Compra_Por_Produ
cto(dtInicio, dtFin,idproducto5);
_getch();
}
else if (opcion6 == '6')
{
_getch();
}
system("cls");
} while (opcion6 != '0');
break;
}
}
system("cls");
} while (opcion != '0');
return(0);
}