unit MegaDemoClient_Main; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, uROClient, uROClientIntf, uRORemoteService, uROBinMessage, ComCtrls, uROPoweredByRemObjectsButton, uDAPoweredByDataAbstractButton, ExtCtrls, Grids, DBGrids, DBCtrls, ActnList; type TMegaDemoClient_MainForm = class(TForm) PageControl1: TPageControl; tpLogin: TTabSheet; tpCustomerManagement: TTabSheet; tpBank: TTabSheet; Label1: TLabel; DAPoweredByDataAbstractButton1: TDAPoweredByDataAbstractButton; sslPageHint: TStatusBar; GroupBox1: TGroupBox; Label2: TLabel; Label3: TLabel; tbUserName: TEdit; tbPassword: TEdit; bLogin: TButton; bLogout: TButton; GroupBox2: TGroupBox; Label4: TLabel; rbPreDefLogin1: TRadioButton; rbPreDefLogin2: TRadioButton; rbPreDefLogin3: TRadioButton; Label5: TLabel; rbPreDefLogin4: TRadioButton; rbPreDefLogin5: TRadioButton; rbPreDefLogin6: TRadioButton; Panel1: TPanel; DBNavigator1: TDBNavigator; gCustomers: TDBGrid; tsbApplyUpdatesCustomers: TButton; ActionList1: TActionList; aApplyUpdate: TAction; gOrdersByCustomer: TDBGrid; Splitter1: TSplitter; procedure bLoginClick(Sender: TObject); procedure bLogoutClick(Sender: TObject); procedure rbPreDefLoginClick(Sender: TObject); procedure PageControl1Changing(Sender: TObject; var AllowChange: Boolean); procedure FormShow(Sender: TObject); procedure PageControl1Change(Sender: TObject); procedure aApplyUpdateExecute(Sender: TObject); procedure aApplyUpdateUpdate(Sender: TObject); private { Private declarations } procedure PrivilegesSetup; public { Public declarations } end; var MegaDemoClient_MainForm: TMegaDemoClient_MainForm; implementation uses MegaDemoClient_Data, MegaDemoLibrary_Intf, uDADataTable; {$R *.dfm} procedure TMegaDemoClient_MainForm.bLoginClick(Sender: TObject); var serverLoginInfo: LoginInfo; begin bLogout.Click; // Forces a logout click if (MegaDemoClient_DataModule.fLoginService.Login(tbUserName.Text, tbPassword.Text, serverLoginInfo) = false) then begin ShowMessage('Invalid login'); end else begin if MegaDemoClient_DataModule.fLoginInfo <> nil then MegaDemoClient_DataModule.fLoginInfo.Free; MegaDemoClient_DataModule.fLoginInfo := serverLoginInfo; ShowMessage('Welcome ' + MegaDemoClient_DataModule.fLoginInfo.JobTitle + ' ' + MegaDemoClient_DataModule.fLoginInfo.FirstName); MegaDemoClient_DataModule.tbl_Customers.Close; MegaDemoClient_DataModule.tbl_Customers.Open; bLogin.Enabled := false; bLogout.Enabled := true; end; PrivilegesSetup; end; procedure TMegaDemoClient_MainForm.bLogoutClick(Sender: TObject); begin PrivilegesSetup; if not MegaDemoClient_DataModule.LoggedIn then Exit; if MegaDemoClient_DataModule.FLoginInfo <> nil then FreeAndNil(MegaDemoClient_DataModule.FLoginInfo); MegaDemoClient_DataModule.tbl_Customers.Close; MegaDemoClient_DataModule.tbl_OrdersByCustomer.Close; bLogin.Enabled := true; bLogout.Enabled := false; end; procedure TMegaDemoClient_MainForm.rbPreDefLoginClick(Sender: TObject); var senderRadioButton: TRadioButton; ctrlLabel: string; textIdx: integer; begin senderRadioButton := sender as TRadioButton; if (senderRadioButton.Checked) then begin ctrlLabel := senderRadioButton.Caption; textIdx := pos('/', ctrlLabel); tbUserName.Text := copy(ctrlLabel, 1, textIdx - 1); tbPassword.Text := copy(ctrlLabel, textIdx + 1, Pos(' ', ctrlLabel) - textIdx - 1); end; end; procedure TMegaDemoClient_MainForm.PageControl1Changing(Sender: TObject; var AllowChange: Boolean); begin if (not MegaDemoClient_DataModule.LoggedIn) and (PageControl1.TabIndex = 0) then begin ShowMessage('You must login first'); AllowChange := False; end; end; procedure TMegaDemoClient_MainForm.PrivilegesSetup; begin tpCustomerManagement.TabVisible := MegaDemoClient_DataModule.LoggedIn; tpBank.TabVisible := MegaDemoClient_DataModule.LoggedIn and (MegaDemoClient_DataModule.fLoginInfo.Job_Type = JobType_Manager); gOrdersByCustomer.Visible := MegaDemoClient_DataModule.LoggedIn and (MegaDemoClient_DataModule.fLoginInfo.Job_Type <> JobType_Engineer); Splitter1.Visible := gOrdersByCustomer.Visible; Splitter1.top := 0; end; procedure TMegaDemoClient_MainForm.FormShow(Sender: TObject); begin PrivilegesSetup; PageControl1.ActivePage := tpLogin; PageControl1.OnChange(PageControl1); end; procedure TMegaDemoClient_MainForm.PageControl1Change(Sender: TObject); begin case ((sender as TPageControl).ActivePageIndex) of 0: sslPageHint.SimpleText := 'Login page. Click on the pre-configured logins to avoid typing a username and a password'; 1: sslPageHint.SimpleText := 'Customer magamenet page. You can view all customers and create new ones, if your privileges allow you to'; else sslPageHint.SimpleText := ''; end; end; procedure TMegaDemoClient_MainForm.aApplyUpdateExecute(Sender: TObject); begin try MegaDemoClient_DataModule.tbl_Customers.ApplyUpdates; except on e: Exception do ShowMessage(E.Message); end; end; procedure TMegaDemoClient_MainForm.aApplyUpdateUpdate(Sender: TObject); begin TAction(Sender).Enabled := MegaDemoClient_DataModule.tbl_Customers.HasDelta; end; end.