unit U_YX_WorkRZLR;

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, cxCurrencyEdit,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxDropDownEdit, cxGroupBox,
  cxCheckBox, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
  IdFTP, ImgList, Menus,ShellAPI;

type
  TfrmYX_WorkRZLR = class(TForm)
    ToolBar1: TToolBar;
    TBSave: TToolButton;
    TBClose: TToolButton;
    ScrollBox1: TScrollBox;
    ADOTemp: TADOQuery;
    ADOCmd: TADOQuery;
    DataSource1: TDataSource;
    Order_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    CDS_CON: TClientDataSet;
    DSCON: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryTmp: TADOQuery;
    ADOQuery2: TADOQuery;
    Panel1: TPanel;
    Label1: TLabel;
    Panel21: TPanel;
    Label52: TLabel;
    RZBiaoTi: TEdit;
    Label51: TLabel;
    Label7: TLabel;
    ListView1: TListView;
    Panel12: TPanel;
    Label48: TLabel;
    Button4: TButton;
    Panel13: TPanel;
    Image1: TImage;
    WJName: TEdit;
    Button7: TButton;
    WJPach: TEdit;
    Button8: TButton;
    Panel2: TPanel;
    PopupMenu2: TPopupMenu;
    MenuItem1: TMenuItem;
    N3: TMenuItem;
    MenuItem2: TMenuItem;
    N4: TMenuItem;
    ImageList1: TImageList;
    IdFTP1: TIdFTP;
    ODPat: TOpenDialog;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    RZNote: TEdit;
    Label3: TLabel;
    RZDate: TDateTimePicker;
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSaveClick(Sender: TObject);
    procedure v1PRTColorPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure v1OrderUnitPropertiesButtonClick(Sender: TObject;
      AButtonIndex: Integer);
    procedure Image1Click(Sender: TObject);
    procedure MenuItem1Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure MenuItem2Click(Sender: TObject);
    procedure N4Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure ListView1DblClick(Sender: TObject);
  private
    lstPat:TStringList;
    procedure InitData();
    function  SaveData():Boolean;
    function  getOrderNo(fconNo:string):string;
    procedure CFSaveData();
    procedure Initimage();
    { Private declarations }
  public
    PState,CopyInt,PriceFlag:Integer;
    FMainId,FFMainId,FOrderNo:String;
    FXS:Integer;
    canshu1,canshu2:string;
    fFlileFlag:string;
    { Public declarations }
  end;

var
  frmYX_WorkRZLR: TfrmYX_WorkRZLR;
  newh:hwnd;
implementation
uses
  U_DataLink,U_ZDYHelp,U_Fun,U_ZDYHelpSel, U_ZdyAttachment, U_ZdyAttachGYS,
  U_CPManageSel, getpic, U_ZdyAttachCP_HX_sel,U_ContractList_CX;

{$R *.dfm}
procedure TfrmYX_WorkRZLR.CFSaveData();
var
  fCFID:string;
