home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk15 / stocks.pak / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-08-24  |  3.8 KB  |  157 lines

  1. unit Main;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Menus, StdCtrls, ExtCtrls, DBCtrls, DB, DBTables, Report;
  8.  
  9. type
  10.   TfmMain = class(TForm)
  11.     MainMenu1: TMainMenu;
  12.     File1: TMenuItem;
  13.     PrinterSetup1: TMenuItem;
  14.     N1: TMenuItem;
  15.     exit1: TMenuItem;
  16.     View1: TMenuItem;
  17.     StockAnalysis1: TMenuItem;
  18.     N2: TMenuItem;
  19.     CustomerAddress1: TMenuItem;
  20.     CustomerCharts1: TMenuItem;
  21.     Help1: TMenuItem;
  22.     About1: TMenuItem;
  23.     Timer1: TTimer;
  24.     MarketBrowser1: TMenuItem;
  25.     Image1: TImage;
  26.     Bevel1: TBevel;
  27.     Database: TDatabase;
  28.     LabTime: TLabel;
  29.     Bevel2: TBevel;
  30.     PSetup: TPrinterSetupDialog;
  31.     procedure Timer(Sender: TObject);
  32.     procedure exit1Click(Sender: TObject);
  33.     procedure MarketBrowser1Click(Sender: TObject);
  34.     procedure CustomerCharts1Click(Sender: TObject);
  35.     procedure CustomerAddress1Click(Sender: TObject);
  36.     procedure StockAnalysis1Click(Sender: TObject);
  37.     procedure PrinterSetup1Click(Sender: TObject);
  38.     procedure About1Click(Sender: TObject);
  39.     procedure FormCreate(Sender: TObject);
  40.   private
  41.     DBPath: String[127];
  42.     procedure UpdateRSConnect;
  43.     procedure InitRSRUN;
  44.   public
  45.     function DataPath: string;
  46.   end;
  47.  
  48. var
  49.   fmMain: TfmMain;
  50.  
  51. implementation
  52.  
  53. {$R *.DFM}
  54.  
  55. uses Browser, CstChart, CustInfo, IndChart, About, IniFiles;
  56.  
  57. procedure TfmMain.UpdateRSConnect;
  58. const
  59.   TiniFilename = 'RPTSMITH.CON';   { ReportSmith connections file }
  60.   AppConTitle = 'STOCKS';
  61.   ConnectNamesSection = 'ConnectNamesSection';
  62.   ConnectNamesKey = 'ConnectNames';
  63.   StocksSection = 'STOCKS';
  64.   TypeKey = 'Type';
  65.   ServerKey = 'Server';
  66.   TypeVal = 62;
  67.   ServerVal = 'DBASE';  { databases in this application are DBFs }
  68.   DataFilePathKey = 'DataFilePath';
  69. var
  70.   TempStr,
  71.   ConFile: string[127];
  72.   RSCON: TIniFile;
  73. begin
  74.  { the ReportSmith CON file is actually an INI file -- assumes in win dir}
  75.   RSCon := TIniFile.Create(TiniFilename);
  76.   TempStr := RSCon.ReadString(ConnectNamesSection, ConnectNamesKey, '');
  77.   if Pos(AppConTitle,TempStr) = 0 then
  78.   begin
  79.     if TempStr <> '' then
  80.       TempStr := TempStr + ',';
  81.     RSCon.WriteString(ConnectNamesSection, ConnectNamesKey, TempStr+AppConTitle);
  82.   end;
  83.   RSCon.WriteInteger(StocksSection, TypeKey, TypeVal);
  84.   RSCon.WriteString(StocksSection, DataFilePathKey, DBpath);
  85.   RSCon.WriteString(StocksSection, ServerKey, ServerVal);
  86.   RSCon.Free;
  87. end;
  88.  
  89. procedure TfmMain.InitRSRUN;
  90. var
  91.   ParamList: TStringList;
  92. begin
  93.   { get the actual location of the database from the alias or database,
  94.     the path is needed for the reports -- assumes alias is defined }
  95.   ParamList := TStringList.Create;
  96.   try
  97.     Session.GetAliasParams(Database.AliasName, ParamList);
  98.     DBPath := ParamList.Values['PATH'];
  99.   finally
  100.     ParamList.Free;
  101.   end;
  102.   { set up the ReportSmith "connection" identifying the database location }
  103.   UpdateRSConnect;
  104. end;
  105.  
  106. procedure TfmMain.FormCreate(Sender: TObject);
  107. begin
  108.   InitRSRUN;
  109. end;
  110.  
  111. procedure TfmMain.Timer(Sender: TObject);
  112. begin
  113.   LabTime.Caption := DateTimeToStr(Now);
  114. end;
  115.  
  116. procedure TfmMain.exit1Click(Sender: TObject);
  117. begin
  118.   Close;
  119. end;
  120.  
  121. procedure TfmMain.MarketBrowser1Click(Sender: TObject);
  122. begin
  123.   fmMktBrowser.ShowBrowser;
  124. end;
  125.  
  126. procedure TfmMain.CustomerCharts1Click(Sender: TObject);
  127. begin
  128.   fmCustChart.ShowCharts
  129. end;
  130.  
  131. procedure TfmMain.CustomerAddress1Click(Sender: TObject);
  132. begin
  133.   fmCustInfo.Show;
  134. end;
  135.  
  136. procedure TfmMain.StockAnalysis1Click(Sender: TObject);
  137. begin
  138.   fmIndustChart.ShowCharts;
  139. end;
  140.  
  141. procedure TfmMain.PrinterSetup1Click(Sender: TObject);
  142. begin
  143.   PSetup.Execute;
  144. end;
  145.  
  146. procedure TfmMain.About1Click(Sender: TObject);
  147. begin
  148.   fmAboutBox.ShowModal;
  149. end;
  150.  
  151. function TfmMain.DataPath: string;
  152. begin
  153.    DataPath := DBPath;
  154. end;
  155.  
  156. end.
  157.