MyBank

Publicado por N 04/10/2005

[ Hits: 5.149 ]

Download MyBank.tar.bz2




O QUE E MYBANK?
===============

O MyBank é uma ferramenta de gerenciamento de arquivos em blocos (binários).

O MyBank pode, ler, escrever, modificar e excluir dados em arquivos em blocos (binários).



Nycholas de Oliveira e Oliveira - o_lalertom

  



Esconder código-fonte

/*
#
#   Sistema de gerenciamento de dados em blocos (binários).
#   Copyright (C) 2005 by Nycholas de Oliveira e Oliveira <nycholas@gmail.com>
#
#   This program is free software; you can redistribute it and/or
#   modify it under the terms of the GNU General Public License
#   as published by the Free Software Foundation; either version 2
#   of the License, or (at your option) any later version.
#
#   <Este programa é software livre; você pode redistribuí-lo e/ou modificá-lo sob os
#   termos da Licença Pública Geral GNU conforme publicada pela Free Software Foundation;
#   tanto a versão 2 da Licença, como (a seu critério) qualquer versão posterior.>
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   <Este programa é distribuído na expectativa de que seja útil, porém, SEM NENHUMA
#   GARANTIA; nem mesmo a garantia implícita de COMERCIABILIDADE OU ADEQUAÇÃO A UMA 
#   FINALIDADE ESPECÍFICA. Consulte a Licença Pública Geral do GNU para mais detalhes.>
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
#   <Você deve ter recebido uma cópia da Licença Pública Geral do GNU junto com este 
#   programa; se não, escreva para a Free Software Foundation, Inc., no endereço 59
#   Temple Street, Suite 330, Boston, MA 02111-1307 USA.>
#

#########################################################
# NOME        : Nycholas de Oliveira e Oliveira         #
# E-MAIL      : nycholas@gmail.com                      #
# ICQ         : 114965471                               #
# MSN         : o_lalertom@hotmail.com                  #
# ORKUT       : Nycholas Oliveira - nycholas@gmail.com  #
# DESCRICAO   : Programa Meu Banco                      #
# DESCRICAO   : Trabalha com arquivos em blocos         #
# LOCALIZACAO : Uberlandia - MG                         #
# LOCALIZACAO : Brasil                                  #
#########################################################
*/

#include <stdio.h>
#include <string.h>

#define BANCO          "./MyBD"
#define MAX_NOME       50
#define MAX_SOBRENOME  50
#define MAX_NASCIMENTO 20
#define MAX_MAIL       50
#define MAX_CHAR       256
#define MAX_OPCAO      5
#define SLEEP          3

struct DADOS {
   char nome[MAX_NOME];
   char sobreNome[MAX_SOBRENOME];
   char nascimento[MAX_NASCIMENTO];
   char mail[MAX_MAIL];
};

void menu (void);
void open_file(void);
void close_file(void);
void insert_file(void);
void print_file(void);
void update_file(void);
void query_file(void);
void query_avanc_file(void);
void delete_file(void);
void sobre(void);

FILE *File;

int main (void) {

   menu();

   return(0);
}

void menu (void) {
   char KeyBoardMenu[MAX_OPCAO];

   while (KeyBoardMenu[0] != '0') {
      system("clear");
      
      printf("++++++++++++++++ MENU ++++++++++++++++\n");
      printf("+ (1) Inserir Registro               +\n");
      printf("+ (2) Listar Registros               +\n");
      printf("+ (3) Alterar Registro               +\n");
      printf("+ (4) Buscar Registro                +\n");
      printf("+ (5) Buscar Registro (avancado)     +\n");
      printf("+ (6) Excluir Registro               +\n");
      printf("+ (7) Sobre                          +\n");
      printf("+ (0) Sair                           +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n\n");
      
      scanf("%s", KeyBoardMenu);
      
      if (strlen(KeyBoardMenu) == 1) {
         switch (KeyBoardMenu[0]) {
            case '1':
               open_file();
               insert_file();
               close_file();
               break;
            case '2': 
               open_file();
               print_file();
               close_file();
               break;
            case '3':
               open_file();
               update_file();
               close_file();
               break;
            case '4':
               open_file();
               query_file();
               close_file();
               break;
            case '5':
               open_file();
               query_avanc_file();
               close_file();
               break;
            case '6':
               open_file();
               delete_file();
               close_file();
               break;
            case '7':
               sobre();
               break;
            case '0':
               KeyBoardMenu[0] = '0';
               break;
            default:
               printf(" !! Comando Invalido (%s) !! ", KeyBoardMenu[0]);
               sleep(SLEEP);
               break;
         }
      } else {
         printf(" !! Comando Invalido (%s) !! ", KeyBoardMenu[0]);
         sleep(SLEEP);
      }
   }
   system("clear");
}

void open_file (void) {
   if ((File = fopen(BANCO, "rb+")) == NULL) {
      if ((File = fopen(BANCO, "wb+")) == NULL) {
         printf("\nFalha na abertura do arquivo %s\n", BANCO);
         sleep(SLEEP);
      }
   }
}

void close_file (void) {
   if ((fclose(File)) != 0) {
      printf("\nFalha no fechamento do arquivo %s\n", BANCO);
      sleep(SLEEP);
   }
}

void insert_file (void) {
   char KeyBoardInsert[MAX_OPCAO];
   
   struct DADOS Insert;
   
   while (KeyBoardInsert[0] != '0') {
      system("clear");
      
      printf("++++++++++++ (1) INSERCAO ++++++++++++\n");
      printf("+ (1) Inserir Um Registro            +\n");
      printf("+ (0) Voltar ao Menu Principal       +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n");
      
      scanf("%s", KeyBoardInsert);
      
      if (KeyBoardInsert[0] == '1') {
         fgetc(stdin);
         printf("Nome: ");
         fgets(Insert.nome, MAX_NOME-1, stdin);
         Insert.nome[strlen(Insert.nome)-1] = 0;
         printf("Sobrenome: ");
         fgets(Insert.sobreNome, MAX_SOBRENOME-1, stdin);
         Insert.sobreNome[strlen(Insert.sobreNome)-1] = 0;
         printf("Nascimento: "); 
         fgets(Insert.nascimento, MAX_NASCIMENTO-1, stdin);
         Insert.nascimento[strlen(Insert.nascimento)-1] = 0;
         printf("E-mail: ");
         fgets(Insert.mail, MAX_MAIL-1, stdin);
         Insert.mail[strlen(Insert.mail)-1] = 0;

         fseek(File, 0, SEEK_END);
         fwrite(&Insert, sizeof(struct DADOS), 1, File);
         fflush(File);
      }
   } 
}

void  print_file (void) {
   int  NumCadastroTotal;
   int  NumCadastro;
   long PosicaoFile;
   char KeyBoardImprime[MAX_OPCAO];

   struct DADOS Imprime;

   NumCadastroTotal = 0;
   
   rewind(File);
   
   while (fread(&Imprime, sizeof(struct DADOS), 1, File) == 1) {
      NumCadastroTotal++;
   }
    
   rewind(File);

   while (KeyBoardImprime[0] != '0') {
      while (fread(&Imprime, sizeof(struct DADOS), 1, File) == 1) {
         PosicaoFile = ftell(File); 
         NumCadastro = (PosicaoFile/sizeof(struct DADOS));
         
         system("clear");
      
         printf("++++++++++++ (2) LISTAGEM ++++++++++++\n");
         printf("+ (1) Proximo Registro               +\n");
         printf("+ (2) Registro Anterior              +\n");
         printf("+ (3) Primeiro Registro              +\n");
         printf("+ (4) Ultimo Registro                +\n");
         printf("+ (0) Voltar ao Menu Principal       +\n");
         printf("++++++++++++++++++++++++++++++++++++++\n\n");
         
         if ((strlen(Imprime.nome)) == 0 && (strlen(Imprime.sobreNome)) == 0 && (strlen(Imprime.nascimento)) == 0 && (strlen(Imprime.mail)) == 0) {
            printf("::::::::::::::::::::::::::::::::::::::\n");
            printf(" :: Numero: %d/%d\n", NumCadastro, NumCadastroTotal);
            printf(" :: REGISTRO EXCLUIDO \n");
            printf("::::::::::::::::::::::::::::::::::::::\n\n");
         } else {
            printf("::::::::::::::::::::::::::::::::::::::\n");
            printf(" :: Numero: %d/%d\n", NumCadastro, NumCadastroTotal);
            printf(" :: Nome: %s\n", Imprime.nome);
            printf(" :: Sobrenome: %s\n", Imprime.sobreNome);
            printf(" :: Nascimento: %s\n", Imprime.nascimento);
            printf(" :: E-mail: %s\n", Imprime.mail);
            printf("::::::::::::::::::::::::::::::::::::::\n\n");
         }
         
         
         scanf("%s", KeyBoardImprime);
         
         if (strlen(KeyBoardImprime) == 1) {
            switch (KeyBoardImprime[0]) {
               case '1':
                  if (NumCadastro == NumCadastroTotal) {
                     rewind(File);
                  }
                  break;
               case '2':
                  if (fseek(File, -2*sizeof(struct DADOS), SEEK_CUR) < 0) {
                     fseek(File, -1*sizeof(struct DADOS), SEEK_END);
                  }
                  break;
               case '3':
                  rewind(File);
                  break;
               case '4':
                  fseek(File, -1*sizeof(struct DADOS), SEEK_END);
                  break;
               case '0':
                  fseek(File, sizeof(struct DADOS), SEEK_END);
                  KeyBoardImprime[0] = '0';
                  break;
               default:
                  printf(" !! Comando Invalido (%s) !! ", KeyBoardImprime[0]);
                  sleep(SLEEP);
                  break;
            }
         } else {
            printf(" !! Comando Invalido (%s) !! ", KeyBoardImprime[0]);
            sleep(SLEEP);
         }
      }
   }
}

