unit U_CPManage_ColCX;

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, RM_BarCode,
  cxButtonEdit, cxTextEdit,jpeg,U_SLT,Math, Menus, cxLookAndFeels,
  cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, cxNavigator;

type
  TfrmCPManage_ColCX = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource1: TDataSource;
    ADOQueryTree: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    cxSplitter1: TcxSplitter;
    ToolButton2: TToolButton;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    ODPat: TOpenDialog;
    IdFTP1: TIdFTP;
    SaveDialog1: TSaveDialog;
    Panel2: TPanel;
    DSCYNO: TDataSource;
    CDS_CYNO: TClientDataSet;
    RMBarCodeObject1: TRMBarCodeObject;
    Panel3: TPanel;
    adoqueryPicture: TADOQuery;
    Panel6: TPanel;
    Label23: TLabel;
    LBCPAP: TLabel;
    BTLP: TButton;
    BTNP: TButton;
    TCBNOR: TComboBox;
    DataSource3: TDataSource;
    CDS_Sub: TClientDataSet;
    ADOQuery1: TADOQuery;
    Label16: TLabel;
    RMDB_Sub: TRMDBDataSet;
    RM2: TRMGridReport;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1CYNo: TcxGridDBColumn;
    v1CPName: TcxGridDBColumn;
    v1DefStr2: TcxGridDBColumn;
    v1DefStr10: TcxGridDBColumn;
    v1CYName: TcxGridDBColumn;
    v1CYEName: TcxGridDBColumn;
    v1CYCF: TcxGridDBColumn;
    v1CYECF: TcxGridDBColumn;
    v1CYSpec: TcxGridDBColumn;
    v1DefStr6: TcxGridDBColumn;
    v1CYMF: TcxGridDBColumn;
    v1CYKZ: TcxGridDBColumn;
    v1CYHX: TcxGridDBColumn;
    v1CYColor: TcxGridDBColumn;
    v1CYSeHao: TcxGridDBColumn;
    v1DefStr7: TcxGridDBColumn;
    v1CYPrice12: TcxGridDBColumn;
    v1CYPrice3: TcxGridDBColumn;
    v1CYPrice5: TcxGridDBColumn;
    v1CYPrice15: TcxGridDBColumn;
    v1CYPrice: TcxGridDBColumn;
    v1DefStr11: TcxGridDBColumn;
    v1CYNote: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    v1XYPlace: TcxGridDBColumn;
    Panel4: TPanel;
    Label17: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    Button1: TButton;
    RadioGroup1: TRadioGroup;
    ADOQuery2: TADOQuery;
    TSsel: TToolButton;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    ADOQuery3: TADOQuery;
    ADOQuery4: TADOQuery;
    cxGrid4: TcxGrid;
    Tv4: TcxGridDBTableView;
    v4CYNo: TcxGridDBColumn;
    v4ColorName: TcxGridDBColumn;
    v4ColorNo: TcxGridDBColumn;
    v4Note: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    cxSplitter4: TcxSplitter;
    v4Ssel: TcxGridDBColumn;
    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 ToolButton1Click(Sender: TObject);
    procedure BTLPClick(Sender: TObject);
    procedure BTNPClick(Sender: TObject);
    procedure TCBNORChange(Sender: TObject);
    procedure CYNOKeyPress(Sender: TObject; var Key: Char);
    procedure Image2Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton14Click(Sender: TObject);
    procedure ToolButton15Click(Sender: TObject);
    procedure ToolButton16Click(Sender: TObject);
    procedure ToolButton17Click(Sender: TObject);
    procedure ToolButton18Click(Sender: TObject);
    procedure ToolButton21Click(Sender: TObject);
    procedure ToolButton12Click(Sender: TObject);
    procedure ToolButton13Click(Sender: TObject);
    procedure TV2CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
    procedure CheckBox1Click(Sender: TObject);
    procedure TSselClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
  private
    { Private declarations }
    CPID:string;
    LP,CP,NP,AP,RN:Integer;
    PState:Integer;
    FCPID,FTopID:String;
    canshu1:string;
    procedure InitTree();
//    procedure InitGrid();
    procedure ReadINIFile();
    procedure InitImage();
    procedure initsub();
    procedure InitImage1();
    procedure InitGrid(CP,NOR:Integer);
    procedure setBtn(CP:Integer);
    procedure setstatus();
  public
    FYPCPID:string;
    { Public declarations }
  end;

var
  frmCPManage_ColCX: TfrmCPManage_ColCX;
  Mach: array of TfrmSlt;

implementation
uses
  U_DataLink,U_Fun,U_CPAdd,U_FileUp, U_YPTypeHelp,U_CPAdd_ZLR;

