КАТЕГОРИИ:
АстрономияБиологияГеографияДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРиторикаСоциологияСпортСтроительствоТехнологияФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника
|
Боулби Джонunit Unit14;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, DBCtrls, DB, ADODB, Grids, DBGrids, StdCtrls, Mask, jpeg;
type TForm14 = class(TForm) DBGrid1: TDBGrid; DataSource1: TDataSource; ADOConnection1: TADOConnection; DBNavigator1: TDBNavigator; Button1: TButton; Button2: TButton; DBEdit1: TDBEdit; DBEdit2: TDBEdit; Label1: TLabel; Label2: TLabel; ADOTable1: TADOTable; DBGrid2: TDBGrid; ADODataSet1: TADODataSet; DataSource2: TDataSource; DBNavigator2: TDBNavigator; Button3: TButton; Button4: TButton; Label3: TLabel; Label4: TLabel; DBEdit3: TDBEdit; DBEdit4: TDBEdit; Image1: TImage; DBEdit5: TDBEdit; DBEdit6: TDBEdit; DBEdit7: TDBEdit; Label5: TLabel; Label6: TLabel; Label7: TLabel; procedure ADOConnection1BeforeConnect(Sender: TObject); procedure FormActivate(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure Button2Click(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form14: TForm14;
implementation
uses FindForm,FindForm2, StrUtils, IniFiles;
{$R *.dfm}
// процедура подключения базы через ini файл procedure TForm14.ADOConnection1BeforeConnect(Sender: TObject); var p1,p2:integer; IniFile: TIniFile; aPath:string; fn:string; st:string; begin p1:=Pos('.exe', Application.ExeName);
fn:=Copy(Application.ExeName, 1, p1-1) + '.ini'; IniFile:=TIniFile.Create(fn);
aPath := IniFile.ReadString('data','aPath','');
if aPath = ' ' then MessageDlg('Нет файла: '+ fn ,mtError, [mbOk],0);
st:=ADOConnection1.ConnectionString; p1:=Pos('Data Source', st); p2:=PosEx(';',st,p1); Delete (st,p1,p2-p1); Insert ('Data Source='+ aPath + 'kurs.mdb',st,p1); ADOConnection1.ConnectionString:=st; end;
// кнопка Все рейсы procedure TForm14.Button1Click(Sender: TObject); begin ADODataSet1.Close; ADODataSet1.CommandText:= 'select * from Билеты'; ADODataSet1.Open; ADOTable1.Close; ADOTable1.TableName:= 'Пассажиры'; ADOTable1.Open; end;
// кнопка Найти рейс procedure TForm14.Button2Click(Sender: TObject); begin Form1.ShowModal; if Form1.ModalResult = mrOk then
begin ADODataSet1.Close; ADODataSet1.CommandText:='select * from Билеты WHERE '+'pribitiya Like''%'+Form1.Edit1.Text+'%'''; ADODataSet1.Open; ADOTable1.Close; ADOTable1.TableName:= 'Пассажиры'; ADOTable1.Open; ADODataSet1.Filtered:=True; end; if ADODataSet1.RecordCount = 0 then begin ADODataSet1.Filtered:=False; ShowMessage ('Нет такого рейса'); end;
end;
// кнопка Закрыть procedure TForm14.Button3Click(Sender: TObject); begin Close; end;
// кнопка Найти по цене procedure TForm14.Button4Click(Sender: TObject); begin Form2.ShowModal; if Form2.ModalResult = mrOk then
begin ADODataSet1.Close; ADODataSet1.CommandText:='select * from Билеты WHERE '+'money Like''%'+Form2.Edit1.Text+'%'''; ADODataSet1.Open; ADOTable1.Close; ADOTable1.TableName:= 'Пассажиры'; ADOTable1.Open; ADODataSet1.Filtered:=True; end; if ADODataSet1.RecordCount = 0 then begin ADODataSet1.Filtered:=False; ShowMessage ('Нет рейса по такой стоимости'); end; end;
// процедура активации базы procedure TForm14.FormActivate(Sender: TObject); begin try ADOTable1.Active:=True; ADOConnection1.Open; ADODataSet1.Active:=True; except on e:Exception do begin DBGrid1.Enabled:=False; MessageDlg('Ошибка доступа к файлу',mtError,[mbOk],0); end; end; end;
// процедура закрытия формы procedure TForm14.FormClose(Sender: TObject; var Action: TCloseAction); begin if DBGrid1.EditorMode then begin ADODataSet1.UpdateBatch(arCurrent); end; end;
end. unit FindForm;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm1 = class(TForm) Edit1: TEdit; Button1: TButton; Label1: TLabel; procedure FormActivate(Sender: TObject); procedure Edit1Change(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); //procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form1: TForm1;
implementation
{$R *.dfm}
{procedure TForm1.Button1Click(Sender: TObject); begin Close; end;}
procedure TForm1.Edit1Change(Sender: TObject); begin if Length(Edit1.Text) > 0 then Button1.Enabled:=True else Button1.Enabled:=False; end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key = #13) and (Length(Edit1.Text) > 0) then Button1.SetFocus; end;
procedure TForm1.FormActivate(Sender: TObject); begin Edit1.Clear; Edit1.SetFocus; end;
end. unit FindForm2;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
type TForm2 = class(TForm) Button1: TButton; Edit1: TEdit; Label1: TLabel; procedure Edit1Change(Sender: TObject); procedure Edit1KeyPress(Sender: TObject; var Key: Char); procedure FormActivate(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Edit1Change(Sender: TObject); begin if Length(Edit1.Text) > 0 then Button1.Enabled:=True else Button1.Enabled:=False; end;
procedure TForm2.Edit1KeyPress(Sender: TObject; var Key: Char); begin if (Key = #13) and (Length(Edit1.Text) > 0) then Button1.SetFocus; end;
procedure TForm2.FormActivate(Sender: TObject); begin Edit1.Clear; Edit1.SetFocus; end;
end. Боулби Джон
|