unit DialogOsoba;

interface

uses
  Windows, Messages, Classes, SysUtils, Graphics, Controls, StdCtrls, Forms,
  Dialogs, DBCtrls, DB, Mask, ExtCtrls, Buttons;

type
  TDlgOsoba = class(TForm)
    ScrollBox: TScrollBox;
    Label2: TLabel;
    EditNAZWISKO: TDBEdit;
    Label3: TLabel;
    EditIMIE: TDBEdit;
    Label4: TLabel;
    EditDATAUR: TDBEdit;
    Label5: TLabel;
    EditMCOWOSC: TDBEdit;
    Label6: TLabel;
    EditULICAINR: TDBEdit;
    Label7: TLabel;
    EditKODP: TDBEdit;
    Label8: TLabel;
    EditMIASTO: TDBEdit;
    Label9: TLabel;
    EditPESEL: TDBEdit;
    Panel2: TPanel;
    Label1: TLabel;
    EditIDOSOBY: TDBEdit;
    BitBtnOK: TBitBtn;
    BitBtnAnuluj: TBitBtn;
    procedure BitBtnOKClick(Sender: TObject);
    procedure BitBtnAnulujClick(Sender: TObject);
    procedure EditNAZWISKOExit(Sender: TObject);
    procedure EditIMIEExit(Sender: TObject);
    procedure EditDATAURExit(Sender: TObject);

  private

  public
    procedure Zapamietaj();
  end;

var
  DlgOsoba: TDlgOsoba;

implementation
{$R *.DFM}
Uses
   DataModule;

procedure TDlgOsoba.BitBtnOKClick(Sender: TObject);
var
   sa_puste : Boolean;

begin
   sa_puste := False;

   if(DM.QueryOsobyNAZWISKO.IsNull) or (DM.QueryOsobyNAZWISKO.Value  = '') then begin
      sa_puste := True;
      EditNAZWISKO.Color := clYellow;
   end
   else begin
      EditNAZWISKO.Color := clWindow;
   end;

   if(DM.QueryOsobyIMIE.IsNull) or (DM.QueryOsobyIMIE.Value = '') then begin
      sa_puste := True;
      EditIMIE.Color := clYellow;
   end
   else begin
      EditIMIE.Color := clWindow;
   end;

   if(DM.QueryOsobyDATAUR.IsNull) then begin
      sa_puste := True;
      EditDATAUR.Color := clYellow;
   end
   else begin
      EditDATAUR.Color := clWindow;
   end;

   if Sa_puste then begin
      ModalResult := mrNone;
      EXIT;
   end;

   Zapamietaj();
end;

procedure TDlgOsoba.BitBtnAnulujClick(Sender: TObject);
begin
   DM.QueryOsoby.Cancel();
end;

procedure TDlgOsoba.EditNAZWISKOExit(Sender: TObject);
begin
   if (DM.QueryOsobyNAZWISKO.IsNull) or (DM.QueryOsobyNAZWISKO.Value  = '') then begin
      EditNAZWISKO.Color := clYellow;
   end
   else begin
      EditNAZWISKO.Color := clWindow;
   end;
end;

procedure TDlgOsoba.EditIMIEExit(Sender: TObject);
begin
   if(DM.QueryOsobyIMIE.IsNull) or (DM.QueryOsobyIMIE.Value = '') then begin
      EditIMIE.Color := clYellow;
   end
   else begin
      EditIMIE.Color := clWindow;
   end;
end;

procedure TDlgOsoba.EditDATAURExit(Sender: TObject);
begin
   if(DM.QueryOsobyDATAUR.IsNull) then begin
      EditDATAUR.Color := clYellow;
   end
   else begin
      EditDATAUR.Color := clWindow;
   end;
end;

procedure TDlgOsoba.Zapamietaj();
begin
	(*
   mozna uzyæ:
   DM.Database.ApplyUpdates([DM.QueryOsoby]);

   lub
   DM.QueryOsoby.ApplyUpdates();

   lub
	*)
   DM.Database.StartTransaction();
   try
      DM.QueryOsoby.ApplyUpdates();
      DM.Database.Commit();
   except
      DM.Database.Rollback();
      raise;
   end;
   DM.QueryOsoby.CommitUpdates();
end;

end.