{$R *.dfm}
procedure TfrmCPManage_ColCX.initsub();
begin
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * ');
    sql.Add(',LBType=(select Top 1 X.CPName from CP_Type X where X.CPID='''+trim(CDS_Main.Fieldbyname('CYType').AsString)+''')');
    sql.Add(' from CP_YDang ');
    sql.Add('where CYType='''+trim(CDS_Main.Fieldbyname('CYID').AsString)+'''');
    open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_Sub);
  SInitCDSData20(ADOQueryTemp,CDS_Sub);
end;

procedure TfrmCPManage_ColCX.InitImage1();
begin
 
end;

procedure TfrmCPManage_ColCX.setstatus();
begin

end;

procedure TfrmCPManage_ColCX.InitImage();
var
  i,j:integer;
  jpg:TJpegImage;
  myStream: TADOBlobStream;
begin

end;

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

procedure TfrmCPManage_ColCX.InitGrid(CP,NOR:Integer);
begin
  ToolBar1.SetFocus;
  Panel2.Visible:=True;
  Panel2.Refresh;
  BTLP.Enabled:=False;
  BTNP.Enabled:=False;
  try
    ADOQueryMain.DisableControls;
    LP:= CP-1;
    NP:= CP+1;
    With ADOQueryTemp do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Select_CP_YDang1 :CYType,:CP,:RON,:WSql,:Stats');
      Parameters.ParamByName('CYType').Value:=Trim(ADOQueryTree.fieldbyname('CPID').AsString);
      Parameters.ParamByName('CP').Value:=CP;
      Parameters.ParamByName('RON').Value:=NOR;
      Parameters.ParamByName('WSql').Value:=' CYID='''+trim(FYPCPID)+'''';
      Parameters.ParamByName('Stats').Value:=1;
      Open;
    end;
    LBCPAP.Caption:= IntToStr(CP)+'/'+ IntToStr(Ceil(ADOQueryTemp.FieldByName('AR').AsInteger/RN));
    AP:= Ceil(ADOQueryTemp.FieldByName('AR').AsInteger/RN);
    Label16.Caption:='共计 '+IntToStr(ADOQueryTemp.FieldByName('AR').AsInteger)+' 条记录';
    if CP>1 then
    begin
      BTLP.Enabled:=true;
    end;
    if CP<Ceil(ADOQueryTemp.FieldByName('AR').AsInteger/RN) then
    begin
      BTNP.Enabled:=true;
    end;
    with ADOQueryMain do
    begin
      Close;
      Filtered:=False;
      sql.Clear;
      sql.Add(' exec P_Select_CP_YDang1 :CYType,:CP,:RON,:WSql,:Stats ');
      Parameters.ParamByName('CYType').Value:=Trim(ADOQueryTree.fieldbyname('CPID').AsString);
      Parameters.ParamByName('CP').Value:=CP;
      Parameters.ParamByName('RON').Value:=NOR;
      Parameters.ParamByName('WSql').Value:=' CYID='''+trim(FYPCPID)+'''';
      Parameters.ParamByName('Stats').Value:=2;
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
  Panel2.Visible:=False;
end;

procedure TfrmCPManage_ColCX.FormDestroy(Sender: TObject);
begin
  frmCPManage_ColCX:=nil;
end;

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

procedure TfrmCPManage_ColCX.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('样品列表',Tv1,'样品管理');
  if  DirectoryExists(ExtractFileDir('D:\Right1209')) then
    winexec('cmd /c rd /s /q D:\Right1209',sw_hide);
  Close;
end;

procedure TfrmCPManage_ColCX.FormShow(Sender: TObject);
begin
  InitTree();
  ReadCxGrid('样品列表',Tv1,'样品管理');
  Label16.Caption:='';
  RN:=StrToInt(Trim(TCBNOR.Text));
  setstatus();
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CYID='''' ');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_CYNO);
  SInitCDSData20(ADOQueryTemp,CDS_CYNO);
  CDS_CYNO.Delete;
  InitGrid(1,RN);
end;

procedure TfrmCPManage_ColCX.cxDBTreeList1DblClick(Sender: TObject);
begin
  CP:=1;
  InitGrid(1,RN);
end;

procedure TfrmCPManage_ColCX.TBRafreshClick(Sender: TObject);
begin
  InitTree();
  InitGrid(1,RN);
end;

procedure TfrmCPManage_ColCX.ToolButton1Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  TcxGridToExcel('样品档案',cxGrid1);
end;

procedure TfrmCPManage_ColCX.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 TfrmCPManage_ColCX.BTLPClick(Sender: TObject);
begin
  CP:=LP;
  InitGrid(CP,RN);
end;

