unit unitApplicantRep;

interface

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

type
  TfrmAppRep = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    lvApplicants: TListView;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    txtSearch: TEdit;
    btnSearch: TBitBtn;
    cmbSearch: TComboBox;
    btnPrint: TBitBtn;
    lvGirlsApp: TListView;
    TabSheet2: TTabSheet;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    txtSearch2: TEdit;
    btnSearch2: TBitBtn;
    cmbSem: TComboBox;
    btnPrintB: TBitBtn;
    lvBoysApp: TListView;
    PopupMenu1: TPopupMenu;
    UpdateApplicant1: TMenuItem;
    AdmitApplicant1: TMenuItem;
    PopupMenu2: TPopupMenu;
    UpdateApplicant2: TMenuItem;
    AdmitApplicant2: TMenuItem;
    procedure btnSearchClick(Sender: TObject);
    procedure btnPrintClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btnPrintBClick(Sender: TObject);
    procedure btnSearch2Click(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Girlsapplicants;
    procedure Boysapplicants;
    procedure viewFirstsem;
    procedure viewSecsem;
    procedure viewBoysFirstSem;
    procedure viewBoysSem;
       { Public declarations }
  end;

var
  frmAppRep: TfrmAppRep;

implementation

uses DM;

{$R *.dfm}

procedure TfrmAppRep.Girlsapplicants;
var newState : TListItem;
begin
       if DataModule1.tr.InTransaction then
           DataModule1.tr.Commit;

           DataModule1.query.SQL.Clear;
           //DataModule1.query.SQL.Add('SELECT * FROM STUDENTPROF');
 DataModule1.query.SQL.Add('SELECT APPID,STUDENT_ID,APP_LNAME,APP_FNAME,MIDDLE_NAME,GENDER,APP_BDAY,ADDRESS,YEAR_COURSE,APP_SCHOLARSHIP,APP_STATUS,ACADYR,SEM,DATEAPPLIED,CONPERSON,MOBNO,REL FROM STUDENTPROF WHERE GENDER = :A');
          // DataModule1.query.SQL.Add(' FROM studentprof a, ADDRESS C WHERE a.GENDER = : ORDER BY APPID');
           DataModule1.query.Params.AsString[0] := 'Female';
           DataModule1.query.Prepare;
           DataModule1.query.Open();
           lvGirlsApp.Items.BeginUpdate;
           lvGirlsApp.Items.Clear;

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

                    newState := lvGirlsApp.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]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
       
                    DataModule1.query.Next;
                  end;
                      if DataModule1.tr.InTransaction then
                          DataModule1.tr.Commit;
                          lvGirlsApp.Items.EndUpdate;
 end;

procedure TfrmAppRep.Boysapplicants;
var newState : TListItem;
begin
       if DataModule1.tr.InTransaction then
           DataModule1.tr.Commit;

           DataModule1.query.SQL.Clear;
           DataModule1.query.SQL.Add('SELECT *');
           DataModule1.query.SQL.Add(' FROM studentprof a WHERE a.GENDER = :A ORDER BY APPID');
           DataModule1.query.Params.AsString[0] := 'Male';
           DataModule1.query.Prepare;
           DataModule1.query.Open();
           lvBoysApp.Items.BeginUpdate;
           lvBoysApp.Items.Clear;

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

                    newState := lvBoysApp.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]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
                    newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
                    DataModule1.query.Next;
                  end;
                      if DataModule1.tr.InTransaction then
                        DataModule1.tr.Commit;
                          lvBoysApp.Items.EndUpdate;
end;

procedure TfrmAppRep.viewFirstsem;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
          DataModule1.tr.Commit;

          DataModule1.query.SQL.Clear;
         DataModule1.query.SQL.Add('SELECT *');
           DataModule1.query.SQL.Add(' FROM studentprof WHERE a.ACADYR = :A AND a.SEM = :B AND a.GENDER = :C ORDER BY a.APPID');
          DataModule1.query.Params.AsString[0] := trim(txtSearch.Text);
          DataModule1.query.Params.AsString[1] := 'First Semester';
          DataModule1.query.Params.AsString[2] := 'Female';
          DataModule1.query.Prepare;
          DataModule1.query.Open();
          lvGirlsApp.Items.BeginUpdate;
          lvGirlsApp.Items.Clear;

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

            newState := lvGirlsApp.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]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
            //newState.SubItems.Add(DataModule1.query.Fields.AsString[17]);
            DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
               DataModule1.tr.Commit;
               lvGirlsApp.Items.EndUpdate;
end;


procedure TfrmAppRep.viewSecsem;
var newState : TListItem;
begin
        if DataModule1.tr.InTransaction then
            DataModule1.tr.Commit;

            DataModule1.query.SQL.Clear;
            DataModule1.query.SQL.Add('SELECT * ');
           DataModule1.query.SQL.Add(' FROM studentprof a WHERE a.ACADYR = :A AND a.SEM = :B AND a.GENDER = :C ORDER BY a.APPID');
            DataModule1.query.Params.AsString[0] := trim(txtSearch.Text);
            DataModule1.query.Params.AsString[1] := 'Second Semester';
            DataModule1.query.Params.AsString[2] := 'Female';
            DataModule1.query.Open();
            lvGirlsApp.Items.BeginUpdate;
            lvGirlsApp.Items.Clear;

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

            newState := lvGirlsApp.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]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
           // newState.SubItems.Add(DataModule1.query.Fields.AsString[17]);
            DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
                DataModule1.tr.Commit;
                lvGirlsApp.Items.EndUpdate;
