Скачиваний:
14
Добавлен:
28.06.2014
Размер:
5.12 Кб
Скачать
//---------------------------------------------------------------------------
#include <vcl.h>
#include <stdio.h>
#include <dstring.h>
#pragma hdrstop

#include "Unit1.h"
#include "Unit2.h"
#include "Unit3.h"
#include "Unit4.h"
#include "Unit5.h"
#include "Unit6.h"
#include "Unit7.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
FILE *FN;
Auto Info,InfoOld;
int tmp = 0, fileclosed;
extern void PrintList(FILE *);
extern void DelInfo(FILE *,Auto);
extern int Search(FILE*);
//---------------------------------------------------------------------------
//Надписи на столбцах
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
  Form1->StrGr->Cells[0][0] = "Наименование автомобиля";
  Form1->StrGr->Cells[1][0] = "Марка автомобиля";
  Form1->StrGr->Cells[2][0] = "Число мест";
  Form1->StrGr->Cells[3][0] = "Расход бензина";
}
//---------------------------------------------------------------------------
//Создать новый, пустой файл
//-1 в начале говорит о том, что ссылка на первый элемент пуста
//0 говорит о том, что в файле 0 записей
void __fastcall TForm1::N2Click(TObject *Sender)
{
 for (int i = 1; i <= Form1->StrGr->RowCount; i++)
  {
    Form1->StrGr->Cells[0][i] = "";
    Form1->StrGr->Cells[1][i] = "";
    Form1->StrGr->Cells[2][i] = "";
    Form1->StrGr->Cells[3][i] = "";
  }
  char *s;
  int i = -1;
  if (OpDial->Execute())
  {
    s = strcat(OpDial->FileName.c_str(),".bin");
    if ((FN = fopen(s,"w+b"))==NULL)
      ShowMessage("Не удалось создать файл");
    else
    {
      fseek(FN,0,0);
      fwrite(&i, sizeof(int),1,FN);
      i++;
      fwrite(&i, sizeof(int),1,FN);
      fileclosed = 1;
    }
  }
}
//---------------------------------------------------------------------------
//Открытие файла
void __fastcall TForm1::N3Click(TObject *Sender)
{
  for (int i = 1; i <= Form1->StrGr->RowCount; i++)
  {
    Form1->StrGr->Cells[0][i] = "";
    Form1->StrGr->Cells[1][i] = "";
    Form1->StrGr->Cells[2][i] = "";
    Form1->StrGr->Cells[3][i] = "";
  }
  char *s;
  if (OpDial->Execute())
  {
    if (fileclosed == 0)
      fclose(FN);
    s = (OpDial->FileName).c_str();
    if ((FN = fopen(s,"r+b"))==NULL)
      ShowMessage("Не удалось открыть файл");
    else
    {
      PrintList(FN);
      fileclosed = 1;
    }
  }
}
//---------------------------------------------------------------------------
//Закрытие файла
void __fastcall TForm1::N4Click(TObject *Sender)
{
  int i;
  for (i = 1; i < 18; i++)
  {
    Form1->StrGr->Cells[0][i] = "";
    Form1->StrGr->Cells[1][i] = "";
    Form1->StrGr->Cells[2][i] = "";
    Form1->StrGr->Cells[3][i] = "";
  }
  fileclosed = fclose(FN);
  ShowMessage("Файл закрыт!");

}
//---------------------------------------------------------------------------
//Поиск по условиям
void __fastcall TForm1::N6Click(TObject *Sender)
{
  Form5->Show();
  tmp = Search(FN);
  Form5->Label2->Caption = "Всего найдено записей: "+IntToStr(tmp);
  PrintList(FN);
}
//---------------------------------------------------------------------------
//Поиск по условиям пользователя
void __fastcall TForm1::N7Click(TObject *Sender)
{
  Form7->Show();
}
//---------------------------------------------------------------------------
//Выход из программы
void __fastcall TForm1::N9Click(TObject *Sender)
{
  if (fileclosed)
    fclose(FN);
  if (Application->MessageBox(
  "Закрыть программу?","Выход", MB_YESNO+MB_ICONQUESTION)==IDYES)
    Application->Terminate();
}
//---------------------------------------------------------------------------
//Добавить элемент в файл
void __fastcall TForm1::N11Click(TObject *Sender)
{
 if (fileclosed)
  Form2->Show();
}
//---------------------------------------------------------------------------
//Изменение записи списка
void __fastcall TForm1::N12Click(TObject *Sender)
{
  tmp = Form1->StrGr->Row;
  Form4->Show();
  Form4->Edit1->Text = Form1->StrGr->Cells[0][tmp];
  Form4->Edit2->Text = Form1->StrGr->Cells[1][tmp];
  Form4->Edit3->Text = Form1->StrGr->Cells[2][tmp];
  Form4->Edit4->Text = Form1->StrGr->Cells[3][tmp];
  strcpy(InfoOld.Name, Form1->StrGr->Cells[0][tmp].c_str());
  strcpy(InfoOld.Mark, Form1->StrGr->Cells[1][tmp].c_str());
  InfoOld.SeatsNumb = StrToInt(Form1->StrGr->Cells[2][tmp]);
  InfoOld.UseP = StrToFloat(Form1->StrGr->Cells[3][tmp]);
}
//---------------------------------------------------------------------------
//Удаление выбранного элемента из списка
void __fastcall TForm1::N13Click(TObject *Sender)
{
  if (Application->MessageBox(
  "Хотите удалить эту информацию?","Удаление",
  MB_YESNO+MB_ICONQUESTION)==IDYES)
  {
    tmp = Form1->StrGr->Row;
    strcpy(Info.Name, Form1->StrGr->Cells[0][tmp].c_str());
    strcpy(Info.Mark, Form1->StrGr->Cells[1][tmp].c_str());
    DelInfo(FN,Info);
    PrintList(FN);
  }
}
//---------------------------------------------------------------------------



Соседние файлы в папке Программа
  • #
    28.06.20141.57 Кб15Project1.cpp
  • #
    28.06.201418.6 Кб14Project1.obj
  • #
    28.06.2014876 б14Project1.res
  • #
    28.06.20142.29 Mб14Project1.tds
  • #
    28.06.20148 б14test
  • #
    28.06.20145.12 Кб14Unit1.cpp
  • #
    28.06.201451 б14Unit1.ddp
  • #
    28.06.20143.03 Кб14Unit1.dfm
  • #
    28.06.20141.69 Кб15Unit1.h
  • #
    28.06.2014108.56 Кб14Unit1.obj
  • #
    28.06.20145.13 Кб15Unit1.~cpp