Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Отчет с Рамкой(КУРСОВОЙ).doc
Скачиваний:
0
Добавлен:
01.03.2025
Размер:
1.11 Mб
Скачать

Розділ 3. Технологічний розділ

    1. Розробка програмного продукту

Наш проект складається з різних файлів, які між собою зв’язані та тісно позязані, якщо одного файла будет не вистачати, програма не буде працювати, а якщо запустить то працюватиме не коректно. В каталозі, де записаний проект, знаходиться як мінімум шість файлів. Їх автоматично створив і належним чином наповнив C++ Builder. Взагалі, C++ Builder багато робить за програміста, але, по-перше, не всі, а, по-друге, бувають випадки, коли це заважає.

Отже в будь-якому проекті є:

  • Вихідний файл проекту (project source fail) (Project1.cpp)-містить WinMain і код, який C++ Builder пише автоматично.

  • Вихідний файл форми (form source file) (Unit1.cpp) і заголовний файл форми (form header file) (Unit1.h)-ця пара завжди відповідає одній з форм, в цих файлах знаходиться код внесений середовищем і програмістом (C++ Builder тут вставляє тільки оголошення та оформляє функції, решту пишете прогрміст).

  • Файл ресурсів форми (form resource file) (Unit1.dfm)-цей файл теж створюється з кожною новою формою, цей файл містить опис форми.

  • Файл ресурсів програми (application resource fail) (Project1.res) - стандартний файл ресурсів, тут містяться ресурси для всього додатки (іконка і т.п.)

  • Інформаційний файл проекту (Project1.bpr)-тут інсталяційні опції компілятора і всякий збір файлів які потрібні для компіляції.

Створюваний проект містить : Project1.cpp, Project1.bpr, Project1.res, Project1.exe, Unit1.dfm, Unit3.dfm, Unit5.dfm, Unit1.cpp, Unit3.cpp, Unit5.cpp, Unit1.h, Unit3.h, Unit5.h. Якщо видалити хоча б один файл, програма буде працювати не коректно або зовсім не запускатися.

Лістинг Project1.bpr

#include <vcl.h>

#pragma hdrstop

//---------------------------------------------------------------------------

USEFORM("Unit1.cpp", Form1);

USEFORM("Unit3.cpp", Form3);

USEFORM("Unit5.cpp", Form5);

//---------------------------------------------------------------------------

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

try {

Application->Initialize();

Application->CreateForm(__classid(TForm1), &Form1);

Application->CreateForm(__classid(TForm3), &Form3);

Application->CreateForm(__classid(TForm5), &Form5);

Application->Run();

}

catch (Exception &exception) {

Application->ShowException(&exception);

}

catch (...) {

try {

throw Exception("");

}

catch (Exception &exception) {

Application->ShowException(&exception);

}

}

return 0;

}

Лістинг Unit 1.cpp

//---------------------------------------------------------------------------

#include <vcl.h>

#include <math.hpp>

#include <ComObj.hpp>

#include <utilcls.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit3.h"

#include "Unit5.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma link "Excel_2K_SRVR"

#pragma resource "*.dfm"

TForm1 *Form1;

float norm=0;

//---------------------------------------------------------------------------

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button1Click(TObject *Sender)

