double arrow

Листинг кода лаборат. работ №3,4.

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

 

#include <vcl.h>

#pragma hdrstop

 

#include "Unit1.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

void KolichStud()

{ Form1->Label11->Caption="Всего студентов "+

IntToStr(Form1->tSpisok->RecordCount);

}

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

boolean Proverka1(AnsiString sp,AnsiString sr)

{int gr,gp; AnsiString s;

s=Trim(sp);

if (s.Length()==0)

{ShowMessage("Не заполнено поле <Год поступления>");

return false;}

 

gp=StrToInt(s);

if ((gp>2010)||(gp<1990)||(gp==0))

{ShowMessage("Нереальный год поступления"+IntToStr(gp));

return false;}

 

s=Trim(sr);

if (s.Length()==0)

{ShowMessage("Не заполнено поле <Год рождения>");

return false;}

 

gp=StrToInt(s);

if ((gp>=1995)||(gp<1950)||(gp==0))

{ShowMessage("Нереальный год рождения"+IntToStr(gp));

return false;}

 

return true;

}

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

void __fastcall TForm1::FormCreate(TObject *Sender)

{

tSpisok->Open();

KolichStud();

}

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

void __fastcall TForm1::bCloseClick(TObject *Sender)

{

Close();

}

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

 

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)

{ switch (RadioGroup1->ItemIndex)

{ case 0:{tSpisok->IndexName="";break;}

case 1:tSpisok->IndexName="indSpisokFIO";break;

case 2:tSpisok->IndexName="indSpisokGodPost";break;

case 3:tSpisok->IndexName="indSpisokGodRoj";break;

case 4:tSpisok->IndexName="indSpisokSredBall";break;

case 5:tSpisok->IndexName="indSpisokSpec";break;

}//конец switch

 

}

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

 

void __fastcall TForm1::Button1Click(TObject *Sender)

{

int NewShifr;

Panel1->Show();Panel2->Hide();

tSpisok->IndexName="";//устанавливаем главный индекс, чтобы получить значение наибольшего шифра

tSpisok->Last();//наибольший шифр в последней записи

NewShifr=tSpisok->FieldByName("Shifr")->AsInteger+1;

Edit1->Text=IntToStr(NewShifr);//записали новый уникальный шифр в Edit1

// очищаем остальные окна ввода

Edit2->Text="";Edit3->Text="0";Edit4->Text="0";

tSpisok->Insert();

 

}

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

 

void __fastcall TForm1::Button2Click(TObject *Sender)

{

{ Panel1->Hide();Panel2->Show();

tSpisok->Edit();

Edit5->Text=tSpisok->FieldByName("Shifr")->AsString;

Edit6->Text=tSpisok->FieldByName("FIO")->AsString;

Edit7->Text=tSpisok->FieldByName("GodPost")->AsString;

Edit8->Text=tSpisok->FieldByName("GodRoj")->AsString;

}

}

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

 

 

void __fastcall TForm1::Button5Click(TObject *Sender)

{

tSpisok->Cancel();

}

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

 

void __fastcall TForm1::Button7Click(TObject *Sender)

{

tSpisok->Cancel();

}

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

 

void __fastcall TForm1::Button4Click(TObject *Sender)

{

tSpisok->FieldByName("Shifr")->AsString=Edit1->Text;

tSpisok->FieldByName("FIO")->AsString= Edit2->Text;

tSpisok->FieldByName("GodPost")->AsString= Edit3->Text;

tSpisok->FieldByName("GodRoj")->AsString= Edit4->Text;

tSpisok->Post();

KolichStud();

 

 

}

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

 

void __fastcall TForm1::Button6Click(TObject *Sender)

{

tSpisok->FieldByName("Shifr")->AsString=Edit5->Text;

tSpisok->FieldByName("FIO")->AsString= Edit6->Text;

tSpisok->FieldByName("GodPost")->AsString= Edit7->Text;

tSpisok->FieldByName("GodRoj")->AsString= Edit8->Text;

tSpisok->Post();

 

}

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

 

void __fastcall TForm1::Button3Click(TObject *Sender)

{

if (MessageDlg("Подтвердите удаление записи\n "+tSpisok->FieldByName("FIO")->AsString,

mtConfirmation, TMsgDlgButtons()<< mbYes<< mbNo,0)==mrYes)

{ tSpisok->Delete();Beep();}

KolichStud();

 

}

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

 

void __fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit4KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit7KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit8KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

Лабораторная работа №5

 