begin
  with ADOQuery2 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from JYOrder_Sub_CF where subID='''+Trim(Order_Sub.fieldbyname('subID').asstring)+'''');
    open;
  end;
  if ADOQuery2.IsEmpty then
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      SQL.Add('select A.CengJI,A.MLName,A.MLSeHao,A.MLID ');
      sql.Add(',HXNo=(select Top 1 B.HXNo from CP_YDang_JG B where B.CengJi=A.CengJi and B.CYID=A.CYID and B.IFZY=1)');
      sql.Add(',GYDM=(select Top 1 B.GYDM from CP_YDang_JG B where B.CengJi=A.CengJi and B.CYID=A.CYID and B.IFZY=1)');
      sql.Add(' from CP_YDang_ML A ');
      SQL.Add('where A.CYID='''+trim(Order_Sub.fieldbyname('PRTCode').AsString)+'''');
      sql.Add(' and A.IFSel=1 ');
      sql.Add(' order by A.Cengji,A.MLID');
      open;
    end;
    while not ADOQuery1.Eof do
    begin
      IF GetLSNo(ADOQueryCmd,fCFID,'JC','JYOrder_Sub_CF',4,1)=False then
      begin
        Application.MessageBox('取子流水号失败！','提示',0);
        Exit;
      end;
      with ADOQueryCmd do
      begin
        Close;
        SQL.Clear;
        sql.Add('select * from JYOrder_Sub_CF where CFID='''+Trim(fCFID)+'''');
        Open;
        IF IsEmpty then Append
        else edit;
        fieldbyname('CFID').Value:=trim(fCFID);
        fieldbyname('PRTCode').Value:=trim(Order_Sub.fieldbyname('PRTCode').AsString);
        fieldbyname('PrtCodeName').Value:=trim(ADOQuery1.fieldbyname('MLName').AsString);
        fieldbyname('PrtSpec').Value:=trim(Order_Sub.fieldbyname('PrtSpec').AsString);
        fieldbyname('SOrddefstr1').Value:=trim(ADOQuery1.fieldbyname('MLSeHao').AsString);
        fieldbyname('PRTColor').Value:=trim(ADOQuery1.fieldbyname('MLColor').AsString);
        fieldbyname('PRTHX').Value:=trim(ADOQuery1.fieldbyname('HXName').AsString);
        fieldbyname('PRTOrderRollNum').Value:=Order_Sub.fieldbyname('PRTOrderRollNum').AsFloat;
        fieldbyname('PrtOrderQty').Value:=Order_Sub.fieldbyname('PRTOrderQty').AsFloat;
        fieldbyname('OrderUnit').Value:=trim(Order_Sub.fieldbyname('OrderUnit').AsString);
        FieldByName('PRTType').Value:=trim(ADOQuery1.fieldbyname('CengJi').AsString)+'层';
        fieldbyname('MainID').Value:=trim(Order_Sub.fieldbyname('MainID').AsString);
        fieldbyname('SubID').Value:=trim(Order_Sub.fieldbyname('SubID').AsString);
        post;
      end;
      ADOQuery1.Next;
    end;
  end
  else
  begin
    with ADOQuery1 do
    begin
      Close;
      sql.Clear;
      sql.Add('update JYOrder_Sub_CF set ');
      sql.Add('PRTCode='''+trim(Order_Sub.fieldbyname('PRTCode').AsString)+'''');
      sql.Add(',PrtSpec='''+trim(Order_Sub.fieldbyname('PrtSpec').AsString)+'''');
      {if Order_Sub.fieldbyname('PRTOrderRollNum').AsFloat=0 then
      sql.Add(',PRTOrderRollNum=0')
      else
      sql.Add(',PRTOrderRollNum='''+trim(Order_Sub.fieldbyname('PRTOrderRollNum').AsString)+'''');
      if Order_Sub.fieldbyname('PrtOrderQty').AsFloat=0 then
      sql.Add(',PrtOrderQty=0')
      else
      sql.Add(',PrtOrderQty='''+trim(Order_Sub.fieldbyname('PrtOrderQty').AsString)+'''');}
      sql.Add(',OrderUnit='''+trim(Order_Sub.fieldbyname('OrderUnit').AsString)+'''');
      sql.Add(' where Subid='''+trim(Order_Sub.fieldbyname('Subid').AsString)+'''');
      ExecSQL;
    end;
  end;
end;

function TfrmYX_WorkRZLR.getOrderNo(fconNo:string):string;
var
  str1:string;
  i:integer;
begin
  str1:=trim(fconNo)+'01';
  with ADOTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select MainID from JYOrder_Main where orderNo='+quotedstr(trim(str1)));
    open;
  end;
  IF not ADOTemp.IsEmpty then
  begin
    for i:=1 to 99 do
    begin
      str1:=trim(fconNo)+rightstr(inttostr(100+i),2);
      with ADOCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select MainID from JYOrder_Main where orderNo='+quotedstr(trim(str1)));
        open;
      end;
      IF ADOCmd.IsEmpty then break;
    end;
  end;
  result:=str1;
end;

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

procedure TfrmYX_WorkRZLR.InitData();
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add(' select * from YX_WorkRZ where RZID='''+trim(FMainid)+''' ');
    Open;
  end;
  SCSHDataNew(ADOQuery1,ScrollBox1,2);
  RZDate.DateTime:=ADOQuery1.fieldbyname('RZDate').AsDateTime;
  if PState=0 then
  begin
    RZDate.DateTime:=SGetServerDateTime(ADOTemp);
    //RZRenWu.Text:=Trim(DName);
  end;
  Initimage();
end;

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

procedure TfrmYX_WorkRZLR.Initimage();
var
  ListItem: TListItem;
  Flag: Cardinal;
  info: SHFILEINFOA;
  Icon: TIcon;
begin
  ListView1.Items.Clear;
  with adoqueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select fileName from TP_File ');
    sql.Add('where WBID='''+trim(FMainid)+''' ');
    sql.Add('and TFType=''日志''');
    open;
    if not IsEmpty then
    begin
      while not eof do
      begin
        with ListView1 do
        begin
           LargeImages := ImageList1;
           Icon := TIcon.Create;
           ListItem := Items.Add;
           Listitem.Caption := trim(fieldbyname('fileName').AsString);
           Flag := (SHGFI_LARGEICON or SHGFI_ICON or SHGFI_USEFILEATTRIBUTES);
           SHGetFileInfo(Pchar(trim(fieldbyname('fileName').AsString)), 0, info, Sizeof(info), Flag);
           Icon.Handle := info.hIcon;
           ImageList1.AddIcon(Icon);
           ListItem.ImageIndex := ImageList1.Count - 1;
        end;
        next;
      end;
    end;
  end;