{

float ras=0;

ras=StrToFloat(Edit3->Text);

if(ComboBox2->ItemIndex==-1){

ShowMessage("Виберіть фамілію водія");

return;

}

if(Edit1->Text==""){

Application->MessageBox("Повторите ввод",

"Вы не ввели Общий проезд", MB_OK);

Edit1->SetFocus();

return;

}

if(Edit2->Text==""){

Application->MessageBox("Повторите ввод",

"Вы не ввели поле 'Видано литров'", MB_OK);

Edit2->SetFocus();

return;

}

if(ADOQuery1->RecordCount>0){

Edit4->Visible=false;

Edit5->Visible=false;

Label6->Visible=false;

Label7->Visible=false;

Label8->Visible=false;

}

ADOQuery1->Append();

ADOQuery1->Edit();

ADOQuery1->FieldByName("viezd")->AsFloat=StrToFloat(Edit5->Text);

ADOQuery1->FieldByName("data")->AsString=DateToStr(DateTimePicker1->Date);

ADOQuery1->FieldByName("nomer")->AsString=ComboBox3->Items->Strings[ComboBox3->ItemIndex];

ADOQuery1->FieldByName("vodit")->AsString=ComboBox2->Items->Strings[ComboBox2->ItemIndex];

ADOQuery1->FieldByName("ob_proezd")->AsFloat=StrToFloat(Edit1->Text);

ADOQuery1->FieldByName("bal_viezda")->AsFloat=StrToFloat(Edit4->Text);

ADOQuery1->FieldByName("vidano")->AsFloat=StrToFloat(Edit2->Text);

norm=ADOQuery1->FieldByName("norm")->AsFloat;

ADOQuery1->FieldByName("norm")->AsFloat=

ADOQuery1->FieldByName("ob_proezd")->AsFloat*ras/100;

ADOQuery1->FieldByName("bal_zaizd")->AsFloat=

ADOQuery1->FieldByName("bal_viezda")->AsFloat+

ADOQuery1->FieldByName("vidano")->AsFloat-

ADOQuery1->FieldByName("norm")->AsFloat;

Edit6->Text=RoundTo(ADOQuery1->FieldByName("bal_zaizd")->AsFloat,-2);

ADOQuery1->FieldByName("bal_zaizd")->AsFloat=StrToFloat(Edit6->Text);

ADOQuery1->FieldByName("vozvrat")->AsFloat=

ADOQuery1->FieldByName("ob_proezd")->AsFloat+

ADOQuery1->FieldByName("viezd")->AsFloat;

Edit4->Text=RoundTo(ADOQuery1->FieldByName("bal_zaizd")->AsFloat,-2);

Edit5->Text=ADOQuery1->FieldByName("vozvrat")->AsFloat;

ADOQuery1->Post();

Edit1->Text="";

Edit2->Text="";

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button2Click(TObject *Sender)

{

ADOQuery1->Edit();

ADOQuery1->Last();

if(ADOQuery1->RecordCount==0){

Edit4->Visible=true;

Edit5->Visible=true;

Label6->Visible=true;

Label7->Visible=true;

Label8->Visible=true;

Edit4->Text="";

Edit5->Text="";

return;

}

ADOQuery1->Delete();

Edit4->Text=RoundTo(ADOQuery1->FieldByName("bal_zaizd")->AsFloat,-2);

Edit5->Text=ADOQuery1->FieldByName("vozvrat")->AsFloat;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)

{

ComboBox2->Items->LoadFromFile("CBv.txt");

ComboBox3->Items->LoadFromFile("CBn.txt");

DateTimePicker1->Time = Time();

DateTimePicker1->Date = Date();

DateTimePicker1->DateTime=Now();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)

{

Label5->Caption = FormatDateTime("dd.mm.yyyy",Date())+" "+FormatDateTime("hh:nn:ss",Time());

Timer1->Interval=1000;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N2Click(TObject *Sender)

{

Form1->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N5Click(TObject *Sender)

{

Edit4->Visible=true;

Edit5->Visible=true;

Label6->Visible=true;

Label7->Visible=true;

Label8->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N1Click(TObject *Sender)

{

Form1->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N7Click(TObject *Sender)

{

Form5->Show();

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N8Click(TObject *Sender)

{

Form3->Show();

Form3->Edit8->SetFocus();

Form3->Button3->Visible=true;

Form3->Edit8->Visible=true;

Form3->Label8->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N9Click(TObject *Sender)

{

Form3->Show();

Form3->Edit7->SetFocus();

Form3->Button2->Visible=true;

Form3->Edit7->Visible=true;

Form3->Label7->Visible=true;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N11Click(TObject *Sender)

{

Form3->Show();

Form3->Button2->Visible=true;

Form3->Button3->Visible=true;

Form3->Edit7->Visible=true;

Form3->Edit8->Visible=true;

Form3->Label7->Visible=true;

Form3->Label8->Visible=true;

ComboBox3->Items->SaveToFile("CBn.txt");

ComboBox2->Items->SaveToFile("CBv.txt");

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N12Click(TObject *Sender)

{

Form3->Show();

Form3->Button1->Visible=true;

Form3->ComboBox1->Visible=true;

Form3->Button4->Visible=true;

Form3->ComboBox2->Visible=true;

ComboBox3->Items->SaveToFile("CBn.txt");

ComboBox2->Items->SaveToFile("CBv.txt");

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button3Click(TObject *Sender)

{

if(ComboBox3->ItemIndex==-1){

ShowMessage("Виберіть номер машини");

return;

}

Label1->Visible=true;

Label2->Visible=true;

Label3->Visible=true;

Label4->Visible=true;

Edit1->Visible=true;

Edit2->Visible=true;

Edit3->Visible=true;

DateTimePicker1->Visible=true;

ComboBox2->Visible=true;

Button1->Visible=true;

Button2->Visible=true;

ADOQuery1->Close();

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("SELECT * FROM baza WHERE (data >=:d1) and (data <=:d2) and nomer=:m ORDER BY data");

ADOQuery1->Parameters->ParamByName("d1")->Value=DateTimePicker2->Date;

ADOQuery1->Parameters->ParamByName("d2")->Value=DateTimePicker3->Date;

ADOQuery1->Parameters->ParamByName("m")->Value=ComboBox3->Items->Strings[ComboBox3->ItemIndex];

ADOQuery1->Active=true;

ADOQuery1->Open();

if(ADOQuery1->Eof){

ShowMessage("База пуста. Не має жодного запису");

}

if(ADOQuery1->RecordCount==0){

Edit4->Visible=true;

Edit5->Visible=true;

Label6->Visible=true;

Label7->Visible=true;

Label8->Visible=true;

Edit4->Text="";

Form1->Edit5->Text="";

return;

}

if(Form1->ADOQuery1->RecordCount>0){

Label6->Visible=false;

Label7->Visible=false;

Label8->Visible=false;

Edit4->Visible=false;

Edit5->Visible=false;

}

ADOQuery1->Last();

Edit4->Text=RoundTo(Form1->ADOQuery1->FieldByName("bal_zaizd")->AsFloat,-2);

ADOQuery1->Last();

Edit5->Text=Form1->ADOQuery1->FieldByName("vozvrat")->AsFloat;

}

//---------------------------------------------------------------------------

void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)

{

ComboBox3->Items->SaveToFile("CBn.txt");

ComboBox2->Items->SaveToFile("CBv.txt");

}

//---------------------------------------------------------------------------

void __fastcall TForm1::N6Click(TObject *Sender)

{

Variant v,v1;

if(!fStart)

{

try

{

//Создаем объект Excel.Application

vVarApp=CreateOleObject("Excel.Application");

fStart=true;

}

catch(...)

{

MessageBox(0, "Ошибка при открытии сервера Word",

"Ошибка", MB_OK);

return;

}

}

//Делаем сервер видимым

vVarApp.OlePropertySet("Visible",true);

//Создаем книгу

vVarBooks=vVarApp.OlePropertyGet("Workbooks");

//Сколько страниц в книге

vVarApp.OlePropertySet("SheetsInNewWorkbook",2);

vVarBooks.OleProcedure("Add");

vVarBook=vVarBooks.OlePropertyGet("Item",1);

vVarSheets=vVarBook.OlePropertyGet("Worksheets") ;

vVarSheet=vVarSheets.OlePropertyGet("Item",1);

vVarSheet.OlePropertySet("Name","Отчет");

vVarSheet.OleProcedure("Activate");

vAsCurDir=GetCurrentDir();

//Application->MessageBox(vAsCurDir,"OK",MB_OK);

//AnsiString vAsCurDir1="F:\4 курс\EXEL\Word Builder\b.gif";

//vVarBook.OlePropertyGet("ActiveSheet").

// OleFunction("SetBackgroundPicture",vAsCurDir1.c_str());

vVarSheet=vVarSheets.OlePropertyGet("Item",2);

vVarSheet.OlePropertySet("Name","Отчет1");

vVarSheet.OleProcedure("Activate");

/*vVarSheets.OlePropertyGet("Item",3).

OlePropertySet("Name","Пустой лист"); */

String exp1, exp2, exp3, exp4, exp5, exp6, exp7, exp8, exp9, exp10, exp11;

int index=3, i, j;

// Выбираем лист 1 текущей книги

vVarSheet = vVarSheets.OlePropertyGet("Item", 2);

// Делаем его активным

vVarSheet.OleProcedure("Activate");

// Это заголовок таблицы

String k="Вывод из DBGrid в Excel";

// Назначаем диапазон ячеек

vVarCell = vVarSheet.OlePropertyGet("Range", "A1:J2");

// Объединяем ячейки в диапазоне

vVarCell.OleProcedure("Merge");

// Выравнимаем текст по центру

vVarSheet.OlePropertyGet("Rows", 1).OlePropertySet("HorizontalAlignment", 3);

// Ставим зеленый цвет заливки

vVarSheet.OlePropertyGet("Cells", 1,1).OlePropertyGet("Interior").OlePropertySet("ColorIndex",4);

// Ставим жирный шрифт

vVarSheet.OlePropertyGet("Cells", 1,1).OlePropertyGet("Font").OlePropertySet("Bold",1);

// Прорисовываем границы ячейки (1, 1)

vVarApp.OlePropertyGet("Cells", 1,1).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells", 1,1).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells", 1,1).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells", 1,1).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

// Устанавливаем размер шрифта 18

vVarSheet.OlePropertyGet("Rows",1).OlePropertyGet("Font").OlePropertySet("Size",12);

// Выводим заголовок

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",1,1).OlePropertySet("Value", k.c_str());

// Далее идет вывод из DBGrid и форматирование ячеек. Как я уже говорил мы выводим 0, 1 и 6 ячейки

//Заносим номер дня в первую строку таблицы

vVarCell=vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,1);

vBorder(vVarCell,2,1,55);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",10);

vVarCell.OlePropertySet("Value", "Дата");

//Занести значение во вторую строку ячейку на выбранном листе

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,2);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Номер машини");

//Занести значение в третью строку ячейку на выбранном листе

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,3);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Фамілія Водія");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,4);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Км при виїзді");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,5);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Км при заїзді");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,6);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Загальний проїзд");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,7);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",12);

vVarCell.OlePropertySet("Value", "Норма");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,8);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Залишок заїзд");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,9);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Залишок виїзд");

