unit U_ZHCPBigTP;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, cxMemo, cxRichEdit, ComCtrls, cxContainer,
  cxTextEdit, cxMaskEdit, cxButtonEdit, StdCtrls, ToolWin, DBClient, ADODB,
  ExtCtrls, BtnEdit, cxCalendar,StrUtils, cxDropDownEdit,jpeg,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP, cxPC,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGroupBox, cxCheckBox,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport,IniFiles,ShellAPI;

type
  TfrmZHCPBigTP = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    ADOQuery1: TADOQuery;
    Label26: TLabel;
    CDS_Print: TClientDataSet;
    RM1: TRMGridReport;
    Panel3: TPanel;
    Panel6: TPanel;
    ODPat: TOpenDialog;
    Image1: TImage;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    adoqueryPicture: TADOQuery;
    Panel16: TPanel;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Image1DblClick(Sender: TObject);
  private
    procedure InitData();
    procedure ReadINIFile10();
    { Private declarations }
  public
    FMainId,FIMNO,FileName:String;
    { Public declarations }
  end;

var
  frmZHCPBigTP: TfrmZHCPBigTP;
implementation
uses
  U_DataLink,U_ZDYHelp,U_RTFun;

{$R *.dfm}

procedure TfrmZHCPBigTP.TBCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TfrmZHCPBigTP.InitData();
var
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin
  with adoqueryPicture do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from Image_Info A');
    sql.Add(' inner join Image_File B on A.IMID=B.IMID');
    sql.Add(' and A.WBID='''+Trim(FMainId)+'''');
    sql.Add(' and isnull(A.IMNo,'''')='''+Trim(FIMNO)+''' and A.Valid=''Y'' and B.IFType=''大'' and B.Valid=''Y'' ');
    Open;
  end;
  if adoqueryPicture.IsEmpty=False then
  begin
    FileName:=Trim(adoqueryPicture.fieldbyname('ImagePath').AsString);
    jpg:=TJpegImage.Create();
    myStream:=tadoblobstream.Create(tblobfield(adoqueryPicture.fieldbyname('ImageFile')),bmread);
    jpg.LoadFromStream(myStream);
    Image1.Picture.Assign(jpg);
    Image1.Width:=adoqueryPicture.fieldbyname('ImageWidth').Value;
    Image1.Height:=adoqueryPicture.fieldbyname('ImageHeight').Value;
    if Trim(adoqueryPicture.fieldbyname('FangXiang').AsString)='垂直' then
    begin
      Image1.Top:=1;
      Image1.Left:=Round((Panel6.Width-Image1.Width)/2);
    end else
    begin
      Image1.Left:=1;
      Image1.Top:=Round((Panel6.Height-Image1.Height)/2);
    end;
    Image1.Visible:=True;
  end;
end;



procedure TfrmZHCPBigTP.FormShow(Sender: TObject);
begin
  InitData();
end;



procedure TfrmZHCPBigTP.ReadINIFile10();
var
  programIni:Tinifile;  //配置文件名
  FileName:string;
begin
  FileName:=ExtractFilePath(Paramstr(0))+'SYSTEMSET.INI';
  programIni:=Tinifile.create(FileName);
  server:=programIni.ReadString('SERVER','服务器地址','127.0.0.1');
  programIni.Free;
end;


procedure TfrmZHCPBigTP.Image1DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath,FFName:string;
  FInt:integer;
  maxno:string;
  j,i:Integer;
  fPrintFile,fFileName:string;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    ReadINIFile10();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=server;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  Panel16.Visible:=true;
  Panel16.Refresh;
  fPrintFile:= ExtractFilePath(Application.ExeName)+'Photo\';
  if not DirectoryExists(ExtractFileDir(FPrintFile)) then
    CreateDir(ExtractFileDir(fPrintFile));
  FFName:=Trim(FileName);
  FFName:=fPrintFile+FFName;
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('YP\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

end.