end;

procedure TfrmAppRep.btnSearchClick(Sender: TObject);
begin
 if (cmbSearch.Text = 'First Semester') then
          begin
                  viewFirstsem;
          end
            else if (cmbSearch.Text = 'Second Semester') then
            begin
                  viewSecsem;
            end
                  else  begin
                    MessageDlg('Please input first the textbox when searching.',mtInformation,[mbOK],0);
                end;
end;

procedure TfrmAppRep.btnPrintClick(Sender: TObject);
begin
    DataModule1.rep.Filename := 'C:\Users\janine\Documents\DOMS\Reports\Applicant_Report.rep';
    DataModule1.rep.Report.Params.Items[0].Value := txtSearch.Text;
    DataModule1.rep.Report.Params.Items[1].Value := cmbSearch.Text;
    DataModule1.rep.Report.Params.Items[2].Value := 'Female';
    DataModule1.rep.Preview := True;
    DataModule1.rep.Execute();
end;

procedure TfrmAppRep.FormShow(Sender: TObject);
begin
    Girlsapplicants;
    Boysapplicants;
       end;

procedure TfrmAppRep.btnPrintBClick(Sender: TObject);
begin
    DataModule1.rep.Filename := 'C:\Users\janine\Documents\DOMS\Reports\BoysApplicantRep.rep';
    DataModule1.rep.Report.Params.Items[0].Value := txtSearch2.Text;
    DataModule1.rep.Report.Params.Items[1].Value := cmbSem.Text;
    DataModule1.rep.Report.Params.Items[2].Value := 'Male';
    DataModule1.rep.Preview := True;
    DataModule1.rep.Execute();
end;

procedure TfrmAppRep.viewBoysSem;
var newState : TListItem;
begin
        if DataModule1.tr.InTransaction then
           DataModule1.tr.Commit;

           DataModule1.query.SQL.Clear;
           DataModule1.query.SQL.Add('SELECT APPID,STUDENT_ID,APP_LNAME,APP_FNAME,MIDDLE_NAME,GENDER,APP_BDAY,PERMANENT_ADD,YEAR_COURSE,APP_SCHOLARSHIP,APP_STATUS,ACADYR,SEM,DATEAPPLIED,CONTACTPERSON,MOBILE_NO,RELATIONSHIP,CONTACT_ADD');
           DataModule1.query.SQL.Add('FROM APPLICANTS WHERE ACADYR = :A AND SEM = :B AND GENDER = :C ORDER BY APPID');
           DataModule1.query.Params.AsString[0] := trim(txtSearch2.Text);
           DataModule1.query.Params.AsString[1] := 'Second Semester';
           DataModule1.query.Params.AsString[2] := 'Male';
           DataModule1.query.Prepare;
           DataModule1.query.Open();
           lvBoysApp.Items.BeginUpdate;
           lvBoysApp.Items.Clear;

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

                      newState := lvBoysApp.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]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
                      newState.SubItems.Add(DataModule1.query.Fields.AsString[17]);
                      DataModule1.query.Next;
                  end;
                      if DataModule1.tr.InTransaction then
                        DataModule1.tr.Commit;
                         lvBoysApp.Items.EndUpdate;
end;


procedure TfrmAppRep.viewBoysFirstSem;
var newState : TListItem;
begin
      if DataModule1.tr.InTransaction then
        DataModule1.tr.Commit;

        DataModule1.query.SQL.Clear;
        DataModule1.query.SQL.Add('SELECT APPID,STUDENT_ID,APP_LNAME,APP_FNAME,MIDDLE_NAME,GENDER,APP_BDAY,PERMANENT_ADD,YEAR_COURSE,APP_SCHOLARSHIP,APP_STATUS,ACADYR,SEM,DATEAPPLIED,CONTACTPERSON,MOBILE_NO,RELATIONSHIP,CONTACT_ADD');
        DataModule1.query.SQL.Add('FROM APPLICANTS WHERE ACADYR = :A AND SEM = :B AND GENDER = :C ORDER BY APPID');
        DataModule1.query.Params.AsString[0] := trim(txtSearch2.Text);
        DataModule1.query.Params.AsString[1] := 'First Semester';
        DataModule1.query.Params.AsString[2] := 'Male';
        DataModule1.query.Prepare;
        DataModule1.query.Open();
        lvBoysApp.Items.BeginUpdate;
        lvBoysApp.Items.Clear;

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

            newState := lvBoysApp.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]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[12]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[13]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[14]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[15]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[16]);
            newState.SubItems.Add(DataModule1.query.Fields.AsString[17]);
            DataModule1.query.Next;
end;
            if DataModule1.tr.InTransaction then
            DataModule1.tr.Commit;
            lvBoysApp.Items.EndUpdate;
end;

procedure TfrmAppRep.btnSearch2Click(Sender: TObject);
begin
 if (cmbSem.Text = 'First Semester') then
          begin
                  viewBoysFirstSem;
          end
            else if (cmbSem.Text = 'Second Semester') then
            begin
                  viewBoysSem;
            end
                 else  begin
                    MessageDlg('Please input first the textbox when searching.',mtInformation,[mbOK],0);
                end;
end;

end.