vVarCell= vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",3,10);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

vVarCell.OlePropertySet("ColumnWidth",15);

vVarCell.OlePropertySet("Value", "Видано літрів");

DBGrid1->DataSource->DataSet->First();

for (int i=1; i<=DBGrid1->DataSource->DataSet->RecordCount; i++) {

exp1=DBGrid1->Fields[0]->AsDateTime;

exp2=DBGrid1->Fields[1]->AsString;

exp3=DBGrid1->Fields[2]->AsString;

exp4=DBGrid1->Fields[3]->AsString;

exp5=DBGrid1->Fields[4]->AsString;

exp6=DBGrid1->Fields[5]->AsString;

exp7=DBGrid1->Fields[6]->AsString;

exp8=DBGrid1->Fields[7]->AsString;

exp9=DBGrid1->Fields[8]->AsString;

exp10=DBGrid1->Fields[9]->AsString;

vVarApp.OlePropertyGet("Cells",index+1,1).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,1).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,1).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,1).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,2).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,2).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,2).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,2).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,3).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,3).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,3).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,3).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,4).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,4).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,4).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,4).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,5).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,5).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,5).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,5).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,6).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,6).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,6).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,6).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,7).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,7).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,7).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,7).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,8).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,8).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,8).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,8).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,9).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,9).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,9).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,9).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,10).OlePropertyGet("Borders",10).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,10).OlePropertyGet("Borders",7).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,10).OlePropertyGet("Borders",8).OlePropertySet("Weight",2);

