unit U_PBKCList;

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;

type
  TfrmPBKCList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    DataSource1: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    Label3: TLabel;
    Label4: TLabel;
    C_CodeName: TEdit;
    C_Code: TEdit;
    CDS_Main: TClientDataSet;
    Tv1: TcxGridDBTableView;
    cxGrid2Level1: TcxGridLevel;
    cxGrid2: TcxGrid;
    v2Column1: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v1Column1: TcxGridDBColumn;
    Label5: TLabel;
    ConNo: TEdit;
    Label6: TLabel;
    MJID: TEdit;
    v1Column6: TcxGridDBColumn;
    Label7: TLabel;
    v1Column3: TcxGridDBColumn;
    v1Column4: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    Panel4: TPanel;
    Label11: TLabel;
    Panel10: TPanel;
    Image2: TImage;
    RichEdit1: TRichEdit;
    MovePanel2: TMovePanel;
    v1Column2: TcxGridDBColumn;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    Label8: TLabel;
    MJStr3: TComboBox;
    v1Column7: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    Label2: TLabel;
    Edit1: TEdit;
    v1Column12: TcxGridDBColumn;
    Label1: TLabel;
    KuWei: TEdit;
    v1Column13: TcxGridDBColumn;
    Label12: TLabel;
    CheJian: TComboBox;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    Label9: TLabel;
    CarNo: TEdit;
    Label10: TLabel;
    BatchNoHZ: TEdit;
    CPType: TComboBox;
    ToolButton1: TToolButton;
    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 C_CodeNameChange(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);
    procedure ToolButton1Click(Sender: TObject);
  private
    FLeft,FTop:Integer;
    procedure InitGrid();
    { Private declarations }
  public
    { Public declarations }
    FMainid,FSubId,FConNo,FColor,FCodeName:String;

  end;

var
  frmPBKCList: TfrmPBKCList;

implementation
uses
  U_DataLink,U_Fun;

{$R *.dfm}

procedure TfrmPBKCList.FormDestroy(Sender: TObject);
begin
  frmPBKCList:=nil;
end;

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

procedure TfrmPBKCList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      SQL.Add('exec P_View_PBCPKCMX :WSQl');
      Parameters.ParamByName('WSQl').Value:='';
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_Main);
    SInitCDSData20(ADOQueryMain,CDS_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;

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

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

procedure TfrmPBKCList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('²Ö¿â¿â´æÁÐ±íPB',Tv1,'Å÷²¼²Ö¿â');
  Close;
end;

procedure TfrmPBKCList.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('²Ö¿â¿â´æÁÐ±íPB',Tv1,'Å÷²¼²Ö¿â');
end;

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

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

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

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

procedure TfrmPBKCList.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 TfrmPBKCList.N1Click(Sender: TObject);
begin
  SelOKNo(CDS_Main,True);
end;

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

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

procedure TfrmPBKCList.ToolButton1Click(Sender: TObject);
begin
  ModalResult:=1;
end;

end.
