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, cxFilter, dxScrollbarAnnotations;

type
  TfrmClothTypeSel = class(TForm)
    ADOConnection1: TADOConnection;
    cxDBTreeList1: TcxDBTreeList;
    cxDBTreeList1cxDBTreeListColumn2: TcxDBTreeListColumn;
    DataSource1: TDataSource;
    ADOQueryHelp: TADOQuery;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
  private
    { Private declarations }
  public
    FCTType: string;
    { Public declarations }
  end;

var
  frmClothTypeSel: TfrmClothTypeSel;

implementation

uses
  U_DataLink;
{$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.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Key = VK_ESCAPE then  // VK_ESCAPE 是 ESC 键的常量
  begin
    Key := 0;  // 清除按键，防止继续传递
    Close;     // 或者 ModalResult := mrCancel;
  end;
end;

procedure TfrmClothTypeSel.FormShow(Sender: TObject);
begin
  with ADOQueryHelp do
  begin
    Close;
    SQL.Clear;
    SQL.Add('select * from BS_Cloth_Type where CTType=' + quotedstr(FCTType) + ' order by CTlevel,CTOrder,CTName');
    Open;
  end;
  cxDBTreeList1.Items[0].Expand(false);

  KeyPreview := True;
end;

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

end.