vVarApp.OlePropertyGet("Cells",index+1,10).OlePropertyGet("Borders",9).OlePropertySet("Weight",2);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 1).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 2).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 3).OlePropertySet("ColumnWidth", 12);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 4).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 5).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 6).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 7).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 8).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 9).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Columns").OlePropertyGet("Item", 10).OlePropertySet("ColumnWidth", 10);

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,1).OlePropertySet( "Value", exp1.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,2).OlePropertySet( "Value", exp2.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,3).OlePropertySet( "Value", exp3.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,4).OlePropertySet( "Value", exp4.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,5).OlePropertySet( "Value", exp5.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,6).OlePropertySet( "Value", exp6.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,7).OlePropertySet( "Value", exp7.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,8).OlePropertySet( "Value", exp8.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,9).OlePropertySet( "Value", exp9.c_str());

vVarSheet.OlePropertyGet("Cells").OlePropertyGet("Item",index+1,10).OlePropertySet( "Value", exp10.c_str());

index++;

DBGrid1->DataSource->DataSet->Next();

}

/*//Ячейку итог заполним

vVarCell=vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",4,11);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clRed,0,0,0);

vVarCell.OlePropertySet("Value","Итог:");

//добавить формулы подсчета суммы в строки

vVarCell=vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",5,11);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clRed,0,0,0);

vVarCell.OlePropertySet("Value","=СУММ(D5:J5)");

//добавить формулы подсчета суммы в строки

vVarCell=vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",6,11);

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clRed,0,0,0);

vVarCell.OlePropertySet("Value","=СУММ(D6:J6)");

//Изменим размер ячеек

vVarCell=vVarSheet.OlePropertyGet("Cells").

OlePropertyGet("Item",4,2);

vBorder(vVarCell,2,1,55);

vVarCell.OlePropertySet("RowHeight", 20);

vVarCell.OlePropertySet("ColumnWidth",10);

//Объединяем ячейки

vVarCell=vVarSheet.OlePropertyGet("Range","B4:C4");

vVarCell.OleProcedure("Merge");

vBorder(vVarCell,2,1,55);

vFont(vVarCell,-4108,-4108,12,37,1,clBlack,0,0,0);

//Вписываем вид товара

vVarCell.OlePropertySet("Value", "Товар\\Дни недели:");

vVarCell=vVarSheet.OlePropertyGet("Range","B5:C5");

vVarCell.OleProcedure("Merge");

vBorder(vVarCell,2,1,55);

vFont(vVarCell,1,1,12,37,1,clBlack,0,0,0);

//Вписываем вид товара

vVarCell.OlePropertySet("Value", "Компьютеры:");

vVarCell=vVarSheet.OlePropertyGet("Range","B6:C6");

vVarCell.OleProcedure("Merge");

vBorder(vVarCell,2,1,55);

vFont(vVarCell,1,1,12,37,1,clBlack,0,0,0);

//Вписываем вид товара

vVarCell.OlePropertySet("Value", "Принтеры:"); */

