unit unitPrevRoom;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls;

type
  TfrmPreviousRoom = class(TForm)
    lvChangeRoom: TListView;
  private
    { Private declarations }
  public
    procedure loadChangeRoom(Occid : integer);
  end;

var
  frmPreviousRoom: TfrmPreviousRoom;

implementation

uses DM;

{$R *.dfm}
procedure TfrmPreviousRoom.loadChangeRoom(Occid : integer);
var newState : TListItem;
begin
     DataModule1.query.SQL.Clear;
     DataModule1.query.SQL.Add('SELECT a.OCC_ID, a.BUIL_ID, b.DESCRIPTION, a.RM_NO, a.DATECHANGED FROM RM_HIST A, BUILDING B WHERE a.OCC_ID = :A AND b.BUIL_ID = a.BUIL_ID');
     DataModule1.query.Params.AsString[0] := IntToStr(Occid);
     DataModule1.query.Prepare;
     DataModule1.query.Open();
     lvChangeRoom.Items.BeginUpdate;
     lvChangeRoom.Items.Clear;

               if DataModule1.query.Fields.IsNull[0] then Exit;
                while not DataModule1.query.Eof do begin

                    newState := lvChangeRoom.Items.Add;
                    newState.Caption := DataModule1.query.Fields.AsString[0];
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[1]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[2]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[3]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[4]);
                    DataModule1.query.Next;
                    end;

                         if DataModule1.tr.InTransaction then
                          DataModule1.tr.Commit;
                             lvChangeRoom.Items.EndUpdate;

end;

end.
