unit unitUpdateOcc;

interface

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

type
  TfrmUpdate = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label3: TLabel;
    Label2: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Image1: TImage;
    Label1: TLabel;
    StatusBar1: TStatusBar;
    txtID: TEdit;
    txtLname: TEdit;
    txtFname: TEdit;
    txtoccid: TEdit;
    btnBrowse: TBitBtn;
    txtgen: TEdit;
    Panel1: TPanel;
    OpenDialog1: TOpenDialog;
    procedure btnBrowseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
      primary : String;
      systemDate : TDateTime;
      DateTimeformat : string;
      procedure loadImage;

  end;

var
  frmUpdate: TfrmUpdate;

implementation

uses DM, JPEG;

{$R *.dfm}

procedure TfrmUpdate.btnBrowseClick(Sender: TObject);
var Stream: TFileStream;
begin
  If OpenDialog1.Execute then begin
    Stream := TFileStream.Create(OpenDialog1.FileName, fmOpenRead);
    if DataModule1.tr.InTransaction then
        DataModule1.tr.Commit;
     DataModule1.tr.StartTransaction;
    DataModule1.query.SQL.Clear;
  DataModule1.query.SQL.Add('UPDATE OCCUPANTS SET IMAGE = :blob WHERE OCC_ID = :b');
    DataModule1.query.ParamsSetBlob('blob',Stream);
     DataModule1.query.Params.AsInteger[1] := StrToInt(txtoccid.Text);
    DataModule1.query.ExecSQL;
    Stream.Free;
    if DataModule1.tr.InTransaction then
      DataModule1.tr.Commit;
    loadImage;
  end;
end;

procedure TfrmUpdate.loadImage;
var
    Stream: TMemoryStream;
    Jpg: TJpegImage;
begin
    Image1.Picture := nil;
  if DataModule1.tr.InTransaction then
        DataModule1.tr.Commit;

    DataModule1.tr.StartTransaction;
    DataModule1.query.SQL.Clear;
    DataModule1.query.SQL.Add('SELECT IMAGE FROM OCCUPANTS WHERE OCC_ID =:a');
    DataModule1.query.Params.AsInteger[0] := StrToInt(txtoccid.Text);
    DataModule1.query.Prepare;
   DataModule1.query.Open();
      if DataModule1.query.Fields.BlobData[0] <> nil then begin
        Stream := TMemoryStream.Create;
       Jpg := TJPEGImage.Create;
          try
           DataModule1.query.ReadBlob('IMAGE',Stream);
            Jpg.LoadFromStream(Stream);
            Image1.Picture.Graphic := Jpg;
          finally
            Stream.Free;
            Jpg.Free;
          end;
      end

      else begin
          Image1.Picture := nil;
      end;
  if DataModule1.tr.InTransaction then
    DataModule1.tr.Commit;
end;
procedure TfrmUpdate.FormShow(Sender: TObject);
begin
       DateTimeToString(DateTimeformat, 'dddddd', now());
       Label1.Caption := DateTimeformat;
       StatusBar1.Panels.Items[1].Text := 'Date -- ' + label1.Caption;
end;

end.
