unit U_TatGYList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxDateRanges, dxBarBuiltInMenu, U_BaseList,
  cxPC, dxScrollbarAnnotations, cxContainer, dxCore, cxDateUtils, cxMaskEdit,
  cxDropDownEdit, dxSkinsCore, dxSkinsDefaultPainters, cxProgressBar,
      
     
     
     
     
    
    
    
   dxSkinOffice2013White, 
    
     
    dxSkinSharpPlus, 
     
    
    
   dxSkinWXI,  cxImage, cxDBEdit, IdFTP,
  ShellAPI;

type
  TfrmTatGYList = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBAdd: TToolButton;
    TBEdit: TToolButton;
    TBDel: TToolButton;
    TBPrint: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    Label2: TLabel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DS_1: TDataSource;
    Label3: TLabel;
    ConNo: TcxTextEdit;
    Label5: TLabel;
    C_Name: TcxTextEdit;
    TBExport: TToolButton;
    CDS_1: TClientDataSet;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1OrderNo: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1PRTMF: TcxGridDBColumn;
    v1PRTKZ: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1Column7: TcxGridDBColumn;
    TBCopy: TToolButton;
    TBView: TToolButton;
    v1Column19: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    Label10: TLabel;
    C_Code: TcxTextEdit;
    v1Column31: TcxGridDBColumn;
    CustName: TcxTextEdit;
    Label7: TLabel;
    lbl1: TLabel;
    cxTabControl1: TcxTabControl;
    Tv1Column1: TcxGridDBColumn;
    Label4: TLabel;
    OrderNo: TcxTextEdit;
    Tv1Column2: TcxGridDBColumn;
    TBEnd: TToolButton;
    TBNoEnd: TToolButton;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    ToolButton1: TToolButton;
    btnChk: TToolButton;
    btnReChk: TToolButton;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    OrdType: TcxComboBox;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column11: TcxGridDBColumn;
    Tv1Column12: TcxGridDBColumn;
    Tv1Column13: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    DSImage: TDataSource;
    ADOQuery1: TADOQuery;
    Picture4: TcxDBImage;
    Tv1Column16: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBEditClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure TBExportClick(Sender: TObject);
    procedure TBPrintClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBAddClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure conPress(Sender: TObject; var Key: Char);
    procedure TBViewClick(Sender: TObject);
    procedure TBCopyClick(Sender: TObject);
    procedure OrdTypeChange(Sender: TObject);
    procedure C_CodeKeyPress(Sender: TObject; var Key: Char);
    procedure BatchNoHZKeyPress(Sender: TObject; var Key: Char);
    procedure CustNameKeyPress(Sender: TObject; var Key: Char);
    procedure C_NameKeyPress(Sender: TObject; var Key: Char);
    procedure cxTabControl1Change(Sender: TObject);
    procedure TBEndClick(Sender: TObject);
    procedure TBNoEndClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure btnChkClick(Sender: TObject);
    procedure btnReChkClick(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
    procedure Picture4DblClick(Sender: TObject);
    procedure ConNoPropertiesChange(Sender: TObject);
  private
    FInt, PFInt: Integer;
    procedure InitGrid();
    procedure InitForm();
    function DelData(): Boolean;
    procedure InitButton();
    { Private declarations }
  public
    canshu1, FCheJian: string;
    fStatus : Integer; //0新增, 1修改
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_TatGYInPut, U_TatCardInPut;

{$R *.dfm}

procedure TfrmTatGYList.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
end;

procedure TfrmTatGYList.InitButton();
begin

  TBAdd.Enabled := False;
  TBCopy.Enabled := False;
  TBEdit.Enabled := False;
  TBDel.Enabled := False;
  TBEnd.Enabled := False;
  TBNoEnd.Enabled := False;
  btnChk.Enabled := False;
  btnReChk.Enabled := False;
  if Trim(canshu1) = '录入' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          TBAdd.Enabled := true;
          TBCopy.Enabled := true;
          TBDel.Enabled := true;
          TBEdit.Enabled := true;
          btnChk.Enabled := true;

        end;
      1:
        begin
          TBAdd.Enabled := true;
          TBCopy.Enabled := true;
          TBEnd.Enabled := true;
          TBEdit.Enabled := true;
          btnReChk.Enabled := true;
        end;
      2:
        begin
          TBNoEnd.Enabled := true;
        end;
    end;
  end;

  if Trim(canshu1) = '管理' then
  begin
    case cxTabControl1.TabIndex of
      0:
        begin
          TBAdd.Enabled := true;
          TBCopy.Enabled := true;
          TBDel.Enabled := true;
          TBEdit.Enabled := true;
          btnChk.Enabled := true;
        end;
      1:
        begin
          TBAdd.Enabled := true;
          TBCopy.Enabled := true;
          TBEnd.Enabled := true;
          TBEdit.Enabled := true;
          btnReChk.Enabled := true;
        end;
      2:
        begin
          TBNoEnd.Enabled := true;
        end;
    end;
  end;

end;

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

procedure TfrmTatGYList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      sql.Add('select A.*,B.*,FileName=(select FileName from TP_File X inner join Bs_Contract_Sub Y on X.FileName=Y.AttName where Y.ConSID = B.ConSID   )   ');
      sql.Add(' from Tat_Plan_Main A inner join Tat_Plan_Sub B on A.Mainid=B.MainId');
      sql.Add('where 1=1 ');
      case cxTabControl1.TabIndex of
        0:
          begin
            sql.Add('and isnull(Status,''0'') =''11'' ');
          end;
        1:
          begin
            sql.Add('and isnull(Status,''0'') =''22'' ');
          end;
        2:
          begin
            sql.Add('and isnull(Status,''0'') in(''11'',''22'') ');
          end;
      end;

      sql.add('order by A.FILLTIME DESC');
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmTatGYList.InitForm();
begin

  ReadCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
  BegDate.Date := SGetServerDate(ADOQueryTemp) - 30;
  EndDate.Date := SGetServerDate(ADOQueryTemp);
  InitButton();
  InitGrid();
end;

procedure TfrmTatGYList.TBFindClick(Sender: TObject);
begin
  TBRafresh.Click;
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.TBNoEndClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Tat_Plan_Main SET status=''0'',Comper=null,Comptime=null ');
      sql.Add('where mainID=' + quotedstr(trim(CDS_1.fieldbyname('mainID').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('生产单撤销结束')));
      sql.Add(',' + quotedstr(trim('计划单号：' + trim(CDS_1.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('撤销结束成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('撤销结束失败！', '提示信息', 0);
  end;
end;

procedure TfrmTatGYList.TBEditClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmTatGYInPut := TfrmTatGYInPut.Create(Application);
    with frmTatGYInPut do
    begin
      //PState := 1;
      fStatus := 1;
      FMainId := Trim(Self.CDS_1.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.CDS_1.fieldbyname('SubId').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
        Self.CDS_1.Locate('MainId', frmTatGYInPut.FMainId, []);
      end;
    end;
  finally
    frmTatGYInPut.Free;
  end;
end;

procedure TfrmTatGYList.TBEndClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Tat_Plan_Main SET status=''10'' ,Comper=''' + trim(DName) + ''',Comptime=getdate() ');
      sql.Add('where mainID=' + quotedstr(trim(CDS_1.fieldbyname('mainID').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('生产单结束')));
      sql.Add(',' + quotedstr(trim('计划单号：' + trim(CDS_1.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('结束成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('结束失败！', '提示信息', 0);
  end;
end;

procedure TfrmTatGYList.TBDelClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    SQL.Add('select A.*');
    sql.Add('from Tat_Plan_Card A');
    sql.Add(' where  isnull(Status,''0'') <>''-1'' and A.SubId=''' + Trim(CDS_1.fieldbyname('SubId').AsString) + '''');
    sql.Add(' and A.MainId=''' + Trim(CDS_1.fieldbyname('MainId').AsString) + '''');
    Open;
  end;
  if ADOQueryTemp.IsEmpty = False then
  begin
    Application.MessageBox('已产生安排数据不能删除!', '提示', 0);
    Exit;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  if DelData() then
  begin
    CDS_1.Delete;
  end;
end;

function TfrmTatGYList.DelData(): Boolean;
begin
  try
    Result := false;
    ADOQueryCmd.Connection.BeginTrans;
    with ADOQueryCmd do
    begin
      Close;
      sql.Clear;
      sql.Add('delete Tat_Plan_Sub where SubId=''' + Trim(CDS_1.fieldbyname('SubId').AsString) + '''');
      ExecSQL;
    end;
    with ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from Tat_Plan_Sub where MainId=''' + Trim(CDS_1.fieldbyname('MainId').AsString) + '''');
      Open;
    end;
    if ADOQueryTemp.IsEmpty then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Tat_Plan_Main where MainId=''' + Trim(CDS_1.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;
    end;
    if Trim(CDS_1.fieldbyname('SubId').AsString) = '' then
    begin
      with ADOQueryCmd do
      begin
        Close;
        sql.Clear;
        sql.Add('delete Tat_Plan_Main where MainId=''' + Trim(CDS_1.fieldbyname('MainId').AsString) + '''');
        ExecSQL;
      end;
    end;
    ADOQueryCmd.Connection.CommitTrans;
    Result := True;
  except
    ADOQueryCmd.Connection.RollbackTrans;
    Result := False;
    Application.MessageBox('数据删除异常！', '提示', 0);
  end;
end;

procedure TfrmTatGYList.TBExportClick(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel('坯布生产单', cxGrid1);
end;

procedure TfrmTatGYList.TBPrintClick(Sender: TObject);
var
  WSql: string;
begin
  if CDS_1.IsEmpty then
    Exit;
  WSql := Trim(CDS_1.fieldbyname('MainId').AsString);

  try
    frmLabelPrint := TfrmLabelPrint.Create(Application);
    with frmLabelPrint do
    begin
      FLMType := 'TatPlanPrint2';
      FFiltration1 := WSql;
      FFiltration2 := WSql;
      FFiltration3 := WSql;
      if ShowModal = 1 then
      begin
//        Self.InitGrid();
      end;
    end;
  finally
    frmLabelPrint.Free;
  end;

end;

procedure TfrmTatGYList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmTatGYList.TBAddClick(Sender: TObject);
begin

  try
    frmTatGYInPut := TfrmTatGYInPut.Create(Application);
    with frmTatGYInPut do
    begin
      FStatus := 0;
      FMainId := '';
      FSubId := '';
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTatGYInPut.Free;
  end;
end;

procedure TfrmTatGYList.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.ConNoPropertiesChange(Sender: TObject);
begin
  TBRafresh.Click;
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.FormShow(Sender: TObject);
begin
  inherited;
  canshu1 := DParameters1;
  InitForm();

end;

procedure TfrmTatGYList.conPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
  begin
    if Length(Trim(ConNo.Text)) < 4 then
      Exit;
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Filtered := False;
        Close;
        sql.Clear;
        //sql.Add('exec Tat_Plan_QryList :MainId,:WSql');
       // Parameters.ParamByName('WSql').Value:=' and OM.conNo like '''+'%'+Trim(ConNoM.Text)+'%'+''''
                                             // +' and ConType=''生产'' ';
        sql.Add('select * from Tat_Plan_Main A inner join Tat_Plan_Sub B on A.Mainid=B.MainId');
        sql.Add(' where A.ConNo like ''' + '%' + Trim(ConNo.Text) + '%' + '''');

        Open;
      end;
      SCreateCDS(ADOQueryMain, CDS_1);
      SInitCDSData(ADOQueryMain, CDS_1);
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

procedure TfrmTatGYList.TBViewClick(Sender: TObject);
begin
  try
    frmTatGYInPut := TfrmTatGYInPut.Create(Application);
    with frmTatGYInPut do
    begin
      PState := 1;
      FMainId := Trim(Self.CDS_1.fieldbyname('MainId').AsString);
      FSubId := Trim(Self.CDS_1.fieldbyname('SubId').AsString);
      FConNo := Trim(Self.CDS_1.fieldbyname('ConNo').AsString);
      TBSave.Visible := False;
      ScrollBox1.Enabled := False;
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmTatGYInPut.Free;
  end;
end;

procedure TfrmTatGYList.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid('坯布生产计划单', Tv1, '坯布生产管理');
end;

procedure TfrmTatGYList.Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQuery1 do
  begin
    close;
    sql.Clear;
    sql.Add(' select * from TP_File A    ');
    sql.Add(' where TFType =''HX'' and A.FileName =' + quotedstr(trim(CDS_1.fieldbyname('FileName').AsString)));
//    ShowMessage(sql.text);
    open;
  end;
end;

procedure TfrmTatGYList.btnChkClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    exit;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Tat_Plan_Main SET status=''22'',chker=''' + trim(DName) + ''',Chktime=getdate() ');
      sql.Add('where mainID=' + quotedstr(trim(CDS_1.fieldbyname('mainID').AsString)));

      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('工艺单审核')));
      sql.Add(',' + quotedstr(trim('计划单号：' + trim(CDS_1.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    application.MessageBox('审核成功！', '提示信息');
    TBRafresh.Click;
  except
    application.MessageBox('审核失败！', '提示信息', 0);
  end;
end;

procedure TfrmTatGYList.btnReChkClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    exit;
  if cxTabControl1.TabIndex <> 1 then
  begin
    Application.MessageBox('只能在已审核状态下进行该操作!', '提示', 0);
    Exit;
  end;
  try
    with ADOQueryCmd do
    begin
      close;
      sql.Clear;
      sql.Add('update  Tat_Plan_Main SET status=''11'',chker=null,Chktime=null ');
      sql.Add('where mainID=' + quotedstr(trim(CDS_1.fieldbyname('mainID').AsString)));
      sql.Add('insert into SY_SysLog(operor,opertime,Model,acction,opevent,result) values( ');
      sql.Add(' ' + quotedstr(trim(DName)));
      sql.Add(',getdate() ');
      sql.Add(',' + quotedstr(trim(self.Caption)));
      sql.Add(',' + quotedstr(trim('工艺单撤销审核')));
      sql.Add(',' + quotedstr(trim('计划单号：' + trim(CDS_1.FieldByName('OrderNo').AsString))));
      sql.Add(',' + quotedstr(trim('成功')));
      sql.Add(')');
      execsql;
    end;
    TBRafresh.Click;
  except
    application.MessageBox('计划单撤销开始失败！', '提示信息', 0);
  end;
end;

procedure TfrmTatGYList.TBCopyClick(Sender: TObject);
begin
  if CDS_1.IsEmpty then
    Exit;
  try
    frmTatGYInPut := TfrmTatGYInPut.Create(Application);
    with frmTatGYInPut do
    begin
      PState := 1;
      FCopyInt := 1;
      FMainId := Trim(Self.CDS_1.fieldbyname('MainId').AsString);
      FConNo := Trim(Self.CDS_1.fieldbyname('ConNo').AsString);
      if ShowModal = 1 then
      begin

      end;
    end;
  finally
    frmTatGYInPut.Free;
  end;
end;

procedure TfrmTatGYList.OrdTypeChange(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmTatGYList.Picture4DblClick(Sender: TObject);
var
  IdFTP1: TIdFTP;
  FPath, FFName: string;
  FInt: integer;
  mfileSize: Integer;
  mCreationTime: TdateTime;
  mWriteTime: TdateTime;
begin
  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;
  FPath := 'D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName := Trim(CDS_1.fieldbyname('FileName').AsString);
  FFName := FPath + FFName;
  if FileExists(FFName) then
  begin
    FInt := 1;
    GetFileInfo(FFName, mfileSize, mCreationTime, mWriteTime);

    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select TFID,WBID,TFDate,Files,Filler,FillTime,FileName from TP_File A     ');
      SQL.Add(' where FileName=''' + Trim(CDS_1.fieldbyname('FileName').AsString) + '''');
      SQL.Add(' and FileType=''HX'' ');
      SQL.Add(' and TFDate>''' + FormatDateTime('yyyy-MM-dd hh:nn:ss', mWriteTime) + '''');
//     ShowMessage(SQL.Text);
      Open;
    end;
    if not ADOQueryTemp.IsEmpty then
    begin
      if FileExists(FFName) then
        DeleteFile(FFName);
      FInt := 0;
    end;

  end;
  if FInt <> 1 then
    IdFTP1.Get(UserDataFlag + 'HX\' + CDS_1.fieldbyname('FileName').AsString, pchar(FFName));

  if IdFTP1.Connected then
  begin
    IdFTP1.Quit;
    IdFTP1.Free;
  end;
  ShellExecute(Handle, 'open', PChar(FFName), '', '', SW_SHOWNORMAL);

end;

procedure TfrmTatGYList.C_CodeKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.BatchNoHZKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.CustNameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmTatGYList.cxTabControl1Change(Sender: TObject);
begin
  InitButton();
  InitGrid();
end;

procedure TfrmTatGYList.C_NameKeyPress(Sender: TObject; var Key: Char);
begin
  if Key = #13 then
    TBRafresh.Click();
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

end.

