unit U_SLT_YH;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
  Dialogs, ExtCtrls,jpeg, cxControls, cxContainer, cxEdit, cxImage,IdFTP,ShellAPI,
  StdCtrls, DB, ADODB, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, Menus,DBClient,IniFiles, cxTextEdit, cxCurrencyEdit;

type
  TfrmSLT_YH = class(TFrame)
    PopupMenu1: TPopupMenu;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    SaveDialog1: TSaveDialog;
    XG: TMenuItem;
    Panel1: TPanel;
    Image2: TImage;
    Image1: TImage;
    ImagePath: TLabel;
    IMID: TLabel;
    Panel2: TPanel;
    Image11: TImage;
    Image22: TImage;
    TJHX: TLabel;
    TJHXType: TLabel;
    TJMLNo: TLabel;
    cxImage1: TcxImage;
    Panel16: TPanel;
    Ssel: TMemo;
    ADOQuery1: TADOQuery;
    procedure N2Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure cxImage1DblClick(Sender: TObject);
    procedure SselClick(Sender: TObject);
    procedure cxImage1Click(Sender: TObject);
    procedure XGClick(Sender: TObject);
  private
    lstPat: TStringList;
    procedure ReadINIFile10();

    { Private declarations }
  public
    FileName,FIMID,FIMNO,FWBID,FImagePath,FTJHX:String;
    procedure Init(fFileName:string;fPicture:TJpegImage);
    procedure CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
    { Public declarations }
  end;

implementation
uses
  U_DataLink,U_Fun,U_HXKYHK,U_TJHXMX,U_MLManage_LRTJ,U_SLT_Note;
{$R *.dfm}

procedure TfrmSLT_YH.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 TfrmSLT_YH.Init(fFileName:string;fPicture:TJpegImage);
begin
  FileName:=trim(fFileName);
  cxImage1.Picture.Assign(fPicture);
end;
procedure TfrmSLT_YH.N2Click(Sender: TObject);
begin
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('UPdate Image_Info  Set Valid=''N'',DelTime=getdate(),Deler='''+Trim(DName)+''',DelerCode='''+Trim(DCode)+'''');
    sql.Add('where IMID='''+trim(FIMID)+'''');
    sql.Add('UPdate Image_File  Set Valid=''N'',DelTime=getdate(),Deler='''+Trim(DName)+''',DelerCode='''+Trim(DCode)+'''');
    sql.Add('where IMID='''+trim(FIMID)+'''');
    ExecSQL;
  end;
  frmHXKYHK.initimageSH(FWBID);
end;

procedure TfrmSLT_YH.N3Click(Sender: TObject);
var
  IdFTP1: TIdFTP;
  fPrintFile,FFName:string;
  FInt:integer;
begin
  if Application.MessageBox('原图下载需要等待时间，确定要查看原图吗？','提示',32+4)<>IDYES then Exit;
  try
    IdFTP1:=TIdFTP.Create(self);
    IdFTP1.Host :=PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    IdFTP1.Free;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  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('TJ\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmSLT_YH.CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
var
  Bitmap: TBitmap;
  Ratio: Double;
  ARect: TRect;  //230 152
  AHeight, AHeightOffset: Integer;
  AWidth, AWidthOffset: Integer;
begin
  Bitmap := TBitmap.Create;
  try
    AWidth :=Width;
    AWidthOffset := 0;
    AHeight := Height;
    AHeightOffset := 0;

    Bitmap.Width := Width;
    Bitmap.Height := Height;
    Bitmap.Canvas.Brush.Color := clBtnFace;
    
    Bitmap.Canvas.FillRect(Rect(0, 0, Width, Height));
    ARect := Rect(AWidthOffset, AHeightOffset, AWidth + AWidthOffset, AHeight + AHeightOffset);
    Bitmap.Canvas.StretchDraw(ARect, AJPeg);
    Image1.Picture.Assign(BitMap);
  finally
    Bitmap.Free;
  end;
end;

procedure TfrmSLT_YH.cxImage1DblClick(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+'.jpg';
  if not FileExists(FFName) then
  begin
    IdFTP1.Get('TJ\'+FileName,FFName);
  end;
  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  Panel16.Visible:=false;
  ShellExecute(Handle, 'open',PChar(FFName),'', '', SW_SHOWNORMAL);
end;

procedure TfrmSLT_YH.SselClick(Sender: TObject);
begin
  if Ssel.Text='' then
  begin
    Ssel.Text:='√';
  end
  else
  begin
    Ssel.Text:='';
  end;
end;

procedure TfrmSLT_YH.cxImage1Click(Sender: TObject);
begin
  if Ssel.Text='' then
  begin
    Ssel.Text:='√';
    Ssel.Color:=clRed;
  end
  else
  begin
    Ssel.Text:='';
    Ssel.Color:=clWindow;
  end;
  with ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add('select * from Image_Info where IMID='''+trim(FIMID)+'''');
    open;
  end;
  frmHXKYHK.TJNote.Text:=Trim(ADOQuery1.fieldbyname('TJNote').AsString);
  frmHXKYHK.FIMID:=self.FIMID;
  frmHXKYHK.Panel6.Left:=Self.Left+self.Width;
  frmHXKYHK.Panel6.Top:=self.Top;
  frmHXKYHK.Panel6.visible:=false;
  frmHXKYHK.Panel6.BringToFront;
end;

procedure TfrmSLT_YH.XGClick(Sender: TObject);
begin
  frmHXKYHK.Panel6.Visible:=true;
end;

end.
