unit U_MachineSel;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin, StdCtrls,
  cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP, ShellAPI, IniFiles, cxCheckBox, cxCalendar, cxButtonEdit,
  cxTextEdit, cxPC, cxCheckComboBox, cxDropDownEdit, Menus, RM_e_Xls,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, 
   dxDateRanges, dxBarBuiltInMenu,
  cxContainer, dxScrollbarAnnotations, U_BaseHelp,
  System.ImageList, Vcl.ImgList;

type
  TfrmMachineSel = class(TfrmBaseHelp)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ToolButton2: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Panel1: TPanel;
    v2Column8: TcxGridDBColumn;
    Label1: TLabel;
    v2Column12: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    Tv2Column1: TcxGridDBColumn;
    Tv2Column2: TcxGridDBColumn;
    Tv2Column3: TcxGridDBColumn;
    TBSel: TToolButton;
    ADOConnection1: TADOConnection;
    MCNO: TcxTextEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CustomerChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBSelClick(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();
  public
    fFlag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage: string;
  end;

var
  frmMachineSel: TfrmMachineSel;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmMachineSel.InitGrid();
begin
  MCNO.SetFocus;
  try
    ADOQueryBaseCmd.DisableControls;
    with ADOQueryBaseCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select MCID=cast(A.MCID as varchar(30)),A.* from BS_Machine A order by MCNO ');
      Open;
    end;
    SCreateCDS(ADOQueryBaseCmd, CDS_HZ);
    SInitCDSData(ADOQueryBaseCmd, CDS_HZ);
  finally
    ADOQueryBaseCmd.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmMachineSel.FormDestroy(Sender: TObject);
begin
  inherited;
  frmMachineSel := nil;
end;

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

procedure TfrmMachineSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(Trim(Self.Caption), Tv2, '机台管理');
  Close;
end;

procedure TfrmMachineSel.FormShow(Sender: TObject);
begin
  inherited;

  ReadCxGrid(Trim(Self.Caption), Tv2, '机台管理');
  InitGrid();
end;

procedure TfrmMachineSel.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMachineSel.TBSelClick(Sender: TObject);
begin
  MCNO.SetFocus;
  if not CDS_HZ.Locate('Ssel',True,[]) then
  begin
    Application.MessageBox('没有选择数据', '提示', 0);
    Exit;
  end;
  ModalResult := 1;
end;

procedure TfrmMachineSel.ToolButton2Click(Sender: TObject);
var
  sql: string;
begin
  if ADOQueryBaseCmd.Active then
  begin
    sql := SGetFilters(Panel1, 1, 2);
    SDofilter(ADOQueryBaseCmd, sql);
    SCreateCDS(ADOQueryBaseCmd, CDS_HZ);
    SInitCDSData(ADOQueryBaseCmd, CDS_HZ);
  end;
end;

procedure TfrmMachineSel.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryBaseCmd.IsEmpty then
    Exit;
//  SelExportData(Tv2, ADOQueryMain, trim(Self.Caption));
  TcxGridToExcel(self.Caption, cxgrid2);
end;

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

procedure TfrmMachineSel.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, True);
end;

procedure TfrmMachineSel.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  SelOKNo(CDS_HZ, False);
end;

procedure TfrmMachineSel.CustomerChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmMachineSel.FormCreate(Sender: TObject);
begin
  inherited;
  try
    with ADOConnection1 do
    begin
      Connected := false;
      ConnectionString := DConString;
      Connected := true;
    end;
    ADOQueryBaseCmd.Connection := ADOConnection1;
    ADOQueryBaseTemp.Connection := ADOConnection1;
  except
    {if Application.MessageBox('网络连接失败,是否要再次连接?','提示',32+4)=IDYES then
    begin
      try
        with ADOConnection1 do
        begin
          Connected:=false;
          ConnectionString:=DConString;
          //ConnectionString:='23242';
          Connected:=true;
        end;
      except
      end;
    end; }
  end;
end;

end.

