unit U_GYSList;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses,
  cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView,
  cxGridDBTableView, cxGrid, DBClient, cxCheckBox, cxCalendar, cxSplitter,
  RM_Dataset, RM_System, RM_Common, RM_Class, RM_GridReport, RM_e_Xls,
  Menus, cxButtonEdit, cxDropDownEdit;

type
  TfrmGYSList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBFind: TToolButton;
    TBClose: TToolButton;
    Tv1: TcxGridDBTableView;
    cxGrid1Level1: TcxGridLevel;
    cxGrid1: TcxGrid;
    cxGridPopupMenu1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    Order_Main: TClientDataSet;
    ToolButton3: TToolButton;
    Panel1: TPanel;
    Label9: TLabel;
    KHNameJC: TEdit;
    v1Column6: TcxGridDBColumn;
    Label4: TLabel;
    KHZhongLei: TComboBox;
    v1Column8: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
    procedure TBCloseClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure CustomerNoNameChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure KHNameJCChange(Sender: TObject);
  private
    procedure InitGrid();
    procedure InitForm();
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmGYSList: TfrmGYSList;

implementation
uses
  U_DataLink,U_RTFun;

{$R *.dfm}

procedure TfrmGYSList.FormDestroy(Sender: TObject);
begin
  frmGYSList:=nil;
end;

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

procedure TfrmGYSList.FormCreate(Sender: TObject);
begin
  cxgrid1.Align:=alClient;
end;

procedure TfrmGYSList.TBCloseClick(Sender: TObject);
begin
  Close;
  WriteCxGrid('供应商查询长阳总仓',Tv1,'供应商管理');
end;

procedure TfrmGYSList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      sql.Clear;
      sql.Add('select A.*,ZJM=dbo.getPinYin(A.KHNameJC)  ');
      sql.Add(' from ZH_KH_Info A  ');
      sql.Add(' where Type=''GYS'' and Valid=''Y'' and isnull(KHNameJC,'''')<>'''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmGYSList.InitForm();
begin
  ReadCxGrid('供应商查询长阳总仓',Tv1,'供应商管理');
  InitGrid();
end;

procedure TfrmGYSList.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmGYSList.TBRafreshClick(Sender: TObject);
begin
  InitGrid();
end;

procedure TfrmGYSList.FormShow(Sender: TObject);
begin
  InitForm();
end;

procedure TfrmGYSList.ToolButton3Click(Sender: TObject);
begin
  ModalResult:=1;
end;

procedure TfrmGYSList.CustomerNoNameChange(Sender: TObject);
begin
  if ADOQueryMain.Active=False then Exit;
  SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
  SCreateCDS20(ADOQueryMain,Order_Main);
  SInitCDSData20(ADOQueryMain,Order_Main);
end;

procedure TfrmGYSList.Tv1DblClick(Sender: TObject);
begin
  ToolButton3.Click;
end;

procedure TfrmGYSList.KHNameJCChange(Sender: TObject);
var
  fsj:String;
begin
  if Trim(KHNameJC.Text)<>'' then
  begin
    fsj:=' KHNameJC like '''+'%'+Trim(KHNameJC.Text)+'%'+''''
         +' or ZJM like '''+'%'+Trim(KHNameJC.Text)+'%'+'''';
  end;
  if ADOQueryMain.Active then
  begin
   // SDofilter(ADOQueryMain,fsj);
    try
      ADOQueryMain.DisableControls;
      with ADOQueryMain do
      begin
        if Trim(fsj)='' then
        begin
          Filtered:=False;
        end else
        begin
          Filtered:=False;
          Filter:=fsj;
          Filtered:=True;
        end;
      end;
    finally
      ADOQueryMain.EnableControls;
    end;
    SCreateCDS20(ADOQueryMain,Order_Main);
    SInitCDSData20(ADOQueryMain,Order_Main);
  end;
end;

end.
