2.2 Algoritm asosida bajarilgan ishlar
C++ Builder 6 dasturini ishga tushirib yangi proyekt yaratib olamiz va dasturni
yaratish paytida kerak bo’ladigan kompanentalarni tashlab olamiz. ADO
komponentlar to‘plamiga tegishli bo‘lgan ADOConnection, ADOTable va
DataAccess komponentlar to‘plamiga tegishli bo‘lgan DataSource
komponentlaridan foydalanamiz.
16
2.6-rasm. Dasturning ishlagandagi ko’rinishi
Shundan so’ng F9 tugmasini bossak bizga yuqoridagidagi oyna ochiladi. Xavfsizlik
tizimini quyidagi kodlar orqali amalga oshirganman
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn2Click(TObject *Sender)
{
Close();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn1Click(TObject *Sender)
17
{
if (Edit1->Text=="Admin" && Edit2->Text==123456) { Form1->Hide();
Form2->ShowModal();
} else {ShowMessage("Login yoki Parol xato kiritilgan");}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Help1Click(TObject *Sender)
{
ShowMessage("Login yoki Parolni bilmasangiz kirmaganiz maqul bu
yerdagi ma'lumotlar sir saqlanadi");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::BitBtn3Click(TObject *Sender)
{
Form2->Show();
}
18
2.7-rasm.Dasturning ishlagandagi ko’rinishi
2.8-rasm. Dasturning malumotlarni kiritish oynasi
Bu oyna orqli abituriyentlar jadvaliga malumot qo’shish, o’zgartirish mumkin.
Buning uchun qo’shish tugmasining ichiga quyidagicha kodlarni yozganman (2.8-
rasm)
fastcall TForm4::TForm4(TComponent* Owner)
: TForm(Owner)
19
{
}
//---------------------------------------------------------------------------
void __fastcall TForm4::BitBtn1Click(TObject *Sender)
{ ADOnom->Post();
}
void __fastcall TForm4::FormActivate(TObject *Sender)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm4::BitBtn3Click(TObject *Sender)
{
ADODori->Post();
Form4->DBEdit1->Text="";
Form4->DBEdit2->Text="";
Form4->DBEdit3->Text="";
Form4->DBEdit4->Text="";}
//---------------------------------------------------------------------------
void __fastcall TForm4::ComboBox1Click(TObject *Sender)
20
{
}
2.8-rasm. Dasturning malumotlarini tahrirlash oynasi
Dasturning ma’lumotlarini tahrirlash bu yerda biz xato kiritgan ma’lumotlarni
o’zgartirish imkonyatlariga ega bo’lamiz.Uning saqlash tugmachasi ichiga quyidagi
kodlarni yozganman
Form6->Show();
tahrir=dm->ADOQdori->FieldByName("N")->AsString;
Form6->Caption="Tahrirlash";
Form6->Edit1->Text=dm->ADOQdori->FieldByName("Nomi")->AsString;
Form6->Edit2->Text=dm->ADOQdori->FieldByName("Soni")->AsString;
Form6->Edit3->Text=dm->ADOQdori->FieldByName("Narxi")->AsString;
Form6->Edit4->Text=dm->ADOQdori->FieldByName("Sana")->AsString;
21
}
2.9-rasm. Dasturning malumotlarini qidirish oynasi
void __fastcall TForm7::BitBtn1Click(TObject *Sender)
{ AnsiString a;
a=Edit1->Text;
dm->ADOQdori->Active=0;
dm->ADOQdori->SQL->Clear();
if (Edit1->Text==" ") {
dm->ADOQdori->SQL->Add("select *From Dori");
}
else {
dm->ADOQdori->SQL->Add("select *From Dori where Nomi like '%"+Edit1-
>Text+"%' or Soni like '%"+Edit1->Text+"%' or Narxi like '%"+Edit1->Text+"%'
or Sana like '%"+Edit1->Text+"%'");
}
22
dm->ADOQdori->ExecSQL();
dm->ADOQdori->Active=1;
}
2.10-rasm. Dasturning malumotlarini o’chirish oynasi
AnsiString tr;
tr=dm->ADOQdori->FieldByName("N")->AsString;
switch (MessageDlg("O'chirilsinmi?",mtWarning,mbYesNo,0)) {
case mrYes: dm->ADOQdori->Active=0;
dm->ADOQdori->SQL->Clear();
dm->ADOQdori->SQL->Add("delete from Dori where N="+tr) ;
dm->ADOQdori->ExecSQL();
dm->ADOQdori->SQL->Clear();
dm->ADOQdori->SQL->Add("select *from Dori");
dm->ADOQdori->Active=1;
mrNo:
default:;}
23
C++Builder bоsh хususiyati аvvаlаm bоr uning dаsturni vizuаl ishlаsh jаrаyonidа
nаfаqаt tаyyor kоmpоnеntаlаrdаn fоydаlаnish, bаlki yangi kоmpоnеntаlаrni yarаtish
qоbiliyatidа hаm nаmоyon bo‘lаdi. Yangi kоmpоnеntаlаr, dаstlаbki kоmpоnеntаlаr
kаbi, sоddаbo‘lishi mumkin, bundа ulаrning funktsiоnаl imkоniyatlаri sаl-pаl
kеngаytirilgаn yoki o‘zining mutlаqо o‘zigахоs ko‘rinishi, хulq-аtvоri vа kоdining
mаzmuni bilаn fаrqlаnаdigаn bo‘lаdi.
Do'stlaringiz bilan baham: |