void update_file (void) {
   int  NumCadastroTotal;
   int  NumCadastro;
   int  NumReg;
   int  NumAlt;
   long PosicaoFile;
   char KeyBoardUpdate[MAX_OPCAO];
   char KeyBoardUpdateSub[5];
   
   struct DADOS DadosAntigo;
   struct DADOS ptrDadosNovo;
  
   NumCadastroTotal = 0;
   
   rewind(File);
   
   while (fread(&DadosAntigo, sizeof(struct DADOS), 1, File) == 1) {
      NumCadastroTotal++;
   }
   
   while (KeyBoardUpdate[0] != '0') {
      system("clear");
      
      printf("++++++++++++ (3) ALTERACAO +++++++++++\n");
      printf("+ (1) Alterar Um Registro            +\n");
      printf("+ (0) Voltar ao Menu Principal       +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n\n");
      
      scanf("%s", KeyBoardUpdate);
      
      printf(" => Registros: %d\n\n", NumCadastroTotal);
      
      if (strlen(KeyBoardUpdate) == 1) {
         switch (KeyBoardUpdate[0]) {
            case '1':
               printf("Informe o Numero do Registro Que Deseja Alterar: ");
               scanf("%d", &NumAlt);
            
               fseek(File, (NumAlt-1)*sizeof(struct DADOS), SEEK_SET);
               
               PosicaoFile = ftell(File);
               NumReg      = (PosicaoFile/sizeof(struct DADOS));
               
               if (fread(&DadosAntigo, sizeof(struct DADOS), 1, File) != 1) {
                   printf("\nRegistro Inexistente %d/%d\n", (NumReg+1), NumCadastroTotal);
                   sleep(SLEEP);
               } else {
                  printf("\n::::::::::::::::::::::::::::::::::::::\n");
                  printf(" :: Numero: %d/%d\n", (NumReg+1), NumCadastroTotal);
                  printf(" :: Nome: %s\n", DadosAntigo.nome);
                  printf(" :: Sobrenome: %s\n", DadosAntigo.sobreNome);
                  printf(" :: Nascimento: %s\n", DadosAntigo.nascimento);
                  printf(" :: E-mail: %s\n", DadosAntigo.mail);
                  printf("::::::::::::::::::::::::::::::::::::::\n\n");
                  printf("Voce Tem Certeza Que Deseja Alterar Esse Registro (%d) [Yes/No] ?\n", (NumReg+1));
               
                  scanf("%s", KeyBoardUpdateSub);
                  
                  if (strlen(KeyBoardUpdateSub) == 1) {
                     switch (KeyBoardUpdateSub[0]) {
                        case 's':
                        case 'S':
                        case 'y':
                        case 'Y':
                           ptrDadosNovo = DadosAntigo;
      
                           fgetc(stdin);
                        
                           printf("Nome: ");
                           fgets(ptrDadosNovo.nome, MAX_NOME-1, stdin);
                           ptrDadosNovo.nome[strlen(ptrDadosNovo.nome)-1] = 0;
                           printf("Sobrenome: ");
                           fgets(ptrDadosNovo.sobreNome, MAX_SOBRENOME-1, stdin);
                           ptrDadosNovo.sobreNome[strlen(ptrDadosNovo.sobreNome)-1] = 0;
                           printf("Nascimento: "); 
                           fgets(ptrDadosNovo.nascimento, MAX_NASCIMENTO-1, stdin);
                           ptrDadosNovo.nascimento[strlen(ptrDadosNovo.nascimento)-1] = 0;   
                           printf("E-mail: ");
                           fgets(ptrDadosNovo.mail, MAX_MAIL-1, stdin);
                           ptrDadosNovo.mail[strlen(ptrDadosNovo.mail)-1] = 0;
                        
                           fseek(File, NumReg*sizeof(struct DADOS), SEEK_SET);
                           fwrite(&ptrDadosNovo, sizeof(struct DADOS), 1, File);
                           break;
                        case 'n':
                        case 'N':
                           continue;
                           break;
                        default:
                           printf(" !! Comando Invalido (%s) !! ", KeyBoardUpdate[0]);
                           sleep(SLEEP);
                           break;
                     }
                  } else {
                     printf(" !! Comando Invalido (%s) !! ", KeyBoardUpdate[0]);
                     sleep(SLEEP);
                  }
               }
               break;
            case '0':
               KeyBoardUpdate[0] = '0';
               break;
            default:
               printf(" !! Comando Invalido (%s) !! ", KeyBoardUpdate[0]);
               sleep(SLEEP);
               break;
         }
      } else {
         printf(" !! Comando Invalido (%s) !! ", KeyBoardUpdate[0]);
         sleep(SLEEP);
      }
   }  
}

