Смекни!
smekni.com

Разработка базы данных и прикладного программного обеспечения для автобусного парка (стр. 3 из 3)

begin

if EditFlag then

begin

Caption := 'Edit station';

ledName.Text := fmMain.DBGridStations.DataSource.DataSet.Fields[1].AsString;

lcmbbxRoute.KeyValue := fmMain.DBGridStations.DataSource.DataSet.Fields[2].AsInteger;

end

else

begin

Caption := 'Add station';

ledName.Clear;

lcmbbxRoute.KeyValue := 1;

end;

end;

procedure TfmStations.btnCancelClick(Sender: TObject);

begin

close;

end;

procedure TfmStations.btnOKClick(Sender: TObject);

begin

if (ledName.Text <> '') and (lcmbbxRoute.Text <> '') then

begin

if EditFlag then

begin

fmMain.ADOCommand.CommandText := 'UPDATE stations SET name=''' + ledName.Text

+ ''', routeid=' + IntToStr(lcmbbxRoute.KeyValue) + ' WHERE id=' +

fmMain.DBGridStations.DataSource.DataSet.Fields[0].AsString;

fmMain.ADOQueryStopPoints.Requery;

end

else

begin

fmMain.ADOCommand.CommandText := 'INSERT INTO stations (name, routeid) VALUES (''' + ledName.Text + ''', ' + IntToStr(lcmbbxRoute.KeyValue) + ')';

end;

fmMain.ADOCommand.Execute;

fmMain.ADOQueryStations.Requery;

close;

end

else

ShowMessage('Incorrect parameters!');

end;

end.

добавление/редактирование остановочных пунктов

private

{ Private declarations }

public

{ Public declarations }

EditFlag: boolean;

end;

var

fmStopPoints: TfmStopPoints;

implementation

uses uMain;

{$R *.dfm}

procedure TfmStopPoints.btnCancelClick(Sender: TObject);

begin

Close;

end;

procedure TfmStopPoints.FormShow(Sender: TObject);

begin

if EditFlag then

begin

Caption := 'Edit stop point';

with fmMain.DBGridStopPoints.DataSource.DataSet do

begin

ADOQueryRoutes.SQL.Text := 'SELECT * FROM routes WHERE id = ' +

'ANY (SELECT routeid FROM stations WHERE id = ' +

Fields[3].AsString + ')';

ADOQueryRoutes.Active := true;

ADOQueryRoutes.Requery;

ledName.Text := Fields[1].AsString;

lcmbbxRoute.KeyValue := dtsrcRoutes.DataSet.Fields[0].AsInteger;

lcmbbxStation.KeyValue := Fields[3].AsInteger;

if Fields[2].AsString = 'forward' then cmbbxDirection.ItemIndex := 0 else

cmbbxDirection.ItemIndex := 1;

end;

end

else

begin

Caption := 'Add stop point';

ledName.Clear;

lcmbbxStation.KeyValue := 1;

ADOQueryRoutes.SQL.Text := 'SELECT * FROM routes WHERE id = ' +

'ANY (SELECT routeid FROM stations WHERE id = 1)';

ADOQueryRoutes.Active := true;

ADOQueryRoutes.Requery;

end;

end;

procedure TfmStopPoints.lcmbbxStationCloseUp(Sender: TObject);

begin

ADOQueryRoutes.SQL.Text := 'SELECT * FROM routes WHERE id = ' +

'ANY (SELECT routeid FROM stations WHERE stations.id = ' +

IntToStr(lcmbbxStation.KeyValue) + ')';

ADOQueryRoutes.Open;

ADOQueryRoutes.Requery;

lcmbbxRoute.DropDown;

end;

procedure TfmStopPoints.btnOKClick(Sender: TObject);

begin

if (ledName.Text <> '') and (lcmbbxRoute.Text <> '') and (lcmbbxStation.Text <> '') then

begin

if EditFlag then

begin

fmMain.ADOCommand.CommandText := 'UPDATE stoppoints SET name=''' + ledName.Text

+ ''', routeid=' + IntToStr(lcmbbxRoute.KeyValue) + ', direction=''' +

cmbbxDirection.Text + ''', stationid=' + IntToStr(lcmbbxStation.KeyValue)

+ ' WHERE id=' + fmMain.DBGridStopPoints.DataSource.DataSet.Fields[0].AsString;

end

else

begin

fmMain.ADOCommand.CommandText :=

'INSERT INTO stoppoints (name, direction, stationid, routeid) VALUES ('''

+ ledName.Text + ''', ''' + cmbbxDirection.Text + ''', ' +

IntToStr(lcmbbxStation.KeyValue) + ', ' + IntToStr(lcmbbxRoute.KeyValue) + ')';

end;

fmMain.ADOCommand.Execute;

fmMain.ADOQueryStopPoints.Requery;

close;

end

else

ShowMessage('Incorrect parameters!');

end;

end.