procedure TfrmCPManage_ColCX.BTNPClick(Sender: TObject);
begin
  CP:=NP;
  InitGrid(CP,RN);
end;

procedure TfrmCPManage_ColCX.setBtn(CP:Integer);
begin
  if (CP=null) or (CP=1)  then
  begin
    CP:=1;
    BTLP.Enabled:=False;
  end else
  begin
   BTLP.Enabled:=True;
  end;
  if NP>AP then
  begin
    BTNP.Enabled:=False;
  end
  else
  begin
    BTNP.Enabled:=True;
  end;
end;

procedure TfrmCPManage_ColCX.TCBNORChange(Sender: TObject);
begin
  RN:=StrToInt(TCBNOR.Text);
  InitGrid(1,RN);
end;

procedure TfrmCPManage_ColCX.CYNOKeyPress(Sender: TObject; var Key: Char);
var FMXCYID:string;
begin
  if Key=#13 then
  begin
    TEdit(Sender).SetFocus;
    if Trim(TEdit(Sender).Text)='' then Exit;
    with ADOQuery2 do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CP_YDang where '+Trim(TEdit(Sender).Name)+'='+Quotedstr(Trim(TEdit(Sender).Text)));
      Open;
      //ShowMessage(SQL.Text);
    end;
    with ADOQuery3 do
    begin
      Close;
      sql.Clear;
      sql.Add('select * from CP_YDang where CYID='''+Trim(ADOQuery2.fieldbyname('CYType').AsString)+'''');
      Open;
      //ShowMessage(SQL.Text);
    end;
    if ADOQuery3.IsEmpty=false then
    begin
      CPID:=Trim(ADOQuery3.fieldbyname('CYType').AsString);
      FMXCYID:=Trim(ADOQuery3.fieldbyname('CYID').AsString);
    end
    else
    begin
      CPID:=Trim(ADOQuery2.fieldbyname('CYType').AsString);
      FMXCYID:=Trim(ADOQuery2.fieldbyname('CYID').AsString);
    end;
    with ADOQuery2 do
    begin
      Close;
      sql.Clear;
      sql.Add(' exec P_Select_CP_YDang1 :CYType,:CP,:RON,:WSql,:Stats ');
      Parameters.ParamByName('CYType').Value:=CPID;
      Parameters.ParamByName('CP').Value:=1;
      Parameters.ParamByName('RON').Value:=100;
      Parameters.ParamByName('WSql').Value:=' CYID='''+Trim(FMXCYID)+''' ';
      Parameters.ParamByName('Stats').Value:=2;
      Open;
    end;
    SCreateCDS20(ADOQuery2,CDS_Main);
    SInitCDSData20(ADOQuery2,CDS_Main);
  end;
end;

procedure TfrmCPManage_ColCX.Image2Click(Sender: TObject);
begin
  Panel4.Visible:=False;
end;

procedure TfrmCPManage_ColCX.FormCreate(Sender: TObject);
begin
  canshu1:=Trim(DParameters1);
end;

procedure TfrmCPManage_ColCX.ToolButton14Click(Sender: TObject);
begin
  if CDS_Main.IsEmpty then exit;
  frmCPAdd:=TfrmCPAdd.Create(self);
  with frmCPAdd do
  begin
    CopyInt:=2;
    FCYID:=Trim(Self.CDS_Main.fieldbyname('CYID').AsString);
    FCPID:=Trim(Self.CDS_Main.fieldbyname('CYID').AsString);
    FCPNo:=Trim(Self.ADOQueryTree.fieldbyname('CPNo').AsString);
    FCPName:=trim(Self.ADOQueryTree.fieldbyname('CPName').AsString);
    if ShowModal=1 then
    begin
      initsub();
      Self.CDS_Sub.Locate('CYID',FCYID,[]);
    end;
    free;
  end;
end;

procedure TfrmCPManage_ColCX.ToolButton15Click(Sender: TObject);
begin
  if self.CDS_Sub.IsEmpty then exit;
  try
    frmCPAdd:=TfrmCPAdd.Create(Application);
    with frmCPAdd do
    begin
      CopyInt:=1;
      FCYID:=Trim(Self.CDS_Sub.fieldbyname('CYID').AsString);
      FCPID:=Trim(Self.CDS_Sub.fieldbyname('CYType').AsString);
      FCPNo:=Trim(Self.ADOQueryTree.fieldbyname('CPNo').AsString);
      if ShowModal=1 then
      begin
        initsub();
        Self.CDS_Sub.Locate('CYID',FCYID,[]);
      end;
    end;
  finally
    frmCPAdd.Free;
  end;
end;

procedure TfrmCPManage_ColCX.ToolButton16Click(Sender: TObject);
var
  i:integer;
  FieldName:string;
begin
  if CDS_Sub.IsEmpty then Exit;
  try
    frmCPAdd:=TfrmCPAdd.Create(Application);
    with frmCPAdd do
    begin
      CopyInt:=0;
      FCYID:=Trim(Self.CDS_Sub.fieldbyname('CYID').AsString);
      FCPID:=Trim(Self.CDS_Sub.fieldbyname('CYType').AsString);
      FCPNo:=Trim(Self.ADOQueryTree.fieldbyname('CPNo').AsString);
      if ShowModal=1 then
      begin
        initsub();
        Self.CDS_Sub.Locate('CYID',FCYID,[]);
      end;
    end;
  finally
    frmCPAdd.Free;
  end;
end;

procedure TfrmCPManage_ColCX.ToolButton17Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  try
    frmCPAdd:=TfrmCPAdd.Create(Application);
    with frmCPAdd do
    begin
      CopyInt:=0;
      FCYID:=Trim(Self.CDS_Sub.fieldbyname('CYID').AsString);
      FCPID:=Trim(Self.CDS_Sub.fieldbyname('CYType').AsString);
      FCPNo:=Trim(Self.ADOQueryTree.fieldbyname('CPNo').AsString);
      TMXSave.Visible:=false;
      frmCPAdd.ToolButton1.Visible:=false;
      frmCPAdd.ToolButton7.Visible:=false;
      frmCPAdd.ToolButton8.Visible:=false;
      frmCPAdd.ToolButton9.Visible:=false;
      frmCPAdd.ToolButton4.Visible:=false;
      frmCPAdd.ToolButton5.Visible:=false;
      if ShowModal=1 then
      begin

      end;
    end;
  finally
    frmCPAdd.Free;
  end;
end;

procedure TfrmCPManage_ColCX.ToolButton18Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  with ADOQueryCmd do
  begin
    close;
    sql.Clear;
    sql.Add('delete CP_YDang where CYID='''+Trim(CDS_Sub.fieldbyname('CYID').AsString)+'''');
    SQL.Add('delete CP_YDang_Color where CYID='''+Trim(CDS_Sub.fieldbyname('CYID').AsString)+'''');
    SQL.Add('delete CP_YDang_ML where CYID='''+Trim(CDS_Sub.fieldbyname('CYID').AsString)+'''');
    SQL.Add('delete CP_YDang_JG where CYID='''+Trim(CDS_Sub.fieldbyname('CYID').AsString)+'''');
    execsql;
  end;
  CDS_Sub.Delete;
end;

procedure TfrmCPManage_ColCX.ToolButton21Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then exit;
  Panel4.Visible:=true;
end;

procedure TfrmCPManage_ColCX.ToolButton12Click(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then exit;
  try
    frmFileUp:=TfrmFileUp.Create(Application);
    with frmFileUp do
    begin
      Code.Text:=Trim(Self.CDS_Sub.fieldbyname('CYNO').AsString);
      CYID:=Trim(Self.CDS_Sub.fieldbyname('CYID').AsString);
      if ShowModal=1 then
      begin
        Self.InitGrid(NP-1,RN);
        Self.CDS_Sub.Locate('CYID',CYID,[]);
      end;
    end;
  finally
    frmFileUp.Free;
  end;
end;

procedure TfrmCPManage_ColCX.ToolButton13Click(Sender: TObject);
var
  fHandle:THandle;
  FInt:Integer;
  FFName,FPath:String;
begin
  if CDS_Sub.IsEmpty then exit;
  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from XD_File where CYNO='''+Trim(CDS_Sub.fieldbyname('CYNO').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(UserDataFlag+'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 TfrmCPManage_ColCX.TV2CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  if CDS_Sub.IsEmpty then Exit;
  InitImage1();
end;

procedure TfrmCPManage_ColCX.CheckBox1Click(Sender: TObject);
begin
  TBRafresh.Click;
end;

procedure TfrmCPManage_ColCX.TSselClick(Sender: TObject);
begin
  if CDS_Sub.IsEmpty then Exit;
  if CDS_Sub.Locate('ssel',True,[])=false then
  begin
    Application.MessageBox('没有选择数据','提示');
    exit;
  end;
  ModalResult:=1;
end;

procedure TfrmCPManage_ColCX.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,true);
end;

procedure TfrmCPManage_ColCX.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,false);
end;

procedure TfrmCPManage_ColCX.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from CP_YDang_Color where CYID='''+trim(CDS_Main.fieldbyname('CYID').AsString)+'''');
    Open;
  end;
  SCreateCDS20(ADOQuery1,CDS_Sub);
  SInitCDSData20(ADOQuery1,CDS_Sub);
end;

end.
