end;
if DM.qWork.RecordCount = 3 then
begin
DM.qWork.Next;
cbLanguage3.ItemIndex := cbLanguage3.Items.IndexOf(DM.qWork.FieldByName('Language').Text);
end;
DM.qWork.Close;
Strana := DM.tbCountryCountry.Text;
eCountry.Text := DM.tbCountryCountry.Text;
eCapital.Text := DM.tbCountryCapital.Text;
end;
procedure TfrmEditCountry.cbLanguage1Change(Sender: TObject);
begin
if (cbLanguage1.Text = cbLanguage2.Text) then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
if (cbLanguage1.Text = cbLanguage3.Text) then
begin
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmEditCountry.cbLanguage2Change(Sender: TObject);
begin
if (cbLanguage2.Text = cbLanguage1.Text) or (cbLanguage2.Text = cbLanguage3.Text) and (cbLanguage2.Text <> '--- íåò ---') then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmEditCountry.cbLanguage3Change(Sender: TObject);
begin
if (cbLanguage2.Text = '--- íåò ---') then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
if (cbLanguage3.Text = cbLanguage1.Text) or (cbLanguage2.Text = cbLanguage3.Text) and (cbLanguage3.Text <> '--- íåò ---') then
begin
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmEditCountry.bbOpenDialogClick(Sender: TObject);
begin
DM.odFlag.Execute;
if DM.odFlag.FileName <> '' then
try
DM.tbCountryFlag.LoadFromFile(DM.odFlag.FileName);
except
MessageDlg('Îøèáêà çàãðóçêè ôàéëà ñ ðèñóíêîì ôëàãà', mtError, [mbOk],0)
end;
end;
procedure TfrmEditCountry.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_Escape then frmEditCountry.Close;
end;
procedure TfrmEditCountry.bbCreateClick(Sender: TObject);
var Temp: LongInt;
var myStream: TMemoryStream;
begin
if eCountry.Text = '' then
begin
MessageDlg('Âû íå ââåëè íàçâàíèå ñòðàíû!', mtWarning, [mbOK], 0);
eCountry.SetFocus;
Exit;
end;
if eCapital.Text = '' then
begin
MessageDlg('Âû íå ââåëè íàçâàíèå ñòîëèöû!', mtWarning, [mbOK], 0);
eCapital.SetFocus;
Exit;
end;
DM.tbCountry.Filtered := False;
if eCountry.Text <> Strana then
if DM.tbCountry.Locate('Country',eCountry.Text,[loCaseInsensitive]) = True then
begin
MessageDlg('Còðàía '''+eCountry.Text+''' óæå ñóùåñòâóåò â Áàçå äàííûõ!', mtWarning, [mbOK], 0);
eCountry.Clear;
eCountry.SetFocus;
Exit;
end;
//ïîèñê êîíòèíåíòà
DM.tbKontinent.Locate('Kontinent', cbKontinent.Text, []);
DM.tbCountry.Locate('Country',Strana,[]);
//âíåñåíèå çàïèñåé â òàáëèöó ñòðàí
DM.tbCountry.Edit;
DM.tbCountryID_Kontinent.Value := DM.tbKontinentID.Value;
DM.tbCountryCountry.Value := eCountry.Text;
DM.tbCountryCapital.Value := eCapital.Text;
DM.tbCountry.Post;
//ïîèñê ïåðâîãî ÿçûêà è çàïèñü â ãëàâíóþ òàáëèöó
DM.tbLanguage.Locate('Language', cbLanguage1.Text, []);
DM.tbMain.Filter := 'ID_Country = '+DM.tbCountryID.Text;
DM.tbMain.Filtered := True;
DM.tbMain.First;
while DM.tbMain.RecordCount > 0 do DM.tbMain.Delete;
DM.tbMain.Filtered := False;
DM.tbMain.IndexFieldNames := 'ID';
DM.tbMain.Last;
Temp := DM.tbMainID.Value;
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 1;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
//ïîèñê âòîðîãî ÿçûêà è çàïèñü â ãëàâíóþ òàáëèöó
if cbLanguage2.Text <> '--- íåò ---' then
begin
DM.tbLanguage.Locate('Language', cbLanguage2.Text, []);
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 2;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
end;
//ïîèñê òðåòüåîãî ÿçûêà è çàïèñü â ãëàâíóþ òàáëèöó
if cbLanguage3.Text <> '--- íåò ---' then
begin
DM.tbLanguage.Locate('Language', cbLanguage3.Text, []);
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 3;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
end;
//âêëþ÷åíèå ïðèâÿçêè
DM.tbCountry.Filtered := True;
DM.tbCountry.Locate('Country',eCountry.Text,[]);
frmEditCountry.Close;
end;
end.
Приложение Г
Файл реализации модуля “NewCountry.pas”
unit NewCountry;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, ExtCtrls, Buttons, DBCtrls, DB;
type
TfrmNewCountry = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
imFlag: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
eCapital: TEdit;
memoInformation: TMemo;
cbLanguage1: TComboBox;
cbLanguage2: TComboBox;
cbLanguage3: TComboBox;
Label6: TLabel;
Label7: TLabel;
bbOpenDialog: TButton;
bbCreate: TBitBtn;
cbKontinent: TComboBox;
eCountry: TEdit;
procedure bbOpenDialogClick(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure cbLanguage1Change(Sender: TObject);
procedure cbLanguage2Change(Sender: TObject);
procedure cbLanguage3Change(Sender: TObject);
procedure bbCreateClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmNewCountry: TfrmNewCountry;
implementation
uses Module;
{$R *.DFM}
procedure TfrmNewCountry.bbOpenDialogClick(Sender: TObject);
begin
DM.odFlag.Execute;
if DM.odFlag.FileName <> '' thentry
imFlag.Picture.LoadFromFile(DM.odFlag.FileName);
except
MessageDlg('Îøèáêà çàãðóçêè ôàéëà ñ ðèñóíêîì ôëàãà', mtError, [mbOk],0)
end;
end;
procedure TfrmNewCountry.FormShow(Sender: TObject);
begin
cbKontinent.Clear;
cbLanguage1.Clear;
cbLanguage2.Clear;
cbLanguage3.Clear;
eCapital.Clear;
eCountry.Clear;
memoInformation.Clear;
imFlag.Picture.Bitmap.Canvas.FillRect(Rect(0,0,120,90));
DM.qWork.SQL.Clear;
DM.qWork.SQL.Add('Select Language from Language order by Language');
DM.qWork.Open;
cbLanguage2.Items.Add('--- íåò ---');
cbLanguage3.Items.Add('--- íåò ---');
DM.qWork.First;
while DM.qWork.Eof = False do
begin
cbLanguage1.Items.Add(DM.qWork.FieldByName('Language').Text);
cbLanguage2.Items.Add(DM.qWork.FieldByName('Language').Text);
cbLanguage3.Items.Add(DM.qWork.FieldByName('Language').Text);
DM.qWork.Next;
end;
DM.qWork.Close;
DM.qWork.SQL.Clear;
DM.qWork.SQL.Add('Select Kontinent from Kontinent order by Kontinent');
DM.qWork.Open;
DM.qWork.First;
while DM.qWork.Eof = False do
begin
cbKontinent.Items.Add(DM.qWork.FieldByName('Kontinent').Text);
DM.qWork.Next;
end;
DM.qWork.Close;
cbKontinent.ItemIndex := 0;
cbLanguage1.ItemIndex := 0;
cbLanguage2.ItemIndex := 0;
cbLanguage3.ItemIndex := 0;
end;
procedure TfrmNewCountry.cbLanguage1Change(Sender: TObject);
begin
if (cbLanguage1.Text = cbLanguage2.Text) then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
if (cbLanguage1.Text = cbLanguage3.Text) then
begin
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmNewCountry.cbLanguage2Change(Sender: TObject);
begin
if (cbLanguage2.Text = cbLanguage1.Text) or (cbLanguage2.Text = cbLanguage3.Text) and (cbLanguage2.Text <> '--- íåò ---') then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmNewCountry.cbLanguage3Change(Sender: TObject);
begin
if (cbLanguage2.Text = '--- íåò ---') then
begin
cbLanguage2.ItemIndex := cbLanguage3.ItemIndex;
cbLanguage3.ItemIndex := 0;
end;
if (cbLanguage3.Text = cbLanguage1.Text) or (cbLanguage2.Text = cbLanguage3.Text) and (cbLanguage3.Text <> '--- íåò ---') then
begin
cbLanguage3.ItemIndex := 0;
end;
end;
procedure TfrmNewCountry.bbCreateClick(Sender: TObject);
var Temp: LongInt;
var myStream: TMemoryStream;
begin
if eCountry.Text = '' then
begin
MessageDlg('Âû íå ââåëè íàçâàíèå ñòðàíû!', mtWarning, [mbOK], 0);
eCountry.SetFocus;
Exit;
end;
if eCapital.Text = '' then
begin
MessageDlg('Âû íå ââåëè íàçâàíèå ñòîëèöû!', mtWarning, [mbOK], 0);
eCapital.SetFocus;
Exit;
end;
if DM.tbCountry.Locate('Country',eCountry.Text,[loCaseInsensitive]) = True then
begin
MessageDlg('Còðàía '''+eCountry.Text+''' óæå ñóùåñòâóåò â Áàçå äàííûõ!', mtWarning, [mbOK], 0);
eCountry.Clear;
eCountry.SetFocus;
Exit;
end;
//îòêëþ÷åíèå ïðèâÿçêè
DM.tbCountry.Filtered := False;
//ïîèñê êîíòèíåíòà
DM.tbKontinent.Locate('Kontinent', cbKontinent.Text, []);
//ñîçäàíèå Èäåíòèôèêàöèîííîãî íàìåðà
DM.tbCountry.IndexFieldNames := 'ID';
DM.tbCountry.Last;
Temp := DM.tbCountryID.Value;
//âíåñåíèå çàïèñåé â òàáëèöó ñòðàí
DM.tbCountry.Insert;
DM.tbCountryID.Value := Temp+1;
DM.tbCountryID_Kontinent.Value := DM.tbKontinentID.Value;
DM.tbCountryCountry.Value := eCountry.Text;
DM.tbCountryCapital.Value := eCapital.Text;
myStream := TMemoryStream.Create;
memoInformation.Lines.SaveToStream(myStream);
DM.tbCountryInformation.LoadFromStream(myStream);
myStream.Clear;
imFlag.Picture.Bitmap.SaveToStream(myStream);
// imFlag.Picture.SaveToFile('temp.bmp');
// DM.tbCountryFlag.LoadFromFile('temp.bmp');
DM.tbCountryFlag.LoadFromStream(myStream);
myStream.Destroy;
DM.tbCountry.Post;
//ïîèñê ïåðâîãî ÿçûêà è çàïèñü â ãëàâíóþ òàáëèöó
DM.tbLanguage.Locate('Language', cbLanguage1.Text, []);
DM.tbMain.IndexFieldNames := 'ID';
DM.tbMain.Last;
Temp := DM.tbMainID.Value;
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 1;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
if cbLanguage2.Text <> '--- íåò ---' then
begin
DM.tbLanguage.Locate('Language', cbLanguage2.Text, []);
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 2;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
end;
if cbLanguage3.Text <> '--- íåò ---' then
begin
DM.tbLanguage.Locate('Language', cbLanguage3.Text, []);
DM.tbMain.Insert;
DM.tbMainID.Value := Temp + 3;
DM.tbMainID_Country.Value := DM.tbCountryID.Value;
DM.tbMainID_Language.Value := DM.tbLanguageID.Value;
DM.tbMain.Post;
end;
DM.tbCountry.Filtered := True;
frmNewCountry.Close;
end;
procedure TfrmNewCountry.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if key = vk_Escape then frmNewCountry.Close;
end;
end.
Приложение Д
Файл реализации модуля “NewLanguage.pas”
unit NewLanguage;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, DB;
type
TfrmNewLanguage = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
eLanguage: TEdit;
bbCreate: TBitBtn;
procedure bbCreateClick(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmNewLanguage: TfrmNewLanguage;
implementation
uses Module;
{$R *.DFM}
procedure TfrmNewLanguage.bbCreateClick(Sender: TObject);
var Temp: LongInt;
begin
if eLanguage.Text <> '' then
if DM.tbLanguage.Locate('Language', eLanguage.Text, [loCaseInsensitive]) = False then
begin
DM.tbLanguage.IndexFieldNames := 'ID';
DM.tbLanguage.Last;
Temp := DM.tbLanguageID.Value;
DM.tbLanguage.Insert;
DM.tbLanguageID.Value := Temp + 1;
DM.tbLanguageLanguage.Value := eLanguage.Text;
DM.tbLanguage.Post;
MessageDlg('ßçûê '''+eLanguage.Text+''' ñîçäàí',mtInformation,[mbOk],0);
frmNewLanguage.Close;