Смекни!
smekni.com

Информационная система военного округа (стр. 4 из 4)

if (ADOTable1->TableName==WideString("sostav"))

{

TLocateOptions Opts1;

Opts1.Clear();

Opts1<<loPartialKey<<loCaseInsensitive;

ADOTable1->Locate("kod_slugashego",Edit2->Text,Opts1);

}

}

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

void __fastcall TForm1::Button6Click(TObject *Sender)

{

ADOTable1->Append();

Form2->Show();

}

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

void __fastcall TForm1::Button7Click(TObject *Sender)

{

DataSource3->DataSet=ADOStoredProc1;

ADOQuery1->Active=false;

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("CREATE PROCEDURE proc2;1 as SELECT nazvanie_armii, COUNT(Nomer_podrazdelenia) AS col FROM chast GROUP BY nazvanie_armii HAVING COUNT(nazvanie_armii)>=ALL(SELECT COUNT(nazvanie_armii) FROM Chast GROUP BY nazvanie_armii)");

ADOStoredProc1->ProcedureName="proc2;1";

ADOQuery1->ExecSQL();

ADOStoredProc1->Active=false;

ADOStoredProc1->ExecProc();

ADOStoredProc1->Active=true;

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add ("drop procedure proc2");

ADOQuery1->ExecSQL();

}

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

void __fastcall TForm1::Button8Click(TObject *Sender)

{

ADOQuery1->Active=false;

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("Create trigger trig on Obedinenie for update as begin if update([nazvanie_armii]) begin UPDATE chast SET chast.nazvanie_armii=inserted.nazvanie_armii FROM chast, deleted, inserted WHERE chast.nazvanie_armii=deleted.nazvanie_armii end end");

ADOQuery1->ExecSQL();

ADOTable1->Active=false;

Form2->DBEdit1->DataField="";

Form2->DBEdit2->DataField="";

Form2->DBEdit3->DataField="";

Form2->DBEdit4->DataField="";

Form2->DBEdit5->DataField="";

Form2->DBEdit6->DataField="";

Form2->DBEdit7->DataField="";

DBText1->DataField="";

DBText1->DataSource=DataSource1;

DBText1->DataField="nazvanie_armii";

ADOTable1->TableName="Obedinenie";

Label4->Caption=ADOTable1->TableName;

ADOTable1->Active=true;

ADOTable2->Active=false;

ADOTable2->TableName="Chast" ;

Label5->Caption=ADOTable2->TableName;

ADOTable2->Active=true;

DBText1->DataField="nazvanie_armii";

}

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

void __fastcall TForm1::Button9Click(TObject *Sender)

{

ADOQuery1->Active=false;

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("DROP TRIGGER trig");

ADOQuery1->ExecSQL();

}

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

void __fastcall TForm1::Button11Click(TObject *Sender)

{

ADOTable1->Active=false;

ADOTable1->Active=true;

ADOTable2->Active=false;

ADOTable2->Active=true;

}

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

void __fastcall TForm1::Button10Click(TObject *Sender)

{

ADOQuery1->Active=false;

ADOQuery1->SQL->Clear();

ADOQuery1->SQL->Add("UPDATE Obedinenie SET nazvanie_armii=:nd1 WHERE nazvanie_armii=:nd2");

ADOQuery1->Parameters->ParamByName("nd1")->Value=Edit3->Text;

ADOQuery1->Parameters->ParamByName("nd2")->Value=DBText1->Caption;

ADOQuery1->ExecSQL();

ADOTable1->Active=false;

ADOTable1->Active=true;

ADOTable2->Active=false;

ADOTable2->Active=true;

}

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

void __fastcall TForm1::Button12Click(TObject *Sender)

{

for(int i=1;i<=colcount;i++)

{

qrdbed[i]->DataSet=Form1->ADOTable1;

qrdbed[i]->DataField=ADOTable1->Fields->FieldByNumber(i)->FieldName;

qrlabl[i]->Caption=ADOTable1->Fields->FieldByNumber(i)->FieldName;

qrdbed[i]->Visible=true;

qrlabl[i]->Visible=true;

}

for(int i=colcount+1;i<=7;i++)

{

qrdbed[i]->Visible=false;

qrlabl[i]->Visible=false;

}

Form3->QRLabel13->Caption=Label4->Caption;

Form3->QuickRep1->Preview();

}

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

void __fastcall TForm1::Button13Click(TObject *Sender)

{

Form3->QuickRep1->Print();

}

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

void __fastcall TForm1::Button14Click(TObject *Sender)

{

TLocateOptions Opts;

Opts.Clear();

Opts<<loPartialKey<<loCaseInsensitive;

ADOTable1->Locate("Nomer_podrazdelenia",Edit2->Text,Opts);

}

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

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

UNIT2:

#include <vcl.h>

#pragma hdrstop

#include "Unit1.h"

#include "Unit2.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm2 *Form2;

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

__fastcall TForm2::TForm2(TComponent* Owner)

: TForm(Owner)

{

}

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

void __fastcall TForm2::Button2Click(TObject *Sender)

{

Form1->ADOTable1->Post();

Hide();

}

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

void __fastcall TForm2::Button1Click(TObject *Sender)

{

Hide();

}

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

9. Список литературы

1. "Базы данных: основы, проектирование, использование", М.П. Малыхина, СПб.: БХВ-Петербург, 2004. – 512 с.: ил.

2. "SQL Server 2000 Программирование", в 2 ч./Р. Вьейра: Часть I; Пер. с англ.; Под ред. С.М. Молявко. – М.: Бином. Лаборатория знаний, 2004. – 735 с., ил.