unit U_ZdyMapSel;

interface

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

type
  TfrmZdyMapSel = 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 InitPerson();
    { Private declarations }
  public
     FInitSql, FZdyName: string;
    { Public declarations }
  end;

var
  frmZdyMapSel: TfrmZdyMapSel;

implementation

uses
  U_DataLink;

{$R *.dfm}

procedure TfrmZdyMapSel.FormDestroy(Sender: TObject);
begin
  frmZdyMapSel := nil;
end;

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

  with ADOTmp do
  begin
    Close;
    sql.Clear;
//    sql.Add('select UserID Note, UserName ZDYName from SY_User where Udept=''挡车工'' order by UserID ');
    sql.Add(FInitSql);
    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('Note').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;
      TSpeedButton(Controls[j]).Caption := BB[j].FdDysName;
      if BB[j].FDdys = '平机' then
        TSpeedButton(Controls[j]).Font.Color := clNavy;
      if BB[j].FDdys = '平机1' then
        TSpeedButton(Controls[j]).Font.Color := clBlack;
      if BB[j].FDdys = '平机2' then
        TSpeedButton(Controls[j]).Font.Color := clMaroon;
      if BB[j].FDdys = '提花' then
        TSpeedButton(Controls[j]).Font.Color := clPurple;
      if BB[j].FDdys = '提花1' then
        TSpeedButton(Controls[j]).Font.Color := clGreen;
      if BB[j].FDdys = '提花2' then
        TSpeedButton(Controls[j]).Font.Color := clOlive;
      {TSpeedButton(Controls[j]).Hint:=BB[j];
      if Length(BB[j])>4 then
      begin
        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]; }
    end;
  end;
end;

procedure TfrmZdyMapSel.FormShow(Sender: TObject);
begin
  InitPerson();
end;

procedure TfrmZdyMapSel.btn1Click(Sender: TObject);
begin
  FZdyName := Trim(TSpeedButton(Sender).Caption);
  ModalResult := 1;
end;

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

end;

end.

