Скачиваний:
42
Добавлен:
02.05.2014
Размер:
69.12 Кб
Скачать

Void SortBd()

{ if(!records)

{ clrscr();

printf("\nNet zapisi, nazhmite lubyu klavishy.");

getch();

} else

{ int c = SortMenu();

switch(c)

{ case 0:

{ for(int i=0;i<nrecords;++i)

for(int k=0;k<nrecords-1;++k)

if(strcmp(records[k].imia, records[k+1].imia) > 0)swap(records[k], records[k+1]);

break;}

case 1:

{ for(int i=0;i<nrecords;++i)

for(int k=0;k<nrecords-1;++k)

if(strcmp(records[k].telefon, records[k+1].telefon) > 0)swap(records[k], records[k+1]);

break;

} case 2:

{ for(int i=0;i<nrecords;++i)

for(int k=0;k<nrecords-1;++k)

if(records[k].god_ystanovki > records[k+1].god_ystanovki)swap(records[k], records[k+1]);

break;}

case 3:

{ for(int i=0;i<nrecords;++i)

for(int k=0;k<nrecords-1;++k)

if(records[k].colich_abonentov > records[k+1].colich_abonentov)swap(records[k], records[k+1]);

break;

} case 4:

{ for(int i=0;i<nrecords;++i)

for(int k=0;k<nrecords-1;++k)

if(records[k].plata_telefon > records[k+1].plata_telefon)swap(records[k], records[k+1]);

break;}}}}

void ProsmotrBD()//ProsmotrBD

{ if(!records)

{ clrscr();

printf("\nNet zapisi, nazhmite lubyu klavishy.");

getch();}

else

{ int loop = 1;

int n = 0;

while(loop == 1)

{ clrscr();

OutputTable(n, 20);

printf("\n\nNazhmite vverx dlia peredvizhenie vverx, vniz dlia peredvizhenia vniz,\n <Esc> dlia vozvrata v menu.");

int c = getch();

switch(c)

{ case 72: --n;break;

case 80: ++n;break;

case 27: loop = 0;break;

default:break;}

if(n < 0) n = 0;

if(n >= nrecords - 10) n = nrecords - 10;}}}

int ChooseRecord()//ViborZapisi

{ int choice = -1;

if(!records)

{ clrscr();

printf("\nNet zapisi, nazhmite lubyu klavishy.");

getch();}

else

{ int loop = 1;

int n = 0;

while(loop == 1)

{ clrscr();

printf("N: |imia |telefon |god_ystanovki |coloch_abonentov |plata_telefon\n");

printf("\n%d", n + 1);

OutputRecord(records[n]);

printf("\n\nNazmite vverx dlia prosmotra sledyushei zapisi, vniz dlia prosmotra predidyshei,\n<Esc> to return to menu, <Enter> to choose record.");

int c = getch();

switch(c)

{ case 72: ++n;break;

case 80: --n;break;

case 27: loop = 0;break;

case 13: loop = 0;choice = n;break;

default:break;}

if(n < 0) n = nrecords - 1;

if(n >= nrecords) n = 0;}}

return choice;}

void EditRecord()//RedaktirovanieZapisi

{ int c = ChooseRecord();

if(c>=0 && c<nrecords)

{ printf("\n\nVi yvereni shto xotite to reinput this zapis?");

if(YesNoDialog() == 13)

{InputRecord(records[c]);}}}

void DeleteRecord()//Ydalenie zapisi

{ int c = ChooseRecord();

if(c>=0 && c<nrecords)

{ printf("\n\nVi yvereni?chto xotite ydalit ety zapis?");

if(YesNoDialog() == 13)

{ --nrecords;

if(nrecords <= 0)

{ delete[] records;

records = 0;}

else{ record * newrecords = new record[nrecords];

int k = 0;

for(int i=0;i<nrecords+1;++i)

{if(i!=c) { newrecords[k] = records[i];

++k;}}

delete[] records;

records = newrecords;}}}}

void CreateBD()//SozdanieBD

{ if(records)

{ clrscr();

printf("Baza dannix ne soxranena!Xotite soxranit ee?");

if(YesNoDialog() == 13) SaveBD();

delete[] records;}

do{ printf("Input novyu zapis:\n");

AddRecord();

printf("\n\nXotite prodolzhit?");}

while(YesNoDialog() !=27);}

void SaveBD()//SoxranenieBD

{ if(!records)

{ clrscr();

printf("\nNechego to save!!! ,nazhmite lubyu klavishy.");

getch();

return;}

FILE * m_fp=fopen(FileDialog(), "wb");

if(m_fp)

{ //Header

fwrite("Baza_dann",1,9,m_fp);

//Number of records

fwrite(&nrecords, 1, sizeof(long int), m_fp);

record * r = records; //Records

for(int i=0;i<nrecords;++i)

{ fwrite(&(r->imia), 1, STR_SIZE - 1, m_fp);

fwrite(&(r->telefon), 1,STR_SIZE - 1, m_fp);

fwrite(&(r->god_ystanovki), 1, sizeof(long int), m_fp);

fwrite(&(r->colich_abonentov), 1, sizeof(long int), m_fp);

fwrite(&(r->plata_telefon), 1, sizeof(long int), m_fp);

++r;}

fclose(m_fp);}

else

{ printf("\nNevozmozhno sozdat file!");

getch();}}

void LoadBD()//ZagryzkaBD

{ if(records)

{ clrscr();

printf("Baza dannix ne soxranena!Xotite soxranit ee?");

if(YesNoDialog() == 13) SaveBD();

delete[] records;}

FILE * m_fp=fopen(FileDialog(), "rb");

if(m_fp)

{ fseek(m_fp, 0, SEEK_SET);

char header[10];

fread(header,1,9,m_fp);

header[9] = 0;

char true_header[] = "Baza_dann";

if(memcmp(header,true_header,9) != 0)

{ printf("Wrong file format!!!");

getch();

return; }//Number of records

fread(&nrecords, 1, sizeof(long int), m_fp);

if(nrecords<0) nrecords = 0;

records = new record[nrecords];

record * r = records;

for(int i=0;i<nrecords;++i)

{ fread(&(r->imia), 1, STR_SIZE - 1, m_fp);

fread(&(r->telefon), 1, STR_SIZE - 1, m_fp);

fread(&(r->god_ystanovki), 1, sizeof(long int), m_fp);

fread(&(r->colich_abonentov), 1, sizeof(long int), m_fp);

fread(&(r->plata_telefon), 1, sizeof(long int), m_fp);

++r;}

fclose(m_fp);}

else

{ printf("\nFile ne naiden");

getch();}}

Соседние файлы в папке Курсовая работа - Создание и работа с базой данных "Плата за телефон"