unit unitStuDRep;

interface

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

type
  TfrmStuDrep = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    lvdate: TListView;
    TabSheet2: TTabSheet;
    GroupBox1: TGroupBox;
    dtpDate: TDateTimePicker;
    BitBtn1: TBitBtn;
    BitBtn2: TBitBtn;
    lvIndRep: TListView;
    GroupBox2: TGroupBox;
    txtSearch: TEdit;
    btnID: TBitBtn;
    btnPrint2: TBitBtn;
    procedure FormShow(Sender: TObject);
    procedure btnGoClick(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
    procedure btnIDClick(Sender: TObject);
    procedure btnPrint2Click(Sender: TObject);
    
  private
    { Private declarations }
  public
        procedure loadLog;
        procedure loadDate;
        procedure loadID;
        procedure loadInvRep;
  end;

var
  frmStuDrep: TfrmStuDrep;

implementation

uses DM;

{$R *.dfm}

procedure TfrmStuDrep.FormShow(Sender: TObject);
begin
      loadLog;
      loadInvRep;
end;

procedure TfrmStuDrep.btnGoClick(Sender: TObject);
begin
      loadDate;
end;

procedure TfrmStuDrep.loadLog;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
          DataModule1.query.SQL.Add('SELECT a.OCC_ID, b.APPID, c.STUDENT_ID, c.APP_LNAME, c.APP_FNAME, a.DATELOG, a.TIMELOG, d.STATUSDESC, a.NAME, a.ADDRESS, a.CONTACTNO, a.REASON_OVERNYT');
          DataModule1.query.SQL.Add('FROM LOGGED A, OCCUPANTS B,  APPLICANTS C, STATUS D');
          DataModule1.query.SQL.Add('WHERE d.STATUSID = a.STATUSID AND c.APPID = b.APPID and b.OCC_ID = a.OCC_ID');
          DataModule1.query.Prepare;
          DataModule1.query.Open();
          lvdate.Items.BeginUpdate;
          lvdate.Items.Clear;

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

         newState := lvdate.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]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[5]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[6]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[7]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[8]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[9]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[10]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[11]);
         DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
              DataModule1.tr.Commit;
              lvdate.Items.EndUpdate;
end;

procedure TfrmStuDrep.loadDate;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
          DataModule1.query.SQL.Add('SELECT a.OCC_ID, b.APPID, c.STUDENT_ID, c.APP_LNAME, c.APP_FNAME, a.DATELOG, a.TIMELOG, d.STATUSDESC, a.NAME, a.ADDRESS, a.CONTACTNO, a.REASON_OVERNYT');
          DataModule1.query.SQL.Add('FROM LOGGED A, OCCUPANTS B,  APPLICANTS C, STATUS D');
          DataModule1.query.SQL.Add('WHERE d.STATUSID = a.STATUSID AND c.APPID = b.APPID and b.OCC_ID = a.OCC_ID AND a.DATELOG = :A');
          DataModule1.query.Params.AsString[0] := DateToStr(dtpDate.Date);
          DataModule1.query.Prepare;
          DataModule1.query.Open();
          lvdate.Items.BeginUpdate;
          lvdate.Items.Clear;

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

         newState := lvdate.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]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[5]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[6]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[7]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[8]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[9]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[10]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[11]);
         DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
              DataModule1.tr.Commit;
              lvdate.Items.EndUpdate;
end;

procedure TfrmStuDrep.loadInvRep;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
          DataModule1.query.SQL.Add('SELECT a.OCC_ID, b.APPID, c.STUDENT_ID, c.APP_LNAME, c.APP_FNAME, a.DATELOG, a.TIMELOG, d.STATUSDESC, a.NAME, a.ADDRESS, a.CONTACTNO, a.REASON_OVERNYT');
          DataModule1.query.SQL.Add('FROM LOGGED A, OCCUPANTS B,  APPLICANTS C, STATUS D');
          DataModule1.query.SQL.Add('WHERE d.STATUSID = a.STATUSID AND c.APPID = b.APPID and b.OCC_ID = a.OCC_ID');
          DataModule1.query.Prepare;
          DataModule1.query.Open();
          lvIndRep.Items.BeginUpdate;
          lvIndRep.Items.Clear;

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

         newState := lvIndRep.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]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[5]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[6]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[7]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[8]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[9]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[10]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[11]);
         DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
              DataModule1.tr.Commit;
              lvIndRep.Items.EndUpdate;
end;

procedure TfrmStuDrep.btnPrintClick(Sender: TObject);
begin
    DataModule1.rep.Filename := 'C:\Users\janine\Documents\DOMS\Reports\DailyReport.rep';
    DataModule1.rep.Report.Params.Items[0].Value := DateToStr(dtpDate.date);
    DataModule1.rep.Preview := True;
    DataModule1.rep.Execute();
end;

procedure TfrmStuDrep.loadID;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
          DataModule1.query.SQL.Add('SELECT a.OCC_ID, b.APPID, c.STUDENT_ID, c.APP_LNAME, c.APP_FNAME, a.DATELOG, a.TIMELOG, d.STATUSDESC, a.NAME, a.ADDRESS, a.CONTACTNO, a.REASON_OVERNYT');
          DataModule1.query.SQL.Add('FROM LOGGED A, OCCUPANTS B,  APPLICANTS C, STATUS D');
          DataModule1.query.SQL.Add('WHERE d.STATUSID = a.STATUSID AND c.APPID = b.APPID and b.OCC_ID = a.OCC_ID AND C.STUDENT_ID = :A');
          DataModule1.query.Params.AsString[0] := trim(txtSearch.Text);
          DataModule1.query.Prepare;
          DataModule1.query.Open();
          lvIndRep.Items.BeginUpdate;
          lvIndRep.Items.Clear;

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

         newState := lvIndRep.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]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[5]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[6]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[7]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[8]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[9]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[10]);
         newState.SubItems.Add(DataModule1.query.Fields.AsString[11]);
         DataModule1.query.Next;
end;
         if DataModule1.tr.InTransaction then
              DataModule1.tr.Commit;
              lvIndRep.Items.EndUpdate;
end;

procedure TfrmStuDrep.btnIDClick(Sender: TObject);
begin
      loadID;
end;


procedure TfrmStuDrep.btnPrint2Click(Sender: TObject);
begin
    DataModule1.rep.Filename := 'C:\Users\janine\Documents\DOMS\Reports\StudentLogged.rep';
    DataModule1.rep.Report.Params.Items[0].Value := trim(txtSearch.Text);
    DataModule1.rep.Preview := True;
    DataModule1.rep.Execute();
end;

end.