void query_file (void) {
   int  NumCadastroTotal;
   int  NumCadastro;
   int  NumReg;
   char KeyBoardQuery[MAX_OPCAO];
   char KeyBoardQuerySub[MAX_OPCAO];
   
   struct DADOS Query;
   
   NumCadastroTotal = 0;
   
   rewind(File);
   
   while (fread(&Query, sizeof(struct DADOS), 1, File) == 1) {
      NumCadastroTotal++;
   }
   
   while (KeyBoardQuery[0] != '0') {
      system("clear");
      
      printf("++++++++++++++ (4) BUSCA +++++++++++++\n");
      printf("+ (1) Buscar Um Registro             +\n");
      printf("+ (0) Voltar ao Menu Principal       +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n\n");
      
      scanf("%s", KeyBoardQuery);
      
      printf(" => Registros: %d\n\n", NumCadastroTotal);
      
      if (strlen(KeyBoardQuery) == 1) {
         switch (KeyBoardQuery[0]) {
            case '1':
               printf("Informe o Numero do Registro Que Deseja Localizar: ");
               scanf("%d", &NumReg);
         
               fseek(File, (NumReg-1)*sizeof(struct DADOS), SEEK_SET);
            
               if (fread(&Query, sizeof(struct DADOS), 1, File) != 1) {
                   printf("\nRegistro inexistente %d/%d\n", NumReg, NumCadastroTotal);
                   sleep(SLEEP);
               } else {
                  if ((strlen(Query.nome)) == 0 && (strlen(Query.sobreNome)) == 0 && (strlen(Query.nascimento)) == 0 && (strlen(Query.mail)) == 0) {
                        printf("::::::::::::::::::::::::::::::::::::::\n");
                        printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                        printf(" :: REGISTRO EXCLUIDO \n");
                        printf("::::::::::::::::::::::::::::::::::::::\n\n");
                  } else {
                        printf("\n::::::::::::::::::::::::::::::::::::::\n");
                        printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                        printf(" :: Nome: %s\n", Query.nome);
                        printf(" :: Sobrenome: %s\n", Query.sobreNome);
                        printf(" :: Nascimento: %s\n", Query.nascimento);
                        printf(" :: E-mail: %s\n", Query.mail);
                        printf("::::::::::::::::::::::::::::::::::::::\n\n");
                  }      
                  
                  scanf("%s", KeyBoardQuerySub);
                  
                  switch (KeyBoardQuerySub[0]) {
                     case '1':
                        continue;
                        break;
                     case '0':
                        continue;
                        break;
                     default:
                        printf(" !! Comando Invalido (%s) !! ", KeyBoardQuery[0]);
                        sleep(SLEEP);
                        break;
                  }
               }
               break;
            case '0':
               KeyBoardQuery[0] = '0';
               break;
            default:
               printf(" !! Comando Invalido (%s) !! ", KeyBoardQuery[0]);
               sleep(SLEEP);
               break;
         }
      } else {
         printf(" !! Comando Invalido (%s) !! ", KeyBoardQuery[0]);
         sleep(SLEEP);
      }
   }   
}

