unit U_JTSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, ToolWin, ComCtrls, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGrid, DBClient, ADODB, ImgList, StdCtrls, ExtCtrls,
  cxCheckBox, cxTextEdit, cxPC;

type
  TfrmJTSel = class(TForm)
    TV1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    V1Name: TcxGridDBColumn;
    ToolBar1: TToolBar;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    DataSource1: TDataSource;
    ClientDataSet1: TClientDataSet;
    TBClose: TToolButton;
    ToolButton1: TToolButton;
    Panel1: TPanel;
    Label1: TLabel;
    MachNo: TEdit;
    ThreeImgList: TImageList;
    V1Column1: TcxGridDBColumn;
    V1Column4: TcxGridDBColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure MachNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    FCheJain, Workshop: string;
    { Public declarations }
  end;

var
  frmJTSel: TfrmJTSel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmJTSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin

  Action := caFree;
end;

procedure TfrmJTSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select * from BS_Machine A');
      sql.add(' where Workshop=''' + trim(Workshop) + ''' ');
//      if cxTabControl1.TabIndex=0 then
//      begin
//        sql.Add(' and not exists(select StopFlag from Cloth_JiTai B where B.CarNo=A.ZDYName and B.StopFlag=0)');
//      end else
//      if cxTabControl1.TabIndex=1 then
//      begin
//        sql.Add(' and  exists(select StopFlag from Cloth_JiTai B where B.CarNo=A.ZDYName and B.StopFlag=0)');
//      end;
      sql.Add(' order by A.MachNo');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmJTSel.ToolButton1Click(Sender: TObject);
begin

  if ClientDataSet1.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据。', '提示', 0);
    Exit;
  end;

  ModalResult := 1;
end;

procedure TfrmJTSel.MachNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS20(ADOQueryMain, ClientDataSet1);
    SInitCDSData20(ADOQueryMain, ClientDataSet1);
  end;
end;

procedure TfrmJTSel.cxTabControl1Change(Sender: TObject);
begin
  InitGrid();
end;

end.

