home *** CD-ROM | disk | FTP | other *** search
- { MastApp Main Window.
-
- By default, the database component's alias is DBDEMOS, and so the
- application accesses the Paradox tables. To upsize the application
- to Local Interbase Server, take the following steps:
-
- 1 Pull down the Tools menu, launch Database Desktop and select its
- File|Aliases... to create a new alias. Press the NEW button and name
- the alias MASTSQL. Set the alias type to INTRBASE and specify a server
- name of C:\DELPHI\DEMOS\DATA\MASTSQL.GDB. Set the user name to SYSDBA
- and then press KEEP NEW.
-
- 2 Enter the password "masterkey" (it MUST be entered in lowercase) and
- press CONNECT in order to validate the alias you have just created.
- (If you cannot connect, make sure the IBLOCAL bin directory is on your
- DOS path and you specified the correct location for the MASTSQL.GDB
- file. If you still cannot connect, refer to INSTALL.TXT and README.TXT
- for more information.)
-
- Press DISCONNECT, OK and then answer YES when asked whether to save
- these changes in your configuration file.
-
- 3 Close the Database Desktop and return to Delphi. Close the project (in
- order to close all open forms) then and re-open it by selecting
- MASTAPP.DPR from the pick list at the bottom of the File menu.
- Select the database component in the lower left corner of the MainForm
- and set its Connected property to False. Click on the AliasName property's
- dropdown list and select MASTSQL. (If MASTSQL is not listed, go back to
- the Database Desktop and make sure you can connect from there). Finally,
- set the Database component's Connected property to True, enter the
- password ("masterkey") and run.
-
- You've just "upsized" MASTAPP to a client-server application! To switch
- between the desktop and SQL versions, close all units and forms (the easiest
- way is to close and re-open the project as instructed above), use the
- Object Inspector to set MainForm.Database's Connected property to False, pick
- an AliasName (DBDEMOS to use the Paradox database, MASTSQL to use
- the Local InterBase Server version), and set Connected to True.
- Now you're ready to run.
- }
-
- unit Main;
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Buttons, StdCtrls, Menus, ExtCtrls, DB, Report;
-
- type
- TMainForm = class(TForm)
- MainPanel: TPanel;
- OrderBtn: TSpeedButton;
- BrowseBtn: TSpeedButton;
- PartsBtn: TSpeedButton;
- CloseBtn: TSpeedButton;
- ReportBtn: TSpeedButton;
- Database: TDatabase;
- MainMenu1: TMainMenu;
- File1: TMenuItem;
- PrinterSetup1: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- NewOrder2: TMenuItem;
- N5: TMenuItem;
- View1: TMenuItem;
- Orders1: TMenuItem;
- PartsInventiry1: TMenuItem;
- Help1: TMenuItem;
- About1: TMenuItem;
- N7: TMenuItem;
- StayOnTop2: TMenuItem;
- PrintReport1: TMenuItem;
- HelpBtn: TSpeedButton;
- Report: TReport;
- Report11: TMenuItem;
- Report21: TMenuItem;
- N6: TMenuItem;
- Contents1: TMenuItem;
- PrinterSetup: TPrinterSetupDialog;
- Invoice: TMenuItem;
- procedure BrowseCustOrd(Sender: TObject);
- procedure CloseApp(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure BrowseParts(Sender: TObject);
- procedure ToggleStayonTop(Sender: TObject);
- procedure NewOrder(Sender: TObject);
- procedure HelpBtnClick(Sender: TObject);
- procedure PrinterSetupClick(Sender: TObject);
- procedure AboutClick(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure ReportBtnClick(Sender: TObject);
- procedure OrderReport(Sender: TObject);
- procedure CustomerReport(Sender: TObject);
- procedure InvoiceReport(Sender: TObject);
- private
- procedure UpdateRSConnect(const Dbpath:string);
- procedure InitRSRUN;
- procedure SetReportPreview;
- end;
-
- var
- MainForm: TMainForm;
-
- implementation
-
- uses CustOrd, BrParts, EdOrders, About, PickRep, Custqry, IniFiles;
-
- {$R *.DFM}
-
- procedure TMainForm.BrowseCustOrd(Sender: TObject);
- begin
- BrCustOrdForm.Show;
- end;
-
- procedure TMainForm.CloseApp(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TMainForm.UpdateRSConnect(const Dbpath: string);
- const
- TiniFilename = 'RPTSMITH.CON'; {ReportSmith connections file}
- AppConTitle = 'MASTAPP';
- SQLConTitle = 'MASTSQL';
- ConnectNamesSection = 'ConnectNamesSection';
- ConnectNamesKey = 'ConnectNames';
- MASTAPPSection = 'MASTAPP';
- MASTSQLSection = 'MASTSQL';
- TypeKey = 'Type';
- ServerKey = 'Server';
- SQLTypeVal = 67;
- SQLServerVal = 'IBLOCAL';
- SQLDataFilePathKey = 'Database';
- SQLUseridKey = 'USERID';
- SQLUseridVal = 'SYSDBA';
- TypeVal = 61;
- ServerVal = 'PARADOX';
- DataFilePathKey = 'DataFilePath';
- var
- TempStr,
- ConFile: string[127];
- RSCON: TIniFile;
- begin
- { the ReportSmith CON file is actually an INI file -- assumes in win dir}
- RSCon := TIniFile.Create(TiniFilename);
- TempStr := RSCon.ReadString(ConnectNamesSection, ConnectNamesKey, '');
- if Database.IsSQLBased then { CON file contents differs for SQL connections }
- begin
- if Pos(SQLConTitle,TempStr) = 0 then
- begin
- if TempStr <> '' then
- TempStr := TempStr + ',';
- RSCon.WriteString(ConnectNamesSection, ConnectNamesKey, TempStr+SQLConTitle);
- end;
- RSCon.WriteInteger(MASTSQLSection, TypeKey, SQLTypeVal);
- RSCon.WriteString(MASTSQLSection, SQLDataFilePathKey, DBpath);
- RSCon.WriteString(MASTSQLSection, ServerKey, SQLServerVal);
- RSCon.WriteString(MASTSQLSection, SQLUseridKey, SQLUseridVal);
- end
- else
- begin
- if Pos(AppConTitle,TempStr) = 0 then
- begin
- if TempStr <> '' then
- TempStr := TempStr + ',';
- RSCon.WriteString(ConnectNamesSection, ConnectNamesKey, TempStr+AppConTitle);
- end;
- RSCon.WriteInteger(MASTAPPSection, TypeKey, TypeVal);
- RSCon.WriteString(MASTAPPSection, DataFilePathKey, DBpath);
- RSCon.WriteString(MASTAPPSection, ServerKey, ServerVal);
- end;
- RSCon.Free;
- end;
-
- procedure TMainForm.InitRSRUN;
- var
- ParamList: TStringList;
- DBPath: string[127];
- begin
- Report.ReportDir := ExtractFilePath(Application.ExeName);
- { get the actual location of the database from the alias,
- the path is needed for the reports -- assumes alias is defined }
- ParamList := TStringList.Create;
- try
- Session.GetAliasParams(Database.AliasName, ParamList);
- if Database.IsSQLBased then
- DBPath := ParamList.Values['SERVER NAME']
- else
- DBPath := ParamList.Values['PATH'];
- finally
- ParamList.Free;
- end;
- { set up the ReportSmith "connection" identifying the database location }
- UpdateRSConnect(DBPath);
- end;
-
- procedure TMainForm.FormCreate(Sender: TObject);
- var W: longint;
- begin
- ClientWidth := CloseBtn.Left + CloseBtn.Width - 1;
- ClientHeight := CloseBtn.Top + CloseBtn.Height - 1;
- MainPanel.Align := alClient;
- { position the form at the top of display }
- Left := 0;
- Top := 0;
- { initialize ReportSmith }
- InitRSRUN;
- end;
-
- procedure TMainForm.BrowseParts(Sender: TObject);
- begin
- BrPartsForm.Show;
- end;
-
-
- procedure TMainForm.ToggleStayonTop(Sender: TObject);
- begin
- with Sender as TMenuItem do
- begin
- Checked := not Checked;
- if Checked then MainForm.FormStyle := fsStayOnTop
- else MainForm.FormStyle := fsNormal;
- end;
- end;
-
- procedure TMainForm.NewOrder(Sender: TObject);
- begin
- OrderForm.Enter;
- ClientHeight := CloseBtn.Height - 1;
- end;
-
- procedure TMainForm.HelpBtnClick(Sender: TObject);
- begin
- Application.HelpCommand(HELP_CONTENTS,0);
- end;
-
- procedure TMainForm.PrinterSetupClick(Sender: TObject);
- begin
- PrinterSetup.Execute;
- end;
-
- procedure TMainForm.AboutClick(Sender: TObject);
- begin
- AboutBox.ShowModal;
- end;
-
- procedure TMainForm.FormDestroy(Sender: TObject);
- begin
- Application.HelpCommand(HELP_QUIT,0);
- end;
-
- procedure TMainForm.ReportBtnClick(Sender: TObject);
- begin
- if PickRpt.ShowModal = mrOK then
- begin
- if PickRpt.OrderRadBtn.Checked then
- OrderReport(nil)
- else if PickRpt.CustRadBtn.Checked then
- CustomerReport(nil)
- else
- InvoiceReport(nil);
- Report.Preview := False;
- end;
- end;
-
- procedure TMainForm.SetReportPreview;
- begin
- if Report.Preview then
- ShowWindow(Report.ReportHandle, SW_SHOWNORMAL)
- else
- ShowWindow(Report.ReportHandle, SW_SHOWMINIMIZED);
- end;
-
- procedure TMainForm.OrderReport(Sender: TObject);
- begin
- with CustQueryDlg do
- begin
- MsgLab.Caption := 'Print all orders ranging:';
- if FromDate = 0 then FromDate := Now;
- if ToDate = 0 then ToDate := Now;
- if ShowModal = mrOk then with Report do
- begin
- if Database.IsSQLBased then
- ReportName := 'ORDERSQL.RPT'
- else
- ReportName := 'ORDERHST.RPT';
- InitialValues.Clear;
- InitialValues.Add('@startdate=<''' + FormatDateTime('mm"/"dd"/"yy', FromDate) + '''>');
- InitialValues.Add('@enddate=<''' + FormatDateTime('mm"/"dd"/"yy', ToDate) + '''>');
- SetReportPreview;
- Run;
- end;
- end;
- end;
-
- procedure TMainForm.CustomerReport(Sender: TObject);
- begin
- with Report do
- begin
- InitialValues.Clear;
- if Database.IsSQLBased then
- ReportName := 'CUSTSQL.RPT'
- else
- ReportName := 'CUSTLIST.RPT';
- SetReportPreview;
- Run;
- end;
- end;
-
- procedure TMainForm.InvoiceReport(Sender: TObject);
- begin
- with Report do
- begin
- InitialValues.Clear;
- if Database.IsSQLBased then
- ReportName := 'INVSQL.RPT'
- else
- ReportName := 'INVOICE.RPT';
- SetReportPreview;
- Run;
- end;
- end;
-
- end.
-