void query_avanc_file (void) {
   int  NumCadastroTotal;
   int  NumCadastro;
   int  NumReg;
   int  NumEncontrado;
   int  Buscados;
   char KeyBoardQueryAvanc[MAX_OPCAO];
   char KeyBoardQueryAvancSub[MAX_OPCAO];
   char KeyBoardQueryAvancSub2[MAX_OPCAO];
   char Nome[MAX_NOME];
   char SobreNome[MAX_SOBRENOME];
   char Nascimento[MAX_NASCIMENTO];
   char Mail[MAX_MAIL];
   char Tudo[MAX_CHAR];
   
   struct DADOS QueryAvanc;
   
   NumCadastroTotal = 0;
   
   rewind(File);
   
   while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
      NumCadastroTotal++;
   }
   
   while (KeyBoardQueryAvanc[0] != '0') {
      system("clear");
      
      printf("+++++++ (5) BUSCA AVANCADA +++++++++++\n");
      printf("+ (1) Buscar Um Registro             +\n");
      printf("+ (0) Voltar ao Menu Principal       +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n\n");
      
      scanf("%s", KeyBoardQueryAvanc);
      
      rewind(File);
      
      if (strlen(KeyBoardQueryAvanc) == 1) {
         switch (KeyBoardQueryAvanc[0]) {
            case '1':
               printf(" => Registros: %d\n\n", NumCadastroTotal);
      
               printf(" >> (n) Buscar Por Nome\n");
               printf(" >> (s) Buscar Por Sobrenome\n");
               printf(" >> (d) Buscar Por Data de Nacimento\n");
               printf(" >> (e) Buscar Por E-Mail\n");
               printf(" >> (p) Buscar Por Palavra-Chave\n\n");
         
               scanf("%s", KeyBoardQueryAvancSub);
      
               if (strlen(KeyBoardQueryAvancSub) == 1) {
                  switch (KeyBoardQueryAvancSub[0]) {
                     case 'n':
                     case 'N':
                        printf("Digite o Nome a Ser Pesquisado: ");
                        
                        scanf("%s", Nome);
                        
                        NumReg        = 1;
                        Buscados      = 0;
                        NumEncontrado = 0;
                        
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(Nome, QueryAvanc.nome) == 0) {
                              Buscados++;
                           }
                        }
                     
                        printf("\n  => Foram Encontrados %d Registros Com Esse Nome (%s)\n", Buscados, Nome);
                        
                        rewind(File);
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(Nome, QueryAvanc.nome) == 0) {
                              NumEncontrado++;
                           
                              printf("\n::::::::::::::::::::::::::::::::::::::\n");
                              printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                              printf(" :: Nome: %s\n", QueryAvanc.nome);
                              printf(" :: Sobrenome: %s\n", QueryAvanc.sobreNome);
                              printf(" :: Nascimento: %s\n", QueryAvanc.nascimento);
                              printf(" :: E-mail: %s\n", QueryAvanc.mail);
                              printf("::::::::::::::::::::::::::::::::::::::\n\n");
                           
                              if (NumEncontrado == Buscados) {
                                 scanf("%s", KeyBoardQueryAvancSub2);
                        
                                 switch (KeyBoardQueryAvancSub2[0]) {
                                    case '1':
                                       continue;
                                       break;
                                    case '0':
                                       KeyBoardQueryAvancSub[0] = '0';
                                       break;
                                    default:
                                       printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                       sleep(SLEEP);
                                       break;
                                 }
                              }
                           }
                           NumReg++;
                        }
                        break;
                     case 's':
                     case 'S':
                        printf("Digite o Sobrenome a Ser Pesquisado: ");
                     
                        scanf("%s", SobreNome);
                     
                        NumReg        = 1;
                        Buscados      = 0;
                        NumEncontrado = 0;
                        
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(SobreNome, QueryAvanc.sobreNome) == 0) {
                              Buscados++;
                           }
                        }
                     
                        printf("\n  => Foram Encontrados %d Registros Com Esse SobreNome (%s)\n", Buscados, SobreNome);
                     
                        rewind(File);
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(SobreNome, QueryAvanc.sobreNome) == 0) {
                              NumEncontrado++;
                           
                              printf("\n::::::::::::::::::::::::::::::::::::::\n");
                              printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                              printf(" :: Nome: %s\n", QueryAvanc.nome);
                              printf(" :: Sobrenome: %s\n", QueryAvanc.sobreNome);
                              printf(" :: Nascimento: %s\n", QueryAvanc.nascimento);
                              printf(" :: E-mail: %s\n", QueryAvanc.mail);
                              printf("::::::::::::::::::::::::::::::::::::::\n\n");
                        
                              if (NumEncontrado == Buscados) {
                                 scanf("%s", KeyBoardQueryAvancSub2);
                        
                                 switch (KeyBoardQueryAvancSub2[0]) {
                                    case '1':
                                       continue;
                                       break;
                                    case '0':
                                       KeyBoardQueryAvancSub[0] = '0';
                                       break;
                                    default:
                                       printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                       sleep(SLEEP);
                                       break;
                                 }
                              }
                           }
                           NumReg++;
                        }
                        break;
                     case 'd':
                     case 'D':
                        printf("Digite a Data de Nascimento a Ser Pesquisado: ");
                     
                        scanf("%s", Nascimento);
                        
                        NumReg        = 1;
                        Buscados      = 0;
                        NumEncontrado = 0;
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {  
                           if (strcmp(Nascimento, QueryAvanc.nascimento) == 0) {
                              Buscados++;
                           }
                        }
                     
                        printf("\n  => Foram Encontrados %d Registros Com Essa Data de Nascimento (%s)\n", Buscados, Nascimento);
                     
                        rewind(File);
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {  
                           if (strcmp(Nascimento, QueryAvanc.nascimento) == 0) {
                              NumEncontrado++;
                           
                              printf("\n::::::::::::::::::::::::::::::::::::::\n");
                              printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                              printf(" :: Nome: %s\n", QueryAvanc.nome);
                              printf(" :: Sobrenome: %s\n", QueryAvanc.sobreNome);
                              printf(" :: Nascimento: %s\n", QueryAvanc.nascimento);
                              printf(" :: E-mail: %s\n", QueryAvanc.mail);
                              printf("::::::::::::::::::::::::::::::::::::::\n\n");
                        
                              if (NumEncontrado == Buscados) {
                                 scanf("%s", KeyBoardQueryAvancSub2);
                        
                                 switch (KeyBoardQueryAvancSub2[0]) {
                                    case '1':
                                       continue;
                                       break;
                                    case '0':
                                       KeyBoardQueryAvancSub[0] = '0';
                                       break;
                                    default:
                                       printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                       sleep(SLEEP);
                                       break;
                                 }
                              }
                           }
                           NumReg++;
                        }
                        break;
                     case 'e':
                     case 'E':
                        printf("Digite o E-Mail a Ser Pesquisado: ");
                     
                        scanf("%s", Mail);
                     
                        NumReg        = 1;
                        Buscados      = 0;
                        NumEncontrado = 0;
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(Mail, QueryAvanc.mail) == 0) {
                              Buscados++;
                           }
                        }
                     
                        printf("\n  => Foram Encontrados %d Registros Com Esse E-Mail (%s)\n", Buscados, Mail);
                     
                        rewind(File);
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if (strcmp(Mail, QueryAvanc.mail) == 0) {
                              NumEncontrado++;
                           
                              printf("\n::::::::::::::::::::::::::::::::::::::\n");
                              printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                              printf(" :: Nome: %s\n", QueryAvanc.nome);
                              printf(" :: Sobrenome: %s\n", QueryAvanc.sobreNome);
                              printf(" :: Nascimento: %s\n", QueryAvanc.nascimento);
                              printf(" :: E-mail: %s\n", QueryAvanc.mail);
                              printf("::::::::::::::::::::::::::::::::::::::\n\n");
                        
                              if (NumEncontrado == Buscados) {
                                 scanf("%s", KeyBoardQueryAvancSub2);
                        
                                 switch (KeyBoardQueryAvancSub2[0]) {
                                    case '1':
                                       continue;
                                       break;
                                    case '0':
                                       KeyBoardQueryAvancSub[0] = '0';
                                       break;
                                    default:
                                       printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                       sleep(SLEEP);
                                       break;
                                 }
                              }
                           }
                           NumReg++;
                        }
                        break;
                     case 'p':
                     case 'P':
                        printf("Digite Uma Palavra-Chave a Ser Pesquisado: ");
                     
                        scanf("%s", Tudo);
                     
                        NumReg        = 1;
                        Buscados      = 0;
                        NumEncontrado = 0;
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if ((strcmp(Tudo, QueryAvanc.nome) == 0) || (strcmp(Tudo, QueryAvanc.sobreNome) == 0) || (strcmp(Tudo, QueryAvanc.nascimento) == 0) || (strcmp(Tudo, QueryAvanc.mail) == 0)) {
                              Buscados++;
                           }
                        }
                     
                        printf("\n  => Foram Encontrados %d Registros Com Essa Palavra-Chave (%s)\n", Buscados, Tudo);
                     
                        rewind(File);
                     
                        while (fread(&QueryAvanc, sizeof(struct DADOS), 1, File) == 1) {
                           if ((strcmp(Tudo, QueryAvanc.nome) == 0) || (strcmp(Tudo, QueryAvanc.sobreNome) == 0) || (strcmp(Tudo, QueryAvanc.nascimento) == 0) || (strcmp(Tudo, QueryAvanc.mail) == 0)) {
                              NumEncontrado++;
                            
                              printf("\n::::::::::::::::::::::::::::::::::::::\n");
                              printf(" :: Numero: %d/%d\n", NumReg, NumCadastroTotal);
                              printf(" :: Nome: %s\n", QueryAvanc.nome);
                              printf(" :: Sobrenome: %s\n", QueryAvanc.sobreNome);
                              printf(" :: Nascimento: %s\n", QueryAvanc.nascimento);
                              printf(" :: E-mail: %s\n", QueryAvanc.mail);
                              printf("::::::::::::::::::::::::::::::::::::::\n\n");
                        
                              if (NumEncontrado == Buscados) {
                                 scanf("%s", KeyBoardQueryAvancSub2);
                        
                                 if (strlen(KeyBoardQueryAvancSub) == 1) {
                                    switch (KeyBoardQueryAvancSub2[0]) {
                                       case '1':
                                          continue;
                                          break;
                                       case '0':
                                          KeyBoardQueryAvancSub[0] = '0';
                                          break;
                                       default:
                                          printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                          sleep(SLEEP);
                                          break;
                                    }
                                 } else {
                                    printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub2[0]);
                                    sleep(SLEEP);
                                 }
                              } 
                           }
                           NumReg++;
                        }
                        break;
                     case '0':
                        KeyBoardQueryAvanc[0] = '0';
                        break;
                     default:
                        printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub[0]);
                        sleep(SLEEP);
                        break;
                  }
               } else {
                  printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub[0]);
                  sleep(SLEEP);
               }
               break;
            case '0':
               KeyBoardQueryAvanc[0] = '0';
               break;
            default:
               printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub[0]);
               sleep(SLEEP);
               break;
            }
      } else {
         printf(" !! Comando Invalido (%s) !! ", KeyBoardQueryAvancSub[0]);
         sleep(SLEEP);
      }
   }   
}

