unit U_ClothTypeSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, DB, ADODB, cxLookAndFeels,
  cxLookAndFeelPainters, cxTLdxBarBuiltInMenu, dxSkinsCore,
  dxSkinsDefaultPainters, Datasnap.DBClient, Vcl.StdCtrls, Vcl.ExtCtrls;

type
  TfrmClothTypeSel = class(TForm)
    ADOConnection1: TADOConnection;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    ADOQueryTree: TADOQuery;
    CDS_Tree: TClientDataSet;
    DS_Tree: TDataSource;
    Panel8: TPanel;
    Label1: TLabel;
    CTName: TEdit;
    ADOQueryTemp: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure CTNameChange(Sender: TObject);
  private
    { Private declarations }
  public
    FCTType: string;
    { Public declarations }
  end;

var
  frmClothTypeSel: TfrmClothTypeSel;

implementation

uses
  U_DataLink, U_RTFun;
{$R *.dfm}

procedure TfrmClothTypeSel.FormCreate(Sender: TObject);
begin
  cxDBTreeList1.Align := alclient;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
  except
  end;
end;

procedure TfrmClothTypeSel.FormShow(Sender: TObject);
begin
  with ADOQueryTree do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from BS_Cloth_Type where CTType=' + quotedstr(FCTType));
    Open;
  end;
  SCreateCDS(ADOQueryTree, CDS_Tree);
  SInitCDSData(ADOQueryTree, CDS_Tree);
  cxDBTreeList1.Items[0].Expand(false);
end;

procedure TfrmClothTypeSel.CTNameChange(Sender: TObject);
var
  Fctname: string;
begin
  inherited;

  with ADOQueryTemp do
  begin
    close;
    sql.Clear;
    sql.Add('select * from BS_Cloth_Type where CTName like ''%' + trim(ctname.Text) + '%'' ');
    open;
  end;

  if ADOQueryTemp.IsEmpty then
    Fctname := ''
  else
    Fctname := ctname.Text;

  with ADOQueryTree do
  begin
    close;
    sql.Clear;
    sql.add('exec P_BS_CloInfo_Tree ''%' + trim(Fctname) + '%'' ');
    open;
  end;
  SCreateCDS(ADOQueryTree, CDS_Tree);
  SInitCDSData(ADOQueryTree, CDS_Tree);
  cxDBTreeList1.Items[0].Expand(false);
  cxDBTreeList1.fullexpand;

  CDS_Tree.Locate('CTName', ADOQueryTree.FieldByName('FirstName').AsString, [])
end;

procedure TfrmClothTypeSel.cxDBTreeList1DblClick(Sender: TObject);
begin
  if CDS_Tree.IsEmpty then
    exit;
  ModalResult := 1;
end;

end.

