unit U_MLMangeRSSel;

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, cxTextEdit,
  cxButtonEdit, Menus, cxLookAndFeelPainters, cxButtons, cxImage, jpeg;

type
  TfrmMLMangeRSSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    DataSource2: TDataSource;
    ADOQueryMain: TADOQuery;
    CDS_Main: TClientDataSet;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    TCK: TToolButton;
    Panel5: TPanel;
    Label2: TLabel;
    MLNo: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    MLName: TEdit;
    GYLXName: TEdit;
    tv1: TcxGridDBTableView;
    v1MLNo: TcxGridDBColumn;
    v1MLName: TcxGridDBColumn;
    v1MLMF: TcxGridDBColumn;
    v1MLKZ: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1GYLXName: TcxGridDBColumn;
    v1SKID: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    Label3: TLabel;
    Label7: TLabel;
    DYID: TEdit;
    cxGrid1: TcxGrid;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxDBTreeList1DblClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure MLNoChange(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
    procedure TCKClick(Sender: TObject);
    procedure DYIDKeyPress(Sender: TObject; var Key: Char);
  private
    { Private declarations }
    PState:Integer;
    FCPID,FTopID:String;
    procedure InitGrid();
  public
    canshu1:string;
    { Public declarations }
  end;

var
  frmMLMangeRSSel: TfrmMLMangeRSSel;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}



procedure TfrmMLMangeRSSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * ');
      sql.Add(',SKID=(select B.SKID from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(',BPCode=(select B.BPCode from BP_ZDY B where B.BPID=A.MBPID)');
      sql.Add(' from ML_Manage A ');
      sql.Add(' where isnull(MLType,'''')=''染色面料'' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmMLMangeRSSel.FormDestroy(Sender: TObject);
begin
  frmMLMangeRSSel:=nil;
end;

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

procedure TfrmMLMangeRSSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('染色面料Sel',Tv1,'样品管理');
  Close;
end;
procedure TfrmMLMangeRSSel.FormShow(Sender: TObject);
begin
  InitGrid();
  ReadCxGrid('染色面料Sel',Tv1,'样品管理');
end;

procedure TfrmMLMangeRSSel.cxDBTreeList1DblClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmMLMangeRSSel.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRSSel.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;

procedure TfrmMLMangeRSSel.MLNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel5,1,2));
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  end;
end;



procedure TfrmMLMangeRSSel.tv1DblClick(Sender: TObject);
begin
  if CDS_Main.IsEmpty then Exit;
  ModalResult:=1;
end;

procedure TfrmMLMangeRSSel.TCKClick(Sender: TObject);
begin
  {try
    frmMLManage_LRRS:=TfrmMLManage_LRRS.Create(Application);
    with frmMLManage_LRRS do
    begin
      FCYID:=Trim(Self.CDS_Main.fieldbyname('MLID').AsString);
      FGYName:='染色';
      viewFlag:=True;
      if ShowModal=1 then
      begin
        Self.InitGrid();
      end;
    end;
  finally
    frmMLManage_LRRS.Free;
  end; }
end;



procedure TfrmMLMangeRSSel.DYIDKeyPress(Sender: TObject; var Key: Char);
begin
  if Key=#13 then
  begin
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        Close;
        sql.Clear;
        sql.Add('select A.*,B.*,C.DYID,D.ColNo colorNo,D.ColNameKH colorName,B.ColNameEng colorNameEng ');
        sql.Add(',BP.SKID,BP.BPCode');
        sql.Add('from BP_DY C ');
        sql.Add('inner join ML_Manage A on A.MLID=C.MLID ');
        sql.add('left join BP_ZDY BP on A.MBPID=BP.BPID ');
        sql.Add('left join BP_ColZDY D on D.PTID=C.TFID and BP.SKID=D.SKID ');
        sql.Add('left join RT_PTColor B on B.PTID=D.PTID ');
        sql.Add(' Where C.DYID='''+Trim(DYID.Text)+'''');
        //ShowMessage(sql.Text);
        Open;
      end;
      SCreateCDS20(ADOQueryMain,CDS_Main);
      SInitCDSData20(ADOQueryMain,CDS_Main);
      DYID.Text:='';
    finally
      ADOQueryMain.EnableControls;
    end;
  end;
end;

end.