void delete_file (void) {
   int  NumCadastroTotal;
   int  NumCadastro;
   int  NumReg;
   char KeyBoardDelete[MAX_OPCAO];
   char KeyBoardDeleteSub[MAX_OPCAO];
   
   struct DADOS Delete;
   
   NumCadastroTotal = 0;
   
   rewind(File);
   
   while (fread(&Delete, sizeof(struct DADOS), 1, File) == 1) {
      NumCadastroTotal++;
   }
   
   while (KeyBoardDelete[0] != '0') {
      system("clear");
      
      printf("++++++++++++++ (6) EXCLUI ++++++++++++\n");
      printf("+ (1) Excluir Um Registro            +\n");
      printf("+ (0) Voltar ao Menu Principal       +\n");
      printf("++++++++++++++++++++++++++++++++++++++\n\n");
      
      scanf("%s", KeyBoardDelete);
      
      printf(" => Registros: %d\n\n", NumCadastroTotal);
      
      if (strlen(KeyBoardDelete) == 1) {
         switch (KeyBoardDelete[0]) {
            case '1':
               printf("Informe o Numero do Registro Que Deseja Excluir: ");
               scanf("%d", &NumReg);
            
               fseek(File, (NumReg-1)*sizeof(struct DADOS), SEEK_SET);
               
               if (fread(&Delete, sizeof(struct DADOS), 1, File) != 1) {
                   printf("\nRegistro inexistente %d/%d\n", (NumReg), NumCadastroTotal);
                   sleep(SLEEP);
               } else {
                  printf("\n::::::::::::::::::::::::::::::::::::::\n");
                  printf(" :: Numero: %d/%d\n", (NumReg), NumCadastroTotal);
                  printf(" :: Nome: %s\n", Delete.nome);
                  printf(" :: Sobrenome: %s\n", Delete.sobreNome);
                  printf(" :: Nascimento: %s\n", Delete.nascimento);
                  printf(" :: E-mail: %s\n", Delete.mail);
                  printf("::::::::::::::::::::::::::::::::::::::\n\n");
                  printf("Tem  Certeza Que Deseja Excluir Esse Registro (%d) [Yes/No] ?\n", (NumReg));
                  
                  scanf("%s", KeyBoardDeleteSub);
                  
                  if (strlen(KeyBoardDeleteSub) == 1) {
                     switch (KeyBoardDeleteSub[0]) {
                        case 's':
                        case 'S':
                        case 'y':
                        case 'Y':
                           strcpy(Delete.nome, "");
                           strcpy(Delete.sobreNome, "");
                           strcpy(Delete.nascimento, "");
                           strcpy(Delete.mail, "");
                           fseek(File, (NumReg-1)*sizeof(struct DADOS), SEEK_SET);
                           fwrite(&Delete, sizeof(struct DADOS), 1, File);
                           break;
                        case 'n':
                        case 'N':
                           KeyBoardDelete[0] = '0';
                           break;
                        default:
                           printf(" !! Comando Invalido (%s) !! ", KeyBoardDeleteSub[0]);
                           sleep(SLEEP);
                           break;
                     }
                  } else {
                     printf(" !! Comando Invalido (%s) !! ", KeyBoardDeleteSub[0]);
                     sleep(SLEEP);
                  }
               }
               break;
            case '0':
               KeyBoardDelete[0] = '0';
               break;
            default:
               printf(" !! Comando Invalido (%s) !! ", KeyBoardDelete[0]);
               sleep(SLEEP);
               break;
         }
      } else {
         printf(" !! Comando Invalido (%s) !! ", KeyBoardDelete[0]);
         sleep(SLEEP);
      }
   }   
}

