unit U_HXKTJ_CX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, ToolWin, ComCtrls,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGridLevel,
  cxClasses, cxControls, cxGridCustomView, cxGrid, DBClient, ADODB, ImgList,
  StdCtrls, ExtCtrls, cxTextEdit, cxGridCustomPopupMenu, cxGridPopupMenu,IniFiles,
  cxButtonEdit, BtnEdit, cxTL, cxMaskEdit, cxInplaceContainer, cxDBTL,U_SLT_TJ,
  cxTLData, cxContainer, cxCurrencyEdit, cxCheckBox, cxSplitter,jpeg,Math, Menus, cxCalendar,
  IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdFTP,
  dxDockControl, dxDockPanel, cxImage;

type
  TfrmHXKTJ_CX = class(TForm)
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    Ord_TJ: TClientDataSet;
    ADOConnection1: TADOConnection;
    ThreeImgList: TImageList;
    DataSource2: TDataSource;
    Panel2: TPanel;
    DataSource4: TDataSource;
    ADOQueryTree: TADOQuery;
    Order_Tree: TClientDataSet;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyleRepository2: TcxStyleRepository;
    cxStyle2: TcxStyle;
    adoqueryPicture: TADOQuery;
    ScrollBox2: TScrollBox;
    ADOQuery1: TADOQuery;
    SaveDialog2: TSaveDialog;
    ODPat2: TOpenDialog;
    IdFTP2: TIdFTP;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    Image2: TImage;
    Image1: TImage;
    ImagePath: TLabel;
    IMID: TLabel;
    Panel3: TPanel;
    Image11: TImage;
    Image22: TImage;
    TJHX: TLabel;
    TJHXType: TLabel;
    TJMLNo: TLabel;
    cxImage1: TcxImage;
    Ssel: TMemo;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    JS:integer;
    FDYID:String;
    lstPat: TStringList;
		AJpeg: TJPEGImage;
    procedure CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
    procedure ReadINIFile10();
    { Private declarations }
  public
    my,mz:integer;
    FIMID:string;
    FSMRK:string;
    { Public declarations }
  end;
var
  frmHXKTJ_CX: TfrmHXKTJ_CX;
  Mach1: array of TfrmSLT_TJ;
implementation
uses
  U_DataLink,U_RTFun, U_BPZdy_HXK,U_CPTypePB,U_FileUp_TP,U_SCPerson
  ,U_FileUp,U_FileUp_PB,U_FileUp_TPSH,U_SLT_BF1,U_HXKTJ_Type,U_ZDYHelp;

{$R *.dfm}

procedure TfrmHXKTJ_CX.FormCreate(Sender: TObject);
begin
  lstPat := TStringList.Create;
end;

procedure TfrmHXKTJ_CX.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  Finalize(Mach1);
  Action:=caFree;
end;

procedure TfrmHXKTJ_CX.CreThumb(AJPeg:TJPEGImage;Image1:TImage;Width, Height: Integer);
var
  Bitmap: TBitmap;
  Ratio: Double;
  ARect: TRect;
  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 TfrmHXKTJ_CX.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 TfrmHXKTJ_CX.FormDestroy(Sender: TObject);
begin
  frmHXKTJ_CX:=nil;
end;

procedure TfrmHXKTJ_CX.FormShow(Sender: TObject);
var jpg:TJpegImage;
    myStream: TADOBlobStream;
begin
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select A.*,B.*,MLDLNo SKID ');
    sql.Add(' from ML_Manage A ');
    sql.Add(' left join Image_Info B on B.TJML=A.TJML ');
    sql.Add(' left join BP_DY C on C.TFID=B.IMID and C.MLID=A.MLID');
    sql.Add(' left join BP_DY D on D.TFID=A.PTID and D.MLID=A.MLID');
    sql.Add(' where isnull(A.MLType,'''')=''烫金面料'' and isnull(C.DYID,'''')='''+trim(FSMRK)+'''');
    Open;
  end;
  if ADOQueryCmd.fieldbyname('ImageFile').asstring<>'' then
  begin
    jpg:=TJpegImage.Create();
    myStream:=tadoblobstream.Create(tblobfield(ADOQueryCmd.fieldbyname('ImageFile')),bmread);
    jpg.LoadFromStream(myStream);
  end;
  FDYID:=Trim(ADOQueryCmd.fieldbyname('IMID').AsString);
  ImagePath.Caption:=trim(ADOQueryCmd.fieldbyname('ImagePath').AsString);
  TJHX.Caption:=trim(ADOQueryCmd.fieldbyname('TJHX').AsString);
  TJHXType.Caption:=trim(ADOQueryCmd.fieldbyname('TJHXType').AsString);
  TJMLNo.Caption:=trim(ADOQueryCmd.fieldbyname('TJMLNo').AsString);
  if triM(ADOQueryCmd.fieldbyname('IMID').AsString)<>'' then
  begin
    cxImage1.Picture.Assign(jpg);
  end;
  cxImage1.Visible:=True;
  cxImage1.Properties.Stretch:=True;
end;

end.