Внешний вид формы программы:

Листинг кода:

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

 

#include <vcl.h>

#pragma hdrstop

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

USEFORM("Unit1.cpp", Form1);

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

WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)

{

try

{

Application->Initialize();

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

Application->Run();

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

catch (...)

{

try

{

throw Exception("");

}

catch (Exception &exception)

{

Application->ShowException(&exception);

}

}

return 0;

}

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

 

Лабораторная работа №6,7

 

Внешний вид формы программы:

Листинг кода:

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

 

#include <vcl.h>

#pragma hdrstop

 

#include "Unit1.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

TForm1 *Form1;

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

void KolichStud()

{ Form1->Label11->Caption="Всего студентов "+

IntToStr(Form1->tSpisok->RecordCount);

}

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

boolean Proverka1(AnsiString sp,AnsiString sr)

{int gr,gp; AnsiString s;

s=Trim(sp);

if (s.Length()==0)

{ShowMessage("Не заполнено поле <Год поступления>");

return false;}

 

gp=StrToInt(s);

if ((gp>2010)||(gp<1990)||(gp==0))

{ShowMessage("Нереальный год поступления"+IntToStr(gp));

return false;}

 

s=Trim(sr);

if (s.Length()==0)

{ShowMessage("Не заполнено поле <Год рождения>");

return false;}

 

gp=StrToInt(s);

if ((gp>=1995)||(gp<1950)||(gp==0))

{ShowMessage("Нереальный год рождения"+IntToStr(gp));

return false;}

 

return true;

}

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

void __fastcall TForm1::FormCreate(TObject *Sender)

{

tSpisok->Open();

KolichStud();

}

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

void __fastcall TForm1::bCloseClick(TObject *Sender)

{

Close();

}

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

 

void __fastcall TForm1::RadioGroup1Click(TObject *Sender)

{ switch (RadioGroup1->ItemIndex)

{ case 0:{tSpisok->IndexName="";break;}

case 1:tSpisok->IndexName="indSpisokFIO";break;

case 2:tSpisok->IndexName="indSpisokGodPost";break;

case 3:tSpisok->IndexName="indSpisokGodRoj";break;

case 4:tSpisok->IndexName="indSpisokSredBall";break;

case 5:tSpisok->IndexName="indSpisokSpec";break;

}//конец switch

 

}

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

 

void __fastcall TForm1::Button1Click(TObject *Sender)

{

int NewShifr;

Panel1->Show();Panel2->Hide();

tSpisok->IndexName="";//устанавливаем главный индекс, чтобы получить значение //наибольшего шифра

tSpisok->Last();//наибольший шифр в последней записи

NewShifr=tSpisok->FieldByName("Shifr")->AsInteger+1;

Edit1->Text=IntToStr(NewShifr);//записали новый уникальный шифр в Edit1

// очищаем остальные окна ввода

Edit2->Text="";Edit3->Text="0";Edit4->Text="0";

tSpisok->Insert();

 

}

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

 

void __fastcall TForm1::Button2Click(TObject *Sender)

{

{ Panel1->Hide();Panel2->Show();

tSpisok->Edit();

Edit5->Text=tSpisok->FieldByName("Shifr")->AsString;

Edit6->Text=tSpisok->FieldByName("FIO")->AsString;

Edit7->Text=tSpisok->FieldByName("GodPost")->AsString;

Edit8->Text=tSpisok->FieldByName("GodRoj")->AsString;

}

}

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

 

 

void __fastcall TForm1::Button5Click(TObject *Sender)

{

tSpisok->Cancel();

}

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

 

void __fastcall TForm1::Button7Click(TObject *Sender)

{

tSpisok->Cancel();

}

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

 

void __fastcall TForm1::Button4Click(TObject *Sender)

{

tSpisok->FieldByName("Shifr")->AsString=Edit1->Text;

tSpisok->FieldByName("FIO")->AsString= Edit2->Text;

tSpisok->FieldByName("GodPost")->AsString= Edit3->Text;

tSpisok->FieldByName("GodRoj")->AsString= Edit4->Text;

tSpisok->Post();

KolichStud();

 

 

}

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

 

void __fastcall TForm1::Button6Click(TObject *Sender)

{

tSpisok->FieldByName("Shifr")->AsString=Edit5->Text;

tSpisok->FieldByName("FIO")->AsString= Edit6->Text;

tSpisok->FieldByName("GodPost")->AsString= Edit7->Text;

tSpisok->FieldByName("GodRoj")->AsString= Edit8->Text;

tSpisok->Post();

 

}

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

 

void __fastcall TForm1::Button3Click(TObject *Sender)

{

if (MessageDlg("Подтвердите удаление записи\n "+tSpisok->FieldByName("FIO")->AsString,

mtConfirmation, TMsgDlgButtons()<< mbYes<< mbNo,0)==mrYes)

{ tSpisok->Delete();Beep();}

KolichStud();

 

}

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

 

void __fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit4KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit7KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

void __fastcall TForm1::Edit8KeyPress(TObject *Sender, char &Key)

{

if (((Key>='0')&&(Key<='9'))||(Key==8)) return;

else Key=0;

 

}

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

 

Лабораторная работа №8

 

Внешний вид формы программы:

Листинг кода:

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

 

#include <vcl.h>

#pragma hdrstop

 

#include "Unit1.h"

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

#pragma package(smart_init)

#pragma resource "*.dfm"

AnsiString ModeTSyn;

TForm1 *Form1;

void ShowKol()

{Form1->lKol->Caption="Всего фото "+IntToStr(Form1->tVid->RecordCount);

 

}

void ShowButtons()

{Form1->bDob->Show();Form1->bZam->Show();Form1->bUd->Show();Form1->bP->Show();

 

}

void HideButtons()

{Form1->bDob->Hide();Form1->bZam->Hide();Form1->bUd->Hide();Form1->bP->Hide();

 

}

 

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

__fastcall TForm1::TForm1(TComponent* Owner)

: TForm(Owner)

{

}

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

 

void __fastcall TForm1::FormCreate(TObject *Sender)

{

tVid->Open(); ShowKol();

}

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

 

void __fastcall TForm1::FormActivate(TObject *Sender)

{

Image1->Hide(); tVid->IndexName="indVidNaim";

}

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

 

void __fastcall TForm1::bExitClick(TObject *Sender)

{

Close();

}

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

 

void __fastcall TForm1::bDobClick(TObject *Sender)

{

AnsiString s;

HideButtons();

if (OpenPictureDialog1->Execute())

{ s=OpenPictureDialog1->FileName;

Image1->Picture->LoadFromFile(s);

//можно и так: Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);

tVid->Insert();

tVid->FieldByName("Photo")->Assign(Image1->Picture);

tVid->FieldByName("Naim")->AsString=s;

tVid->FieldByName("Path")->AsString=s;

tVid->Post();

ShowKol();

}// конец if

ShowButtons();

 

}

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

 

void __fastcall TForm1::bZamClick(TObject *Sender)

{

AnsiString s; int n;

s="Уточните действие:\nЗаменить только изображение, сохранив надписи (Yes)";

s=s+"\nЗаменить все элементы (All) ";

HideButtons();

 

if (OpenPictureDialog1->Execute())

{ tVid->Edit();

Image1->Picture->LoadFromFile(OpenPictureDialog1->FileName);

 

n=MessageDlgPos(s,

mtConfirmation, TMsgDlgButtons()<< mbYes<< mbAll<<mbCancel,0,300,400);

switch (n)

{case 6:{tVid->FieldByName("Photo")->Assign(Image1->Picture);//Yes

tVid->Post();

break;}

case 8:{tVid->FieldByName("Photo")->Assign(Image1->Picture);//All

tVid->FieldByName("Naim")->AsString=OpenPictureDialog1->FileName;

tVid->FieldByName("Path")->AsString=OpenPictureDialog1->FileName;

tVid->Post();

break;}

case 2:{ tVid->Cancel();break;}//Cancel

}

}

ShowButtons();

 

}

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

 

void __fastcall TForm1::bUdClick(TObject *Sender)

{

HideButtons();

if (MessageDlgPos("Подтвердите удаление фото "+

tVid->FieldByName("Naim")->AsString,

mtConfirmation, TMsgDlgButtons()<< mbYes<< mbNo,0,350,400)==mrYes)

{tVid->Delete();ShowKol();

}

ShowButtons();

 

}

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

 

void __fastcall TForm1::bPClick(TObject *Sender)

{

if (lP->Visible==true)

{lP->Visible=false;DBText1->Visible=false;

bP->Caption="Показать путь";

}

else {lP->Visible=true;DBText1->Visible=true;

bP->Caption="Спрятать путь";

}

 

}

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

 

 


Понравилась статья? Добавь ее в закладку (CTRL+D) и не забудь поделиться с друзьями:  



Сейчас читают про: