unit unitHouseparentInfo;

interface

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

type
  TfrmUpdateHP = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label3: TLabel;
    Label2: TLabel;
    Label14: TLabel;
    Image1: TImage;
    Label1: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    StatusBar2: TStatusBar;
    txtLname: TEdit;
    txtFname: TEdit;
    txtparid: TEdit;
    btnBrowse: TBitBtn;
    txtCP: TEdit;
    Panel1: TPanel;
    txtAdd: TMemo;
    txtAcad: TEdit;
    cmbSem: TComboBox;
    Panel2: TPanel;
    btnUpdate: TBitBtn;
    BitBtn2: TBitBtn;
    OpenDialog1: TOpenDialog;
    procedure btnBrowseClick(Sender: TObject);
  private
    { Private declarations }
  public
        procedure UpdateHP;
        procedure loadImage;
    { Public declarations }
  end;

var
  frmUpdateHP: TfrmUpdateHP;

implementation

uses DM, unitLogin, JPEG;

{$R *.dfm}
procedure TfrmUpdateHP.UpdateHP;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
          DataModule1.query.SQL.Add('UPDATE HOUSEPARENT SET ACADYR = :A, SEM = :B, STATUS = :C, MODBY = :D, MODDATE = :E WHERE PAR_ID = :F');
          DataModule1.query.Params.AsString[0] := trim(txtAcad.Text);
          DataModule1.query.Params.AsString[1] := cmbSem.Text;
          DataModule1.query.Params.AsString[2] := frmLogin.fullname;
          DataModule1.query.Params.AsString[3] := DateToStr(Now());
          DataModule1.query.Params.AsInteger[4]:= StrToInt(txtparid.Text);
          DataModule1.query.ExecSQL;

          if DataModule1.tr.InTransaction then
              DataModule1.tr.Commit;
              ShowMessage('Successfully updated');
end;
procedure TfrmUpdateHP.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.query.SQL.Clear;
            DataModule1.query.SQL.Add('UPDATE HOUSEPARENT SET IMAGE = :blob WHERE PAR_ID = :b');
            DataModule1.query.ParamsSetBlob('blob',Stream);
            DataModule1.query.Params.AsInteger[1] := StrToInt(txtparid.Text);
            DataModule1.query.ExecSQL;
            Stream.Free;

            if DataModule1.tr.InTransaction then
                DataModule1.tr.Commit;
                loadImage;
  end;
  end;
procedure TfrmUpdateHP.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 HOUSEPARENT WHERE PAR_ID =:a');
    DataModule1.query.Params.AsInteger[0] := StrToInt(txtparid.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;
end.
