unit unitMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, ExtCtrls, Menus, ComCtrls, jpeg, StdCtrls;

type
  TDORM = class(TForm)
    Label3: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    Image1: TImage;
    StatusBar1: TStatusBar;
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Login1: TMenuItem;
    Logout1: TMenuItem;
    View1: TMenuItem;
    Occupants1: TMenuItem;
    Applicants1: TMenuItem;
    StudentLogged1: TMenuItem;
    Houseparent1: TMenuItem;
    ManageRooms1: TMenuItem;
    RoomAvailability1: TMenuItem;
    RoomAssignment1: TMenuItem;
    Building1: TMenuItem;
    ManageAccounts1: TMenuItem;
    CreateAccounts1: TMenuItem;
    ViewUser1: TMenuItem;
    Reports1: TMenuItem;
    StudentLogged2: TMenuItem;
    Timer1: TTimer;
    ImageList1: TImageList;
    ApplicantsReport1: TMenuItem;
    Occupants2: TMenuItem;
    Exit1: TMenuItem;
    StudentLog1: TMenuItem;
    AddNewFacility1: TMenuItem;
    RoomAvailability2: TMenuItem;
    AboutUs1: TMenuItem;
    procedure Login1Click(Sender: TObject);
    procedure Occupants1Click(Sender: TObject);
    procedure Applicants1Click(Sender: TObject);
    procedure StudentLogged1Click(Sender: TObject);
    procedure Houseparent1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
       procedure RoomAssignment1Click(Sender: TObject);
    procedure Building1Click(Sender: TObject);
    procedure ViewUser1Click(Sender: TObject);
    procedure CreateAccounts1Click(Sender: TObject);
    procedure StudentLogged2Click(Sender: TObject);
    procedure ApplicantsReport1Click(Sender: TObject);
    procedure Logout1Click(Sender: TObject);
    procedure Exit1Click(Sender: TObject);
    procedure Occupants2Click(Sender: TObject);
    procedure StudentLog1Click(Sender: TObject);
    procedure AddNewFacility1Click(Sender: TObject);
    procedure RoomAvailability2Click(Sender: TObject);
  private
    { Private declarations }
  public
        path : String;
        rep : String;
        procedure connectDB;
        procedure writeDB;

  end;

var
  DORM: TDORM;
  systemDate : TDateTime;
        DateTimeformat : string;
implementation

uses DM, unitLogin, unitOcc, unitApplicants, unitStuLogged, unitStudentLog,
  unitHouseparent, unitRoom, unitCleanerAss, unitBuilding, unitUserList,
  unitCreateAcc, unitStuDRep, unitApplicantRep, unitOccupantRep,
  unitRMFacility;

{$R *.dfm}

procedure TDORM.connectDB;
var dbName,dbPass:String;
    dbPath:TextFile;
begin
    try
        AssignFile(dbPath,'path.txt');
        Reset(dbPath);
        ReadLn(dbPath,dbName);
        DataModule1.database.DatabaseName:=dbName;
        ReadLn(dbPath,dbPass);
        DataModule1.database.PassWord:=dbPass;
        DataModule1.database.Connected:=True;
        CloseFile(dbPath);
    except
        ON e:Exception do begin
            ShowMessage('Error:Database File Not Found');
            Close;
        end;
    end;
end;

procedure TDORM.writeDB();
var dbPath:TextFile;
begin
        AssignFile(dbPath,'path.txt');
        Rewrite(dbPath);
        Writeln(dbPath,path+'\DORMITORY_SYSTEM.FDB');
        Writeln(dbPath,'masterkey');
        CloseFile(dbPath);
end;

procedure TDORM.FormShow(Sender: TObject);
begin
      DateTimeToString(DateTimeformat, 'dddddd', now());
      Label3.Caption := DateTimeformat;
      StatusBar1.Panels.Items[2].Text := 'Date --' + label3.Caption;

       path:=GetCurrentDir;
       rep:=GetCurrentDir+'\Reports\';
       writeDB;
       connectDb;

       DORM.View1.Enabled := False;
       DORM.StudentLog1.Enabled := True;
       DORM.ManageRooms1.Enabled := False;
       DORM.ManageAccounts1.Enabled := False;
       DORM.Reports1.Enabled := False;
       DORM.Logout1.Enabled := False;
       DORM.Login1.Enabled := True;
       DORM.Reports1.Enabled := False;
end;


procedure TDORM.Login1Click(Sender: TObject);
begin
         frmLogin.ShowModal;
end;

procedure TDORM.Occupants1Click(Sender: TObject);
begin
       frmOcc.ShowModal;
end;

procedure TDORM.Applicants1Click(Sender: TObject);
begin
      frmApplicants.ShowModal;
end;

procedure TDORM.StudentLogged1Click(Sender: TObject);
begin
      frmStudentLogged.ShowModal;
end;

procedure TDORM.Houseparent1Click(Sender: TObject);
begin
      frmHouseparent.ShowModal;
end;

procedure TDORM.RoomAssignment1Click(Sender: TObject);
begin
    frmCleanerAssign.ShowModal;
end;

procedure TDORM.Building1Click(Sender: TObject);
begin
      frmBuilding.ShowModal;
end;

procedure TDORM.ViewUser1Click(Sender: TObject);
begin
      frmUser.ShowModal;
end;

procedure TDORM.CreateAccounts1Click(Sender: TObject);
begin
      frmCreateAcc.ShowModal;
end;

procedure TDORM.StudentLogged2Click(Sender: TObject);
begin
      frmStuDrep.ShowModal;
end;

procedure TDORM.ApplicantsReport1Click(Sender: TObject);
begin
      frmAppRep.ShowModal;
end;

procedure TDORM.Logout1Click(Sender: TObject);
begin
    DORM.View1.Enabled := False;
    DORM.StudentLog1.Enabled := True;
    DORM.ManageRooms1.Enabled := False;
    DORM.ManageAccounts1.Enabled := False;
    DORM.Logout1.Enabled := False;
    DORM.Login1.Enabled := True;
    DORM.Reports1.Enabled := False;
end;

procedure TDORM.Exit1Click(Sender: TObject);
begin
    Close;
end;

procedure TDORM.Occupants2Click(Sender: TObject);
begin
      frmOccRep.ShowModal;
end;
procedure TDORM.StudentLog1Click(Sender: TObject);
begin
    StudentLog.ShowModal;
end;

procedure TDORM.AddNewFacility1Click(Sender: TObject);
begin
      frmRmFac.ShowModal;
end;

procedure TDORM.RoomAvailability2Click(Sender: TObject);
begin
frmRoom.ShowModal;
end;

end.
