unit unitUpdateApp;

interface

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

type
  TfrmUpdateApplicants = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label3: TLabel;
    Label2: TLabel;
    Label13: TLabel;
    Label14: TLabel;
    Image1: TImage;
    StatusBar1: TStatusBar;
    txtID: TEdit;
    txtLname: TEdit;
    txtFname: TEdit;
    txtoccid: TEdit;
    btnBrowse: TBitBtn;
    txtgen: TEdit;
    OpenDialog1: TOpenDialog;
    Panel1: TPanel;
    Label1: TLabel;
   // procedure btnUpdateClick(Sender: TObject);
    procedure btnCancelClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure btnBrowseClick(Sender: TObject);

  private
    { Private declarations }
  public
    primary : String;
    systemDate : TDateTime;
    DateTimeformat : string;
    procedure clear();
    procedure loadImage;

   // procedure saveLOg;
  end;

var
  frmUpdateApplicants: TfrmUpdateApplicants;

implementation

uses DM, unitLogin, JPEG;

{$R *.dfm}

procedure TfrmUpdateApplicants.clear;
begin
  {  txtID.Text := '';
    txtLname.Text := '';
    txtFname.Text := '';
    txtmname.Text := '';
    txtBday.Text := '';
    txtAdd.Text := '';
    txtYr.Text := '';
    txtScholar.Text := '';
    cmbGen.Text :='';
    cmbStat.Text := '';
    txtCP.Text := '';
    txtAddress.Text := '';
    txtMobile.Text := '';
    txtRel.Text := '';  }
end;

{procedure TfrmUpdate.btnUpdateClick(Sender: TObject);
begin
      //saveLOg;
      if DataModule1.tr.InTransaction then
        DataModule1.tr.Commit;

            DataModule1.query.SQL.Clear;
            DataModule1.query.SQL.Add('UPDATE APPLICANTS');
            DataModule1.query.SQL.Add('SET STUDENT_ID = :A, APP_LNAME = :B, APP_FNAME = :C, MIDDLE_NAME = :D, APP_GENDER = :E, APP_BDAY = :F, PERMANENT_ADD = :G, YEAR_COURSE = :H, APP_SCHOLARSHIP = :I, APP_STATUS = :J, CONTACTPERSON = :K, CONTACT_ADD = :L, MOBILE_NO = :M, RELATIONSHIP = :N');
            DataModule1.query.SQL.Add('WHERE APPID = :O');
            DataModule1.query.Params.AsString[0] := Trim(txtID.Text);
            DataModule1.query.Params.AsString[1] := Trim(txtLname.Text);
            DataModule1.query.Params.AsString[2] := Trim(txtFname.Text);
            DataModule1.query.Params.AsString[3] := Trim(txtmname.Text);
            DataModule1.query.Params.AsString[4] := Trim(cmbGen.Text);
            DataModule1.query.Params.AsString[5] := Trim(txtBday.Text);
            DataModule1.query.Params.AsString[6] := Trim(txtAdd.Text);
            DataModule1.query.Params.AsString[7] := Trim(txtYr.Text);
            DataModule1.query.Params.AsString[8] := Trim(txtScholar.Text);
            DataModule1.query.Params.AsString[9] := Trim(cmbStat.Text);
            DataModule1.query.Params.AsString[10] := Trim(txtCP.Text);
            DataModule1.query.Params.AsString[11] := Trim(txtAddress.Text);
            DataModule1.query.Params.AsString[12] := Trim(txtMobile.Text);
            DataModule1.query.Params.AsString[13] := Trim(txtRel.Text);
            DataModule1.query.Params.AsString[14] := primary;
            DataModule1.query.Prepare;
            DataModule1.query.Open();

                if DataModule1.tr.InTransaction then
                    DataModule1.tr.Commit;
                      ShowMessage('Record has been successfully updated.');
                        clear();
                        Close();
end;  }

procedure TfrmUpdateApplicants.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 APPLICANTS WHERE APPID =: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 TfrmUpdateApplicants.btnCancelClick(Sender: TObject);
begin
      Close();
end;

procedure TfrmUpdateApplicants.FormCreate(Sender: TObject);
begin
       DateTimeToString(DateTimeformat, 'dddddd', now());
       Label1.Caption := DateTimeformat;
       StatusBar1.Panels.Items[1].Text := 'Date -- ' + label1.Caption;
end;

procedure TfrmUpdateApplicants.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 APPLICANTS SET IMAGE = :blob WHERE APPID = :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;
end.