//Пишем заголовок

/* vVarCell=vVarSheet.OlePropertyGet("Range","B2:K3");

vVarCell.OleProcedure("Merge");

vBorder(vVarCell,3,1,46);

vFont(vVarCell,-4108,-4108,16,34,1,clBlue,0,0,-4119);

vVarCell.OlePropertySet("Value", "Отчет за период по проезду");*/

//Отключить вывод сообщений с вопросами типа "Заменить файл..."

vVarApp.OlePropertySet("DisplayAlerts",false);

}

//---------------------------------------------------------------------------

void __fastcall TForm1::Button4Click(TObject *Sender)

{

if(fStart) vVarApp.OleProcedure("Quit");

vVarApp=0;

vVarBooks=0;

vVarBook=0;

vVarSheets=0;

vVarSheet=0;

vVarCells=0;

vVarCell=0;

vAsCurDir=0;

fStart=0;

}

//---------------------------------------------------------------------------

//Функция определяет все параметры рисования квадратной рамки

//вокруг ячейки или группе выделенных ячеек

void __fastcall

TForm1::vBorder(Variant& vVarCell,int Weight,

int LineStyle,int ColorIndex)

{

for(int i=8; i <= 10; i++)

{

switch(LineStyle)

{

case 1:

case -4115:

case 4:

case 5:

case -4118:

case -4119:

case 13:

case -4142:

vVarCell.OlePropertyGet("Borders",10).

OlePropertySet("LineStyle",LineStyle);

break;

default:

vVarCell.OlePropertyGet("Borders",i).

OlePropertySet("LineStyle",1);

}

switch(Weight)

{

case 1:

case -4138:

case 2:

case 4:

vVarCell.OlePropertyGet("Borders",i).

OlePropertySet("Weight",Weight);

break;

default:

vVarCell.OlePropertyGet("Borders",i).

OlePropertySet("Weight",1);

}

vVarCell.OlePropertyGet("Borders",i).

OlePropertySet("ColorIndex",ColorIndex);

}

}

