unit U_SCPerson;

interface

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

type
  TfrmSCPerson = class(TForm)
    ScrollBox1: TScrollBox;
    btn1: TSpeedButton;
    btn2: TSpeedButton;
    btn3: TSpeedButton;
    btn4: TSpeedButton;
    btn5: TSpeedButton;
    btn6: TSpeedButton;
    btn7: TSpeedButton;
    btn8: TSpeedButton;
    btn58: TSpeedButton;
    btn9: TSpeedButton;
    btn10: TSpeedButton;
    btn11: TSpeedButton;
    btn12: TSpeedButton;
    btn13: TSpeedButton;
    btn14: TSpeedButton;
    btn15: TSpeedButton;
    btn59: TSpeedButton;
    btn16: TSpeedButton;
    btn17: TSpeedButton;
    btn18: TSpeedButton;
    btn19: TSpeedButton;
    btn20: TSpeedButton;
    btn21: TSpeedButton;
    btn22: TSpeedButton;
    btn60: TSpeedButton;
    btn23: TSpeedButton;
    btn24: TSpeedButton;
    btn25: TSpeedButton;
    btn26: TSpeedButton;
    btn27: TSpeedButton;
    btn28: TSpeedButton;
    btn29: TSpeedButton;
    btn61: TSpeedButton;
    btn30: TSpeedButton;
    btn31: TSpeedButton;
    btn32: TSpeedButton;
    btn33: TSpeedButton;
    btn34: TSpeedButton;
    btn35: TSpeedButton;
    btn36: TSpeedButton;
    btn62: TSpeedButton;
    btn37: TSpeedButton;
    btn38: TSpeedButton;
    btn39: TSpeedButton;
    btn40: TSpeedButton;
    btn41: TSpeedButton;
    btn42: TSpeedButton;
    btn43: TSpeedButton;
    btn63: TSpeedButton;
    btn44: TSpeedButton;
    btn45: TSpeedButton;
    btn46: TSpeedButton;
    btn47: TSpeedButton;
    btn48: TSpeedButton;
    btn49: TSpeedButton;
    btn50: TSpeedButton;
    btn64: TSpeedButton;
    btn51: TSpeedButton;
    btn52: TSpeedButton;
    btn53: TSpeedButton;
    btn54: TSpeedButton;
    btn55: TSpeedButton;
    btn56: TSpeedButton;
    btn57: TSpeedButton;
    ADOTmp: TADOQuery;
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    procedure InitGrid();
    procedure InitGrid1();
    { Private declarations }
  public
    FlagStr: string;
    flag: integer;
    FSDPerson: string;
    { Public declarations }
  end;

var
  frmSCPerson: TfrmSCPerson;

implementation

uses
  U_DataLink;

{$R *.dfm}
procedure TfrmSCPerson.InitGrid1();
type
  FdDy = record
    inc: integer;
    FDdys: string[32];
    FdDysName: string[32];
  end;
var
  BB: array[0..1000] of FdDy;
  i, j: Integer;
begin

//  with ADOTmp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select C.JTH from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' order by JTH ');
//    Open;
//  end;
//  if ADOTmp.IsEmpty then
//  begin
//    Application.MessageBox('没有定义数据！', '提示', 0);
//    Exit;
//  end;
//  with ADOTmp do
//  begin
//    First;
//    i := 0;
//    while not Eof do
//    begin
//      BB[i].inc := i;
//      BB[i].FDdys := Trim(fieldbyname('JTH').AsString);
//
////      BB[i].FdDysName:=Trim(fieldbyname('defstr3').AsString);
//      i := i + 1;
//      Next;
//    end;
//  end;
//  i := i - 1;
//  if i > 63 then
//  begin
//    i := 63;
//  end;
//  for j := 0 to i do
//  begin
//    with ScrollBox1 do
//    begin
//      TSpeedButton(Controls[j]).Visible := True;
//      TSpeedButton(Controls[j]).Caption := BB[j].FdDysName;
//    end;
//  end;
end;

procedure TfrmSCPerson.InitGrid();
type
  FdDy = record
    inc: integer;
    FDdys: string[32];
    FdDysName: string[32];
  end;
var
//  BB: array[0..100] of FdDy;
  BB: array[0..100] of string;
  i, j: Integer;
begin

  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select C.JTH from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' order by JTH');
    Open;
  end;
  if ADOTmp.IsEmpty then
  begin
    Application.MessageBox('没有定义数据！', '提示', 0);
    Exit;
  end;
  with ADOTmp do
  begin
    First;
    i := 0;
    while not Eof do
    begin
//      BB[i].inc := i;
//      BB[i].FDdys := Trim(fieldbyname('JTH').AsString);
      BB[i] := Trim(fieldbyname('JTH').AsString);
//      BB[i].FdDysName:=Trim(fieldbyname('ZDYName').AsString);
      i := i + 1;
      Next;
    end;
  end;
  i := i - 1;
  if i > 63 then
  begin
    i := 63;
  end;
  for j := 0 to i do
  begin
    with ScrollBox1 do
    begin
      TSpeedButton(Controls[j]).Visible := True;
//      if Length(BB[j].FdDysName) > 7 then
      if Length(BB[j]) > 7 then
      begin
//        TSpeedButton(Controls[j]).Caption := Copy(Trim(BB[j].FdDysName), 1, 4) + #13 + Copy(Trim(BB[j].FdDysName), 5, Length(BB[j].FdDysName) - 4);
        TSpeedButton(Controls[j]).Caption := Copy(Trim(BB[j]), 1, 4) + #13 + Copy(Trim(BB[j]), 5, Length(BB[j]) - 4);
      end
      else
//        TSpeedButton(Controls[j]).Caption := BB[j].FdDysName;
        TSpeedButton(Controls[j]).Caption := BB[j];
   //   TSpeedButton(Controls[j]).Caption:=BB[j].FdDysName;
    end;
  end;
end;

procedure TfrmSCPerson.FormDestroy(Sender: TObject);
begin
  frmSCPerson := nil;
end;

procedure TfrmSCPerson.FormShow(Sender: TObject);
begin
//  IF flag=1 then
//  Initgrid1()
//  else
  Initgrid();
end;

procedure TfrmSCPerson.btn1Click(Sender: TObject);
begin
  with ADOTmp do
  begin

    Close;
    Filtered := False;
    sql.Clear;

    sql.Add('select C.subid from JYOrder_Sub C inner join JYOrder_Main B on C.MainId=B.MainId where 1=1 and B.Status=0 and ZT=''启用'' and C.JTH=''' + Trim(TSpeedButton(Sender).Caption) + ''' ');   //:begdate,:enddate,

    Open;
  end;

//  FSDPerson := Trim(TSpeedButton(Sender).Caption);
  FSDPerson := Trim(ADOTmp.fieldbyname('subid').AsString);     
  ModalResult := 1;
end;

procedure TfrmSCPerson.FormClose(Sender: TObject; var Action: TCloseAction);
begin
 // Action:=caHide;

end;

end.

