unit U_ZdyMapSel2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, DB, ADODB, cxGraphics, cxControls, cxLookAndFeels,
  cxLookAndFeelPainters, dxBarBuiltInMenu, cxPC, DBClient, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmZdyMapSel2 = class(TForm)
    ScrollBox1: TScrollBox;
    btn1: TSpeedButton;
    btn2: TSpeedButton;
    btn3: TSpeedButton;
    btn4: TSpeedButton;
    btn5: TSpeedButton;
    ADOTmp: TADOQuery;
    CDS_Kuang: TClientDataSet;
    cxTabControl1: TcxTabControl;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    SpeedButton3: TSpeedButton;
    SpeedButton6: TSpeedButton;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    SpeedButton10: TSpeedButton;
    SpeedButton11: TSpeedButton;
    SpeedButton12: TSpeedButton;
    SpeedButton13: TSpeedButton;
    SpeedButton16: TSpeedButton;
    SpeedButton17: TSpeedButton;
    SpeedButton18: TSpeedButton;
    SpeedButton19: TSpeedButton;
    SpeedButton20: TSpeedButton;
    SpeedButton21: TSpeedButton;
    SpeedButton22: TSpeedButton;
    SpeedButton23: TSpeedButton;
    SpeedButton26: TSpeedButton;
    SpeedButton27: TSpeedButton;
    SpeedButton28: TSpeedButton;
    SpeedButton29: TSpeedButton;
    SpeedButton30: TSpeedButton;
    SpeedButton31: TSpeedButton;
    SpeedButton32: TSpeedButton;
    SpeedButton33: TSpeedButton;
    SpeedButton36: TSpeedButton;
    SpeedButton37: TSpeedButton;
    SpeedButton38: TSpeedButton;
    SpeedButton39: TSpeedButton;
    SpeedButton40: TSpeedButton;
    SpeedButton41: TSpeedButton;
    SpeedButton42: TSpeedButton;
    SpeedButton43: TSpeedButton;
    SpeedButton46: TSpeedButton;
    SpeedButton47: TSpeedButton;
    SpeedButton48: TSpeedButton;
    SpeedButton49: TSpeedButton;
    SpeedButton50: TSpeedButton;
    SpeedButton51: TSpeedButton;
    SpeedButton52: TSpeedButton;
    SpeedButton53: TSpeedButton;
    SpeedButton56: TSpeedButton;
    SpeedButton57: TSpeedButton;
    SpeedButton58: TSpeedButton;
    SpeedButton59: TSpeedButton;
    SpeedButton60: TSpeedButton;
    SpeedButton61: TSpeedButton;
    SpeedButton62: TSpeedButton;
    SpeedButton63: TSpeedButton;
    SpeedButton66: TSpeedButton;
    SpeedButton67: TSpeedButton;
    SpeedButton68: TSpeedButton;
    SpeedButton69: TSpeedButton;
    SpeedButton70: TSpeedButton;
    SpeedButton71: TSpeedButton;
    SpeedButton72: TSpeedButton;
    SpeedButton73: TSpeedButton;
    SpeedButton76: TSpeedButton;
    SpeedButton77: TSpeedButton;
    SpeedButton78: TSpeedButton;
    SpeedButton79: TSpeedButton;
    SpeedButton80: TSpeedButton;
    SpeedButton81: TSpeedButton;
    SpeedButton82: TSpeedButton;
    SpeedButton83: TSpeedButton;
    SpeedButton86: TSpeedButton;
    SpeedButton87: TSpeedButton;
    SpeedButton88: TSpeedButton;
    SpeedButton89: TSpeedButton;
    SpeedButton90: TSpeedButton;
    SpeedButton91: TSpeedButton;
    SpeedButton92: TSpeedButton;
    SpeedButton93: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton14: TSpeedButton;
    SpeedButton15: TSpeedButton;
    SpeedButton24: TSpeedButton;
    SpeedButton25: TSpeedButton;
    SpeedButton34: TSpeedButton;
    SpeedButton35: TSpeedButton;
    SpeedButton44: TSpeedButton;
    SpeedButton45: TSpeedButton;
    SpeedButton54: TSpeedButton;
    SpeedButton55: TSpeedButton;
    SpeedButton64: TSpeedButton;
    SpeedButton65: TSpeedButton;
    SpeedButton74: TSpeedButton;
    SpeedButton75: TSpeedButton;
    SpeedButton84: TSpeedButton;
    SpeedButton85: TSpeedButton;
    SpeedButton94: TSpeedButton;
    SpeedButton95: TSpeedButton;
    SpeedButton96: TSpeedButton;
    SpeedButton97: TSpeedButton;
    SpeedButton98: TSpeedButton;
    SpeedButton99: TSpeedButton;
    SpeedButton100: TSpeedButton;
    SpeedButton101: TSpeedButton;
    SpeedButton102: TSpeedButton;
    SpeedButton103: TSpeedButton;
    SpeedButton104: TSpeedButton;
    SpeedButton105: TSpeedButton;
    SpeedButton106: TSpeedButton;
    SpeedButton107: TSpeedButton;
    SpeedButton108: TSpeedButton;
    SpeedButton109: TSpeedButton;
    SpeedButton110: TSpeedButton;
    SpeedButton111: TSpeedButton;
    SpeedButton112: TSpeedButton;
    SpeedButton113: TSpeedButton;
    SpeedButton114: TSpeedButton;
    SpeedButton115: TSpeedButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure btn1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitPerson();
    { Private declarations }
  public
    FlagStr: string;
    FSDPerson: string;
    { Public declarations }
  end;