void sobre (void) {

   system("clear");

   printf("  --------------------------------------------------------  \n");
   printf(" < NOME        : Nycholas de Oliveira e Oliveira          > \n");
   printf(" < E-MAIL      : nycholas@gmail.com                       > \n");
   printf(" < ICQ         : 114965471                                > \n");
   printf(" < MSN         : o_lalertom@hotmail.com                   > \n");
   printf(" < ORKUT       : Nycholas Oliveira - nycholas@gmail.com   > \n");
   printf(" < DESCRICAO   : Programa Meu Banco                       > \n");
   printf(" < DESCRICAO   : Trabalha com arquivos em blocos          > \n");
   printf(" < LOCALIZACAO : Uberlandia - MG                          > \n");
   printf(" < LOCALIZACAO : Brasil                                   > \n");
   printf("  --------------------------------------------------------  \n");
   printf("    \\ \n");
   printf("      \\ \n");
   printf("          .--. \n");
   printf("         |0_0 | \n");
   printf("         |:_/ | \n");
   printf("        //   \\ \\ \n");
   printf("       (|     | ) \n");
   printf("       /\\_   _/ \\ \n");
   printf("       \\__)=(___/ \n\n");
   
   sleep((3*SLEEP));
}

Scripts recomendados

codificador de texto

Controle de Funcionários (Básico)

Cadastro de arquivo usando ncurses como menu

Manipulação de arquivos CSV - Estruturado


  

Comentários
[1] Comentário enviado por _luks em 06/03/2006 - 17:36h

mto bom


Contribuir com comentário




Patrocínio

Site hospedado pelo provedor RedeHost.
Linux banner

Destaques

Artigos

Dicas

Tópicos

Top 10 do mês

Scripts