//--------------------------------------------------------

//Функция определяет все параметры шрифта, заливку, подчеркивание

//и выравнивание текста в ячейках или группе выделенных ячеек

void __fastcall

TForm1::vFont(Variant& vVarCell,int HAlignment,

int VAlignment,int Size,int ColorIndex,

int Name,TColor Color,int Style,

int Strikline,int Underline)

{

//Выравнивание

switch(HAlignment)

{

case -4108:

case 7:

case -4117:

case 5:

case 1:

case -4130:

case -4131:

case -4152:

vVarCell.OlePropertySet("HorizontalAlignment",HAlignment);

break;

}

switch(VAlignment)

{

case -4108:

case 7:

case -4117:

case 5:

case 1:

case -4130:

case -4131:

case -4152:

vVarCell.OlePropertySet("VerticalAlignment",VAlignment);

break;

}

//Размер шрифта

vVarCell.OlePropertyGet("Font").

OlePropertySet("Size",Size);

//Цвет шрифта

vVarCell.OlePropertyGet("Font").

OlePropertySet("Color",Color);

//Имя щрифта(Можно включаь сколько угодно)

switch(Name)

{

case 1:

vVarCell.OlePropertyGet("Font").

OlePropertySet("Name","Arial");

break;

case 2:

vVarCell.OlePropertyGet("Font").

OlePropertySet("Name","Times New");

break;

default:

vVarCell.OlePropertyGet("Font").

OlePropertySet("Name","System");

}

//Заливка ячейки

vVarCell.OlePropertyGet("Interior").

OlePropertySet("ColorIndex",ColorIndex);

//Стиль шрифта

switch(Style)

{

case 1:

vVarCell.OlePropertyGet("Font").OlePropertySet("Bold",true);

vVarCell.OlePropertyGet("Font").OlePropertySet("Italic",false);

break;

case 2:

vVarCell.OlePropertyGet("Font").OlePropertySet("Bold",false);

vVarCell.OlePropertyGet("Font").OlePropertySet("Italic",true);

break;

case 3:

vVarCell.OlePropertyGet("Font").OlePropertySet("Bold",true);

vVarCell.OlePropertyGet("Font").OlePropertySet("Italic",true);

break;

default:

vVarCell.OlePropertyGet("Font").OlePropertySet("Bold",false);

vVarCell.OlePropertyGet("Font").OlePropertySet("Italic",false);

}

//Зачеркивание и индексы

switch(Strikline)

{

case 1: //Зачеркнутый

vVarCell.OlePropertyGet("Font").

OlePropertySet("Strikethrough",true);

break;

case 2://Верхний индекс

vVarCell.OlePropertyGet("Font").

OlePropertySet("Superscript",true);

break;

case 3://Верхний индекс

vVarCell.OlePropertyGet("Font").

OlePropertySet("Subscript",true);

break;

case 4://Нижний индекс

vVarCell.OlePropertyGet("Font").

OlePropertySet("Subscript",true);

break;

case 5://Без линий

vVarCell.OlePropertyGet("Font").

OlePropertySet("OutlineFont",true);

break;

case 6://C тенью

vVarCell.OlePropertyGet("Font").

OlePropertySet("Shadow",true);

break;

default://Без линий

vVarCell.OlePropertyGet("Font").

OlePropertySet("OutlineFont",true);

}

//Подчеркивание

switch(Underline)

{

case 2:

case 4:

case 5:

case -4119:

vVarCell.OlePropertyGet("Font").

OlePropertySet("Underline",Underline);

break;

}

}

