home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Report Writers / Crystal Repot 9.0 Full CD version / Setup.exe / Tools / Developers / PEDELF32.ZIP / pedelf32 / SETLOC.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1998-09-30  |  6.5 KB  |  190 lines

  1. unit SetLoc;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, CRDelphi, ExtCtrls;
  8.  
  9. type
  10.   TFrmSetLoc = class(TForm)
  11.     pnlTables: TPanel;
  12.     lblTableNumber: TLabel;
  13.     lbTableNumbers: TListBox;
  14.     pnlTables2: TPanel;
  15.     lblTableName: TLabel;
  16.     lblTablePath: TLabel;
  17.     lblTableType: TLabel;
  18.     lblTableDLLName: TLabel;
  19.     lblTableDescriptiveName: TLabel;
  20.     editTableName: TEdit;
  21.     btnSetName: TButton;
  22.     editTablePath: TEdit;
  23.     btnSetPath: TButton;
  24.     editTablePassword: TEdit;
  25.     editTableTableType: TEdit;
  26.     editTableDLLName: TEdit;
  27.     editTableDescriptiveName: TEdit;
  28.     SetLocation: TButton;
  29.     BitBtn1: TBitBtn;
  30.     OpenDialog1: TOpenDialog;
  31.     Label1: TLabel;
  32.     EditTableUserID: TEdit;
  33.     Label2: TLabel;
  34.     EditDBPassword: TEdit;
  35.     lkj: TLabel;
  36.     procedure btnSetNameClick(Sender: TObject);
  37.     procedure btnSetPathClick(Sender: TObject);
  38.     procedure FormShow(Sender: TObject);
  39.     procedure lbTableNumbersClick(Sender: TObject);
  40.     procedure SetLocationClick(Sender: TObject);
  41.   private
  42.     { Private declarations }
  43.   public
  44.     { Public declarations }
  45.   end;
  46.  
  47. var
  48.   FrmSetLoc: TFrmSetLoc;
  49.  
  50. implementation
  51.  
  52. uses UnitPath, Main;
  53.  
  54. {$R *.DFM}
  55.  
  56. procedure TFrmSetLoc.btnSetNameClick(Sender: TObject);
  57. begin
  58.   {Set the dialog default filename, filter and title}
  59.   OpenDialog1.FileName := '*' + ExtractFileExt(editTableName.Text);
  60.   OpenDialog1.Filter := 'Database Files (*' + UpperCase(OpenDialog1.FileName)
  61.      + ')|*' + OpenDialog1.FileName + '|' + 'All files (*.*)|*.*';
  62.   OpenDialog1.Title := 'Choose New Table...';
  63.   OpenDialog1.InitialDir := editTablePath.Text;
  64.   if OpenDialog1.Execute then
  65.   begin
  66.     Refresh;
  67.     editTableName.Text := ExtractFileName(OpenDialog1.FileName);
  68.     editTablePath.Text := ExtractFilePath(OpenDialog1.FileName);
  69.   end;
  70. end;
  71.  
  72. procedure TFrmSetLoc.btnSetPathClick(Sender: TObject);
  73. begin
  74.   dlgTablePath := TdlgTablePath.Create(Application);
  75.   dlgTablePath.ShowModal;
  76.   dlgTablePath.Release;
  77. end;
  78.  
  79. procedure TFrmSetLoc.FormShow(Sender: TObject);
  80. var
  81.    i, NumTables : integer; {used for looping}
  82. begin
  83. {check for a valid job number first}
  84. LBTableNumbers.Items.Clear;
  85. if Main.JobNumber > 0 Then
  86. begin
  87.    {Get Number of Tables}
  88.    NumTables := PEGetNTables (Main.JobNumber);
  89.  
  90.    {Fill List Box with Table Count}
  91.    for i := 1 to NumTables do
  92.      LBTableNumbers.Items.Add (IntToStr (i));
  93.  
  94.    LBTableNumbers.itemindex := 0;
  95.    lbTableNumbersClick(Sender);
  96. end;
  97. end;
  98.  
  99. procedure TFrmSetLoc.lbTableNumbersClick(Sender: TObject);
  100.  
  101. var
  102.   TableLocation : PETableLocation; {table location structure}
  103.   TableType : PETableType;  {Table info structure}
  104.   SessionInfo : PESessionInfo;
  105.  
  106. begin
  107.    {Retrieve table name and directory path}
  108.    TableLocation.StructSize := SizeOf (PETableLocation);
  109.    PEGetNthTableLocation (Main.JobNumber,LBTableNumbers.ItemIndex, TableLocation);
  110.    EditTableName.Text := ExtractFileName (StrPas (TableLocation.Location));
  111.    EditTablePath.Text := ExtractFilePath (StrPas (TableLocation.Location));
  112.  
  113.    {Retreive table information}
  114.    TableType.StructSize := SizeOf (PeTableType);
  115.    PEGetNthTableType (Main.JobNumber, LBTableNumbers.ItemIndex,TableType);
  116.    EditTableDllName.Text := TableType.DLLName;
  117.    EditTableDescriptiveName.Text := StrPas (TableType.DescriptiveName);
  118.    case TableType.DBType of
  119.    1 : EditTableTableType.Text := 'Standard';
  120.    2 : EditTableTableType.Text := 'SQL';
  121.    3 : EditTableTableType.Text := 'Unknown'; {this should never be used}
  122.    end;
  123.  
  124.    {If table is access or paradox enable the userid and password boxes}
  125.    if EditTableDllName.Text = 'pdbbde.dll' then
  126.       {Check for paradox}
  127.       begin
  128.          {since password not saved in report change text and enable}
  129.          {Paradox does not use a userID}
  130.           editTablePassword.enabled := True;
  131.           editTablePassword.Text := '';
  132.       end
  133.    else if EditTableDllName.Text = 'PDBDAO.DLL' then
  134.       {Check for access tables, and retrieve userid}
  135.       begin
  136.           SessionInfo.StructSize := SizeOf (PeSessionInfo);
  137.           PEGetNthTableSessionInfo (Main.JobNumber, LBTableNumbers.ItemIndex, SessionInfo);
  138.           EditTablePassword.enabled := True;
  139.           EditTablePassword.Text := '';
  140.           EditDBPassword.Enabled := True;
  141.           EditDBPassword.Text := '';
  142.           EditTableUserID.Enabled := True;
  143.           EditTableUserID.Text := SessionInfo.UserID;
  144.       end;
  145. end;
  146.  
  147. procedure TFrmSetLoc.SetLocationClick(Sender: TObject);
  148. var
  149.   TableLocation : PETableLocation; {table location structure}
  150.   LogOnInfo : PELogOnInfo; {Paradox password set through logoninfo structure}
  151.   SessionInfo : PESessionInfo; {The access session info for passwords}
  152.  
  153. begin
  154.    {Retrieve table name and directory path}
  155.    TableLocation.StructSize := SizeOf (PETableLocation);
  156.    StrPCopy (TableLocation.Location, EditTablePath.Text + EditTableName.Text);
  157.    PESetNthTableLocation (Main.JobNumber,LBTableNumbers.ItemIndex, TableLocation);
  158.  
  159.    {If Paradox or access tables check if a password has been entered}
  160.    {If password entered send to the print job}
  161.    if (EditTableDllName.Text = 'pdbbde.dll') and not (editTablePassword.Text = '') then
  162.    begin
  163.       {Paradox password set through log on info}
  164.       LogOnInfo.StructSize := SizeOf (PELogOnInfo);
  165.       {Get the logoninfo structure to fill the report}
  166.       PEGetNthTableLogOnInfo (Main.JobNumber,LBTableNumbers.ItemIndex, LogOnInfo);
  167.  
  168.       {copy the password to logoninfostructure and pass to the report}
  169.       StrPCopy (LogOnInfo.Password,editTablePassword.Text);
  170.       PESetNthTableLogOnInfo (Main.JobNumber,LBTableNumbers.ItemIndex, LogOnInfo, False);
  171.    end
  172.    else if EditTableDllName.Text = 'PDBDAO.DLL' then
  173.      if (not (EditTablePassword.Text = '')) or (not (EditDBPassword.Text = '')) then
  174.       {Check to see if any of the passwords have been set}
  175.       begin
  176.          SessionInfo.StructSize := SizeOf (PeSessionInfo);
  177.  
  178.          {Fill Sessioninfo structure from report}
  179.          PEGetNthTableSessionInfo (Main.JobNumber, LBTableNumbers.ItemIndex, SessionInfo);
  180.  
  181.          {Set the username and password.  The DBPassword is set by preceding with}
  182.          {a carriage return}
  183.          StrPCopy (SessionInfo.PassWord,EditTablePassword.Text+ Chr (10) + EditDBPassword.Text);
  184.          StrPCopy (SessionInfo.UserID, EditTableUserID.Text);
  185.          PESetNthTableSessionInfo (Main.JobNumber, LBTableNumbers.ItemIndex, SessionInfo,True);
  186.       end;
  187. end;
  188.  
  189. end.
  190.