unit U_PlanColorHelp;

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, ComCtrls, ToolWin, ADODB, cxLookAndFeels,
  ImgList;

type
  TfrmPlanColorHelp = class(TForm)
    ToolBar1: TToolBar;
    TQry: TToolButton;
    Tok: TToolButton;
    ToolButton2: TToolButton;
    tclose: TToolButton;
    cxGrid1: TcxGrid;
    tv1: TcxGridDBTableView;
    tv1planNO: TcxGridDBColumn;
    tv1customName: TcxGridDBColumn;
    tv1P_chnName: TcxGridDBColumn;
    tv1P_spec: TcxGridDBColumn;
    tv1colorName: TcxGridDBColumn;
    tv1P_YhNo: TcxGridDBColumn;
    tv1P_colStd: TcxGridDBColumn;
    tv1P_subNum: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    DS_help: TDataSource;
    ADOQueryColor: TADOQuery;
    ADOConnection1: TADOConnection;
    cxLookAndFeelController1: TcxLookAndFeelController;
    ImageList24: TImageList;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxStyle2: TcxStyle;
    cxStyle_gridRow: TcxStyle;
    cxStyle_gridFoot: TcxStyle;
    cxStyle_gridHead: TcxStyle;
    cxStyle_gridGroupBox: TcxStyle;
    cxStyle_yellow: TcxStyle;
    cxStyle_Red: TcxStyle;
    cxStyle_fontBlack: TcxStyle;
    cxStyle_clFuchsia: TcxStyle;
    cxStyle_fontclPurple: TcxStyle;
    cxStyle_fontclGreen: TcxStyle;
    cxStyle_fontclBlue: TcxStyle;
    procedure FormCreate(Sender: TObject);
    procedure TQryClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TokClick(Sender: TObject);
    procedure tv1DblClick(Sender: TObject);
    procedure tcloseClick(Sender: TObject);
  private
    procedure DoQuery();
  public
    fPlanNo:string;
  end;

var
  frmPlanColorHelp: TfrmPlanColorHelp;

implementation
uses
  U_global;
{$R *.dfm}

procedure TfrmPlanColorHelp.FormCreate(Sender: TObject);
begin
  cxGrid1.Align :=alClient;
  with ADOConnection1 do
  begin
    Connected:=false;
    ConnectionString:=gConString;
    Connected:=true;
  end;
end;
////////////////////////////////////////////////////////
  //函数功能：初始化表格
////////////////////////////////////////////////////////
procedure TfrmPlanColorHelp.DoQuery();
//var
 // mBegDate,mEndDate:string;
begin
 // mBegDate:= FormatDateTime('yyyy-MM-dd',begDate.DateTime);
 // mendDate:= FormatDateTime('yyyy-MM-dd',endDate.DateTime+1);
  try
    ADOQueryColor.DisableControls ;
    with ADOQueryColor do
    begin
      close;
      sql.clear;
      sql.Add('select ');
      sql.Add('B.customNo,B.customName,'); 
      sql.Add('A.planNO,A.P_seqNO,A.P_code,A.P_chnName,A.P_spec,B.sysType,');
      sql.Add('A.P_color,A.P_yhNo,A.P_colStd,A.P_num,A.P_subNum,');
      sql.Add('colorName=isnull(C.chnName,A.P_color)');
      sql.Add('from mv_ProductJH_All A');
      sql.Add('inner join MV_planJH_All B ON A.PlannO=B.planNO');
      sql.Add('and A.planNo='+quotedStr(fPlanNo));
      sql.Add('left join mc_color C on C.colorId=A.P_color');
      sql.Add('order by cast(A.P_seqNo as int)');
      Open;
    end;
  finally
    ADOQueryColor.EnableControls ;
  end;
end;
procedure TfrmPlanColorHelp.TQryClick(Sender: TObject);
begin
  DoQuery();
end;

procedure TfrmPlanColorHelp.FormShow(Sender: TObject);
begin
  DoQuery();
end;

procedure TfrmPlanColorHelp.TokClick(Sender: TObject);
begin
  if ADOQueryColor.IsEmpty then exit;
  ModalResult:=1;
end;

procedure TfrmPlanColorHelp.tv1DblClick(Sender: TObject);
begin
  Tok.Click ;
end;

procedure TfrmPlanColorHelp.tcloseClick(Sender: TObject);
begin
  close;
end;

end.
