unit U_JTSKCHZ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage,
  cxEdit, DB, cxDBData, cxGridCustomTableView, cxGridTableView,
  cxGridBandedTableView, cxGridDBBandedTableView, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridDBTableView, cxGrid, StdCtrls, ComCtrls,
  ExtCtrls, ToolWin, cxGridCustomPopupMenu, cxGridPopupMenu, ADODB, DBClient,
  cxDropDownEdit, MovePanel, cxButtonEdit, cxCheckBox, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator, cxTextEdit;

type
  TfrmJTSKCHZ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    CDS_Main: TClientDataSet;
    cxgrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column5: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    cxgrdMJLen: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    cxgrid1Level1: TcxGridLevel;
    MovePanel2: TMovePanel;
    Panel1: TPanel;
    Label5: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Y_CodeName: TEdit;
    Y_Spec: TEdit;
    FactoryName: TEdit;
    BatchNo: TEdit;
    Edit1: TEdit;
    Edit2: TEdit;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridDBColumn9: TcxGridDBColumn;
    cxGridDBColumn10: TcxGridDBColumn;
    cxGridDBColumn11: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    DataSource2: TDataSource;
    ClientDataSet2: TClientDataSet;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoMChange(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure FactoryNameChange(Sender: TObject);
    procedure Tv1CellClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FCode, FClothType, FSeBie, FZZType: string;
  end;

var
  frmJTSKCHZ: TfrmJTSKCHZ;

implementation

uses
  U_DataLink, U_Fun, U_ZDYHelp;

{$R *.dfm}

procedure TfrmJTSKCHZ.FormDestroy(Sender: TObject);
begin
  frmJTSKCHZ := nil;
end;

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

procedure TfrmJTSKCHZ.InitGrid();
var
  fwhere: string;
begin
    fwhere := ' ';
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('exec P_YTCK_Get_KCHZ');
      sql.Add('''' + fwhere + ''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);

  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmJTSKCHZ.TBRafreshClick(Sender: TObject);
begin
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

procedure TfrmJTSKCHZ.ConNoMChange(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  end;
end;

procedure TfrmJTSKCHZ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('JTS¿â´æ²éÑ¯', Tv1, 'JTS¿â´æ');
  Close;
end;

procedure TfrmJTSKCHZ.FormShow(Sender: TObject);
begin
  ReadCxGrid('JTS¿â´æ²éÑ¯', Tv1, 'JTS¿â´æ');
  InitGrid();
end;

procedure TfrmJTSKCHZ.TBFindClick(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 TfrmJTSKCHZ.FactoryNameChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmJTSKCHZ.Tv1CellClick(Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select A.* from CK_YT_CR A   inner join CK_YT_KC B on A.JYID=B.JYID ');
    sql.Add(' where B.Valid=''Y'' and A.CRFlag=''Èë¿â'' ');
    sql.Add(' and isnull(A.FactoryName,'''')='''+Trim(CDS_Main.fieldbyname('FactoryName').AsString)+'''');
    sql.Add(' and isnull(A.FactoryName,'''')='''+Trim(CDS_Main.fieldbyname('FactoryName').AsString)+'''');
    sql.Add(' and isnull(A.Y_CodeName,'''')='''+Trim(CDS_Main.fieldbyname('Y_CodeName').AsString)+'''');
    sql.Add(' and isnull(A.Y_Spec,'''')='''+Trim(CDS_Main.fieldbyname('Y_Spec').AsString)+'''');
    sql.Add(' and isnull(A.BatchNo,'''')='''+Trim(CDS_Main.fieldbyname('BatchNo').AsString)+'''');
    sql.Add(' and isnull(A.ZGColor,'''')='''+Trim(CDS_Main.fieldbyname('ZGColor').AsString)+'''');
    sql.Add(' and isnull(A.Y_CodeNameCP,'''')='''+Trim(CDS_Main.fieldbyname('Y_CodeNameCP').AsString)+'''');
    sql.Add(' and isnull(A.Y_Type,'''')='''+Trim(CDS_Main.fieldbyname('Y_Type').AsString)+'''');
    sql.Add(' and isnull(A.MachNo,'''')='''+Trim(CDS_Main.fieldbyname('MachNo').AsString)+'''');
    if CDS_Main.IsEmpty=False then
    begin
    end else
    begin
      sql.Add(' and 1=2 ');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,ClientDataSet2);
  SInitCDSData20(ADOQueryTemp,ClientDataSet2);
end;

end.

