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, cxLookAndFeels, cxLookAndFeelPainters,
  cxNavigator, dxBarBuiltInMenu, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinBlueprint, dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom,
  dxSkinDarkSide, dxSkinDevExpressDarkStyle, dxSkinDevExpressStyle,
  dxSkinFoggy, dxSkinGlassOceans, dxSkinHighContrast, dxSkiniMaginary,
  dxSkinLilian, dxSkinLiquidSky, dxSkinLondonLiquidSky, dxSkinMcSkin,
  dxSkinMetropolis, dxSkinMetropolisDark, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinOffice2013DarkGray,
  dxSkinOffice2013LightGray, dxSkinOffice2013White, dxSkinPumpkin,
  dxSkinSeven, dxSkinSevenClassic, dxSkinSharp, dxSkinSharpPlus,
  dxSkinSilver, dxSkinSpringTime, dxSkinStardust, dxSkinSummer2008,
  dxSkinTheAsphaltWorld, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinVS2010, dxSkinWhiteprint, dxSkinXmas2008Blue, dxSkinscxPCPainter;

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;
    V1Note: TcxGridDBColumn;
    Panel1: TPanel;
    Label1: TLabel;
    MCNO: TEdit;
    ThreeImgList: TImageList;
    V1Column1: TcxGridDBColumn;
    cxTabControl1: TcxTabControl;
    Label2: TLabel;
    V1Column2: TcxGridDBColumn;
    V1Column3: TcxGridDBColumn;
    V1Column4: TcxGridDBColumn;
    Label3: TLabel;
    MCCJ: TComboBox;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure MCNOChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
  private
    procedure InitGrid();
    { Private declarations }
  public
    flag, flagname, snote, MainType, ReturnStr, FGStr: string;
    fnote, forderno: Boolean;
    PPSTE, JiangeStr: integer;
    { Public declarations }
  end;

var
  frmJTSel: TfrmJTSel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmJTSel.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  MCNO.SetFocus;
  Action := caFree;
end;

procedure TfrmJTSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      sql.Clear;
      sql.Add(' select MCNO,MCCJ  ');
      sql.Add(' ,ZYConNo=(select Top 1 ConNo from Cloth_Main CM inner join Cloth_JiTai CJ on CM.MainId=CJ.MainId');
      sql.Add('           where CJ.CarNo=A.MCNO and CJ.StopFlag=0)');
      sql.Add(' ,C_Code=(select Top 1 C_Code from Cloth_Sub CM inner join Cloth_JiTai CJ on CM.MainId=CJ.MainId');
      sql.Add('           where CJ.CarNo=A.MCNO and CJ.StopFlag=0)');
      sql.Add(' ,C_CodeName=(select Top 1 C_CodeName from Cloth_Sub CM inner join Cloth_JiTai CJ on CM.MainId=CJ.MainId');
      sql.Add('           where CJ.CarNo=A.MCNO and CJ.StopFlag=0)');
      sql.Add(' from Machine A');
      sql.Add(' where  ');
      if cxTabControl1.TabIndex = 0 then
      begin
        sql.Add('   not exists(select StopFlag from Cloth_JiTai B inner join cloth_main X on B.mainid=X.mainid where B.CarNo=A.MCNO and B.StopFlag=0)');
      end
      else if cxTabControl1.TabIndex = 1 then
      begin
        sql.Add('   exists(select StopFlag from Cloth_JiTai B inner join cloth_main X on B.mainid=X.mainid where B.CarNo=A.MCNO and B.StopFlag=0)');
      end;
      sql.Add('  order by [dbo].[getNum](MCNO)');
      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);
var
  fsj: string;
begin
  fsj := 'select Name=MCCJ from Machine   Group by MCCJ ';
  SInitComBoxBySql(ADOQueryTemp, MCCJ, False, fsj);
  InitGrid();
end;

procedure TfrmJTSel.ToolButton1Click(Sender: TObject);
begin
  {if cxTabControl1.TabIndex<>0 then
  begin
    Application.MessageBox('已启用的车号不能选择，请停用后选择。','提示',0);
    Exit;
  end; }
  if cxTabControl1.TabIndex <> 0 then
    Exit;
  if ClientDataSet1.Locate('SSel', True, []) = False then
  begin
    Application.MessageBox('没有选择数据。', '提示', 0);
    Exit;
  end;
  ReturnStr := '';
  with ClientDataSet1 do
  begin
    First;
    while not Eof do
    begin
      if FieldByName('SSel').AsBoolean = True then
      begin
        if JiangeStr <> 99 then
        begin
          if FGStr <> '' then
            ReturnStr := ReturnStr + Trim(fieldbyname('MCNO').AsString) + FGStr
          else
            ReturnStr := ReturnStr + Trim(fieldbyname('MCNO').AsString) + ';'
        end
        else
          ReturnStr := ReturnStr + Trim(fieldbyname('MCNO').AsString);
      end;
      Next;
    end;
  end;
  if JiangeStr <> 99 then
    ReturnStr := Copy(ReturnStr, 1, Length(ReturnStr) - 1);
  ModalResult := 1;
end;

procedure TfrmJTSel.MCNOChange(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.

