unit U_CPSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, ExtCtrls, DBClient, DB, ADODB;

type
  TfrmCPSel = class(TForm)
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    ADOQuery1: TADOQuery;
    ClientDataSet1: TClientDataSet;
    procedure FormDestroy(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormShow(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitJP();
    { Private declarations }
  public
    FHMainId,FHInfo:string;
    { Public declarations }
  end;

var
  frmCPSel: TfrmCPSel;

implementation
uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmCPSel.FormDestroy(Sender: TObject);
begin
  frmCPSel:=nil;
end;

procedure TfrmCPSel.SpeedButton1Click(Sender: TObject);
begin
  FHMainId:=TSpeedButton(Sender).Hint;
  FHInfo:=TSpeedButton(Sender).Caption;
  ModalResult:=1;
end;
procedure TfrmCPSel.InitGrid();
begin
  with ADOQuery1 do
  begin
    Filtered := False;
    Close;
    sql.Clear;
    sql.Add('select A.*   from YT_Plan_Main A');
    sql.Add(' where  isnull(Status,''0'')=''1'' ');
    Open;
  end;
  SCreateCDS20(ADOQuery1, ClientDataSet1);
  SInitCDSData20(ADOQuery1, ClientDataSet1);
  //InitJP();
end;

procedure TfrmCPSel.InitJP();
var
  AA: array[0..100] of string;
  BB: array[0..100] of string;
  i, j: Integer;
begin
  with ClientDataSet1 do
  begin
    First;
    i := 0;
    while not Eof do
    begin
      AA[i] := Trim(fieldbyname('MainId').AsString);
      BB[i] :=Trim(fieldbyname('Y_CodeName').AsString) + #13 + #13
                                         +Trim(fieldbyname('Y_Spec').AsString) + #13 + #13
                                         +Trim(fieldbyname('BatchNo').AsString) + #13 + #13
                                         +Trim(fieldbyname('Y_CodeNameCP').AsString);
      i := i + 1;
      Next;
    end;
  end;
  i := i - 1;
  for j := 0 to i do
  begin
    with Panel1 do
    begin
      TSpeedButton(Controls[j]).Visible := True;
      TSpeedButton(Controls[j]).Hint := AA[j];
      TSpeedButton(Controls[j]).Caption := BB[j];
    end;
  end;
end;

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

procedure TfrmCPSel.FormShow(Sender: TObject);
begin
  InitGrid();
  InitJP();
end;

end.
