unit U_CPAddPN;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ADODB, DBClient, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls, cxGridCustomView,
  cxGrid, ComCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, cxTextEdit,
  cxButtonEdit, StdCtrls, ExtCtrls, cxCurrencyEdit, BtnEdit, cxDropDownEdit,
  cxContainer, cxMaskEdit, cxImage, cxDBEdit, StrUtils, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdFTP, ShellAPI,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxSkinsCore,
  dxSkinBlack, dxSkinBlue, dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee,
  dxSkinDarkRoom, dxSkinDarkSide, dxSkinDevExpressDarkStyle,
  dxSkinDevExpressStyle, dxSkinFoggy, dxSkinGlassOceans,
  dxSkinHighContrast, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMetropolis,
  dxSkinMetropolisDark, dxSkinMoneyTwins, dxSkinOffice2007Black,
  dxSkinOffice2007Blue, dxSkinOffice2007Green, dxSkinOffice2007Pink,
  dxSkinOffice2007Silver, dxSkinOffice2010Black, dxSkinOffice2010Blue,
  dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

type
  TfrmCPAddPN = class(TForm)
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    TBClose: TToolButton;
    CDS_Sub: TClientDataSet;
    ADOQueryMain: TADOQuery;
    DataSource2: TDataSource;
    ADOQueryCmd: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ScrollBox1: TScrollBox;
    Label1: TLabel;
    CYNo: TEdit;
    Label5: TLabel;
    CYName: TEdit;
    Label11: TLabel;
    CYCF: TEdit;
    Label15: TLabel;
    CYMF: TEdit;
    Label22: TLabel;
    CYKZ: TEdit;
    Label23: TLabel;
    CARTYPE: TEdit;
    Label10: TLabel;
    CYPrice: TEdit;
    CYID: TEdit;
    Label3: TLabel;
    CYSpec: TMemo;
    lbl3: TLabel;
    BaoHuDate: TDateTimePicker;
    Label12: TLabel;
    ClientDataSet3: TClientDataSet;
    Label2: TLabel;
    CYXIANC50: TEdit;
    Label4: TLabel;
    CYXIANCZ: TEdit;
    Label14: TLabel;
    CYANLUNX: TEdit;
    Label16: TLabel;
    CYZZQTY: TEdit;
    Label6: TLabel;
    CYGC: TcxButtonEdit;
    Panel1: TPanel;
    DataSource3: TDataSource;
    ClientDataSet6: TClientDataSet;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Label7: TLabel;
    CYPAIZHEN: TEdit;
    Label8: TLabel;
    CYPUNIT: TComboBox;
    Label9: TLabel;
    CYFUNIT: TComboBox;
    Label13: TLabel;
    CYbili: TEdit;
    Label17: TLabel;
    CYCONNO: TEdit;
    Label18: TLabel;
    Label19: TLabel;
    CYNOTE: TMemo;
    Label20: TLabel;
    CYNOTE2: TMemo;
    cyzhenshu: TEdit;
    Label21: TLabel;
    CYCOLOR: TEdit;
    Panel2: TPanel;
    Panel3: TPanel;
    Panel4: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    v3Column37: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    v3Column3: TcxGridDBColumn;
    v3Column4: TcxGridDBColumn;
    v3Column5: TcxGridDBColumn;
    v3Column6: TcxGridDBColumn;
    v3Column7: TcxGridDBColumn;
    v3Column8: TcxGridDBColumn;
    v3Column9: TcxGridDBColumn;
    v3Column10: TcxGridDBColumn;
    v3Column11: TcxGridDBColumn;
    v3Column12: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    Panel5: TPanel;
    cxGrid5: TcxGrid;
    TV5: TcxGridDBTableView;
    cxGridDBColumn32: TcxGridDBColumn;
    cxGridDBColumn34: TcxGridDBColumn;
    cxGridDBColumn35: TcxGridDBColumn;
    cxGridDBColumn36: TcxGridDBColumn;
    cxGridDBColumn37: TcxGridDBColumn;
    cxGridDBColumn38: TcxGridDBColumn;
    cxGridDBColumn39: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn43: TcxGridDBColumn;
    cxGridDBColumn44: TcxGridDBColumn;
    cxGridDBColumn45: TcxGridDBColumn;
    cxGridDBColumn46: TcxGridDBColumn;
    cxGridDBColumn47: TcxGridDBColumn;
    cxGridLevel6: TcxGridLevel;
    Label24: TLabel;
    Label25: TLabel;
    CYRSGY: TEdit;
    CYDXGY: TEdit;
    ToolBar3: TToolBar;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolBar2: TToolBar;
    ToolButton2: TToolButton;
    ADOQueryImage: TADOQuery;
    DataSource1: TDataSource;
    Picture4: TcxDBImage;
    IdFTP1: TIdFTP;
    Tv3Column1: TcxGridDBColumn;
    Tv3Column2: TcxGridDBColumn;
    Tv3Column3: TcxGridDBColumn;
    Tv3Column4: TcxGridDBColumn;
    Tv3Column5: TcxGridDBColumn;
    Tv3Column6: TcxGridDBColumn;
    procedure FormShow(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure CYColorKeyPress(Sender: TObject; var Key: Char);
    procedure CYKZExit(Sender: TObject);
    procedure CYMFExit(Sender: TObject);
    procedure CYGCPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure TV5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure CYFUNITChange(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure Picture4DblClick(Sender: TObject);
  private
    canshu1: string;
    Fint: Integer;
    procedure InitSubGrid();
    procedure InitImage();
    procedure LookImage(FileName: string);
    function SaveData(): Boolean;
    function Setstring(cString: string): string;
    { Private declarations }
  public
    FCYID, FCYCode, FCPID, FCPNO, FCPName: string;
    CopyInt: Integer;
    fFlileFlag: string;

    { Public declarations }
  end;

var
  frmCPAddPN: TfrmCPAddPN;

implementation

uses
  U_DataLink, U_Fun, U_iniParam, U_ZDYHelp, U_ZdyAttachGYS, U_FileUp, getpic;

{$R *.dfm}

procedure TfrmCPAddPN.InitSubGrid();
begin

  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from CP_YDang where CYID=''' + Trim(FCYID) + '''');
      Open;
    end;
    if ADOQueryMain.IsEmpty then
    begin
      BaoHuDate.DateTime := SGetServerDateTime(ADOQueryTemp);
      BaoHuDate.Checked := False;
    end
    else
    begin
      if Trim(ADOQueryMain.FieldByName('BaoHuDate').AsString) = '' then
      begin
        BaoHuDate.DateTime := SGetServerDateTime(ADOQueryTemp);
        BaoHuDate.Checked := False;
      end;
    end;
    SCSHDataNew(ADOQueryMain, ScrollBox1, 2);
    SCSHDataNew(ADOQueryMain, ScrollBox1, 0);

    with ADOQUERY1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FCYId) + '''');
      sql.Add(' and PZType=''单面三角'' ');
      Open;
    end;
    SCreateCDS20(ADOQUERY1, ClientDataSet3);
    SInitCDSData20(ADOQUERY1, ClientDataSet3);
    with ADOQUERY1 do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Cloth_PaiZhen where MainId=''' + Trim(FCYId) + '''');
      sql.Add(' and PZType=''双面三角'' ');
      Open;
    end;
    SCreateCDS20(ADOQUERY1, ClientDataSet6);
    SInitCDSData20(ADOQUERY1, ClientDataSet6);
  finally
    ADOQueryMain.EnableControls;
  end;

  if CopyInt = 1 then
  begin

    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
//        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;
    ClientDataSet6.DisableControls;
    with ClientDataSet6 do
    begin
      First;
      while not Eof do
      begin
        Edit;
        FieldByName('MainId').Value := '';
//        FieldByName('SubId').Value := '';
        FieldByName('PZId').Value := '';
        Post;
        Next;
      end;
    end;
    ClientDataSet6.EnableControls;
  end;
end;

procedure TfrmCPAddPN.FormShow(Sender: TObject);
var
  maxId: string;
begin
  if (Trim(FCYID) = '') or (CopyInt = 1) then
  begin
    if GetLSNo(ADOQueryCmd, maxId, 'Y', 'CP_YDang', 4, 1) = False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！', '提示', 0);
      Exit;
    end;
    CYID.Text := trim(maxId);
  end
  else
  begin
    maxId := Trim(FCYID);
  end;

  InitSubGrid();
  InitImage();
  if CopyInt = 1 then
  begin
    FCYID := '';
    CYID.text := trim(maxId);
    BaoHuDate.DateTime := SGetServerDateTime(ADOQueryTemp);
  end;
end;

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

function TfrmCPAddPN.SaveData(): Boolean;
var
  maxId, FCYNo, maxpz1, maxpz2: string;
begin
  try
    ADOQueryCmd.Connection.BeginTrans;
//    if Trim(FCYID) = '' then
//    begin
//      if GetLSNo(ADOQueryCmd, maxId, 'Y', 'CP_YDang', 4, 1) = False then
//      begin
//        Result := False;
//        ADOQueryCmd.Connection.RollbackTrans;
//        Application.MessageBox('取最大号失败！', '提示', 0);
//        Exit;
//      end;
//      CYID.Text := trim(maxId);
//    end
//    else
//    begin
//      maxId := Trim(FCYID);
//    end;
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from CP_YDang where CYID=''' + Trim(FCYID) + '''');
      Open;
    end;
    with ADOQueryCmd do
    begin
      if Trim(FCYID) = '' then
      begin
        Append;
        FieldByName('CYType').Value := Trim(FCPID);
      end
      else
      begin
        Edit;
      end;
      FieldByName('CYID').Value := Trim(cyid.text);
      if trim(CYNo.Text) = '' then
        CYNo.Text := Trim(cyid.text);
      SSetsaveSqlNew(ADOQueryCmd, 'CP_YDang', ScrollBox1, 2);
      if Trim(FCYID) = '' then
      begin
        FieldByName('Filler').Value := Trim(DName);
      end
      else
      begin
        FieldByName('Editer').Value := Trim(DName);
        FieldByName('EditTime').Value := SGetServerDateTime(ADOQUERYTEMP);
      end;
      Post;
    end;
    ClientDataSet3.DisableControls;
    with ClientDataSet3 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(ADOQueryCmd, maxpz1, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            ADOQueryCmd.Connection.RollbackTrans;
            Application.MessageBox('取排针流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpz1 := Trim(ClientDataSet3.fieldbyname('PZId').AsString);
        end;
        with ADOQueryCmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxpz1) + '''');
          Open;
        end;
        with ADOQueryCmd do
        begin
          if Trim(ClientDataSet3.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(adoquerytemp);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(adoquerytemp);
          end;
          FieldByName('MainId').Value := Trim(cyid.text);
//          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxpz1);
          RTSetSaveDataCDS(ADOQueryCmd, Tv3, ClientDataSet3, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '单面三角';
          FieldByName('PZName').Value := ClientDataSet3.fieldbyname('PZName').AsString;
          Post;
        end;
        ClientDataSet3.Edit;
        ClientDataSet3.FieldByName('PZId').Value := Trim(maxpz1);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet3.EnableControls;

     ///保存三角表
    ClientDataSet6.DisableControls;
    with ClientDataSet6 do
    begin
      First;
      while not Eof do
      begin
        if Trim(ClientDataSet6.fieldbyname('PZId').AsString) = '' then
        begin
          if GetLSNo(adoquerycmd, maxpz2, 'PZ', 'Cloth_PaiZhen', 4, 1) = False then
          begin
            adoquerycmd.Connection.RollbackTrans;
            Application.MessageBox('取三角流水号失败！', '提示', 0);
            Exit;
          end;
        end
        else
        begin
          maxpz2 := Trim(ClientDataSet6.fieldbyname('PZId').AsString);
        end;
        with adoquerycmd do
        begin
          Close;
          SQL.Clear;
          sql.Add('select * from Cloth_PaiZhen where ');
          sql.Add('  PZId=''' + Trim(maxpz2) + '''');
          Open;
        end;
        with adoquerycmd do
        begin
          if Trim(ClientDataSet6.fieldbyname('PZId').AsString) = '' then
          begin
            Append;
            FieldByName('Filler').Value := Trim(DName);
            FieldByName('FillTime').Value := SGetServerDateTime(ADOQUERYTEMP);
          end
          else
          begin
            Edit;
            FieldByName('Editer').Value := Trim(DName);
            FieldByName('EditTime').Value := SGetServerDateTime(ADOQUERYTEMP);
          end;
//          FieldByName('MainId').Value := Trim(maxId);
          FieldByName('MainId').Value := Trim(cyid.text);
//          FieldByName('SubId').Value := Trim(maxsubno);
          FieldByName('PZId').Value := Trim(maxpz2);
          RTSetSaveDataCDS(adoquerycmd, Tv5, ClientDataSet6, 'Cloth_PaiZhen', 0);
          FieldByName('PZType').Value := '双面三角';
          Post;
        end;
        ClientDataSet6.Edit;
        ClientDataSet6.FieldByName('PZId').Value := Trim(maxpz2);
        //Order_Sub.Post;
        Next;
      end;
    end;
    ClientDataSet6.EnableControls;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select count(*) as AA from CP_YDang where CYNo=''' + Trim(CYNo.Text) + '''');
      Open;
      if FieldByName('AA').AsInteger > 1 then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Result := False;
        Application.MessageBox('编号重复！', '提示', 0);
        Exit;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    FCYID := maxId;
    Result := True;
  except
    Result := False;
    ADOQueryCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败!', '提示', 0);
  end;
end;

procedure TfrmCPAddPN.ToolButton1Click(Sender: TObject);
begin

  if CYID.Text = '' then
  begin
    Application.MessageBox('条码不能为空！', '提示', 0);
    Exit;
  end;

  if CYName.Text = '' then
  begin
    Application.MessageBox('产品名称不能为空！', '提示', 0);
    Exit;
  end;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！', '提示', 0);
    ModalResult := 1;
  end;
end;

procedure TfrmCPAddPN.CYColorKeyPress(Sender: TObject; var Key: Char);
var
  c: Integer;
begin
  if Key = '.' then
  begin
    for c := 1 to length(TEdit(Sender).text) do
    begin
      if Tedit(Sender).text[c] = '.' then
        Key := #0;
    end;
  end
  else if Key = #13 then
    PerForm(WM_NEXTDLGCTL, 0, 0)
  else if Key = #8 then
    Key := #8
  else if (Key < '0') or (Key > '9') then
    Key := #0;
end;

procedure TfrmCPAddPN.CYKZExit(Sender: TObject);
begin
//  if pos('GSM', trim(CYKZ.Text)) = 0 then
//    CYKZ.Text := trim(CYKZ.Text) + 'GSM';
end;

procedure TfrmCPAddPN.CYMFExit(Sender: TObject);
begin
  if pos('CM', trim(CYMF.Text)) = 0 then
    CYMF.Text := trim(CYMF.Text) + 'CM';
end;

procedure TfrmCPAddPN.CYGCPropertiesButtonClick(Sender: TObject; AButtonIndex: Integer);
begin
  try
    frmZdyAttachGYS := TfrmZdyAttachGYS.Create(Application);
    with frmZdyAttachGYS do
    begin
      if ShowModal = 1 then
      begin
        CYGC.Text := Trim(CDS_HZ.fieldbyname('coName').AsString);
      end;
    end;
  finally
    frmZdyAttachGYS.Free;
  end;
end;

procedure TfrmCPAddPN.ToolButton3Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName: string;
  fFilePath: string;
  maxNo: string;
  FJStream: TMemoryStream;
  mfileSize: integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin

  if Fint = 1 then
  begin
    with ClientDataSet3 do
    begin
      Append;
      Post;
    end;
  end
  else if Fint = 2 then
    with ClientDataSet6 do
    begin
      Append;
      Post;
    end;

end;

procedure TfrmCPAddPN.ToolButton4Click(Sender: TObject);
begin
  if Fint = 1 then
  begin
    if ClientDataSet3.IsEmpty then
      Exit;
    if Application.MessageBox('确定要删除单面三角数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQUERYCMD do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(ClientDataSet3.fieldbyname('PZID').AsString) + '''');
      ExecSQL;
    end;
    ClientDataSet3.Delete;
  end
  else if Fint = 2 then
  begin
    if ClientDataSet6.IsEmpty then
      Exit;
    if Application.MessageBox('确定要删除双面三角数据吗？', '提示', 32 + 4) <> IDYES then
      Exit;
    with ADOQUERYCMD do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Cloth_PaiZhen where PZID=''' + Trim(ClientDataSet6.fieldbyname('PZID').AsString) + '''');
      ExecSQL;
    end;
    ClientDataSet6.Delete;
  end;
end;

procedure TfrmCPAddPN.Tv3MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 1;
end;

procedure TfrmCPAddPN.TV5MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  Fint := 2;
end;

function TfrmCPAddPN.Setstring(cString: string): string;   {提取数字}
var
  i: integer;
  str: string;
begin
  str := '';
  for i := 1 to length(cString) do
  begin
    if Pos(cString[i], '0123456789.') <= 0 then
      break
    else
      case cString[i] of
        '.':
          str := str + '.';

        '0':
          str := str + '0';
        '1':
          str := str + '1';
        '2':
          str := str + '2';
        '3':
          str := str + '3';
        '4':
          str := str + '4';
        '5':
          str := str + '5';
        '6':
          str := str + '6';
        '7':
          str := str + '7';
        '8':
          str := str + '8';
        '9':
          str := str + '9';
      end;
  end;
  Setstring := str;
end;

procedure TfrmCPAddPN.CYFUNITChange(Sender: TObject);
var
  FKZ, FMF: string;
begin
//  if Pos('GSM', CYKZ.Text) > 0 then
//  begin
  FKZ := Setstring(CYKZ.Text);
  FMF := Setstring(CYmf.Text);
//  showmessage(FKZ);
//  end;
  if (cyfunit.Text = 'M') and (StrToFloatdef(trim(FKZ), 0) <> 0) and (StrToFloatdef(trim(FMF), 0) <> 0) then
  begin

    cybili.text := (format('%.2f', [1000 / strtofloat(FMF) / strtofloat(FKZ) * 100]));
  end;
  if (cyfunit.Text = 'Y') and (StrToFloatdef(trim(FKZ), 0) <> 0) and (StrToFloatdef(trim(FMF), 0) <> 0) then
  begin

    cybili.text := (format('%.2f', [1000 / strtofloat(FMF) / strtofloat(FKZ) * 100 / 0.9144]));
  end;
end;

procedure TfrmCPAddPN.ToolButton2Click(Sender: TObject);
begin
  if Trim(cyid.Text) = '' then
  begin
    Application.MessageBox('条码不能为空！', '提示', 0);
    Exit;
  end;

  FormGetPic := TFormGetPic.create(self);
  with FormGetPic do
  begin
    fFlileFlag := self.fFlileFlag;
    fkeyNo := trim(cyid.Text);
    pat1 := 'FileName';
    pic1 := 'FilesOther';
    FTFType := 'YPP';
    if showmodal = 1 then
    begin
    end;
    free;
  end;
  Initimage();
end;

procedure TfrmCPAddPN.InitImage();
begin
  with ADOQueryImage do
  begin
    close;
    sql.Clear;
    sql.Add('select * from TP_File A');
    sql.Add('where WBID=' + quotedstr(Trim(cyid.Text)));
    open;
  end;
end;

procedure TfrmCPAddPN.Picture4DblClick(Sender: TObject);
begin
  if TcxDBImage(Sender).Picture.Height = 0 then
    exit;

  LookImage(ADOQueryImage.fieldbyname(TcxDBImage(Sender).Hint).asstring);
end;

procedure TfrmCPAddPN.LookImage(FileName: string);
var
  sFieldName: string;
 //	ff: TADOBlobStream;
 // FJStream : TMemoryStream;
begin

  sFieldName := leftbstr(ExtractFilePath(Application.ExeName), 1) + ':\图片查看';

  if not DirectoryExists(pchar(sFieldName)) then
    CreateDirectory(pchar(sFieldName), nil);

  sFieldName := sFieldName + '\' + trim(FileName);

  try
    IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI', 'SERVER', '服务器地址', '127.0.0.1');
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    ;
  end;

  if IdFTP1.Connected then
  begin

    //  Panel2.Caption:='正在下载数据，请稍等...';
    //  Panel2.Visible:=true;
    //  application.ProcessMessages;
    try
      IdFTP1.Get(fFlileFlag + '\' + Trim(FileName), sFieldName, true, false);
    except
   //   Panel2.Visible:=false;
      Application.MessageBox('客户图样文件不存在', '提示', MB_ICONWARNING);
      IdFTP1.Quit;
      Exit;
    end;
  end
  else
  begin
 //   Panel2.Visible:=false;
    Application.MessageBox('无法连接文件服务器', '提示', MB_ICONWARNING);
    IdFTP1.Quit;
    Exit;
  end;
//  Panel2.Visible:=false;
  if IdFTP1.Connected then
    IdFTP1.Quit;
  ShellExecute(Handle, 'open', PChar(sFieldName), '', '', SW_SHOWNORMAL);
end;

end.

