www.pudn.com > fbdelphisw > providersDB.pas


unit providersDB; 
 
interface 
  uses stdctrls,sysutils,mainunit; 
Type 
  TProviders = 
      Record 
        CountryCode   : String[3]; 
        ProviderCode  : String[2]; 
        ProviderName  : String[25]; 
        Country       : String[25]; 
      end; 
var 
  sProviderCountry:string; 
 
  procedure LoadCountry(cmboCountry:TComboBox); 
  procedure LoadProvider(cmboProvider:TComboBox;sCountry:String); 
  procedure LoadCode(txtCountry,txtcode:TEdit;sProvider,sCountry:String); 
implementation 
 
procedure LoadCountry(cmboCountry:TComboBox); 
var 
  Provider : TProviders; 
  iLastPos:Longint; 
  fFile:File; 
  sLastCountry:String; 
begin 
  iLastPos:=0; 
  sLastCountry:=''; 
 
  cmboCountry.items.clear; 
 
  assignfile(fFile,frmMain.sApplicationPath+'Providers.da0'); 
  Reset(fFile,1); 
 
  while iLastPos <= (filesize(fFile)-sizeof(Provider)) do 
    begin 
      seek(fFile,iLastPos); 
      BlockRead(fFile,Provider,sizeof(Provider)); 
      iLastPos:=iLastPos+sizeof(Provider); 
      if sLastCountry <> Provider.Country then 
        cmboCountry.items.add(Provider.Country); 
 
      sLastCountry:=Provider.Country; 
    end; 
 
  closeFile(fFile); 
  cmboCountry.itemindex:=0; 
end; 
 
procedure LoadProvider(cmboProvider:TComboBox ;sCountry:String); 
var 
  Provider : TProviders; 
  iLastPos:Longint; 
  fFile:File; 
  sLastCountry:String; 
begin 
  iLastPos:=0; 
  sLastCountry:=''; 
 
  assignfile(fFile,frmMain.sApplicationPath+'Providers.da0'); 
  Reset(fFile,1); 
 
  cmboProvider.items.clear; 
  cmboProvider.text:=''; 
 
  while iLastPos <= (filesize(fFile)-sizeof(Provider)) do 
    begin 
      seek(fFile,iLastPos); 
      BlockRead(fFile,Provider,sizeof(Provider)); 
      iLastPos:=iLastPos+sizeof(Provider); 
      if Provider.Country = sCountry then 
        begin 
          cmboProvider.items.add(Provider.ProviderName); 
          sProviderCountry:=Provider.Country; 
        end; 
 
      sLastCountry:=Provider.Country; 
    end; 
 
  closeFile(fFile); 
  cmboProvider.itemindex:=0; 
end; 
 
procedure LoadCode(txtCountry,txtcode:TEdit;sProvider,sCountry:String); 
var 
  Provider : TProviders; 
  iLastPos:Longint; 
  fFile:File; 
  sLastCountry:String; 
begin 
  iLastPos:=0; 
  sLastCountry:=''; 
 
  assignfile(fFile,frmMain.sApplicationPath+'Providers.da0'); 
  Reset(fFile,1); 
 
  txtCountry.text:=''; 
  txtcode.text:=''; 
 
  while iLastPos <= (filesize(fFile)-sizeof(Provider)) do 
    begin 
      seek(fFile,iLastPos); 
      BlockRead(fFile,Provider,sizeof(Provider)); 
      iLastPos:=iLastPos+sizeof(Provider); 
      if (Provider.ProviderName = sProvider) and (sCountry =Provider.Country)  then 
        begin 
          txtCountry.text:=Provider.CountryCode; 
          txtcode.text:=Provider.ProviderCode; 
        end; 
    end; 
 
  closeFile(fFile); 
end; 
 
end.