//---------------------------------------------------------------------------

Лістинг Unit 1.h

#ifndef Unit1H

#define Unit1H

//---------------------------------------------------------------------------

#include <Classes.hpp>

#include <Controls.hpp>

#include <StdCtrls.hpp>

#include <Forms.hpp>

#include <ADODB.hpp>

#include <ComCtrls.hpp>

#include <DB.hpp>

#include <DBCtrls.hpp>

#include <DBGrids.hpp>

#include <ExtCtrls.hpp>

#include <Grids.hpp>

#include <Menus.hpp>

#include <Dialogs.hpp>

#include "Excel_2K_SRVR.h"

#include <OleServer.hpp>

//---------------------------------------------------------------------------

class TForm1 : public TForm

{

__published: // IDE-managed Components

TADOConnection *ADOConnection1;

TEdit *Edit1;

TLabel *Label1;

TDateTimePicker *DateTimePicker1;

TLabel *Label2;

TEdit *Edit2;

TLabel *Label3;

TButton *Button1;

TLabel *Label4;

TEdit *Edit3;

TButton *Button2;

TADOQuery *ADOQuery1;

TEdit *Edit4;

TEdit *Edit5;

TLabel *Label5;

TTimer *Timer1;

TMainMenu *MainMenu1;

TMenuItem *N2;

TLabel *Label6;

TLabel *Label7;

TLabel *Label8;

TComboBox *ComboBox2;

TDataSource *DataSource2;

TMenuItem *N4;

TMenuItem *N5;

TMenuItem *N7;

TDateTimeField *ADOQuery1data;

TWideStringField *ADOQuery1nomer;

TWideStringField *ADOQuery1vodit;

TWideStringField *ADOQuery1viezd;

TWideStringField *ADOQuery1vozvrat;

TWideStringField *ADOQuery1ob_proezd;

TFloatField *ADOQuery1norm;

TWideStringField *ADOQuery1bal_viezda;

TWideStringField *ADOQuery1bal_zaizd;

TWideStringField *ADOQuery1vidano;

TDBGrid *DBGrid1;

TEdit *Edit6;

TMenuItem *N6;

TPrintDialog *PrintDialog1;

TMenuItem *N11;

TMenuItem *N12;

TDateTimePicker *DateTimePicker2;

TDateTimePicker *DateTimePicker3;

TComboBox *ComboBox3;

TButton *Button3;

TButton *Button4;

void __fastcall Button1Click(TObject *Sender);

void __fastcall Button2Click(TObject *Sender);

void __fastcall FormCreate(TObject *Sender);

void __fastcall Timer1Timer(TObject *Sender);

void __fastcall N2Click(TObject *Sender);

void __fastcall N5Click(TObject *Sender);

void __fastcall N1Click(TObject *Sender);

void __fastcall N7Click(TObject *Sender);

void __fastcall N8Click(TObject *Sender);

void __fastcall N9Click(TObject *Sender);

void __fastcall N11Click(TObject *Sender);

void __fastcall N12Click(TObject *Sender);

void __fastcall Button3Click(TObject *Sender);

void __fastcall FormClose(TObject *Sender, TCloseAction &Action);

void __fastcall N6Click(TObject *Sender);

void __fastcall Button4Click(TObject *Sender);

private: // User declarations

Variant vVarApp,vVarBooks,vVarBook,vVarSheets,

vVarSheet,vVarCells,vVarCell;

AnsiString vAsCurDir;

bool fStart;

void __fastcall vBorder(Variant& vVarCell,int Weight,

int LineStyle,int ColorIndex);

void __fastcall vFont(Variant& vVarCell,int HAlignment,

int VAlignment,int Size,

int ColorIndex,int Name,

TColor Color,int Style,

int Strikline,int Underline);

public: // User declarations

__fastcall TForm1(TComponent* Owner);

};

