unit U_BS_MachineSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter, RM_Dataset, RM_System,
  RM_Common, RM_Class, RM_GridReport, RM_e_Xls, Menus, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, dxBarBuiltInMenu, cxPC, dxSkinsCore,
  dxSkinsDefaultPainters, dxDateRanges, dxScrollbarAnnotations;

type
  TfrmBS_MachineSel = class(TForm)
    ToolBar1: TToolBar;
    TBClose: TToolButton;
    Panel1: TPanel;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    Label3: TLabel;
    OrderNo: TEdit;
    Tv1OrderNo: TcxGridDBColumn;
    Order_Main: TClientDataSet;
    Tv1C_CodeName: TcxGridDBColumn;
    ToolButton3: TToolButton;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    ToolButton1: TToolButton;
    Label4: TLabel;
    C_Name: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
//    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
    procedure Tv1DblClick(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure OrderNoKeyPress(Sender: TObject; var Key: Char);
  private
    DQdate: TDateTime;
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    FFInt, FCloth: Integer;
    fWorkshop: string;
    { Public declarations }
  end;

var
  frmBS_MachineSel: TfrmBS_MachineSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmBS_MachineSel.FormDestroy(Sender: TObject);
begin
  frmBS_MachineSel := nil;
end;

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

procedure TfrmBS_MachineSel.TBCloseClick(Sender: TObject);
begin
  Close;

end;

procedure TfrmBS_MachineSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      Filtered := False;
      sql.Clear;
      sql.Add('select A.*   ');
      sql.add('from BS_Machine A');
      Open;
    end;
    SCreateCDS(ADOQueryMain, Order_Main);
    SInitCDSData(ADOQueryMain, Order_Main);
  finally
    ADOQueryMain.EnableControls;
    Tbfind.Click;
  end;
end;

procedure TfrmBS_MachineSel.InitForm();
begin
  ReadCxGrid('机台列表选择', Tv1, '机台列表选择');
  InitGrid();
end;

procedure TfrmBS_MachineSel.FormShow(Sender: TObject);
begin

  InitForm();
  if FFInt = 1 then
  begin
    v1Column4.Visible := False;
    v1Column4.Hidden := True;
  end;
//  InitGrid();
end;

procedure TfrmBS_MachineSel.ToolButton1Click(Sender: TObject);
begin
  WriteCxGrid('机台列表选择', Tv1, '机台列表选择');
end;

procedure TfrmBS_MachineSel.ToolButton3Click(Sender: TObject);
begin
  if Order_Main.IsEmpty then
    exit;
  ModalResult := 1;
end;


procedure TfrmBS_MachineSel.Tv1DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmBS_MachineSel.N1Click(Sender: TObject);
begin
  SelOKNo(Order_Main, True);
end;

procedure TfrmBS_MachineSel.N2Click(Sender: TObject);
begin
  SelOKNo(Order_Main, false);
end;

procedure TfrmBS_MachineSel.OrderNoKeyPress(Sender: TObject;
  var Key: Char);
begin
  InitGrid();
end;

procedure TfrmBS_MachineSel.TBRafreshClick(Sender: TObject);
begin
  initgrid();
end;

procedure TfrmBS_MachineSel.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, Order_Main);
  SInitCDSData(ADOQueryMain, Order_Main);
end;

procedure TfrmBS_MachineSel.cxTabControl1Change(Sender: TObject);
begin
  TBRafresh.Click;
end;

end.

