unit U_MachHelp;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData,
  cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxGridCustomTableView,
  cxGridTableView, cxGridDBTableView, cxClasses, cxControls,
  cxGridCustomView, cxGrid, ImgList, ComCtrls, ToolWin, ADODB, cxTL,
  cxMaskEdit, cxInplaceContainer, cxDBTL, StdCtrls, ExtCtrls, cxTLData;

type
  TfrmMachHelp = class(TForm)
    ToolBar2: TToolBar;
    TOk: TToolButton;
    Tclose: TToolButton;
    pics: TImageList;
    cxGrid2: TcxGrid;
    tv2: TcxGridDBTableView;
    tv2deviceNo: TcxGridDBColumn;
    tv2deviceName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1frameNo: TcxGridDBColumn;
    v1frameName: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    DataSource1: TDataSource;
    ADOQueryDept: TADOQuery;
    DataSource2: TDataSource;
    ADOQueryHelp: TADOQuery;
    ADOConnection1: TADOConnection;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    v1frameTop: TcxGridDBColumn;
    Splitter1: TSplitter;
    procedure FormCreate(Sender: TObject);
    procedure Tv1FocusedRecordChanged(Sender: TcxCustomGridTableView;
      APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord;
      ANewItemRecordFocusingChanged: Boolean);
    procedure TcloseClick(Sender: TObject);
    procedure TOkClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure tv2DblClick(Sender: TObject);
  private

    procedure IntDeptGrid();
    procedure IntMachGrid();
  public
    fFrameNo:string;
    fMachGroup:string;
    fSelDept:string;
  end;

var
  frmMachHelp: TfrmMachHelp;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmMachHelp.FormCreate(Sender: TObject);
begin
  cxGrid2.Align :=alClient;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;

end;
//////////////////////////////////////////////////////////
  //函数功能：初始化机台部门
/////////////////////////////////////////////////////////
procedure TfrmMachHelp.IntDeptGrid();
begin
  with ADOQueryDept do
  begin
    close;
    sql.clear;
    sql.Add('select distinct B.frameNo,B.frameName,B.frameTop,');
    sql.Add('frameTopName=(select frameName from yc_frame where frameNo=B.frameTop)'); 
    sql.Add('from dc_machine A');
    sql.Add('inner join yc_frame B on A.dept=B.frameNO');
    if trim(fFrameNo)<>'' then
      sql.Add('where A.dept='''+trim(fFrameNo)+'''');
    if trim(fMachGroup)<>'' then
      sql.Add('where A.MachGroup like ''%'+trim(fMachGroup)+'%''');
    Open;
  end;
end;
procedure TfrmMachHelp.Tv1FocusedRecordChanged(
  Sender: TcxCustomGridTableView; APrevFocusedRecord,
  AFocusedRecord: TcxCustomGridRecord;
  ANewItemRecordFocusingChanged: Boolean);
begin
  IntMachGrid();
end;
//////////////////////////////////////////////////////////
  //函数功能：初始化机台部门
/////////////////////////////////////////////////////////
procedure TfrmMachHelp.IntMachGrid();
begin
  with ADOQueryHelp do
  begin
    close;
    sql.clear;
    sql.Add('select *');
    sql.Add('from dc_machine A');
    sql.Add('where A.dept='''+trim(ADOQueryDept.fieldByName('frameNo').asString)+'''');
    if trim(fMachGroup)<>'' then
      sql.Add('and A.MachGroup like ''%'+trim(fMachGroup)+'%''');    
    Open;
  end;
end;
procedure TfrmMachHelp.TcloseClick(Sender: TObject);
begin
  close;
end;

procedure TfrmMachHelp.TOkClick(Sender: TObject);
begin
  if ADOQueryHelp.IsEmpty then
    ModalResult:=-1
  else
  begin
    fSelDept:=trim(ADOQueryDept.fieldByName('frameNo').asString);
    ModalResult:=1;
  end;
end;

procedure TfrmMachHelp.FormShow(Sender: TObject);
begin
  if trim(fMachGroup)<>'' then
    self.Caption:='机组【'+fMachGroup+'】对应机台选择';
  if trim(fFrameNo)<>'' then
    self.Caption:='部门编号【'+fMachGroup+'】对应机台选择';
  IntDeptGrid();
end;

procedure TfrmMachHelp.tv2DblClick(Sender: TObject);
begin
  Tok.Click ;
end;

end.
