unit U_PBKCListSel;

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, Menus, cxCheckBox, cxCalendar;

type
  TfrmPBKCListSel = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBExport: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    MLCodeName: TEdit;
    JYColor: TEdit;
    CDS_Main: TClientDataSet;
    Label5: TLabel;
    ConNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    MovePanel2: TMovePanel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    cxGrid2: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column19: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v1Column18: TcxGridDBColumn;
    v1Column6: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v2Column6: TcxGridDBColumn;
    v1Column16: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column22: TcxGridDBColumn;
    cxGrid2Level1: TcxGridLevel;
    Label1: TLabel;
    JYColHX: TEdit;
    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 TBExportClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure MLCodeNameChange(Sender: TObject);
    procedure Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
    procedure Image2Click(Sender: TObject);
    procedure Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure CheJianChange(Sender: TObject);
  private
    FLeft, FTop: Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FCKOrdNo, FMainid, FSubId, FConNo, FColor, FCodeName: string;
  end;

var
  frmPBKCListSel: TfrmPBKCListSel;

implementation

uses
  U_DataLink, U_Fun;

{$R *.dfm}

procedure TfrmPBKCListSel.FormDestroy(Sender: TObject);
begin
  frmPBKCListSel := nil;
end;

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

procedure TfrmPBKCListSel.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered := False;
      Close;
      sql.Clear;
      SQL.Add('select A.* ');
      sql.Add(' ,B.MLOrderNo,B.KHName,B.MLCodeName,B.OrdDate  ');
      sql.Add(' ,C.MLColor,C.MLColorNo,C.MLHX');
      sql.Add(' from  CK_MLCP_CR A inner join CK_MLCP_KC D on A.MJID=D.MJID ');
      sql.Add(' inner join ML_OrderMainNew B on A.MainId=B.NewMLID  ');
      sql.Add('  inner join ML_OrderSubidNew C on A.SubId=C.NewSubid  ');
      sql.Add('where A.CRFlag=''Èë¿â'' and D.KCValid=''Y'' ');
      sql.Add(' and exists(select * from FHSQ_Sub X where X.MainId= A.MainId and X.FSId=' + quotedstr(trim(FCKOrdNo)) + ')');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_Main);
    SInitCDSData20(ADOQueryMain, CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmPBKCListSel.TBRafreshClick(Sender: TObject);
begin
 // BegDate.SetFocus;
  ToolBar1.SetFocus;
  MovePanel2.Visible := True;
  MovePanel2.Refresh;
  InitGrid();
  MovePanel2.Visible := False;
end;

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

procedure TfrmPBKCListSel.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.caption), Tv1, 'Å÷²¼²Ö¿â');
  Close;
end;

procedure TfrmPBKCListSel.FormShow(Sender: TObject);
var
  fsj: string;
begin
//  fsj:='select Code=Null,Name=Note from KH_Zdy where TYpe=''CarNo'' Group by Note ';
//  SInitComBoxBySql(ADOQueryTemp,CheJian,False,fsj);
  ReadCxGrid(trim(self.caption), Tv1, 'Å÷²¼²Ö¿â');
end;

procedure TfrmPBKCListSel.TBExportClick(Sender: TObject);
begin
  ModalResult := 1;
end;

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

procedure TfrmPBKCListSel.Panel10MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
begin
  ReleaseCapture;
  TWinControl(Panel4).Perform(WM_SYSCOMMAND, $F012, 0);
end;

procedure TfrmPBKCListSel.Image2Click(Sender: TObject);
begin
  Panel4.Visible := False;
end;

procedure TfrmPBKCListSel.Tv1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  FLeft := X;
  FTop := Y;
end;

procedure TfrmPBKCListSel.Tv1CellDblClick(Sender: TcxCustomGridTableView; ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton; AShift: TShiftState; var AHandled: Boolean);
begin
  {if Trim(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName)<>'CDQK' then Exit;
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select CDQK=dbo.F_Get_Order_SubStr(:MJID,''MJCDHZSL'')');
    Parameters.ParamByName('MJID').Value:=Trim(CDS_Main.fieldbyname('MJID').AsString);
    Open;
  end;
  with CDS_Main do
  begin
    Edit;
    FieldByName('CDQK').Value:=Trim(ADOQueryTemp.fieldbyname('CDQK').AsString);
    Post;
  end; }
  Panel4.Left := FLeft;
  Panel4.Top := FTop + 110;
  Panel4.Visible := True;
  Panel4.Refresh;
  Panel10.Caption := Trim(TV1.Controller.FocusedColumn.Caption);

  RichEdit1.Text := CDS_Main.fieldbyname(TV1.Controller.FocusedColumn.DataBinding.FilterFieldName).AsString;
end;

procedure TfrmPBKCListSel.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, True);
end;

procedure TfrmPBKCListSel.N2Click(Sender: TObject);
begin
  SelOKNo(CDS_Main, False);
end;

procedure TfrmPBKCListSel.CheJianChange(Sender: TObject);
begin
  TBFind.Click;
end;

end.

