Advertisement
difernando5672

Sistema de gestão de uma loja de material de construções

Jul 23rd, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 41.30 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include <time.h>
  6.  
  7. typedef struct humano{
  8.     char nome[20], rua[50], email[40],cpf[12],tel[12];
  9.     int codigo, qcompras, ncompra[100];
  10.     float preco, precototal;
  11. }pessoa;
  12.  
  13. typedef struct prudutos{
  14.     char nome[20], marca[20];
  15.     int codigo, estoque;
  16.     float preco;
  17. }peca;
  18.  
  19. typedef struct venda{
  20.     peca produtos[50];
  21.     float qp;
  22.     int pecax;
  23.     int pAtual;
  24.     int codigo;
  25.     int codpes;
  26.     pessoa cliente;
  27.     float total;
  28. }venda;
  29.  
  30. void pass();
  31. void menuCliente(pessoa *clientes, int *cAtual);
  32. void preencheCliente(pessoa *clientes, int *cAtual);
  33. void alterarCliente(pessoa *clientes, int *cAtual);
  34. void excluirCliente(pessoa *clientes, int *cAtual);
  35. int buscaCodigoCliente(pessoa *clientes, int *cAtual);
  36. void menuEstoque(peca *pecas, int *pAtual);
  37. void preencheProduto(peca *pecas, int *pAtual);
  38. void alterarProduto(peca *pecas, int *pAtual);
  39. void excluirProduto(peca *pecas, int *pAtual);
  40. int buscaPProduto(peca *pecas, int *pAtual);
  41. void menuMovimentar(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas,int *vAtual);
  42. void venderProduto(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas,int *vAtual);
  43. void menuVendas();
  44. void Venda();
  45. void mostrarCliente(pessoa*p, int *max);
  46. void menu(pessoa *clientes, peca *pecas, venda *vendas);
  47. void menuRelatorio(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas,int *vAtual);
  48. void relatorioClienteCad(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual);
  49. void relatorioClienteEsp(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual);
  50. void reporProduto(peca *pecas, int *pAtual);
  51. void salva(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual,int *sAtual);
  52. void atualiza(int *cAtual, int *pAtual, int *vAtual, int *sAtual);
  53. void zerar(int * cAtual, int *pAtual, int *vAtual, int *sAtual);
  54. int verificaCpf(char*cpf);
  55. int verificaTel(char*tel);
  56.  
  57.  
  58.  
  59. int main () {
  60.     peca pecas[100];
  61.     pessoa clientes[100];
  62.     venda vendas[100];
  63.    
  64.     menu(&clientes[0],&pecas[0],&vendas[0]);
  65.     system("pause");
  66.    
  67. }
  68.  
  69. void pass(){
  70.    
  71.  
  72. char tentativa[7], user[20], auxuser, opsair;
  73.     int verifica,verificaa=0,i;
  74.     do{
  75.    
  76.         system("cls");
  77.         printf("\n\n\n\n\n\n\n                      °\n");
  78.         printf("                        °    LOGIN: ");
  79.         fflush(stdin);
  80.        
  81.         user[0] = getch();
  82.        
  83.         if(user[0] == 27){
  84.             system("cls");
  85.             printf("\n\n\n\n\n\n\n                      °\n");
  86.             printf("                        °    ENCERRANDO...\n");
  87.             exit(0);
  88.         }
  89.        
  90.         else{
  91.         printf("%c", user[0]);
  92.         fflush(stdin);
  93.         auxuser = user[0];
  94.         fflush(stdin);
  95.         gets(user);
  96.         verificaa = strcmp(user,"iegofernando5672");
  97.             if(verificaa != 0){
  98.             printf("                        °    Login incorreto!");
  99.             getch();
  100.         }
  101.         else{
  102.         }
  103.         }
  104.     }while(verificaa!=0 || opsair == '2');
  105.        
  106.    
  107.    
  108.    
  109.     do{
  110.         system("cls");
  111.         printf("\n\n\n\n\n\n\n                      °    LOGIN: %c%s\n", auxuser, user);
  112.         printf("                        °    SENHA: ");
  113.         fflush(stdin);
  114.         for(i=0;i<6; i++){
  115.             fflush(stdin);
  116.             tentativa[i] = getch();
  117.             printf("*");
  118.         }
  119.        
  120.         if(strcmp(tentativa,"961100")){
  121.             printf("\n                      °    Senha incorreta ");
  122.             verifica = 1;
  123.             getch();       
  124.         }
  125.         else{
  126.             printf("\n                      °    Pressione qualquer tecla para continuar\n ");
  127.             verifica=0;
  128.             getch();
  129.         }
  130.         system("cls");
  131.  
  132.     }while(verifica==1);
  133.    
  134.    
  135.        
  136.    
  137. }
  138. void menu(pessoa *clientes, peca *pecas, venda *vendas){
  139.     unsigned short ntSleepTmp;
  140.     unsigned short shPercent = 0;
  141.     unsigned short a = 0;
  142.     pass();
  143.    
  144.    
  145.    
  146.    
  147.     FILE *fp;
  148.     FILE *hr;
  149.     FILE *cl;
  150.     FILE *pr;
  151.     FILE *vend;
  152.    
  153.    
  154.    
  155.    
  156.     fp = fopen("dados.txt", "r");
  157.     hr = fopen("hora.txt","r");
  158.     cl = fopen("clientes.txt", "r");
  159.     pr = fopen("produtos.txt", "r");
  160.     vend = fopen("vendas.txt", "r");
  161.    
  162.     int i,j;
  163.     char opc, op1;
  164.     int cli = 0, *cAtual = &cli;
  165.     int pec = 0, *pAtual = &pec;
  166.     int ven = 0, *vAtual = &ven;
  167.     int sal = 0, *sAtual = &sal;
  168.    
  169.     fscanf(fp, "%d", cAtual);
  170.     fscanf(fp, "%d", pAtual);
  171.     fscanf(fp, "%d", vAtual);
  172.     fscanf(fp, "%d", sAtual);
  173.    
  174.     for(i=0;i<*cAtual;i++){
  175.         fscanf(cl, "%[^\n]%*c", &clientes[i].nome);
  176.         fscanf(cl, "%[^\n]%*c", &clientes[i].rua);
  177.         fscanf(cl, "%[^\n]%*c", &clientes[i].email);
  178.         fscanf(cl, "%[^\n]%*c", &clientes[i].cpf);
  179.         fscanf(cl, "%[^\n]%*c", &clientes[i].tel);
  180.         fscanf(cl, "%d%*c", &clientes[i].codigo);
  181.         fscanf(cl, "%d%*c", &clientes[i].qcompras);
  182.         fscanf(cl, "%f%*c", &clientes[i].preco);
  183.         fscanf(cl, "%f%*c", &clientes[i].precototal);
  184.         if (clientes[i].qcompras == 0){
  185.         }
  186.         else{
  187.        
  188.             for(j=0;j<clientes[i].qcompras;j++){
  189.                     fscanf(cl, "%d%*c", &clientes[i].ncompra[j]);
  190.                 }
  191.         }
  192.     }
  193.     fclose(cl);
  194.    
  195.     for(i=0;i<*pAtual;i++){
  196.         fscanf(pr, "%[^\n]%*c", &pecas[i].nome);
  197.         fscanf(pr, "%[^\n]%*c", &pecas[i].marca);
  198.         fscanf(pr, "%f%*c", &pecas[i].preco);
  199.         fscanf(pr, "%d%*c", &pecas[i].estoque);
  200.         fscanf(pr, "%d%*c", &pecas[i].codigo);
  201.     }
  202.     fclose(pr);
  203.    
  204.     for(i=0;i<*vAtual;i++){
  205.         fscanf(vend, "%d", &vendas[i].cliente);
  206.         fscanf(vend, "%d", &vendas[i].codigo);
  207.         fscanf(vend, "%d", &vendas[i].codpes);
  208.         fscanf(vend, "%f", &vendas[i].qp);
  209.     }
  210.     fclose(vend);
  211.     const int vp = *sAtual-1;
  212.     int hora[*sAtual], min[*sAtual], sec[*sAtual], dia[*sAtual], mes[*sAtual], ano[*sAtual];
  213.    
  214.    
  215.  
  216.     for(i=0;i<*sAtual;i++){
  217.         fscanf(hr, "%d", &hora[i]);
  218.         fscanf(hr, "%d", &min[i]);
  219.         fscanf(hr, "%d", &sec[i]);
  220.         fscanf(hr, "%d", &dia[i]);
  221.         fscanf(hr, "%d", &mes[i]);
  222.         fscanf(hr, "%d", &ano[i]);
  223.     }
  224.    
  225.    
  226.     do{
  227.         system("cls");
  228.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  229.         printf("°                                                                                                                                   °\n");
  230.         printf("°    GERENCIAMENTO LOJA DE MATERIAL DE CONSTRUCOES     -    MENU PRINCIPAL           [S]  - SALVAR NO ARQUIVO  [H]  - HISTORICO     °\n");
  231.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  232.         printf("°                          °                          °                        °                     °              °               °\n");
  233.         printf("°      [1]  MENU CLIENTE   °     [2] MOVIMENTACAO     °   [3] MENU PRODUTOS    °    [4] RELATORIOS   °   [5] AJUDA  °  [ESC] LOGOUT °\n");
  234.         printf("°                          °                          °                        °                     °              °               °\n");
  235.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  236.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°° Qtd de clientes: %d - Qtd de prdutos: %d - Qtd de vendas: %d °\n", *cAtual, *pAtual, *vAtual);
  237.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  238.         if(vp==-1){
  239.             printf("\nNao existem dados gravados neste software.\n");
  240.         }
  241.         else{
  242.         printf("Salvo e finalizado por ultimo as: %02d:%02d:%02d - %02d/%02d/%d\n",hora[vp],min[vp],sec[vp],dia[vp],mes[vp],ano[vp]);
  243.         }
  244.    
  245.         fflush(stdin);
  246.         opc = getch();
  247.         switch(opc){
  248.             case '1':
  249.                 menuCliente(clientes, &cli);
  250.             break;
  251.            
  252.             case '2':
  253.                 if(*cAtual == 0){
  254.                     printf("Erro! Nao ha cadastros de cliente.\n");
  255.                     printf("[1] - Cadastrar cliente\n");
  256.                     printf("[2] - Agora nao\n");
  257.                     fflush(stdin);
  258.                     opc = getch();
  259.                     if (opc == '1'){
  260.                         menuCliente(clientes, &cli);
  261.                     }
  262.                    
  263.                 }
  264.                 if(*pAtual == 0){
  265.                     printf("Erro! Nao ha cadastros de produtos.\n");
  266.                     printf("[1] - Cadastrar produto\n");
  267.                     printf("[2] - Agora nao\n");
  268.                     fflush(stdin);
  269.                     opc = getch();
  270.                     if (opc == '1'){
  271.                         menuEstoque(pecas,&pec);
  272.                     }
  273.                 }
  274.                 else{
  275.                     menuMovimentar(clientes,cAtual,pecas,pAtual,vendas,vAtual);
  276.                 }
  277.             break;
  278.             case '3':
  279.                 menuEstoque(pecas,&pec);
  280.             break;
  281.             case '4':
  282.                 menuRelatorio(clientes,cAtual,pecas,pAtual,vendas,cAtual);
  283.             break;
  284.             case '5':
  285.                 printf("\nAJUDA:\n  Neste menu fica disponivel de maneira ampla todas as funcionalidades do menu. Ficam disponiveis as opcoes para: cadastrar\ncliente, movimentar as partes financeiras da organizacao, cadastrar produtos no estoque, gerar relatorios gerais. Logo em cima, temos\ncomo salvar no arquivo e consultar o hitorico.");
  286.                 getch();
  287.             break;
  288.             case 's':
  289.                 while( shPercent < 100)
  290.                  {
  291.                      while(ntSleepTmp += 3000);
  292.                        printf("\r");
  293.  
  294.                      shPercent += 2;
  295.  
  296.                         for(a = 0; a < shPercent/2;a++ )
  297.                            printf("%c", 178);
  298.  
  299.                             printf("%d%%", shPercent);
  300.  
  301.  
  302.  
  303.                 }
  304.                 salva(clientes,cAtual,pecas,pAtual,vendas,vAtual,sAtual);
  305.             break;
  306.            
  307.             case 'h':
  308.                 printf("Historico:\n");
  309.                 atualiza(cAtual,pAtual,vAtual,sAtual);
  310.             break;
  311.             case 27:
  312.                 pass();
  313.             break;
  314.             default:
  315.                 printf("OPCAO INVALIDA!!\n");
  316.                 getch();
  317.         }
  318.     }while(opc != -1);
  319.    
  320.     fclose(fp);
  321.     fclose(hr);
  322. }
  323.  
  324. void atualiza(int *cAtual, int *pAtual, int *vAtual, int *sAtual){
  325.     FILE *hr;
  326.     int hora[*sAtual], min[*sAtual], sec[*sAtual], dia[*sAtual], mes[*sAtual], ano[*sAtual],i;
  327.     int aux;
  328.     char op;
  329.     hr = fopen("hora.txt","r");
  330.         for(i=0;i<*sAtual;i++){
  331.         fscanf(hr, "%d", &hora[i]);
  332.         fscanf(hr, "%d", &min[i]);
  333.         fscanf(hr, "%d", &sec[i]);
  334.         fscanf(hr, "%d", &dia[i]);
  335.         fscanf(hr, "%d", &mes[i]);
  336.         fscanf(hr, "%d", &ano[i]);
  337.     }
  338.     fclose(hr);
  339.     if(*sAtual <10){
  340.         printf("Historico somente exibido apos 10 salvos!");
  341.     }
  342.     else{
  343.    
  344.     for(i=*sAtual-1;i>*sAtual-10;i--){
  345.                     printf("Salvo as: %02d:%02d:%02d - %02d/%02d/%d\n",hora[i],min[i],sec[i],dia[i],mes[i],ano[i]);
  346.                     }
  347.         printf("\n[Z] - ZERAR");
  348.         fflush(stdin);
  349.         op = getch();
  350.         if(op == 'z' || op == 'Z'){
  351.             printf("Deseja zerar os contadores?\n");
  352.             printf("[1] - Sim\n");
  353.             printf("[2] - Nao\n");
  354.             fflush(stdin);
  355.             op = getch();
  356.             if(op == '1'){
  357.                 *sAtual = 0;
  358.                 zerar(cAtual,pAtual,vAtual,sAtual);
  359.             }
  360.        
  361.     }
  362.     }
  363.    
  364.     getch();
  365. }
  366.  
  367. void salva(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual, int *sAtual){
  368.     int i,j;
  369.     FILE *cl;
  370.     cl = fopen("clientes.txt","w");
  371.    
  372.     for(i=0;i<*cAtual;i++){
  373.         fprintf(cl, "%s\n", clientes[i].nome);
  374.         fprintf(cl, "%s\n", clientes[i].rua);
  375.         fprintf(cl, "%s\n", clientes[i].email);
  376.         fprintf(cl, "%s\n", clientes[i].cpf);
  377.         fprintf(cl, "%s\n", clientes[i].tel);
  378.         fprintf(cl, "%d\n", clientes[i].codigo);
  379.         fprintf(cl, "%d\n", clientes[i].qcompras);
  380.         fprintf(cl, "%f\n", clientes[i].preco);
  381.         fprintf(cl, "%f\n", clientes[i].precototal);
  382.             for(j=0;j<clientes[i].qcompras;j++){
  383.                 fprintf(cl, "%d\n", clientes[i].ncompra[j]);
  384.             }
  385.     }
  386.     fclose(cl);
  387.    
  388.     FILE *pr;
  389.     pr = fopen("produtos.txt", "w");
  390.    
  391.     for(i=0;i<*pAtual;i++){
  392.         fprintf(pr, "%s\n", pecas[i].nome);
  393.         fprintf(pr, "%s\n", pecas[i].marca);
  394.         fprintf(pr, "%f\n", pecas[i].preco);
  395.         fprintf(pr, "%d\n", pecas[i].estoque);
  396.         fprintf(pr, "%d\n", pecas[i].codigo);
  397.     }
  398.    
  399.     fclose(pr);
  400.    
  401.     FILE *vend;
  402.     vend = fopen("vendas.txt", "w");
  403.    
  404.     for(i=0;i<*vAtual;i++){
  405.         fprintf(vend, "%d\n", vendas[i].cliente);
  406.         fprintf(vend, "%d\n", vendas[i].codigo);
  407.         fprintf(vend, "%d\n", vendas[i].codpes);
  408.         fprintf(vend, "%f\n", vendas[i].qp);
  409.     }
  410.    
  411.     fclose(vend);
  412.    
  413.     FILE *fp;
  414.     fp = fopen("dados.txt", "w");
  415.     *sAtual = *sAtual +1;
  416.     fprintf(fp, "%d\n", *cAtual);
  417.     fprintf(fp, "%d\n", *pAtual);
  418.     fprintf(fp, "%d\n", *vAtual);
  419.     fprintf(fp, "%d\n", *sAtual);
  420.    
  421.     printf("\nDados gravados!");
  422.     fclose(fp);
  423.    
  424.     FILE *hr;
  425.     hr = fopen("hora.txt","a");
  426.     struct tm *local;
  427.     time_t t;
  428.     t= time(NULL);
  429.     local=localtime(&t);
  430.     int hora=0, min=0, sec=0, dia=0, mes=0, ano=0;
  431.  
  432.     hora=local->tm_hour;
  433.     min=local->tm_min;
  434.     sec=local->tm_sec;
  435.     dia=local->tm_mday;
  436.     mes=local->tm_mon+1;
  437.     ano=local->tm_year+1900;
  438.  
  439.     printf(" Salvo: %02d:%02d:%02d - %02d/%02d/%d\n",hora,min,sec,dia,mes,ano);
  440.    
  441.     fprintf(hr, "%d ", hora);
  442.     fprintf(hr, "%d ", min);
  443.     fprintf(hr, "%d ", sec);
  444.     fprintf(hr, "%d ", dia);
  445.     fprintf(hr, "%d ", mes);
  446.     fprintf(hr, "%d\n", ano);
  447.     fclose(hr);
  448.    
  449.     getch();
  450. }
  451.  
  452. void zerar(int * cAtual, int *pAtual, int *vAtual, int *sAtual){
  453.     pass();
  454.     FILE *fp;
  455.     fp = fopen("dados.txt", "w");
  456.     fprintf(fp, "%d\n", 0);
  457.     fprintf(fp, "%d\n", 0);
  458.     fprintf(fp, "%d\n", 0);
  459.     fprintf(fp, "%d\n", 0);
  460.     *cAtual = 0;
  461.     *pAtual = 0;
  462.     *vAtual = 0;
  463.     *sAtual = 0;
  464.     fclose(fp);
  465.     FILE *hr;
  466.     hr = fopen("hora.txt", "w");
  467.     fclose(hr);
  468.     printf("\nCONTADORES ZERADOS COM SUCESSO!");
  469.     getch();
  470. }
  471.  
  472. void menuMovimentar(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual){
  473.     char opc, i;
  474.     do{
  475.         system("cls");
  476.    
  477.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  478.         printf("°                                                                                                                                   °\n");
  479.         printf("°                                                 MENU MOVIMENTAR         [C] - LISTAR CLIENTES     [P] - LISTAR PRODUTOS           °\n");
  480.         printf("°                                                                                                                                   °\n");
  481.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  482.         printf("°                                  °                               °                          °                                     °\n");
  483.         printf("°        [1]  VENDER PRODUTO       °           [2] CARRINHO        °       [3] AJUDA          °        [ESC] MENU PRINCIPAL         °\n");
  484.         printf("°                                  °                               °                          °                                     °\n");
  485.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  486.         opc = getch();
  487.         fflush(stdin);
  488.         switch(opc){
  489.             case '1':
  490.                 venderProduto(clientes,cAtual,pecas,pAtual,vendas,vAtual);
  491.             break;
  492.             case '2':
  493.                 relatorioClienteEsp(clientes,cAtual,pecas,pAtual,vendas,vAtual);
  494.             break;
  495.             case '3':
  496.                 printf("\nNeste menu sao feitas todas as transacoes da organizacao");
  497.             break;
  498.             case 'c':
  499.                 for(i = 0; i < *cAtual; i++){
  500.                         if(clientes[i].codigo != 0){
  501.                         printf("Codigo: %d -", clientes[i].codigo);
  502.                         printf(" Nome: %s\n", clientes[i].nome);
  503.                         }
  504.                     }
  505.                     getch();
  506.             break;
  507.             case 'p':
  508.                     for (i=0;i<*pAtual;i++){
  509.                         if (pecas[i].codigo == 0){
  510.                         }
  511.                         else{
  512.                             printf("Codigo: %d - Nome: %s - Marca: %s - Estoque: %d - Preco: R$ %.2f \n", pecas[i].codigo, pecas[i].nome, pecas[i].marca, pecas[i].estoque, pecas[i].preco);
  513.                         }
  514.                     }
  515.                     getch();
  516.             break;
  517.             case 27:
  518.                 break;
  519.             default:
  520.                 printf("OPCAO INVALIDA!!\n");
  521.                 getch();
  522.             break;
  523.         }
  524.     }while(opc != 27);
  525. }
  526.  
  527. void venderProduto(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual){
  528.     int codpp = buscaPProduto(pecas,pAtual);
  529.     int codcli = 0;
  530.     float quant;
  531.     char opr;
  532.    
  533.    
  534.     if(pecas[codpp].estoque <= 0){
  535.         printf("NAO HA PECAS NO ESTOQUE!");
  536.         getch();
  537.     }
  538.     else{
  539.    
  540.         if(codpp == -1){
  541.        
  542.             printf("NAO HA PRODUTO COM O CODIGO ESPECIFICADO!\n");
  543.             getch();
  544.         }
  545.         else{
  546.             printf("\n");
  547.             codcli = buscaCodigoCliente(clientes,cAtual);
  548.             if(codcli == -1){
  549.                 printf("NAO HA CLIENTE COM O CODIGO ESPECIFICADO!");
  550.                 getch();
  551.             }
  552.             else{
  553.                 printf("\n");
  554.                 printf("Digite a quantidade: ");
  555.                 scanf("%f",&quant);
  556.                 if (quant <= 0){
  557.                     printf("NAO PERMITIDO VALOR NEGATIVO!\n");
  558.                     getch();
  559.                 }
  560.                 else if(quant > pecas[codpp].estoque){
  561.                     printf("ERRO! QUANTIDADE MAIOR QUE O VALOR DO ESTOQUE.\n");
  562.                     getch();
  563.                 }
  564.                 else{
  565.                
  566.                     vendas[*vAtual].total = pecas[codpp].preco * quant;
  567.                    
  568.                     vendas[*vAtual].qp = quant;
  569.                     vendas[*vAtual].cliente = clientes[codcli];
  570.                     vendas[*vAtual].produtos[vendas[*vAtual].pAtual] = pecas[codpp];
  571.                     vendas[*vAtual].produtos[vendas[*vAtual].pAtual].estoque = quant;
  572.                     pecas[codpp].estoque = pecas[codpp].estoque - quant;
  573.                     vendas[*vAtual].codigo = *vAtual;
  574.                     clientes[codcli].preco = clientes[codcli].preco + vendas[*vAtual].total;
  575.                     clientes[codcli].ncompra[clientes[codcli].qcompras] = *vAtual;
  576.                     clientes[codcli].qcompras = clientes[codcli].qcompras + 1;
  577.                     vendas[*vAtual].pecax = codpp;
  578.                     vendas[*vAtual].codpes = 3000 + *vAtual;
  579.                     clientes[codcli].precototal = clientes[codcli].precototal + vendas[*vAtual].total;
  580.                     printf("\n");
  581.                     printf("O total da venda efetuada foi:R$ %.2f \n", vendas[*vAtual].total);
  582.                     printf("O codigo da venda efetuada foi: %d\n", vendas[*vAtual].codpes);
  583.                     *vAtual += 1;
  584.                    
  585.                    
  586.                    
  587.                     printf("\n\nRelatorio de compra:\n");
  588.                     printf("E - Emitir\n");
  589.                     printf("Enter - Nao emitir\n");
  590.                     opr = getch();
  591.                    
  592.                     if(opr == 27){
  593.                     }
  594.                     else if(opr == 'e'){
  595.                        
  596.                         struct tm *local;
  597.                             time_t t;
  598.                             t= time(NULL);
  599.                             local=localtime(&t);
  600.                         int hora=0, min=0, sec=0, dia=0, mes=0, ano=0;
  601.  
  602.                             hora=local->tm_hour;
  603.                             min=local->tm_min;
  604.                             sec=local->tm_sec;
  605.                             dia=local->tm_mday;
  606.                             mes=local->tm_mon+1;
  607.                             ano=local->tm_year+1900;
  608.                        
  609.                         FILE *re;
  610.                         re = fopen("relatorio.doc", "w");
  611.                        
  612.                         printf("\nAguarde a emissao...\n");
  613.                         printf("\nPara continuar a usar a aplicacao, feche o relatorio.");
  614.                        
  615.                         char emit[60] = "LOJA DE MATERIAL DE CONSTRUCOES SOUSA LTDA.";
  616.                         char emit111[80] = " \t\t -----------------------------------------";
  617.                         char emit1[80] = "\t\t|EMISSAO DE NOTA FISCAL REFERENTE A COMPRA|";
  618.                         char emit2[20] = "Nome: ";
  619.                         char emit3[20] = "Endereco: ";
  620.                         char emit4[20] = "CPF: ";
  621.                         char emit5[20] = "Telefone: ";
  622.                         char emit51[20] = "E-mail: ";
  623.                         char emit6[20] = "COMPRA";
  624.                         char emit7[20] = "Marca: ";
  625.                         char emit8[20] = "Preco: ";
  626.                         char emit9[20] = "Quantidade: ";
  627.                         char emit10[20] = "Total a pagar: ";
  628.                         char emit11[40] = "Agradecemos a preferencia";
  629.                         char emit12[80] = "Software desenvolvido por Diego Fernando - www.facebook.com/dieguinhofernando";
  630.                         char emit13[80] = "Dados pessoais";
  631.                         char emit14[200] = "__________________________________________________________";
  632.                        
  633.                        
  634.                         fprintf(re, "\t\t%s\n\n", emit);
  635.                         fprintf(re, "\n\n%s", emit111);
  636.                         fprintf(re, "\n%s", emit1);
  637.                         fprintf(re, "\n%s", emit111);
  638.                         fprintf(re, "\n\n\n\n\t\t\t\t%s", emit13);
  639.                         fprintf(re, "\n%s", emit14);
  640.                         fprintf(re, "\n%s", emit2);
  641.                         fprintf(re, "%s", clientes[codcli].nome);
  642.                         fprintf(re, "\n%s", emit3);
  643.                         fprintf(re, "%s", clientes[codcli].rua);
  644.                         fprintf(re, "\n%s", emit5);
  645.                         fprintf(re, "%s", clientes[codcli].tel);
  646.                         fprintf(re, "\n%s", emit51);
  647.                         fprintf(re, "%s", clientes[codcli].email);
  648.                         fprintf(re, "\t\t\t\t%s", emit4);
  649.                         fprintf(re, "%s", clientes[codcli].cpf);
  650.                         fprintf(re, "\n%s", emit14);
  651.                        
  652.                         fprintf(re, "\n\n\n\n\t\t\t\tDados da compra");
  653.                         fprintf(re, "\n%s", emit14);
  654.                         fprintf(re, "\nData de emissao: ");
  655.                         fprintf(re, "%02d:%02d:%02d - %02d/%02d/%d", hora, min, sec, dia, mes, ano);
  656.                         fprintf(re, "\nProduto: ");
  657.                         fprintf(re, "%s", pecas[codpp].nome);
  658.                         fprintf(re, "\t\t\t\tMarca: ");
  659.                         fprintf(re, "%s", pecas[codpp].marca);
  660.                         fprintf(re, "\nQuantidade: ");
  661.                         fprintf(re, "%1.f", quant);
  662.                         fprintf(re, "\t\t\t\t\tPreco: ");
  663.                         fprintf(re, "R$ ");
  664.                         fprintf(re, "%.2f", pecas[codpp].preco);
  665.                         fprintf(re, "\nTOTAL A PAGAR: ");
  666.                         fprintf(re, "R$ ");
  667.                         fprintf(re, "%.2f", quant*pecas[codpp].preco);
  668.                         fprintf(re, "\t\t\tCodigo da venda: ");
  669.                         fprintf(re, "%d", vendas[*vAtual-1].codpes);
  670.                         fprintf(re, "\n%s", emit14);
  671.                        
  672.                         fprintf(re, "\n\n\n\n\n\n\n\n\n\n\n\nAgradecemos a preferencia\n");
  673.                         fprintf(re, "Software desenvolvido por Diego Fernando\nhttp://www.facebook.com/dieguinhofernando");
  674.                         fclose(re);
  675.                         system("relatorio.doc");
  676.                        
  677.                         getch();
  678.                        
  679.                     }
  680.                 }
  681.             }
  682.         }
  683.     }
  684.    
  685. }
  686.  
  687. int buscaPProduto(peca *pecas, int *pAtual){
  688.     int i, cod = -1;
  689.     printf("Digite o codigo que deseja buscar: ");
  690.     fflush(stdin);
  691.     scanf("%d",&cod);
  692.     if(cod == 0){
  693.        
  694.     }
  695.    
  696.     else{
  697.         for(i = 0; i < *pAtual; i++){
  698.             if(pecas[i].codigo == cod){
  699.                 printf("Produto encontrado!\n");
  700.                 printf("Codigo: %d - Nome: %s - Marca: %s - Estoque: %d\n", pecas[i].codigo, pecas[i].nome, pecas[i].marca, pecas[i].estoque);
  701.                 return i;
  702.                 getch();
  703.                 }
  704.        
  705.         }
  706.     }
  707.     cod = -1;
  708.     return cod;
  709. }
  710.  
  711. void menuEstoque(peca *pecas, int *pAtual){
  712.     char opc;
  713.     int i;
  714.     do{
  715.         system("cls");
  716.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  717.         printf("°                                                                                                                                   °\n");
  718.         printf("°                                                         MENU PRODUTO                           [L] - LISTAR                       °\n");
  719.         printf("°                                                                                                                                   °\n");
  720.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  721.         printf("°                          °                 °                           °                           °              °               °\n");
  722.         printf("° [1]  CADASTRAR PRODUTO   °     [2] REPOR   °   [3] ALTERAR CADASTRO    °    [4] EXCLUIR CADASTRO   °   [5] AJUDA  °  [ESC] SAIR   °\n");
  723.         printf("°                          °                 °                           °                           °              °               °\n");
  724.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  725.        
  726.         opc = getch();
  727.         fflush(stdin);
  728.         switch(opc){
  729.             case '1':
  730.                 preencheProduto(pecas,pAtual);
  731.             break;
  732.             case '2':
  733.                 reporProduto(pecas, pAtual);
  734.             break;
  735.             case '3':
  736.                 alterarProduto(pecas, pAtual);
  737.             break;
  738.             case '4':
  739.                 excluirProduto(pecas, pAtual);
  740.             break;
  741.             case '5':
  742.             break;
  743.             case 'l':
  744.                     for (i=0;i<*pAtual;i++){
  745.                         if (pecas[i].codigo == 0){
  746.                         }
  747.                         else{
  748.                             printf("Codigo: %d - Nome: %s - Marca: %s - Estoque: %d - Preco: R$ %.2f\n", pecas[i].codigo, pecas[i].nome, pecas[i].marca, pecas[i].estoque, pecas[i].preco);
  749.                         }
  750.                     }
  751.                     getch();
  752.             break;
  753.            
  754.             case 27:
  755.                 break;
  756.             default:
  757.                 printf("OPCAO INVALIDA!!");
  758.                 getch();
  759.             break;
  760.         }
  761.     }while(opc != 27);
  762. }
  763.  
  764. void alterarProduto(peca *pecas, int *pAtual){
  765.    
  766.     if(*pAtual == 0){
  767.                     printf("Erro! Nao ha cadastros de produtos.\n");
  768.                     getch();
  769.     }
  770.     else{
  771.         int busca = buscaPProduto(pecas,pAtual);
  772.         if (busca == -1){
  773.             printf("\nPRODUTO NAO EXISTENTE!");
  774.             getch();
  775.         }
  776.         else{
  777.        
  778.             char op;
  779.             printf("Codigo: %d\n", busca);
  780.             printf("Alterar:\n");
  781.             printf("[1] - Nome: %s\n", pecas[busca].nome);
  782.             printf("[2] - Marca: %s\n", pecas[busca].marca);
  783.             printf("[3] - Preco: R$ %.2f \n", pecas[busca].preco);
  784.             printf("[Enter] - Alteracoes concluidas.\n\n");
  785.             do{
  786.                 fflush(stdin);
  787.                 op = getch();
  788.    
  789.                 switch(op){
  790.                     case '1':
  791.                         printf("Digite novo nome: ");
  792.                         fflush(stdin);
  793.                         gets(pecas[busca].nome);
  794.                         strupr(pecas[busca].nome);
  795.                     break;
  796.                     case '2':
  797.                         printf("Digite nova marca: ");
  798.                     fflush(stdin);
  799.                     gets(pecas[busca].marca);
  800.                     strupr(pecas[busca].marca);
  801.                     break;
  802.                     case '3':
  803.                         printf("Digite novo preco: ");
  804.                         fflush(stdin);
  805.                         scanf("%f", &pecas[busca].preco);
  806.            
  807.                     case 13:
  808.                     break;
  809.                     default:
  810.                         printf("OPCAO INVALIDA!\n");
  811.                         getch();
  812.                 }
  813.             printf("\nALTERACOES CONCLUIDAS");
  814.             }while(op != 13);
  815.         }
  816.        
  817.     }
  818. }
  819.  
  820. void excluirProduto(peca *pecas, int *pAtual){
  821.     if(*pAtual == 0){
  822.                     printf("Erro! Nao ha cadastros de produtos.\n");
  823.                     getch();
  824.     }
  825.     else{
  826.         int busca = buscaPProduto(pecas,pAtual);
  827.         if (busca == -1){
  828.             printf("\nPRODUTO NAO EXISTENTE!");
  829.             getch();
  830.         }
  831.         else{
  832.             pecas[busca].codigo = 0;
  833.             printf("\nPRODUTO EXCLUIDO COM SUCESSO!");
  834.             getch();
  835.         }
  836.    
  837. }
  838. }
  839. void preencheProduto(peca *pecas, int *pAtual){
  840.    
  841.     static int aumenta = 2000;
  842.    
  843.     printf("Digite nome: ");
  844.     fflush(stdin);
  845.     gets(pecas[*pAtual].nome);
  846.     strupr(pecas[*pAtual].nome);
  847.     printf("Digite marca: ");
  848.     fflush(stdin);
  849.     gets(pecas[*pAtual].marca);
  850.     strupr(pecas[*pAtual].marca);
  851.     printf("Digite o preco: ");
  852.     scanf("%f", &pecas[*pAtual].preco);
  853.     printf("Digite a quantidade em estoque: ");
  854.     scanf("%d",&pecas[*pAtual].estoque);
  855.     pecas[*pAtual].codigo = aumenta+*pAtual;
  856.     printf("CADASTRO EFETUADO COM SUCESSO!\n");
  857.     printf("O codigo do produto eh: %d\n",pecas[*pAtual].codigo);
  858.     *pAtual += 1;
  859.     getch();
  860.    
  861. }
  862.  
  863. void reporProduto(peca *pecas, int *pAtual){
  864.     int busca,i ;
  865.     char op;
  866.    
  867.     float qr;
  868.     if(*pAtual == 0){
  869.                     printf("Erro! Nao ha cadastros de produtos.\n");
  870.                     getch();
  871.     }
  872.     else{
  873.         do{
  874.            
  875.             system("cls");
  876.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  877.         printf("°                                                                                                                                   °\n");
  878.         printf("°                                                         MENU PRODUTO                           [L] - LISTAR                       °\n");
  879.         printf("°                                                                                                                                   °\n");
  880.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  881.         printf("°                          °                 °                           °                           °              °               °\n");
  882.         printf("° [1]  CADASTRAR PRODUTO   °     [2] REPOR   °   [3] ALTERAR CADASTRO    °    [4] EXCLUIR CADASTRO   °   [5] AJUDA  °  [ESC] SAIR   °\n");
  883.         printf("°                          °                 °                           °                           °              °               °\n");
  884.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  885.            
  886.             printf("REPOR ESTOQUE:\n\n");
  887.             printf("[1] - Busca por codigo\n[2] - Listar todos\n[3] - Voltar\n");
  888.             fflush(stdin);
  889.             op = getch();
  890.             switch(op){
  891.                 case '1':
  892.                     busca = buscaPProduto(pecas,pAtual);
  893.                     if (busca != -1){
  894.                         printf("Digite a quantidade para reposicao: ");
  895.                         scanf("%f", &qr);
  896.                     if (qr <= 0){
  897.                         printf("\nENTRADA INVALIDA! SO EH PERMITIDO VALORES POSITIVOS.\n");
  898.                         getch();
  899.                         }
  900.                     else{
  901.                         pecas[busca].estoque = pecas[busca].estoque + qr;
  902.                         printf("Estoque atualizado:\nCodigo: %d - Nome: %s - Marca: %s - Estoque: %d\n", pecas[busca].codigo, pecas[busca].nome, pecas[busca].marca, pecas[busca].estoque);
  903.                         getch();
  904.                         }
  905.                     }
  906.                 break;
  907.                
  908.                 case '2':
  909.                     for (i=0;i<*pAtual;i++){
  910.                         if (pecas[i].codigo == 0){
  911.                         }
  912.                         else{
  913.                             printf("Codigo: %d - Nome: %s - Marca: %s - Estoque: %d\n", pecas[i].codigo, pecas[i].nome, pecas[i].marca, pecas[i].estoque);
  914.                         }
  915.                     }
  916.                     getch();
  917.                 break;
  918.                
  919.                 case '3':
  920.                    
  921.                     break;
  922.                
  923.                 default:
  924.                     printf("\nOPCAO INVALIDA!!");
  925.                     getch();
  926.             }
  927.         }while(op != '3');
  928.     }
  929. }
  930.  
  931. int buscaCodigoCliente(pessoa *clientes, int *cAtual)
  932. {
  933.     int i, busca = -1;
  934.     printf("Digite o codigo do cliente a ser pesquisado: ");
  935.     scanf("%d",&busca);
  936.     if(busca == 0){
  937.        
  938.     }
  939.     else{
  940.         for(i = 0; i < *cAtual; i++){
  941.             if(busca == clientes[i].codigo){
  942.        
  943.        
  944.             printf("Cadastro encontrado!\n");
  945.             printf("Nome: %s - Codigo: %d - Busca: %d\n", clientes[i].nome, clientes[i].codigo, busca);
  946.             return i;
  947.             }
  948.         }
  949.     }
  950.     busca = -1;
  951.     return busca;
  952.    
  953. }
  954.  
  955. void menuCliente(pessoa *clientes, int *cAtual)
  956. {
  957.     int opc, i;
  958.     do{
  959.         system("cls");
  960.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  961.         printf("°                                                                                                                                   °\n");
  962.         printf("°                                                         MENU CLIENTE                          [L] - LISTAR                        °\n");
  963.         printf("°                                                                                                                                   °\n");
  964.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  965.         printf("°                             °                             °                             °                  °                      °\n");
  966.         printf("°    [1] CADASTRAR CLIENTE    °     [2] ALTERAR CADASTRO    °    [3] EXCLUIR CADASTRO     °    [4] AJUDA     ° [ESC] MENU PRINCIPAL °\n");
  967.         printf("°                             °                             °                             °                  °                      °\n");
  968.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  969.         fflush(stdin);
  970.         opc = getch();
  971.        
  972.        
  973.         switch(opc){
  974.             case '1':
  975.                 preencheCliente(clientes,cAtual);
  976.             break;
  977.             case '2':
  978.                 alterarCliente(clientes,cAtual);
  979.             break;
  980.             case '3':
  981.                 excluirCliente(clientes, cAtual);
  982.             break;
  983.             case '4':
  984.                 printf("O menu cliente realiza todas as operacoes relacionadas a freguesia da loja.");
  985.                 getch();
  986.             break;
  987.             case 'l':
  988.                     for(i = 0; i < *cAtual; i++){
  989.                         if(clientes[i].codigo != 0){
  990.                         printf("Codigo: %d -", clientes[i].codigo);
  991.                         printf(" Nome: %s -", clientes[i].nome);
  992.                         printf(" Arrecadado total: R$ %.2f\n", clientes[i].precototal);
  993.                         }
  994.                     }
  995.                     getch();
  996.             break;
  997.             case 27:
  998.                 break;
  999.             default:
  1000.                 printf("OPCAO INVALIDA!!\n");
  1001.                 getch();
  1002.             break;
  1003.         }
  1004.     }while(opc != 27);
  1005. }
  1006.  
  1007. void preencheCliente(pessoa *clientes, int *cAtual){
  1008.     char cpf[11];
  1009.     char tel[15];
  1010.    
  1011.     printf("Nome: ");
  1012.     fflush(stdin);
  1013.     gets(clientes[*cAtual].nome);
  1014.     strupr(clientes[*cAtual].nome);
  1015.     printf("Endereco: ");
  1016.     fflush(stdin);
  1017.     gets(clientes[*cAtual].rua);
  1018.     strupr(clientes[*cAtual].rua);
  1019.     printf("E-mail: ");
  1020.     fflush(stdin);
  1021.     gets(clientes[*cAtual].email);
  1022.     do{
  1023.         printf("Digite CPF (apenas numeros): ");
  1024.         fflush(stdin);
  1025.         scanf("%s",&cpf);
  1026.     }while(!verificaCpf(cpf));
  1027.     strcpy(clientes[*cAtual].cpf, cpf);
  1028.    
  1029.     do{
  1030.         printf("Digite telefone (apenas numeros): ");
  1031.         fflush(stdin);
  1032.         scanf("%s",&tel);
  1033.     }while(!verificaTel(tel));
  1034.     strcpy(clientes[*cAtual].tel, tel);
  1035.    
  1036.     clientes[*cAtual].codigo = 1000 + *cAtual;
  1037.     printf("CADASTRO EFETUADO COM SUCESSO!\n");
  1038.     printf("O codigo do cliente eh: %d\n",clientes[*cAtual].codigo);
  1039.     *cAtual += 1;
  1040.     getch();
  1041. }
  1042.  
  1043. int verificaCpf(char*cpf){
  1044.     int i,j;
  1045.     char mi[27] = "abcdefghijklmnopqrstuvwxyz";
  1046.     char mai[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  1047.     if(strlen(cpf) != 11)
  1048.         return 0;
  1049.     for(i = 0; cpf[i] != '\0'; i++){
  1050.         for(j = 0; mi[j] != '\0'; j++){
  1051.             if(cpf[i] == mi[j] || cpf[i] == mai[j])
  1052.                 return 0;
  1053.         }
  1054.     }
  1055.     return 1;
  1056.  
  1057. }
  1058.  
  1059. int verificaTel(char*tel){
  1060.     int i,j;
  1061.     char mi[27] = "abcdefghijklmnopqrstuvwxyz";
  1062.     char mai[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  1063.     if(strlen(tel) < 8)
  1064.         return 0;
  1065.     for(i = 0; tel[i] != '\0'; i++){
  1066.         for(j = 0; mi[j] != '\0'; j++){
  1067.             if(tel[i] == mi[j] || tel[i] == mai[j])
  1068.                 return 0;
  1069.         }
  1070.     }
  1071.     return 1;
  1072. }
  1073.  
  1074.  
  1075. void alterarCliente(pessoa *clientes, int *cAtual){
  1076.     char op2;
  1077.     int i;
  1078.    
  1079.     fflush(stdin);
  1080.    
  1081.  
  1082.    
  1083.    
  1084.     int busca = buscaCodigoCliente(clientes,cAtual);
  1085.     if (busca == -1){
  1086.         printf("\nCODIGO INEXISTENTE!");
  1087.         getch();
  1088.     }
  1089.     else{
  1090.    
  1091.         char op;
  1092.         printf("Codigo: %d\n", busca);
  1093.         printf("Alterar:\n");
  1094.         printf("[1] - Nome: %s\n", clientes[busca].nome);
  1095.         printf("[2] - Endereco: %s\n", clientes[busca].rua);
  1096.         printf("[3] - CPF: %s\n", clientes[busca].cpf);
  1097.         printf("[4] - Telefone: %s\n", clientes[busca].tel);
  1098.         printf("[Enter] - Alteracoes concluidas.\n\n");
  1099.         do{
  1100.    
  1101.             op = getch();
  1102.    
  1103.             switch(op){
  1104.                 case '1':
  1105.                     printf("Digite novo nome: ");
  1106.                     fflush(stdin);
  1107.                     gets(clientes[busca].nome);
  1108.                     strupr(clientes[busca].nome);
  1109.                 break;
  1110.                 case '2':
  1111.                     printf("Digite novo endereco: ");
  1112.                     fflush(stdin);
  1113.                     gets(clientes[busca].rua);
  1114.                     strupr(clientes[busca].rua);
  1115.                 break;
  1116.                 case '3':
  1117.                     printf("Digite novo CPF: ");
  1118.                     fflush(stdin);
  1119.                     gets(clientes[busca].cpf);
  1120.                 break;
  1121.                 case '4':
  1122.                     printf("Digite novo telefone: ");
  1123.                     fflush(stdin);
  1124.                     gets(clientes[busca].tel);
  1125.                 break;
  1126.                 case 13:
  1127.                 break;
  1128.                 default:
  1129.                     printf("OPCAO INVALIDA!\n");
  1130.                     getch();
  1131.             }
  1132.         printf("\nALTERACOES CONCLUIDAS");
  1133.         }while(op != 13);
  1134.     }
  1135.    
  1136.  
  1137.    
  1138. }
  1139.  
  1140. void menuRelatorio(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual){
  1141.     int i, busca;
  1142.     char op,op1;
  1143.     do{
  1144.         system("cls");
  1145.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  1146.         printf("°                                                                                                                                   °\n");
  1147.         printf("°                                                         MENU RELATORIOS                                                           °\n");
  1148.         printf("°                                                                                                                                   °\n");
  1149.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  1150.         printf("°                          °                         °                           °                          °                       °\n");
  1151.         printf("°    [1] DADOS DE TODOS    °    [2] DADOS DE UM      °    [3] DADOS DE TODOS     °      [4] DADOS DE UM     °       [ESC] SAIR      °\n");
  1152.         printf("°         OS CLIENTES      °        CLIENTE          °         OS PRODUTOS       °     PRODUTO ESPECIFICO   °                       °\n");
  1153.         printf("°                          °                         °                           °                          °                       °\n");
  1154.         printf("°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°\n");
  1155.        
  1156.         fflush(stdin);
  1157.         op = getch();
  1158.        
  1159.         switch(op){
  1160.             case '1':
  1161.                 printf("\nListado por ordem de cadastro\n");           
  1162.                 relatorioClienteCad(clientes,cAtual,pecas,pAtual,vendas,cAtual);
  1163.                 break;
  1164.             case '2':
  1165.                 relatorioClienteEsp(clientes,cAtual,pecas,pAtual,vendas,cAtual);
  1166.                 break;
  1167.             case '3':
  1168.                     for (i=0;i<*pAtual;i++){
  1169.                         if (pecas[i].codigo == 0){
  1170.                         }
  1171.                         else{
  1172.                             printf("Codigo: %d - Nome: %s - Marca: %s - Estoque: %d - Preco: R$ %.2f\n", pecas[i].codigo, pecas[i].nome, pecas[i].marca, pecas[i].estoque, pecas[i].preco);
  1173.                         }
  1174.                     }
  1175.                     getch();
  1176.                 break;
  1177.             case '4':
  1178.                 buscaPProduto(pecas,pAtual);
  1179.                     if (busca == -1){
  1180.                         printf("\nPRODUTO NAO EXISTENTE!");
  1181.                         getch();
  1182.                     }
  1183.                     getch();
  1184.                 break;
  1185.             case 27:
  1186.                 break;
  1187.             default:
  1188.                 printf("OPCAO INVALIDA!!");
  1189.                 getch();
  1190.         }
  1191.     }while(op != 27);
  1192.    
  1193.    
  1194. }
  1195.  
  1196. void relatorioClienteCad(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual){
  1197.     int i,j;
  1198.     printf("Clientes:\n\n");
  1199.     for(i = 0; i < *cAtual; i++){
  1200.         if(clientes[i].codigo != 0){
  1201.        
  1202.         printf("Codigo: %d -", clientes[i].codigo);
  1203.         printf(" Nome: %s - ", clientes[i].nome);
  1204.         printf(" Qtd. de vendas: %d - ", clientes[i].qcompras);
  1205.         printf(" Total gasto: R$ %.2f \n", clientes[i].precototal);
  1206.        
  1207.         }
  1208.     }
  1209.     getch();
  1210. }
  1211.  
  1212. void relatorioClienteEsp(pessoa *clientes, int *cAtual, peca *pecas, int *pAtual, venda *vendas, int *vAtual){
  1213.     int busc = buscaCodigoCliente(clientes,cAtual),a,j,i;
  1214.    
  1215.     if(busc == -1){
  1216.         printf("\nCADASTRO NAO EXISTE!");
  1217.         getch();
  1218.     }
  1219.     else{
  1220.        
  1221.         printf("\nCodigo: %d\n", clientes[busc].codigo);
  1222.         printf("Nome: %s\n", clientes[busc].nome);
  1223.         printf("Endereco: %s\n", clientes[busc].rua);
  1224.         printf("E-mail: %s\n", clientes[busc].email);
  1225.         printf("CPF: %s\n", clientes[busc].cpf);
  1226.         printf("Telefone: %s\n\n", clientes[busc].tel);
  1227.         printf("Compras deste cliente:\n\n");
  1228.         if(clientes[busc].qcompras == 0){
  1229.             printf("NAO HA COMPRAS REGISTRADAS.\n");
  1230.            
  1231.         }
  1232.         else{
  1233.  
  1234.             for(j=0;j<clientes[busc].qcompras;j++){
  1235.            
  1236.            
  1237.            
  1238.                 printf("Codigo da compra: %d\n", vendas[clientes[busc].ncompra[j]].codpes);
  1239.                 for(i=0;i<*pAtual;i++){
  1240.                     if(vendas[clientes[busc].ncompra[j]].pecax + 2000 == pecas[i].codigo){
  1241.                         printf("Produto: %s\n",pecas[i].nome);
  1242.                         printf("Marca: %s\n", pecas[i].marca);
  1243.                         printf("Valor: R$ %.2f\n", pecas[i].preco);
  1244.                     }
  1245.                 }
  1246.            
  1247.                 printf("Quantidade: %1.f\n\n", vendas[clientes[busc].ncompra[j]].qp);
  1248.                
  1249.             }
  1250.             printf("TOTAL GASTO: R$ %.2f\n", clientes[busc].precototal);
  1251.         }
  1252.         getch();
  1253.     }
  1254. }
  1255.  
  1256.  
  1257.  
  1258.  
  1259. void excluirCliente(pessoa *clientes, int *cAtual){
  1260.     int i;
  1261.     char op2;
  1262.    
  1263.     printf("[1] - Buscar cadastro\n");
  1264.     printf("[2] - Listar cadastros\n");
  1265.     fflush(stdin);
  1266.     op2 = getch();
  1267.    
  1268.     if(op2 == '1'){
  1269.    
  1270.         int busc=0,vazio=0;
  1271.         busc = buscaCodigoCliente(clientes,cAtual);
  1272.         if(busc == -1){
  1273.             printf("\nCADASTRO NAO EXISTE!");
  1274.             getch();
  1275.         }
  1276.         else{
  1277.    
  1278.             clientes[busc].codigo = vazio;
  1279.             printf("\nCADASTRO EXCLUIDO COM SUCESSO!");
  1280.             getch();
  1281.         }
  1282.     }
  1283.    
  1284.     else if (op2 == '2'){
  1285.         for(i = 0; i < *cAtual; i++){
  1286.             if(clientes[i].codigo != 0){
  1287.                 printf("Codigo: %d -", clientes[i].codigo);
  1288.                 printf(" Nome: %s\n", clientes[i].nome);
  1289.             }
  1290.         }
  1291.         getch();
  1292.     }
  1293.    
  1294. }
  1295.  
  1296. void mostrarCliente(pessoa*p, int *atual){
  1297.     int i;
  1298.     printf("Exibicao do cadastro:\n\n");
  1299.     for(i = 0; i < *atual; i++){
  1300.         printf("Codigo: %d\n", p[i].codigo);
  1301.         printf("Nome: %s\n", p[i].nome);
  1302.         printf("Endereco: %s\n", p[i].rua);
  1303.         printf("%d\n",*atual);
  1304.         printf("E-mail: %s\n", p[i].email);
  1305.         printf("CPF: %s\n", p[i].cpf);
  1306.         printf("Telefone: %s\n\n", p[i].tel);
  1307.     }
  1308.     getch();
  1309. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement