Evo da razjasnim postavicu kompletan kod Unitaa date forme pa mislim da ce biti jasnje sta hocu
Code:
unit UPrikazIzmenaClanova;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, Mask, DBCtrls, Buttons, DBXpress, FMTBcd,
SqlExpr, DB, DBClient, SimpleDS;
type
TfrmPrikazIzmenaClanova = class(TForm)
Panel1: TPanel;
Panel2: TPanel;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
DBEdit6: TDBEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
DBText1: TDBText;
DBMemo1: TDBMemo;
Label7: TLabel;
DataSource1: TDataSource;
SimpleDataSet1: TSimpleDataSet;
procedure BitBtn1Click(Sender: TObject);
procedure DBEdit2Exit(Sender: TObject);
procedure DBEdit3Exit(Sender: TObject);
procedure DBEdit4Exit(Sender: TObject);
procedure DBEdit5Exit(Sender: TObject);
procedure DBEdit6Exit(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
FID:integer;
FPisanje:boolean;
procedure DozvolaPisanja;
procedure PostojiBrLK;
public
function PraznoPolje(Text:String):boolean;
procedure OtvoriSifru(Id:integer;Pisanje:boolean);
function OtvorenRekord(BrRekorda:Integer):boolean;
end;
var
frmPrikazIzmenaClanova: TfrmPrikazIzmenaClanova;
implementation
uses UdmBiblioteka, global, ULogIn;
{$R *.dfm}
var
TD:TTransactionDesc;
procedure TfrmPrikazIzmenaClanova.BitBtn1Click(Sender: TObject);
begin
SimpleDataSet1.Close;
Close;
end;
procedure TfrmPrikazIzmenaClanova.DozvolaPisanja;
var
i:integer;
begin
for i:=0 to ComponentCount-1 do
begin
if Components[i] is TDBEdit then
(Components[I] as TDBEdit).ReadOnly:=not FPisanje;
end;
end;
procedure TfrmPrikazIzmenaClanova.OtvoriSifru(Id: integer;
Pisanje: boolean);
var
SQL:String;
begin
FID := id;
FPisanje := Pisanje;
td.TransactionID := 5;
td.IsolationLevel := xilREADCOMMITTED;
sql := 'select * from Clan where id = '+ IntToStr(FID);
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.CommandText:=SQL;
dmBiblioteka.SQLConn.StartTransaction(TD);
SimpleDataSet1.Open;
dmBiblioteka.SQLConn.Commit(TD);
if FID=-1 then
begin
dmBiblioteka.spID_Clanovi.ExecProc;
SimpleDataSet1.Append;
SimpleDataSet1.FieldByName('ID').AsInteger:=dmBiblioteka.spID_Clanovi.Params[0].AsInteger;
end
else
begin
SimpleDataSet1.Edit;
end;
DozvolaPisanja;
end;
function TfrmPrikazIzmenaClanova.PraznoPolje(Text: String): boolean;
begin
if text=''then
Result:=true
else
Result:=false;
end;
procedure TfrmPrikazIzmenaClanova.DBEdit2Exit(Sender: TObject);
begin
if PraznoPolje(DBEdit2.Text) then
begin
ShowMessage('Polje ' + DBEdit2.DataField + 'ne moze biti prazno');
DBEdit2.SetFocus;
end
else
begin
PostojiBrLK;
end;
end;
procedure TfrmPrikazIzmenaClanova.DBEdit3Exit(Sender: TObject);
begin
if PraznoPolje(DBEdit3.Text) then
begin
ShowMessage('Polje ' + DBEdit3.DataField + 'ne moze biti prazno');
DBEdit3.SetFocus;
end
else
begin
DBEdit4.SetFocus;
end;
end;
procedure TfrmPrikazIzmenaClanova.DBEdit4Exit(Sender: TObject);
begin
if PraznoPolje(DBEdit4.Text) then
begin
ShowMessage('Polje ' + DBEdit4.DataField + 'ne moze biti prazno');
DBEdit4.SetFocus;
end
else
begin
DBEdit5.SetFocus;
end;
end;
procedure TfrmPrikazIzmenaClanova.DBEdit5Exit(Sender: TObject);
begin
if PraznoPolje(DBEdit5.Text) then
begin
ShowMessage('Polje ' + DBEdit5.DataField + 'ne moze biti prazno');
DBEdit5.SetFocus;
end
else
begin
DBEdit6.SetFocus;
end;
end;
procedure TfrmPrikazIzmenaClanova.DBEdit6Exit(Sender: TObject);
begin
if PraznoPolje(DBEdit6.Text) then
begin
ShowMessage('Polje ' + DBEdit2.DataField + 'ne moze biti prazno');
DBEdit6.SetFocus;
end
else
begin
BitBtn2.SetFocus;
end;
end;
procedure TfrmPrikazIzmenaClanova.PostojiBrLK;
var
SQL,broj:String;
begin
broj:=DBEdit2.Text;
sql:='select * from Clan where BR_LICNE_KARTE = ' + QuotedStr(broj);
SimpleDataSet1.Close;
SimpleDataSet1.DataSet.CommandText:=SQL;
dmBiblioteka.SQLConn.StartTransaction(TD);
SimpleDataSet1.Open;
dmBiblioteka. SQLConn.Commit(TD);
if SimpleDataSet1.RecordCount=0 then
begin
SimpleDataSet1.Append;
SimpleDataSet1.FieldByName('id').AsInteger:=dmBiblioteka.spID_Clanovi.Params[0].AsInteger;
SimpleDataSet1.FieldByName('BR_LICNE_KARTE').AsString:=broj;
end;
DBEdit3.SetFocus;
end;
procedure TfrmPrikazIzmenaClanova.BitBtn2Click(Sender: TObject);
begin
if SimpleDataSet1.State in [dsInsert,dsEdit] then
begin
SimpleDataSet1.Post;
dmBiblioteka.SQLConn.StartTransaction(TD);
try
if SimpleDataSet1.ApplyUpdates(0)=0 then
begin
dmBiblioteka.SQLConn.Commit(TD);
SimpleDataSet1.Refresh;
Close;
end
else
begin
UpisULog('Neuspesan pokusaj izmene podataka u bazi' + dmBiblioteka.SQLConn.Params.Values['Database']);
ShowMessage('Neuspesan pokusaj izmene podataka u bazi'#13#10 + dmBiblioteka.SQLConn.Params.Values['Database']);
dmBiblioteka.SQLConn.Rollback(TD);
end
except
dmBiblioteka.SQLConn.Rollback(TD);
end;
end;
end;
function TfrmPrikazIzmenaClanova.OtvorenRekord(BrRekorda: Integer): boolean;
var
i:Integer;
begin
for i := 0 to Screen.CustomFormCount-1 do
if (Screen.CustomForms[i] is TfrmPrikazIzmenaClanova) then
if BrRekorda = (Screen.Forms[i] as TfrmPrikazIzmenaClanova).FID then
begin
Result := True;
Break
end
else
Result := False
else
Result:=False
end;
procedure TfrmPrikazIzmenaClanova.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
frmPrikazIzmenaClanova.Free;
end;
end.
//EVO i DMF Forme
Left = 358
Top = 108
Width = 369
Height = 547
ActiveControl = DBEdit2
Caption = 'Prikaz / Izmena Clanova'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnClose = FormClose
PixelsPerInch = 96
TextHeight = 13
object Panel1: TPanel
Left = 0
Top = 0
Width = 361
Height = 472
Align = alClient
BorderStyle = bsSingle
TabOrder = 0
object Label1: TLabel
Left = 21
Top = 8
Width = 13
Height = 16
Alignment = taCenter
Caption = '&ID'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label2: TLabel
Left = 21
Top = 64
Width = 125
Height = 16
Alignment = taCenter
Caption = '&BROJ LIÈNE KARTE'
FocusControl = DBEdit2
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label3: TLabel
Left = 21
Top = 120
Width = 23
Height = 16
Alignment = taCenter
Caption = '&IME'
FocusControl = DBEdit3
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label4: TLabel
Left = 21
Top = 168
Width = 59
Height = 16
Alignment = taCenter
Caption = '&PREZIME'
FocusControl = DBEdit4
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label5: TLabel
Left = 21
Top = 224
Width = 56
Height = 16
Alignment = taCenter
Caption = '&ADRESA'
FocusControl = DBEdit5
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object Label6: TLabel
Left = 21
Top = 272
Width = 110
Height = 16
Alignment = taCenter
Caption = '&BROJ TELEFONA'
FocusControl = DBEdit6
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object DBText1: TDBText
Left = 32
Top = 40
Width = 65
Height = 17
Alignment = taCenter
DataField = 'ID'
DataSource = DataSource1
end
object Label7: TLabel
Left = 21
Top = 328
Width = 152
Height = 16
Caption = 'NAPOMENA_OPOMENA'
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -13
Font.Name = 'MS Sans Serif'
Font.Style = []
ParentFont = False
end
object DBEdit2: TDBEdit
Left = 20
Top = 85
Width = 121
Height = 21
DataField = 'BR_LICNE_KARTE'
DataSource = DataSource1
TabOrder = 0
OnExit = DBEdit2Exit
end
object DBEdit3: TDBEdit
Left = 20
Top = 138
Width = 121
Height = 21
DataField = 'IME'
DataSource = DataSource1
TabOrder = 1
OnExit = DBEdit3Exit
end
object DBEdit4: TDBEdit
Left = 20
Top = 191
Width = 121
Height = 21
DataField = 'PREZIME'
DataSource = DataSource1
TabOrder = 2
OnExit = DBEdit4Exit
end
object DBEdit5: TDBEdit
Left = 20
Top = 244
Width = 121
Height = 21
DataField = 'ADRESA'
DataSource = DataSource1
TabOrder = 3
OnExit = DBEdit5Exit
end
object DBEdit6: TDBEdit
Left = 21
Top = 297
Width = 121
Height = 21
DataField = 'TELEFON'
DataSource = DataSource1
TabOrder = 4
OnExit = DBEdit6Exit
end
object DBMemo1: TDBMemo
Left = 8
Top = 344
Width = 185
Height = 89
DataField = 'NAPOMENA_OPOMENA'
DataSource = DataSource1
ScrollBars = ssVertical
TabOrder = 5
end
end
object Panel2: TPanel
Left = 0
Top = 472
Width = 361
Height = 41
Align = alBottom
TabOrder = 1
object BitBtn1: TBitBtn
Left = 16
Top = 8
Width = 75
Height = 25
TabOrder = 0
OnClick = BitBtn1Click
Kind = bkClose
end
object BitBtn2: TBitBtn
Left = 128
Top = 8
Width = 75
Height = 25
Caption = '&OK'
TabOrder = 1
OnClick = BitBtn2Click
Kind = bkOK
end
end
object DataSource1: TDataSource
DataSet = SimpleDataSet1
Left = 176
Top = 72
end
object SimpleDataSet1: TSimpleDataSet
Aggregates = <>
DataSet.CommandText = 'select * from CLAN'
DataSet.MaxBlobSize = -1
DataSet.Params = <>
Params = <>
Left = 176
Top = 136
end
end
Znaci kad se forma kreira fiokus je na DBEDit2.Posto se u DBEditima nalaze polja baze br_licne karte,ime,prezime,....mora da se vrsi provera jer su neka od njih u bazi kao not null...ali ako se klikne na Cancel ili OK treba odmah da se izvrsi kod koji je vezan za njiih...medjutim kod mene se preskace iz edita u edit pa se to vrsi onoliko puta koliko edita ima,korisnik bi trrebao 5 puta da klikce na Ok,Cancal da bi obavio akcije...
Nadam se da sam malko razjasnio
@savkic
> Od jednog lika sam saznao da se to moze resiti sa DISPATCH controlom, kako sam ga razumeo fora je napraviti objekat koji ce u sklopu
> dogadjaja OnExit ispitati dal je se preslo u sledeci Edit ili je kliktnuto na neki od button-a,a kako to radi ja pojma nemam
Konfuzno napisano, počni od početka i lepo kaži koji su problemi i šta želiš da postigneš
Tebi konfuzno?A zamisli kako je tek meni
Rekao mi lik da se napravi objekat i da mu se prosledi kao dispatch sta je korisnik uradio,tj da li je kliknuo jedno od dugmadi ili je samo prebacio fokus na sledeci Edit?
Don't worry be happy