unit U_CPManageTPCX;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, BtnEdit, cxButtonEdit,
  cxDropDownEdit, cxTextEdit, cxCalendar, Menus,jpeg;

type
  TfrmCPManageTPCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    DataSource1: TDataSource;
    ADOQueryTree10: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxSplitter1: TcxSplitter;
    Panel1: TPanel;
    Label2: TLabel;
    CYID: TEdit;
    ToolButton2: TToolButton;
    Label1: TLabel;
    CYName: TEdit;
    Label5: TLabel;
    CYSpec: TEdit;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton4: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    ToolButton6: TToolButton;
    Label3: TLabel;
    CYNO: TEdit;
    Panel2: TPanel;
    DSCYNO: TDataSource;
    CDS_CYNO: TClientDataSet;
    Edit1: TEdit;
    Label6: TLabel;
    Label7: TLabel;
    CYKZ: TEdit;
    Label8: TLabel;
    CYCF: TEdit;
    Label10: TLabel;
    CYMF: TEdit;
    Label4: TLabel;
    CYXLType: TEdit;
    Button1: TButton;
    Panel3: TPanel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column19: TcxGridDBColumn;
    v1Column12: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column26: TcxGridDBColumn;
    v1Column29: TcxGridDBColumn;
    v1Column32: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    cxSplitter2: TcxSplitter;
    Panel4: TPanel;
    cxGrid3: TcxGrid;
    Tv3: TcxGridDBTableView;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn14: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    CDS_CB: TClientDataSet;
    DSCB: TDataSource;
    cxGridPopupMenu2: TcxGridPopupMenu;
    CDS_GY: TClientDataSet;
    DSGY: TDataSource;
    cxGridPopupMenu3: TcxGridPopupMenu;
    ADOQuery1: TADOQuery;
    v1Column17: TcxGridDBColumn;
    v3Column1: TcxGridDBColumn;
    v3Column2: TcxGridDBColumn;
    ToolButton11: TToolButton;
    Label9: TLabel;
    GYStr: TComboBox;
    Label11: TLabel;
    HX: TEdit;
    v1Column18: TcxGridDBColumn;
    Button2: TButton;
    Edit2: TEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column20: TcxGridDBColumn;
    v1Column21: TcxGridDBColumn;
    ADOQueryTree: TClientDataSet;
    TBSel: TToolButton;
    Panel5: TPanel;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    Image2: TImage;
    cxGrid62: TcxGrid;
    Tv2: TcxGridDBTableView;
    v6Column1: TcxGridDBColumn;
    cxGridDBColumn40: TcxGridDBColumn;
    cxGridDBColumn41: TcxGridDBColumn;
    cxGridDBColumn42: TcxGridDBColumn;
    cxGridDBColumn49: TcxGridDBColumn;
    cxGridDBColumn51: TcxGridDBColumn;
    cxGridLevel5: TcxGridLevel;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure CYIDKeyPress(Sender: TObject; var Key: Char);
    procedure CYNoChange(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure CYSpecChange(Sender: TObject);
    procedure v1Column19PropertiesChange(Sender: TObject);
    procedure CYMFChange(Sender: TObject);
    procedure CYNameChange(Sender: TObject);
    procedure CYCFChange(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure ToolButton11Click(Sender: TObject);
    procedure CYNOKeyPress(Sender: TObject; var Key: Char);
    procedure GYStrChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBSelClick(Sender: TObject);
  private
    { Private declarations }
    CPID:string;
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitTree();
    procedure InitGrid();
    procedure ReadINIFile();
    procedure InitImage();

  public
    { Public declarations }
  end;

var
  frmCPManageTPCX: TfrmCPManageTPCX;

implementation
uses
  U_DataLink,U_RTFun, U_ZDYHelpSel;

{$R *.dfm}

procedure TfrmCPManageTPCX.InitTree();
var
  i:Integer;
begin
  with ADOQueryTree10 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from CP_Type order by CPlevel,CPOrder,CPName');
    Open;
  end;
  SCreateCDS20(ADOQueryTree10,ADOQueryTree);
  SInitCDSData20(ADOQueryTree10,ADOQueryTree);
  cxDBTreeList1.Items[0].Expand(false);
  //cxDBTreeList1.Items[1].Expand(False);
end;

procedure TfrmCPManageTPCX.InitGrid();
begin
  Panel2.Visible:=True;
  Panel2.Refresh;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      SQL.Add('exec P_Select_CP_YDang :Code,:PState,:CYType');
      Parameters.ParamByName('Code').Value:='';
      Parameters.ParamByName('PState').Value:=0;
      Parameters.ParamByName('CYType').Value:=Trim(ADOQueryTree.fieldbyname('CPID').AsString);
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel2.Visible:=False;
end;

procedure TfrmCPManageTPCX.FormDestroy(Sender: TObject);
begin
  frmCPManageTPCX:=nil;
end;

procedure TfrmCPManageTPCX.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action:=caFree;
 // Action:=caHide;
end;

procedure TfrmCPManageTPCX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('样品列表SF',Tv1,'样品管理');
  WriteCxGrid('样品列表SF1a',Tv2,'样品管理');
  WriteCxGrid('样品列表SF2',Tv3,'样品管理');
  if  DirectoryExists(ExtractFileDir('D:\Right1209')) then
    winexec('cmd /c rd /s /q D:\Right1209',sw_hide);
  Close;
end;
procedure TfrmCPManageTPCX.FormShow(Sender: TObject);
begin
  InitTree();
  ReadCxGrid('样品列表SF',Tv1,'样品管理');
  ReadCxGrid('样品列表SF1a',Tv2,'样品管理');
  ReadCxGrid('样品列表SF2',Tv3,'样品管理');
  
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CYID='''' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_CYNO);
  SInitCDSData20(ADOQueryTemp,CDS_CYNO);
  CDS_CYNO.Delete;
end;

procedure TfrmCPManageTPCX.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmCPManageTPCX.TBRafreshClick(Sender: TObject);
var
  DWCYID:String;
begin
  InitTree();
  if CDS_Main.IsEmpty=False then
    DWCYID:=Trim(CDS_Main.fieldbyname('CYID').AsString);
  InitGrid();
  CDS_Main.Locate('CYID',DWCYID,[]);
end;

procedure TfrmCPManageTPCX.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.CYIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,CPName=(select CPName from CP_Type B where B.CPID=A.CYType)  ');
      sql.Add(' from CP_YDang A where CYID='''+Trim(CYID.Text)+'''');
      Open;
    end;
    CPID:=Trim(ADOQueryMain.fieldbyname('CYType').AsString);
    if Trim(CYID.Text)='' then Exit;
    //SDofilter(ADOQueryMain,' CYID='''+Trim(CYID.Text)+''' ');
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    CYID.Text:='';
    ADOQueryTree.Locate('CPID',CPID,[]);
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from CP_Cost where CYID='''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
      Open;
    end;
    SCreateCDS20(ADOQuery1,CDS_CB);
    SInitCDSData20(ADOQuery1,CDS_CB);
  end;
end;

procedure TfrmCPManageTPCX.CYNoChange(Sender: TObject);
begin
  if Trim(Trim(TEdit(Sender).Text))<>'' then
    if Length(Trim(TEdit(Sender).Text))<4 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.ToolButton4Click(Sender: TObject);
var
   fPrintFile,FFCYID:string;
   DPS,i,j:Integer;
begin
  CYID.SetFocus;
  if CDS_Main.IsEmpty then Exit;
  //if CDS_CYNO.IsEmpty then Exit;
  if Trim(Edit1.Text)<>'' then
  begin
    if TryStrToInt(Edit1.Text,i)=False then
    begin
      Application.MessageBox('份数录入错误!','提示',0);
      exit;
    end;
  end;

  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\样品标签.rmf';
  CDS_Main.DisableControls;
  DPS:=0;
  FFCYID:='';
  i:=1;
  if Trim(Edit1.Text)='' then
  begin
    j:=1;
  end else
  begin
    j:=StrToInt(Edit1.Text);
  end;
  with CDS_Main do
  begin
    First;
    while not Eof do
    begin
      if CDS_Main.FieldByName('SSel').AsBoolean=True then
      begin
        for i:=1 to j do
        begin
          if FileExists(fPrintFile) then
          begin
            RM1.LoadFromFile(fPrintFile);
            RM1.PrintReport;
            //RM1.ShowReport;
          end else
          begin
            Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\样品标签.rmf'),'提示',0);
            Exit;
          end;
        end;

        if DPS=0 then
        begin
          FFCYID:=Trim(CDS_Main.fieldbyname('CYID').AsString);
        end;
      end;
      //CDS_Main.Locate('CYID',Trim(CDS_CYNO.fieldbyname('CYID').AsString),[]);

      Next;
    end;
  end;
  CDS_Main.EnableControls;
  CDS_Main.Locate('CYID',FFCYID,[]);
  Edit1.Text:='1';

end;

procedure TfrmCPManageTPCX.InitImage();
var
  jpg:TJpegImage;
  myStream:TADOBlobStream;
begin
  if CDS_Main.IsEmpty then Exit;
  if Trim(CDS_Main.fieldbyname('CYID').AsString)='' then Exit;
 // if cxPageControl1.ActivePageIndex=6 then
  begin
    Image2.Picture.Assign(nil);
    try
      with ADOQueryTemp do
      begin
        close;
        sql.Clear;
        sql.Add(' select * from TP_File A where A.WBID='''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
        sql.Add(' and TFType=''样品'' ');
        open;
        if RecordCount>0 then
        begin
          if trim(ADOQueryTemp.fieldbyname('FilesOther').AsString)<>'' then
          begin
            myStream:=tadoblobstream.Create(tblobfield(ADOQueryTemp.fieldbyname('FilesOther')),bmread);
            if myStream=nil then exit;
            jpg:=TJPEGImage.Create;
            jpg.LoadFromStream(myStream);
            Image2.Picture.Assign(jpg);
          end;
        end;
      end;
    finally
      jpg.Free;
      myStream.Free;
    end;
  end;
end;

procedure TfrmCPManageTPCX.ToolButton6Click(Sender: TObject);
var
  fHandle:THandle;
  FInt:Integer;
  FFName,FPath:String;
begin
  {FPath:='C:\HTTP1209\';
  if  DirectoryExists(ExtractFileDir(FPath)) then
    winexec('cmd /c rd /s /q C:\HTTP1209',sw_hide);}
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from XD_File where CYID='''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
    Open;
    if IsEmpty then
    begin
      Application.MessageBox('样品图片未上传！','提示',0);
      Exit;
    end;
  end;
  try
    ReadINIFile();
    server:=ReadINIFileStr('SYSTEMSET.INI','SERVER','服务器地址','127.0.0.1');
    if Length(server)<6 then
    begin
      server:='127.0.0.1';
    end;
    IdFTP1.Host :=server;//PicSvr;
    IdFTP1.Username := 'three';
    IdFTP1.Password := '641010';
    IdFTP1.Connect();
  except
    IdFTP1.Quit;
    Application.MessageBox('无法连接到文件服务器，请检查！', '提示', MB_ICONWARNING);
    Exit;
  end;
  FPath:='D:\Right1209\';
  if not DirectoryExists(ExtractFileDir(FPath)) then
    CreateDir(ExtractFileDir(FPath));
  FFName:=Trim(ADOQueryTemp.fieldbyname('FileName').AsString);
  FFName:=FPath+FFName;
  if FileExists(FFName) then
  begin
    FInt:=1;
  end;
  if FInt<>1 then
    IdFTP1.Get('YP\'+Trim(ADOQueryTemp.fieldbyname('FileName').AsString),
                   FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString)
                    );
  if IdFTP1.Connected then IdFTP1.Quit;
  ShellExecute(Handle, 'open',PChar(FPath+Trim(ADOQueryTemp.fieldbyname('FileName').AsString)),'', '', SW_SHOWNORMAL);

end;
procedure TfrmCPManageTPCX.ReadINIFile();
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 TfrmCPManageTPCX.Tv1CellDblClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  //ToolButton6.Click;
  if CDS_Main.FieldByName('CostFlag').AsBoolean=False then
    ModalResult:=1;
end;

procedure TfrmCPManageTPCX.CYSpecChange(Sender: TObject);
begin
  if Length(Trim(CYSpec.Text))<3 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.v1Column19PropertiesChange(Sender: TObject);
var
  mvalue:Boolean;
begin
 { mvalue:=TcxCheckBox(Sender).EditingValue;
  if mvalue=True then
  begin
    with CDS_CYNO do
    begin
      if Locate('CYID',Trim(CDS_Main.fieldbyname('CYID').AsString),[])=False then
      begin
        Append;
        FieldByName('CYID').Value:=Trim(CDS_Main.fieldbyname('CYID').AsString);
        Post;
      end;
    end;
  end else
  begin
    //with CDS_CYNO do
    //begin
    CDS_CYNO.Locate('CYID',Trim(CDS_Main.fieldbyname('CYID').AsString),[]);
    CDS_CYNO.Delete;
    //end;
  end; }
end;

procedure TfrmCPManageTPCX.CYMFChange(Sender: TObject);
begin
  if Length(Trim(TEdit(Sender).Text))<2 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.CYNameChange(Sender: TObject);
begin
  if Length(Trim(TEdit(Sender).Text))<2 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.CYCFChange(Sender: TObject);
begin

  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.Button1Click(Sender: TObject);
begin
  try
    frmZDYHelpSel:=TfrmZDYHelpSel.Create(Application);
    with frmZDYHelpSel do
    begin
      flag:='CYXLType';
      flagname:='系列';
      FGStr:=' ';
      if ShowModal=1 then
      begin
        CYXLType.Text:=ReturnStr;
      end;
    end;
  finally
    frmZDYHelpSel.Free;
  end;
  //if Length(Trim(CYXLType.Text))<2 then Exit;
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.Tv2FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from CP_Cost_HGY where PSID='''+Trim(CDS_CB.fieldbyname('PSID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_GY);
  SInitCDSData20(ADOQueryTemp,CDS_GY);
end;

procedure TfrmCPManageTPCX.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Main.IsEmpty then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from CP_YDang where CYID='''+Trim(CDS_Main.fieldbyname('CYID').asstring)+'''');
    Open;
  end;
  CPID:=Trim(ADOQueryTemp.fieldbyname('CYType').AsString);
  ADOQueryTree.Locate('CPID',CPID,[]);
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    sql.Add('select * from CP_Cost where CYID='''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_CB);
  SInitCDSData20(ADOQuery1,CDS_CB);
  InitImage();
end;

procedure TfrmCPManageTPCX.ToolButton11Click(Sender: TObject);
var
   fPrintFile,FFCYID:string;
   DPS,i,j:Integer;
begin
  CYID.SetFocus;
  if CDS_Main.IsEmpty then Exit;
  fPrintFile:= ExtractFilePath(Application.ExeName) + 'Report\样品标签.rmf';
  with CDS_Main do
  begin
    if FileExists(fPrintFile) then
    begin
      RM1.LoadFromFile(fPrintFile);
      //RM1.PrintReport;
      RM1.ShowReport;
    end else
    begin
      Application.MessageBox(PChar('没有找'+ExtractFilePath(Application.ExeName)+'Report\样品标签.rmf'),'提示',0);
      Exit;
    end;
  end;

end;

procedure TfrmCPManageTPCX.CYNOKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    if Trim(CYNO.Text)='' then Exit;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add('select A.*,CPName=(select CPName from CP_Type B where B.CPID=A.CYType)  ');
      sql.Add(' ,HX=isnull(CYHX,'''')+isnull(CYHX2,'''')+isnull(CYHX3,'''')');
      sql.Add(' from CP_YDang A where CYNO='''+Trim(CYNO.Text)+'''');
      Open;
    end;
    CPID:=Trim(ADOQueryMain.fieldbyname('CYType').AsString);

    //SDofilter(ADOQueryMain,' CYID='''+Trim(CYID.Text)+''' ');
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
    with ADOQuery1 do
    begin
      Close;
      SQL.Clear;
      sql.Add('select * from CP_Cost where CYID='''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
      Open;
    end;
    SCreateCDS20(ADOQuery1,CDS_CB);
    SInitCDSData20(ADOQuery1,CDS_CB);
    CYNO.Text:='';
    ADOQueryTree.Locate('CPID',CPID,[]);
  end;
end;

procedure TfrmCPManageTPCX.GYStrChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmCPManageTPCX.Button2Click(Sender: TObject);
var
   FColumn,FColumnName,Fsj:String;
begin
  if CDS_Main.Locate('SSel',True,[])=False then
  begin
    Application.MessageBox('没有选择数据!','提示',0);
    Exit;
  end;
  FColumn:=Tv1.Controller.FocusedColumn.DataBinding.FilterFieldName;
  FColumnName:=Tv1.Controller.FocusedColumn.Caption;
  if Trim(Edit2.Text)='' then
  begin
    Application.MessageBox('内容不能为空!','提示',0);
    Exit;
  end;
  if Application.MessageBox(Pchar('确定要一键替换<'+FColumnName+'>吗？'),'提示',32+4)<>IDYES then Exit;
  CDS_Main.DisableControls;
  with CDS_Main do
  begin
    while Locate('SSel',True,[]) do
    begin
      if Trim(fsj)='' then
      begin
        fsj:='('''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''';
      end else
      begin
        Fsj:=fsj+','''+Trim(CDS_Main.fieldbyname('CYID').AsString)+'''';
      end;
      Edit;
      FieldByName('SSel').Value:=False;
      FieldByName(FColumn).Value:=Trim(Edit2.Text);
      Post;

    end;
    if Trim(Fsj)<>'' then
    begin
      Fsj:=Fsj+')';
    end;
  end;
  CDS_Main.EnableControls;
  with ADOQueryCmd do
  begin
    Close;
    sql.Clear;
    sql.Add('Update CP_YDang Set '+FColumn+'='''+Trim(Edit2.Text)+'''');
    sql.Add(',Editer='''+Trim(DName)+''',EditTime=getdate()');
    sql.Add(' where CYID in '+fsj);
    ExecSQL;
  end;
end;

procedure TfrmCPManageTPCX.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

procedure TfrmCPManageTPCX.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,False);
end;

procedure TfrmCPManageTPCX.TBSelClick(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
