delphi上传文档和查看文档(一)

2017-10-28 10:34:43来源:oschina作者:小砍侃人点击

分享
第七城市

//上传文档


procedure Tbo.SpeedButton3Click(Sender: TObject); varpdfFile, sqlStr: string; begininherited;if adointer_bzxx.State in [dsedit, dsinsert] then adointer_bzxx.Post;ifnot (odPdf.Execute) then exit;pdfFile := odPdf.FileName;edt1.Text := pdfFile;


sqlStr := sqlStr + 'upDate interPacking set ';if edt1.Text <> '' then sqlStr := sqlStr + ' cPdfFile=:pdfFile,pdfpath=:ppath ';sqlStr := sqlStr + 'where ipId=' + adointer_bzxx.findfield('ipid').AsString;maindm.QryPub.SQL.Clear();maindm.QryPub.SQL.Add(sqlStr);try if edt1.Text <> '' then beginmaindm.QryPub.Parameters.Items[0].DataType := ftBlob;maindm.QryPub.Parameters.ParamByName('pdfFIle').LoadFromFile(pdfFile, ftBlob);maindm.QryPub.Parameters.Items[1].DataType := ftString;maindm.QryPub.Parameters.ParamByName('ppath').Value := pdfFile;end; maindm.QryPub.ExecSQL();except myHs.Error1('更新信息错误!'); abort(); end;myHs.info1('更新信息成功!');


end;


//查看文档


procedure Tbo.SpeedButton4Click(Sender: TObject); varstream: TmemoryStream;pdfDir, fileName, sqlStr: string; beginfileName := gPath + '/pack.Pdf';with mainDm dobegin sqlStr := ''; sqlStr := sqlStr + 'select cPdfFile from interPacking where ipId=' + adointer_bzxx.findfield('ipid').AsString; qryAssist.SQL.Clear(); qryAssist.SQL.Add(sqlStr); tryqryAssist.Open(); exceptmyHs.Error1('提取PDF文件错误!');abort(); end; if FileExists(filename) thenDeleteFile(fileName); if not (qryAssist.Eof) then begintry Stream := TMemoryStream.Create(); TBlobField(qryAssist.FieldByName('cPdfFile')).SaveToStream(Stream); // 显示的转换为BlobField并保存到内存流 Stream.Position := 0; stream.SaveToFile(fileName);finally stream.Free;end; end; qryAssist.Close(); if fileExists(fileName) thenShellExecute(application.Handle, 'open', pchar(fileName), '', '', SW_SHOWNORMAL) elsemyHs.warn1('未能正确提取PDF文件!');end; end;

第七城市

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台