unit U_LSSCListSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxDropDownEdit,
  Buttons;

type
  TfrmLSSCListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitJP();

    { Private declarations }
  public
    FMainid: string;
    { Public declarations }
  end;

var
  frmLSSCListSel: TfrmLSSCListSel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmLSSCListSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Action := caHide;
end;
procedure TfrmLSSCListSel.InitGrid();
var
  i: Integer;
begin
  with ADOQueryMain 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(ADOQueryMain, Order_Main);
  SInitCDSData20(ADOQueryMain, Order_Main);
  InitJP();
end;

procedure TfrmLSSCListSel.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;
procedure TfrmLSSCListSel.InitJP();
var
  AA: array[0..100] of string;
  BB: array[0..100] of string;
  i, j: Integer;
begin
  with Order_Main do
  begin
    First;
    i := 0;
    while not Eof do
    begin
      AA[i] := Trim(fieldbyname('MainId').AsString);
      BB[i] :=Trim(fieldbyname('FactoryName').AsString) + #13+ #13
                                         +Trim(fieldbyname('Y_CodeName').AsString) + #13 + #13
                                         +Trim(fieldbyname('Y_Spec').AsString) + #13 + #13
                                         +Trim(fieldbyname('BatchNo').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 TfrmLSSCListSel.FormShow(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmLSSCListSel.FormDestroy(Sender: TObject);
begin
  frmLSSCListSel:=nil;
end;

procedure TfrmLSSCListSel.SpeedButton1Click(Sender: TObject);
begin
  FMainid:=Trim(TSpeedButton(Sender).Hint);
  ModalResult:=1;
end;

procedure TfrmLSSCListSel.TBCloseClick(Sender: TObject);
begin
  Close;
end;

end.

