unit Profile;

interface

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

type
  TfrmProfile = class(TForm)
    GroupBox1: TGroupBox;
    lblIDNum: TLabel;
    lblName: TLabel;
    lblPosition: TLabel;
    lblAddress: TLabel;
    lblConNum: TLabel;
    lblUName: TLabel;
    lblDateCreated: TLabel;
    lblModifiedOn: TLabel;
    lblStatus: TLabel;
    lblUserAcc: TLabel;
    txtIDNum: TLabel;
    txtName: TLabel;
    txtPosition: TLabel;
    txtAddress: TLabel;
    txtConNum: TLabel;
    txtUName: TLabel;
    txtUAccess: TLabel;
    txtDateCreated: TLabel;
    txtModifiedOn: TLabel;
    txtStatus: TLabel;
    Panel1: TPanel;
    lbEditUName: TLabel;
    lbChangePass: TLabel;
    Label1: TLabel;

    procedure showinfo();
    procedure FormActivate(Sender: TObject);
    procedure lbChangePassClick(Sender: TObject);
    procedure ChangePass();
    procedure lbEditNameClick(Sender: TObject);
    procedure lbEditAddressClick(Sender: TObject);
    procedure lbEditCNumClick(Sender: TObject);
    procedure lbEditUNameClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    name:string;
    position:string;
    address:string;
    CNum:string;
    UName:string;
  end;

var
  frmProfile: TfrmProfile;

implementation

uses Main, DM, jvuib, ChangePass, ChangePass_profile, Profile_editName;
{$R *.dfm}

procedure TfrmProfile.FormActivate(Sender: TObject);
begin
 showinfo();
end;

procedure TfrmProfile.lbChangePassClick(Sender: TObject);
begin
      frmChangePass_profile.showModal;
end;


//..............dirty works here
procedure TfrmProfile.showinfo();
  var status:String;
      acStat:String;
begin

acStat:='Active';
txtStatus.Caption:=acStat;

  txtName.Caption := frmMain.StatusBar1.Panels.Items[1].Text;
  if DModule.TR.InTransaction then
  DModule.TR.Commit;
  DModule.TR.StartTransaction;
  DModule.QR.SQL.Clear;
  DModule.QR.SQL.Add('SELECT *');
  DModule.QR.SQL.Add('FROM USERSINFO WHERE FULLNAME =:a');
  DModule.QR.Params.AsString[0] := trim(txtName.Caption);
  DModule.QR.Prepare;
  DModule.QR.Open();

  if DModule.QR.Fields.IsNull[0] then Exit;
     { if DModule.QR.Eof then begin
      MessageDlg('No Data Found',mtError,[mbOK],0);
   end;}

  while not DModule.QR.Eof do begin
    txtIDNum.Caption := DModule.QR.Fields.AsString[0];
    txtPosition.Caption := DModule.QR.Fields.AsString[2];
    txtAddress.Caption := DModule.QR.Fields.AsString[3];
    txtConNum.Caption := DModule.QR.Fields.AsString[4];
    txtUName.Caption := DModule.QR.Fields.AsString[5];
    txtUAccess.Caption := DModule.QR.Fields.AsString[8];
    txtDateCreated.Caption := DModule.QR.Fields.AsString[7];
    txtModifiedOn.Caption := DModule.QR.Fields.AsString[9];
    status := DModule.QR.Fields.AsString[10];
  DModule.QR.Next;
  end;

  if DModule.TR.InTransaction then
            DModule.TR.Commit;
end;

procedure TfrmProfile.ChangePass();
begin
     //change
end;

procedure TfrmProfile.lbEditNameClick(Sender: TObject);
begin
      token := 'name';
      frmProfile_editName.txtEditName.Text := Trim(txtName.Caption);
      frmProfile_editName.lbIDNum.Caption := txtIDNum.Caption;
      frmProfile_editName.Caption:='Edit name';
      frmProfile_editName.ShowModal;
end;

procedure TfrmProfile.lbEditAddressClick(Sender: TObject);
begin
      token := 'address';
      frmProfile_editName.txtEditName.Text := Trim(txtAddress.Caption);
      frmProfile_editName.lbIDNum.Caption := txtIDNum.Caption;
      frmProfile_editName.Caption:='Edit address';
      frmProfile_editName.ShowModal;
end;

procedure TfrmProfile.lbEditCNumClick(Sender: TObject);
begin
      token := 'cnum';
      frmProfile_editName.txtEditName.Text := Trim(txtConNum.Caption);
      frmProfile_editName.lbIDNum.Caption := txtIDNum.Caption;
      frmProfile_editName.Caption:='Edit contact number';
      frmProfile_editName.ShowModal;
end;

procedure TfrmProfile.lbEditUNameClick(Sender: TObject);
begin
      token := 'uname';
      frmProfile_editName.txtEditName.Text := Trim(txtUName.Caption);
      frmProfile_editName.lbIDNum.Caption := txtIDNum.Caption;
      frmProfile_editName.Caption:='Edit username';
      frmProfile_editName.ShowModal;
end;

end.