end;

function TfrmYX_WorkRZLR.SaveData():Boolean;
var
  maxno,forderNo:String;
begin
  try
    ADOCmd.Connection.BeginTrans;
    ///保存主表
    if Trim(FMainId)='' then
    begin
      if GetLSNo(ADOCmd,maxno,'RZ','YX_WorkRZ',3,1)=False then
      begin
        ADOCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败!','提示',0);
        Exit;
      end;
    end
    else
    begin
      maxno:=Trim(FMainId);
    end;
    with ADOCmd do
    begin
      Close;
      sql.Clear;
      SQL.Add('select * from YX_WorkRZ where RZID='''+Trim(maxno)+'''');
      Open;
    end;
    with ADOCmd do
    begin
      if isempty then
      begin
        Append;
        FieldByName('Filler').Value:=Trim(DName);
      end
      else begin
        Edit;
      end;
      FieldByName('RZID').Value:=Trim(maxno);
      SSetsaveSqlNew(ADOCmd,'YX_WorkRZ',ScrollBox1,2);
      FieldByName('RZDate').AsDateTime:=RZDate.Date;
      FieldByName('SCType').Value:='日志';
      FieldByName('chkstatus').Value:='未完成';
      Post;
    end;
    FMainId:=Trim(maxno);
    ADOCmd.Connection.CommitTrans;
    Result:=True;
  except
    Result:=False;
    ADOCmd.Connection.RollbackTrans;
    Application.MessageBox('保存失败！','提示',0);
  end;
end;

procedure TfrmYX_WorkRZLR.TBSaveClick(Sender: TObject);
begin
  RZDate.SetFocus;
  if SaveData() then
  begin
    Application.MessageBox('保存成功！','提示',0);
    ModalResult:=1;
  end;
end;

procedure TfrmYX_WorkRZLR.v1PRTColorPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
begin
  try
    frmZDYHelp:=TfrmZDYHelp.Create(Application);
    with frmZDYHelp do
    begin
      flag:='OrdColor';
      flagname:='颜色';
      V1Name.Caption:='中文名称';
      V1Note.Caption:='英文名称';
      fnote:=True;
      if ShowModal=1 then
      begin
        Self.Order_Sub.Edit;
        Self.Order_Sub.FieldByName('MLColor').Value:=Trim(ClientDataSet1.fieldbyname('ZDYName').AsString);
        Self.Order_Sub.FieldByName('MLColorNo').Value:=Trim(ClientDataSet1.fieldbyname('Note').AsString);
      end;
    end;
  finally
    frmZDYHelp.Free;
  end;
end;

procedure TfrmYX_WorkRZLR.v1OrderUnitPropertiesButtonClick(Sender: TObject;
  AButtonIndex: Integer);
var
  mvalues:string;
begin

end;

procedure TfrmYX_WorkRZLR.Image1Click(Sender: TObject);
begin
  Panel12.Visible:=false;
end;

procedure TfrmYX_WorkRZLR.MenuItem1Click(Sender: TObject);
var
  OpenDiaLog: TOpenDialog;
  fFileName:string;
  fFilePath:string;
begin
  if FMainId='' then
  begin
    if GetLSNo(ADOCmd,FMainId,'','YX_WorkRZ',3,1)=False then
    begin
      ADOCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败!','提示',0);
      Exit;
    end;
  end;
  OpenDiaLog := TOpenDialog.Create(Self);
  if OpenDiaLog.Execute then
  begin
    fFilePath:=OpenDiaLog.FileName;
    fFileName:=ExtractFileName(OpenDiaLog.FileName);
    Panel12.Visible:=True;
    WJName.Text:=Trim(fFileName);
    WJName.Hint:=Trim(fFileName);
    WJPach.Text:=fFilePath;
    Button8.Visible:=False;
    Button4.Visible:=True;
    Button7.Visible:=True;
    Panel12.Refresh;
  end;
end;

procedure TfrmYX_WorkRZLR.N3Click(Sender: TObject);
var
  fFileName:string;
begin
  if listView1.SelCount<1 then exit;
  if Trim(DParameters1)<>'高权限' then
  begin
    if now-RZDate.DateTime>1 then
    begin
      application.MessageBox('低权限超过一天不能删除','提示');
      exit;
    end;
  end;
  fFileName:=ListView1.Selected.Caption;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('delete  from TP_File ');
    sql.Add('where WBID='''+trim(FMainid)+'''');
    sql.Add('and TFType=''日志''');
    sql.Add('and FileName='+quotedstr(trim(fFileName)));
    execsql;
  end;
  Initimage();