//---------------------------------------------------------------------------

extern PACKAGE TForm1 *Form1;

//---------------------------------------------------------------------------

#endif

Лістинг Unit 3.h

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit3.h"

#include "Unit5.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm3 *Form3;

//---------------------------------------------------------------------------

__fastcall TForm3::TForm3(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm3::Button3Click(TObject *Sender)

{

Form1->ComboBox3->Items->Add(Edit8->Text);

ComboBox1->Items->Add(Edit8->Text);

Application->MessageBox("Номер машини добавлено",

"Результат", MB_OK);

Form3->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm3::Button2Click(TObject *Sender)

{

Form1->ComboBox2->Items->Add(Edit7->Text);

ComboBox2->Items->Add(Edit7->Text);

Application->MessageBox("Фамілію водія добавлено",

"Результат", MB_OK);

Form3->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm3::FormClose(TObject *Sender, TCloseAction &Action)

{

Form3->ComboBox1->Items->SaveToFile("CBn.txt");

Form3->ComboBox2->Items->SaveToFile("CBv.txt");

Button2->Visible=false;

Edit7->Visible=false;

Label7->Visible=false;

Button3->Visible=false;

Edit8->Visible=false;

Label8->Visible=false;

Edit7->Text="";

Edit8->Text="";

ComboBox1->Visible=false;

ComboBox2->Visible=false;

Button1->Visible=false;

Button4->Visible=false;

ComboBox1->ItemIndex=-1;

ComboBox1->Text="Номер машини";

ComboBox2->ItemIndex=-1;

ComboBox2->Text="Водій";

}

//---------------------------------------------------------------------------

void __fastcall TForm3::Button1Click(TObject *Sender)

{

Form1->ComboBox3->Items->Delete(ComboBox1->ItemIndex);

ComboBox1->Items->Delete(ComboBox1->ItemIndex);

Application->MessageBox("Номер машини видалено з бази",

"Результат", MB_OK);

Form3->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm3::Button4Click(TObject *Sender)

{

Form1->ComboBox2->Items->Delete(ComboBox2->ItemIndex);

ComboBox2->Items->Delete(ComboBox2->ItemIndex);

Application->MessageBox("Фамілію водія добавлено",

"Результат", MB_OK);

Form3->Close();

Form1->ComboBox2->Items->Delete(ComboBox2->ItemIndex);

}

//---------------------------------------------------------------------------

void __fastcall TForm3::FormCreate(TObject *Sender)

{

ComboBox2->Items->LoadFromFile("CBv.txt");

ComboBox1->Items->LoadFromFile("CBn.txt");

}

//---------------------------------------------------------------------------

Лістинг Unit 5.h

//---------------------------------------------------------------------------

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit3.h"

#include "Unit5.h"

//---------------------------------------------------------------------------

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm5 *Form5;

//---------------------------------------------------------------------------

__fastcall TForm5::TForm5(TComponent* Owner)

: TForm(Owner)

{

}

//---------------------------------------------------------------------------

void __fastcall TForm5::N4Click(TObject *Sender)

{

Form1->Show();

}

//---------------------------------------------------------------------------

void __fastcall TForm5::N1Click(TObject *Sender)

{

Form5->Close();

}

//---------------------------------------------------------------------------

void __fastcall TForm5::FormActivate(TObject *Sender)

{

ADOQuery1->Active=false;

ADOQuery1->Active=true;

ADOQuery1->Edit();

ADOQuery1->Last();

}

//---------------------------------------------------------------------------

void __fastcall TForm5::FormCreate(TObject *Sender)

{

ADOQuery1->Close();

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("SELECT * FROM baza ORDER BY data");

ADOQuery1->Active=true;

ADOQuery1->Open();

}

//---------------------------------------------------------------------------