Хранимые процедуры

{codecitation class=»brush: pascal; gutter: false;» width=»600px»}

Оформил: DeeCo

procedure TForm1.BGetClick(Sender: TObject);

begin

with ProcGetInf do

begin

ParamByName(‘pFam’).AsString := FamEdit.Text;

ParamByName(‘pNam’).AsString := NamEdit.Text;

ParamByName(‘pPar’).AsString := ParEdit.Text;

ExecProc;

if ParamByName(‘pYear’).AsInteger = 0 then

MessageDlg(‘В базе данных запись отсутствует’, mtError, [mbCancel], 0)

else

begin

SYear.Value := ParamByName(‘pYear’).AsInteger;

CBDep.Text := ParamByName(‘pDep’).AsString;

if ParamByName(‘pSex’).AsString = ‘м’ then

RGSex.ItemIndex := 0

else

RGSex.ItemIndex := 1;

end;

end;

end;

Полный текст модуля:

unit UStoreP;

interface

uses

SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,

Forms, Dialogs, DBTables, DB, Grids, DBGrids, StdCtrls, Spin, ExtCtrls;

type

TForm1 = class(TForm)

Database1: TDatabase;

DataSource1: TDataSource;

ResLabel: TLabel;

ProcGetInf: TStoredProc;

ProcSetInf: TStoredProc;

Table1: TTable;

Query1: TQuery;

DataSource2: TDataSource;

Query1PFAM: TStringField;

Query1PNAM: TStringField;

Query1PPAR: TStringField;

Query1PYEAR: TIntegerField;

Query1PSEX: TStringField;

PTop: TPanel;

LFam: TLabel;

LNam: TLabel;

LPar: TLabel;

FamEdit: TEdit;

BGet: TButton;

BSet: TButton;

LSex: TLabel;

LYear: TLabel;

LDep: TLabel;

SYear: TSpinEdit;

RGSex: TRadioGroup;

BExit: TButton;

CBDep: TComboBox;

NamEdit: TEdit;

ParEdit: TEdit;

PMid: TPanel;

DBGrid2: TDBGrid;

CBDep2: TComboBox;

Label1: TLabel;

PButtom: TPanel;

DBGrid1: TDBGrid;

Titul1: TLabel;

Titul2: TLabel;

Titul3: TLabel;

Table1NUM: TSmallintField;

Table1DEP: TStringField;

Table1FAM: TStringField;

Table1NAM: TStringField;

Table1PAR: TStringField;

Table1YEAR_B: TSmallintField;

Table1SEX: TStringField;

procedure BGetClick(Sender: TObject);

procedure FamEditEnter(Sender: TObject);

procedure BSetClick(Sender: TObject);

procedure BExitClick(Sender: TObject);

procedure FormCreate(Sender: TObject);

procedure CBDep2Change(Sender: TObject);

private

{ Private declarations }

public

{ Public declarations }

end;

var

Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.BGetClick(Sender: TObject);

begin

with ProcGetInf do

begin

ParamByName(‘pFam’).AsString := FamEdit.Text;

ParamByName(‘pNam’).AsString := NamEdit.Text;

ParamByName(‘pPar’).AsString := ParEdit.Text;

ExecProc;

if ParamByName(‘pYear’).AsInteger = 0 then

MessageDlg(‘В базе данных запись отсутствует’, mtError, [mbCancel], 0)

else

begin

SYear.Value := ParamByName(‘pYear’).AsInteger;

CBDep.Text := ParamByName(‘pDep’).AsString;

if ParamByName(‘pSex’).AsString = ‘м’ then

RGSex.ItemIndex := 0

else

RGSex.ItemIndex := 1;

end;

end;

end;

procedure TForm1.FamEditEnter(Sender: TObject);

begin

SYear.Value := 0;

CBDep.Text := »;

RGSex.ItemIndex := -1;

end;

procedure TForm1.BSetClick(Sender: TObject);

begin

with ProcSetInf do

begin

ParamByName(‘pFam’).AsString := FamEdit.Text;

ParamByName(‘pNam’).AsString := NamEdit.Text;

ParamByName(‘pPar’).AsString := ParEdit.Text;

ParamByName(‘pDep’).AsString := CBDep.Text;

ParamByName(‘pYear’).AsInteger := SYear.Value;

if RGSex.ItemIndex = 1 then

ParamByName(‘pSex’).AsString := ‘ж’

else

ParamByName(‘pSex’).AsString := ‘м’;

ExecProc;

if ParamByName(‘mess’).AsInteger = 0 then

MessageDlg(‘В базе данных запись отсутствует’,

mtError, [mbCancel], 0)

else

begin

MessageDlg(‘Запись проведена успешно’, mtCustom, [mbOk], 0);

Table1.Close;

Table1.Open;

Query1.Close;

Query1.Open;

end;

end;

end;

procedure TForm1.BExitClick(Sender: TObject);

begin

Close;

end;

procedure TForm1.FormCreate(Sender: TObject);

begin

CBDep2.ItemIndex := 0;

CBDep2Change(Sender);

end;

procedure TForm1.CBDep2Change(Sender: TObject);

begin

Query1.Close;

Query1.ParamByName(‘pDep’).AsString := CBDep2.Text;

Query1.Open;

end;

end.

{/codecitation}

Добавить комментарий