unit U_DyeTechnicsSel;

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, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxBarBuiltInMenu, dxSkinsCore, dxSkinsDefaultPainters, dxDateRanges,
  dxScrollbarAnnotations;

type
  TfrmDyeTechnicsSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    DTMName: TEdit;
    ADOQueryMain: TADOQuery;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    DTMNo: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    GPM_2: TcxGridPopupMenu;
    DS_2: TDataSource;
    CDS_2: TClientDataSet;
    cxTabControl1: TcxTabControl;
    v2GYGX: TcxGridDBColumn;
    v2Ssel: TcxGridDBColumn;
    v2GYName: TcxGridDBColumn;
    v2GYNO: TcxGridDBColumn;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    ADOQuery1: TADOQuery;
    GPM_1: TcxGridPopupMenu;
    TBOK: TToolButton;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    XUHAO: TcxGridDBColumn;
    cxGridDBColumn1: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    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 DTMNoChange(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TBOKClick(Sender: TObject);
    procedure Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
  private
    { Private declarations }

    procedure InitGrid();
    procedure SetStatus();
    procedure InitGlide();
  public
    fflag: integer;
    { Public declarations }
    RKFlag, FCYID, fmanage, fname: string;
  end;

var
  frmDyeTechnicsSel: TfrmDyeTechnicsSel;

implementation

uses
  U_DataLink, U_RTFun;

{$R *.dfm}

procedure TfrmDyeTechnicsSel.SetStatus();
begin

end;

procedure TfrmDyeTechnicsSel.InitGlide();
begin
  try
    ADOQueryTemp.DisableControls;
    with ADOQueryTemp do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,B.* FROM Dye_Technics_Sub A inner join Dye_Process B on A.PSId=B.PSId ');
      sql.Add(' Where A.DTMID=''' + trim(CDS_2.fieldbyname('DTMID').AsString) + '''');
      SQL.Add(' ORDER BY A.PSNO');
      Open;
    end;
    SCreateCDS(ADOQueryTemp, CDS_1);
    SInitCDSData(ADOQueryTemp, CDS_1);
  finally
    ADOQueryTemp.EnableControls;
  end;
end;

procedure TfrmDyeTechnicsSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      SQL.Clear;
      sql.Add(' select * FROM Dye_Technics_Main WHERE 1=1  ');
      SQL.Add(' AND  DTMID IN (SELECT DTMID FROM BS_Cloth_Dye_Technics E WHERE E.BCIID=');
      SQL.Add('(SELECT BCIID FROM Bs_Cloth_Info G WHERE G.C_NAME=' + QuotedStr(fname));
      SQL.ADD('))');

      if cxTabControl1.TabIndex < 2 then
        sql.Add(' AND  status=''' + inttostr(cxTabControl1.TabIndex) + ''' ');

      sql.Add('order by DTMNo');

      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_2);
    SInitCDSData(ADOQueryMain, CDS_2);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
    //CDS_1.EmptyDataSet;
  end;
end;

procedure TfrmDyeTechnicsSel.FormDestroy(Sender: TObject);
begin
  frmDyeTechnicsSel := nil;
end;

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

procedure TfrmDyeTechnicsSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('工艺登记', Tv2, '工艺管理');
  Close;
end;

procedure TfrmDyeTechnicsSel.FormShow(Sender: TObject);
begin
  fflag := 0;
  ReadCxGrid('工艺登记', Tv2, '工艺管理');
  SetStatus();
  InitGrid();
end;

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

procedure TfrmDyeTechnicsSel.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
    SCreateCDS(ADOQueryMain, CDS_2);
    SInitCDSData(ADOQueryMain, CDS_2);
  end;
end;

procedure TfrmDyeTechnicsSel.DTMNoChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

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

procedure TfrmDyeTechnicsSel.Tv2FocusedRecordChanged(Sender: TcxCustomGridTableView; APrevFocusedRecord, AFocusedRecord: TcxCustomGridRecord; ANewItemRecordFocusingChanged: Boolean);
begin
  InitGlide();
end;

procedure TfrmDyeTechnicsSel.FormCreate(Sender: TObject);
begin
  fmanage := Trim(DParameters1);
end;

procedure TfrmDyeTechnicsSel.TBOKClick(Sender: TObject);
begin
  if CDS_2.IsEmpty then
    exit;
  self.ModalResult := 1;
end;

end.