end;

procedure TfrmYX_WorkRZLR.MenuItem2Click(Sender: TObject);
begin
  if listView1.SelCount<1 then exit;
  Panel12.Visible:=True;
  Button4.Visible:=False;
  Button7.Visible:=False;
  Button8.Visible:=True;
  Panel12.Refresh;
  WJName.Text:=Trim(ListView1.Selected.Caption);
  WJName.Hint:=Trim(ListView1.Selected.Caption);
end;

procedure TfrmYX_WorkRZLR.N4Click(Sender: TObject);
var
  SaveDialog: TSaveDialog;
  fFileName:string;
  fFilePath:string;
begin
  if listView1.SelCount<1 then exit;
  try
    fFileName:=ListView1.Selected.Caption;
    SaveDialog := TSaveDialog.Create(Self);
    SaveDialog.FileName:=fFileName;
    if SaveDialog.Execute then
    begin
      Panel2.Caption:='正在保存数据，请稍等...';
      Panel2.Visible:=true;
      application.ProcessMessages;
      fFilePath:=SaveDialog.FileName;
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','FTP地址','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('FJ\'+ Trim(fFileName), fFilePath,false, true);
        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;
    end;
  except
    Panel2.Visible:=false;
  end;
end;

procedure TfrmYX_WorkRZLR.Button8Click(Sender: TObject);
var
  fFileName:String;
begin
  fFileName:=WJName.Hint;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('UPdate TP_File Set FileName='''+Trim(WJName.Text)+'''');
    sql.Add('where WBID='''+trim(FMainid)+'''');
    sql.Add('and TFType=''日志''');
    sql.Add('and FileName='+quotedstr(trim(fFileName)));
    execsql;
  end;
  Panel12.Visible:=False;
  Initimage();
  //选中上传的文件
  with listview1 do
  begin
    ListView1.Selected :=
    ListView1.FindCaption(0,Trim(fFileName),True,True,True);
    ListView1.SetFocus;
    ListView1.ItemFocused := ListView1.Selected;
  end;
end;

procedure TfrmYX_WorkRZLR.Button4Click(Sender: TObject);
var
  fFileName:string;
  fFilePath:string;
  maxNo:string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    begin
      fFilePath:=WJPach.Text;
      fFileName:=WJName.Text;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select TFId from TP_File ');
        sql.Add('where WBID='''+trim(FMainId)+'''');
        sql.Add(' and TFType=''日志''');
        sql.Add(' and FileName='+quotedstr(trim(fFileName)));
        open;
      end;
      IF ADOQueryCmd.IsEmpty=False  then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！','提示信息',MB_ICONERROR);
        exit;
      end;
      Panel12.Visible:=False;
      Panel2.Caption:='正在上传数据，请稍等...';
      Panel2.Visible:=true;
      application.ProcessMessages;

      if GetLSNo(ADOQueryCmd,maxNo,'RZ','TP_File',4,1)=False then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        Application.MessageBox('取最大号失败！','提示',0);
        Exit;
      end;

      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('delete from TP_File ');
        sql.Add('where WBID='''+trim(FMainid)+'''');
        sql.Add(' and TFType=''日志''');
        sql.Add(' and FileName='+quotedstr(trim(fFileName)));
        execsql;
      end;
      with adoqueryCmd do
      begin
        close;
        sql.Clear;
        sql.Add('select * from TP_File ');
        sql.Add('where WBID='''+trim(FMainid)+''' ');
        sql.Add(' and TFType=''日志''');
        sql.Add(' and FileName='+quotedstr(trim(fFileName)));
        open;
        append;
        fieldbyname('TFID').Value:=trim(maxNO);
        fieldbyname('WBID').Value:=trim(FMainId);
        fieldbyname('TFType').Value:='日志';
        fieldbyname('FileName').Value:=trim(fFileName);
        post;
      end;
      if fFilePath <> '' then
      begin
        try
          IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
          IdFTP1.Username := 'three';
          IdFTP1.Password := '641010';
          IdFTP1.Connect();
          IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
          IdFTP1.Quit;
        except
          IdFTP1.Quit;
          Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
        end;
      end;
      IdFTP1.Quit;
      Panel2.Visible:=false;
      Initimage();
      //选中上传的文件
      with listview1 do
      begin
        ListView1.Selected :=
        ListView1.FindCaption(0,Trim(fFileName),True,True,True);
        ListView1.SetFocus;
        ListView1.ItemFocused := ListView1.Selected;
      end;
    end;
    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！','提示信息',0);
  end;
end;

procedure TfrmYX_WorkRZLR.Button7Click(Sender: TObject);
var
  fFileName:string;
  fFilePath:string;
  maxNo:string;
begin
  try
    adoqueryCmd.Connection.BeginTrans;
    fFilePath:=WJPach.Text;
    fFileName:=WJName.Hint;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select TFId from TP_File ');
      sql.Add('where WBID='''+trim(FMainid)+'''');
      sql.Add(' and TFType=''日志''');
      sql.Add('and FileName='+quotedstr(trim(fFileName)));
      open;
      IF not adoqueryCmd.IsEmpty then
      begin
        ADOQueryCmd.Connection.RollbackTrans;
        application.MessageBox('此附件名称已存在，请修改文件名，继续上传！','提示信息',MB_ICONERROR);
        exit;
      end;
    end;
    Panel12.Visible:=False;
    Panel2.Caption:='正在上传数据，请稍等...';
    Panel2.Visible:=true;
    application.ProcessMessages;

    if GetLSNo(ADOQueryCmd,maxNo,'FJ','TP_File',4,1)=False then
    begin
      ADOQueryCmd.Connection.RollbackTrans;
      Application.MessageBox('取最大号失败！','提示',0);
      Exit;
    end;

    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('delete from TP_File ');
      sql.Add('where WBID='''+trim(FMainid)+'''');
      sql.Add(' and TFType=''日志''');
      sql.Add('and FileName='+quotedstr(trim(fFileName)));
      execsql;
    end;
    with adoqueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('select * from TP_File ');
      sql.Add('where WBID='''+trim(FMainid)+'''');
      sql.Add(' and TFType=''日志''');
      sql.Add('and FileName='+quotedstr(trim(fFileName)));
      open;
      append;
      fieldbyname('TFID').Value:=trim(maxNO);
      fieldbyname('WBID').Value:=trim(FMainid);
      fieldbyname('TFType').Value:='日志';
      fieldbyname('FileName').Value:=trim(fFileName);
      post;
    end;
    if fFilePath <> '' then
    begin
      try
        IdFTP1.Host := ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
        IdFTP1.Username := 'three';
        IdFTP1.Password := '641010';
        IdFTP1.Connect();
        IdFTP1.Put(fFilePath, 'FJ\' + Trim(fFileName));
        IdFTP1.Quit;
      except
        IdFTP1.Quit;
        Application.MessageBox('上传文件失败，请检查文件服务器！', '提示', MB_ICONWARNING);
      end;
    end;
    IdFTP1.Quit;
    Panel2.Visible:=false;
    Initimage();

    //选中上传的文件
    with listview1 do
    begin
      ListView1.Selected :=
      ListView1.FindCaption(0,Trim(fFileName),True,True,True);
      ListView1.SetFocus;
      ListView1.ItemFocused := ListView1.Selected;
    end;

    adoqueryCmd.Connection.CommitTrans;
  except
    adoqueryCmd.Connection.RollbackTrans;
    application.MessageBox('文件保存失败！','提示信息',0);
  end;
end;

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

procedure TfrmYX_WorkRZLR.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
  ModalResult:=1;
end;

procedure TfrmYX_WorkRZLR.ListView1DblClick(Sender: TObject);
var
  sFieldName:string;
  fileName:string;
begin
  if ListView1.Items.Count<1 THEN EXIT;

  if listView1.SelCount<1 then exit;
  sFieldName:=leftbstr(ExtractFilePath(Application.ExeName),1)+':\图片查看';

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

  fileName:=ListView1.Selected.Caption;

  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('FJ\'+ 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.
