unit U_KHListSelJJ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, cxGraphics, cxCustomData, cxStyles, cxTL, cxMaskEdit, DB, ADODB,
  cxInplaceContainer, cxDBTL, cxControls, cxTLData, ComCtrls, ToolWin,
  StdCtrls, cxFilter, cxData, cxDataStorage, cxEdit, cxDBData, DBClient,
  cxGridCustomTableView, cxGridTableView, cxGridDBTableView, ExtCtrls,
  cxSplitter, cxGridLevel, cxClasses, cxGridCustomView, cxGrid,
  cxGridCustomPopupMenu, cxGridPopupMenu, RM_Dataset, RM_System, RM_Common,
  RM_Class, RM_GridReport, IdBaseComponent, IdComponent, IdTCPConnection,
  IdTCPClient, IdFTP,ShellAPI,IniFiles, cxCheckBox, cxCalendar,
  cxButtonEdit, cxTextEdit, cxPC, cxDropDownEdit, Menus, BtnEdit, Buttons,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator;

type
  TfrmKHListSelJJ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    zjm: TEdit;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    Label5: TLabel;
    KHNameJCZJM: TEdit;
    Label2: TLabel;
    Label4: TLabel;
    SHStatus: TComboBox;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Column1: TcxGridDBColumn;
    cxGYSName: TcxGridDBColumn;
    cxGridDBGYSNameZC: TcxGridDBColumn;
    B1GYSFZRen: TcxGridDBColumn;
    cxGridDBGYSTel: TcxGridDBColumn;
    V1SHStatus: TcxGridDBColumn;
    V1FZR: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    V1Column2: TcxGridDBColumn;
    LabKHType: TLabel;
    KHType: TComboBox;
    V1Column3: TcxGridDBColumn;
    V1Column5: TcxGridDBColumn;
    Label3: TLabel;
    YWY: TComboBox;
    Label8: TLabel;
    LiDan: TComboBox;
    Label1: TLabel;
    KHQuYu: TEdit;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    V3Column2: TcxGridDBColumn;
    V3BankName: TcxGridDBColumn;
    V3BankNo: TcxGridDBColumn;
    V3Column3: TcxGridDBColumn;
    V3Column1: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    DS_HZ3: TDataSource;
    CDS_HZ3: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    V3Column4: TcxGridDBColumn;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure zjmChange(Sender: TObject);
    procedure KHTypeClick(Sender: TObject);
    procedure V1Column2CustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure V1SHStatusCustomDrawCell(Sender: TcxCustomGridTableView;
      ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo;
      var ADone: Boolean);
    procedure TV1DblClick(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure TV3DblClick(Sender: TObject);
  private
    { Private declarations }
    ColorInt:Integer;
    procedure InitGrid();
    procedure InitGridBankMain();
  public
    canshu1,canshu2,FGYSType,FF:string;
  end;

var
  frmKHListSelJJ: TfrmKHListSelJJ;

implementation
uses
  U_DataLink,U_RTFun,U_ZDYHelp;

{$R *.dfm}


procedure TfrmKHListSelJJ.InitGrid();
begin
  with ADOQueryMain do
  begin
    Filtered:=False;
    Close;
    SQL.Clear;
    sql.Add(' select *,zjm=dbo.getpinyin(KHName)+KHName+KHNo,KHNameJCZJM=dbo.getpinyin(KHNameJC)+KHNameJC');
    sql.add(',SHStatus=(case when isnull(status,''0'')=''0'' then ''未审核'' else ''已审核'' end)');
    sql.Add(' from KH_Main A ');
    sql.add(' where isnull(KHFlag,'''')='''+Trim('KH')+''' and isnull(Valid,'''')=''Y''  ');
    if Trim(canshu2)<>'高权限' then
    begin
      sql.Add(' and (isnull(YWY,'''')='''+Trim(DName)+''' or isnull(LiDan,'''')='''+Trim(DName)+''')');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryMain,CDS_HZ);
  SInitCDSData20(ADOQueryMain,CDS_HZ);
end;

procedure TfrmKHListSelJJ.FormDestroy(Sender: TObject);
begin
  frmKHListSelJJ:=nil;
end;

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

procedure TfrmKHListSelJJ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('PBGYS11YXCX',Tv1,'客户管理');
  Close;
end;
procedure TfrmKHListSelJJ.FormShow(Sender: TObject);
var
  fsj:String;
begin
  FF:='';
  fsj:='select Name=YWY from KH_Main where isnull(YWY,'''')<>'''' and Valid=''Y'' and isnull(KHFlag,'''')=''KH''  Group by YWY';
  SInitComBoxBySql(ADOQueryTemp,YWY,False,fsj);
  fsj:='select Name=LiDan from KH_Main where isnull(LiDan,'''')<>''''  and Valid=''Y'' and isnull(KHFlag,'''')=''KH'' Group by LiDan';
  SInitComBoxBySql(ADOQueryTemp,LiDan,False,fsj);
  ReadCxGrid('PBGYS11YXCX',Tv1,'客户管理');
  InitGrid();
end;

procedure TfrmKHListSelJJ.TBRafreshClick(Sender: TObject);
begin
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmKHListSelJJ.ToolButton2Click(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain,SGetFilters(Panel1,1,2));
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  end;
end;

procedure TfrmKHListSelJJ.zjmChange(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmKHListSelJJ.KHTypeClick(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmKHListSelJJ.V1Column2CustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id:Integer;
begin
  Id:=TV1.GetColumnByFieldName('KHType').Index;
  if AViewInfo.GridRecord.Values[Id]='外销' then
  begin
    ACanvas.Font.Color:=clBlue;
  end;
end;

procedure TfrmKHListSelJJ.V1SHStatusCustomDrawCell(
  Sender: TcxCustomGridTableView; ACanvas: TcxCanvas;
  AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
var
  id:Integer;
begin
  Id:=TV1.GetColumnByFieldName('SHStatus').Index;
  if AViewInfo.GridRecord.Values[Id]='未审核' then
  begin
    ACanvas.Font.Color:=clRed;
  end;
end;

procedure TfrmKHListSelJJ.TV1DblClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then exit;
  FF:='主';
  ModalResult:=1;
end;

procedure TfrmKHListSelJJ.TV1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitGridBankMain();
end;
procedure TfrmKHListSelJJ.InitGridBankMain();
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid='''+Trim(CDS_HZ.fieldbyname('KHMainid').asstring)+'''');
    if CDS_HZ.IsEmpty then
    begin
      sql.Add(' and 1=2');
    end else
    begin
      sql.Add(' and valid=''Y'' ');
    end;
    sql.Add(' order by XH');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp,CDS_HZ3);
  SInitCDSData20(ADOQueryTemp,CDS_HZ3);
end;

procedure TfrmKHListSelJJ.TV3DblClick(Sender: TObject);
begin
  if  CDS_HZ3.IsEmpty then Exit;
  FF:='子';
  ModalResult:=1;
end;

end.