var
  frmZdyMapSel2: TfrmZdyMapSel2;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmZdyMapSel2.FormDestroy(Sender: TObject);
begin
  frmZdyMapSel2 := nil;
end;

procedure TfrmZdyMapSel2.InitPerson();
var
  i, j: Integer;
begin
//  j := cxTabControl1.TabIndex * 114 + 1;

  if cxTabControl1.TabIndex = 0 then
  begin
    j := 1;
    for i := 0 to 113 do
    begin

      with ScrollBox1 do
      begin
        if CDS_Kuang.locate('keyNo', j + i, []) then
        begin
//        application.MessageBox(pchar(CDS_Kuang.FieldByName('ZDYName').AsString), '提示信息', 0);
          TSpeedButton(Controls[i]).Visible := True;
          TSpeedButton(Controls[i]).Caption := Trim(CDS_Kuang.FieldByName('ZDYName').AsString);
          if Trim(CDS_Kuang.FieldByName('ZYZT').AsString) = '已占用' then
            TSpeedButton(Controls[i]).Font.Color := clOlive
          else
            TSpeedButton(Controls[i]).Font.Color := clGreen;
        end
        else
        begin
          TSpeedButton(Controls[i]).Visible := False;

//        application.MessageBox(pchar('没找到' + inttostr(i)), '提示信息', 0);

        end;

      end;
    end;
    for i := 76 to 113 do
    begin
      with ScrollBox1 do
      begin
        TSpeedButton(Controls[i]).Visible := true;
      end;
    end;

  end
  else
  begin
    j := (cxTabControl1.TabIndex - 1) * 76 + 115;
    for i := 0 to 75 do
    begin

      with ScrollBox1 do
      begin
        if CDS_Kuang.locate('keyNo', j + i, []) then
        begin
//        application.MessageBox(pchar(CDS_Kuang.FieldByName('ZDYName').AsString), '提示信息', 0);
          TSpeedButton(Controls[i]).Visible := True;
          TSpeedButton(Controls[i]).Caption := Trim(CDS_Kuang.FieldByName('ZDYName').AsString);
          if Trim(CDS_Kuang.FieldByName('ZYZT').AsString) = '已占用' then
            TSpeedButton(Controls[i]).Font.Color := clOlive
          else
            TSpeedButton(Controls[i]).Font.Color := clGreen;
        end
        else
        begin
          TSpeedButton(Controls[i]).Visible := False;

//        application.MessageBox(pchar('没找到' + inttostr(i)), '提示信息', 0);

        end;

      end;

    end;
    for i := 76 to 113 do
    begin
      with ScrollBox1 do
      begin
        TSpeedButton(Controls[i]).Visible := false;
      end;
    end;
  end;

end;

procedure TfrmZdyMapSel2.FormShow(Sender: TObject);
begin
//  with ADOTmp do
//  begin
//    Close;
//    sql.Clear;
//    sql.Add('select  A.ZDYName   ');
//    sql.Add(' ,keyNo=cast((ROW_NUMBER() over(order by A.ZDYName) )as int)');
//    sql.Add(' ,ZYZT=(select top 1 ''已占用'' from WFB_MJJY X where X.KuangHao=A.ZDYName and X.MJStr2=''已入库'' )   ');
//    sql.Add(' from KH_ZDY A ');
//    sql.Add(' where Type=''' + Trim(FlagStr) + '''   ');
//    sql.Add(' order by ZDYName ');
//    Open;
//  end;
  with ADOTmp do
  begin
    Close;
    sql.Clear;
    sql.Add('select  A.ZDYName   ');
    sql.Add(' ,keyNo=cast((ROW_NUMBER() over(order by A.ZDYName) )as int)');
    sql.Add(' ,ZYZT=(case when (select count(mjid) from  WFB_MJJY x where X.KuangHao=A.ZDYName and X.MJStr2=''已入库'' group by KuangHao)>0  then ''已占用'' else '''' end  )	   ');
    sql.Add(' from KH_ZDY A ');
    sql.Add(' where Type=''' + Trim(FlagStr) + '''   ');
    sql.Add(' order by ZDYName ');
//    ShowMessage(sql.Text);
    Open;
  end;
  SCreateCDS20(ADOTmp, CDS_Kuang);
  SInitCDSData20(ADOTmp, CDS_Kuang);

  InitPerson();
end;

procedure TfrmZdyMapSel2.btn1Click(Sender: TObject);
begin
  FSDPerson := Trim(TSpeedButton(Sender).Caption);

  if CDS_Kuang.locate('ZDYName', FSDPerson, []) then
  begin

    if Trim(CDS_Kuang.FieldByName('ZYZT').AsString) = '已占用' then
    begin
      if Application.MessageBox('确定要选择已经占用的框吗？', '提示', 32 + 4) = IDYES then
        ModalResult := 1;
    end
    else
      ModalResult := 1;
  end;

end;

procedure TfrmZdyMapSel2.cxTabControl1Change(Sender: TObject);
begin
  InitPerson();
end;

end.

