Ignore:
Timestamp:
Jun 14, 2010, 12:37:31 PM (14 years ago)
Author:
Kevin Toppenberg
Message:

Fixing uploads of PDF files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cprs/branches/tmg-cprs/CPRS-Chart/UploadImages.pas

    r793 r800  
    8484    PolTimer: TTimer;
    8585    DKLanguageController1: TDKLanguageController;
     86    btnPickPDF: TBitBtn;
    8687    procedure UploadButtonClick(Sender: TObject);
    8788    procedure PickImagesButtonClick(Sender: TObject);
     
    9596    procedure FormRefresh(Sender: TObject);
    9697    procedure PolTimerTimer(Sender: TObject);
     98    procedure btnPickPDFClick(Sender: TObject);
     99    procedure FormHide(Sender: TObject);
    97100  private
    98101    { Private declarations }
    99102    Bitmap : TBitmap;
    100103    Picture : TPicture;
     104    FAllowNonImages : boolean;
    101105    FUploadedImagesList : TStringList; //List of strings of images succesfully uploaded.
    102106    function MakeThumbNail(Info: TImageInfo): boolean;
     
    105109    //procedure LoadNotesList();
    106110    function UploadFile(Info: TImageInfo; DelOrig : boolean): boolean;
     111    function CopyFileToTemp(FNamePath : string) : string;
    107112    procedure UploadChosenFiles();
    108113    function ProcessOneLine(Line : string) : string;
     
    116121                           DOS, Provider, Title : string; FilePaths : TStrings) : AnsiString;
    117122    procedure FinishDocument(UploadNote : TAutoUploadNote);
     123    procedure SetAllowNonImages(Value : boolean);
    118124  public
    119125    { Public declarations }
     
    124130    property ScanDir : String read FScanDir write SetScanDir;
    125131    property UploadedImages : TStringList read FUploadedImagesList;
     132    property AllowNonImages : boolean read FAllowNonImages write SetAllowNonImages;
    126133  end;
    127134
     
    142149        rTIU,
    143150        rHTMLTools,
     151        fImagePickPDF, //for PDF picker dialog
    144152        uTMGOptions
    145153        ;
     
    622630    try
    623631      WebBrowser.Navigate(frmImages.NullImageName);
     632      sleep(500); //Give Webbrowser time to release any browsed document.
    624633    except
    625634      on E: Exception do exit;
     
    645654      for i := 0 to OpenFileDialog.Files.Count-1 do begin
    646655        FilesToUploadList.Items.Add(OpenFileDialog.Files.Strings[i]);
     656      end;
     657    end;
     658  end;
     659
     660  procedure TUploadForm.btnPickPDFClick(Sender: TObject);
     661  var i : integer;
     662  begin
     663    if not Assigned(frmImagePickPDF) then begin
     664      frmImagePickPDF := TfrmImagePickPDF.Create(Self);   //free'd in OnHide
     665    end;
     666    if frmImagePickPDF.Execute then begin
     667      for i := 0 to frmImagePickPDF.Files.Count-1 do begin
     668        FilesToUploadList.Items.Add(frmImagePickPDF.Files.Strings[i]);
    647669      end;
    648670    end;
     
    678700    Bitmap.Width := 64;
    679701    Picture := TPicture.Create;
    680 
     702    FAllowNonImages := true;
    681703    FUploadedImagesList := TStringList.Create;
    682704
     
    717739    if SelectedItem > -1 then begin
    718740      FileName := FilesToUploadList.Items[SelectedItem];
    719       //Application.MessageBox('Here I would pass to IE','NOte');
     741      if UpperCase(ExtractFileExt(FileName))='.PDF' then begin
     742        FileName := CopyFileToTemp(FileName);  //returns '' if copy fails
     743        if FileName = '' then FileName := frmImages.NullImageName;
     744      end;
    720745    end else begin
    721746      FileName := frmImages.NullImageName;
     
    728753  end;
    729754
     755  function TUploadForm.CopyFileToTemp(FNamePath : string) : string;
     756  var DestFile : string;
     757      lpDestFile : PAnsiChar;
     758      lpSourceFile : PAnsiChar;
     759  begin
     760    DestFile := frmImages.CacheDir + '\tempbrowseable' + ExtractFileExt(FNamePath);
     761    lpDestFile := PAnsiChar(DestFile);
     762    lpSourceFile := PAnsiChar(FNamePath);
     763    if CopyFile(lpSourcefile,lpDestFile,LongBool(FALSE)) = TRUE then begin  //0=success
     764      Result := DestFile;
     765    end else begin
     766      Result := '';
     767    end;
     768  end;
     769
    730770  procedure TUploadForm.FormRefresh(Sender: TObject);
    731771  begin
     
    735775      on E: Exception do exit;
    736776    end;
     777  end;
     778
     779  procedure TUploadForm.FormHide(Sender: TObject);
     780  begin
     781    FormRefresh(Sender);
     782    frmImagePickPDF.Free;
    737783  end;
    738784
     
    877923    i : integer;
    878924    Location : string;
    879    
     925
    880926  begin
    881927    Result := '';  //default to success for function
     
    9891035    until FindNext(Found) <> 0;   
    9901036    FindClose(Found); 
    991     FilesList.Sort;  //puts filenames in alphanumeric order 
     1037    FilesList.Sort;  //puts filenames in alphanumeric order
    9921038
    9931039    //Now process images in correct order.
     
    11571203        end;
    11581204        AllFiles.AddObject(pFInfo.FPath,pFInfo);  //Store filename, to allow sorting on this.
    1159       until FindNext(Found) <> 0;   
     1205      until FindNext(Found) <> 0;
    11601206      AllFiles.Sort; // Sort on timestamp --> put in ascending alpha filename order
    11611207
     
    11711217        if pFInfo.SBarCode <> '' then begin  //Found a new barcode
    11721218          LastFileTimeStamp := CurFileTimeStamp;
    1173           //Note: The expected format of barcode must be same as that 
     1219          //Note: The expected format of barcode must be same as that
    11741220          //      created by TfrmPtLabelPrint.PrintButtonClick:
    11751221          //      70685-12-31-2008-73-6-1302-0
     
    12771323  end;
    12781324
     1325  procedure TUploadForm.SetAllowNonImages(Value : boolean);
     1326  begin
     1327    FAllowNonImages := Value;
     1328    btnPickPDF.Enabled := Value;
     1329    PickOtherButton.Enabled := Value;
     1330  end;
     1331
    12791332
    12801333
Note: See TracChangeset for help on using the changeset viewer.