unit U_GYSListPBSel;

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;

type
  TfrmGYSListPB = 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;
    KHNameJC: TEdit;
    DS_HZ3: TDataSource;
    CDS_HZ3: TClientDataSet;
    cxGridPopupMenu4: TcxGridPopupMenu;
    Label2: TLabel;
    Label4: TLabel;
    SHStatus: TComboBox;
    Label1: TLabel;
    KHJYFanWei: TEdit;
    Label3: TLabel;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBTableView;
    V1Column4: TcxGridDBColumn;
    V1Column1: TcxGridDBColumn;
    cxGYSName: TcxGridDBColumn;
    cxGridDBGYSNameZC: TcxGridDBColumn;
    B1GYSFZRen: TcxGridDBColumn;
    cxGridDBGYSTel: TcxGridDBColumn;
    V1SHStatus: TcxGridDBColumn;
    V1FZR: TcxGridDBColumn;
    V1GYSCodeFW: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    PopupMenu1: TPopupMenu;
    MainEdit: TMenuItem;
    MainView: TMenuItem;
    TBFJUp1: TPopupMenu;
    BankEdit: TMenuItem;
    BankDel: TMenuItem;
    BankView: TMenuItem;
    cxGrid3: TcxGrid;
    TV3: TcxGridDBTableView;
    V3Column2: TcxGridDBColumn;
    V3BankName: TcxGridDBColumn;
    V3BankNo: TcxGridDBColumn;
    V3Column3: TcxGridDBColumn;
    cxGridLevel3: TcxGridLevel;
    V1KHType: TcxGridDBColumn;
    LabKHType: TLabel;
    KHType: TBtnEditC;
    TBAddBank: TMenuItem;
    FZR: TComboBox;
    V3Column1: TcxGridDBColumn;
    V1Column2: TcxGridDBColumn;
    Label6: TLabel;
    KHQuYu: TEdit;
    TBFJUp: TMenuItem;
    TBFJView: TMenuItem;
    V1Column3: 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 cxTabControl1Change(Sender: TObject);
    procedure TV1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure BankDelClick(Sender: TObject);
    procedure TV3DblClick(Sender: TObject);
    procedure KHTypeBtnDnClick(Sender: TObject);
    procedure V1SHStatusCustomDrawCell(Sender: TcxCustomGridTableView; ACanvas: TcxCanvas; AViewInfo: TcxGridTableDataCellViewInfo; var ADone: Boolean);
  private
    { Private declarations }
    ColorInt: Integer;
    procedure InitGrid();
    procedure setstatus();
    procedure InitGridBankMain();
    procedure InitGridBankMainID(FID: string);
  public
    canshu1, canshu2, FGYSType, XZKHTYpe: string;
  end;

//var
  //frmGYSListPB: TfrmGYSListPB;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp;

{$R *.dfm}
procedure TfrmGYSListPB.setstatus();
begin

end;

procedure TfrmGYSListPB.InitGrid();
begin
  with ADOQueryMain do
  begin
    Filtered := False;
    Close;
    SQL.Clear;
    sql.Add(' select *,zjm=dbo.getpinyin(KHName) ');
    sql.add(',SHStatus=(case when isnull(status,''0'')=''0'' then ''未审核'' else ''已审核'' end)');
    sql.Add(',SDQty=(select Count(*) from TP_File TF where TF.WBID=A.KHMainId and TF.TFType=''供应商资料''  )');
    sql.Add(' from KH_Main A ');
    sql.add(' where isnull(KHFlag,'''')=''' + Trim(canshu2) + ''' and isnull(Valid,'''')=''Y''  ');
    if Trim(canshu1) = '录入' then
    begin
      sql.Add(' and exists(select * from KH_Owner B where B.KHMainId=A.KHMainId and B.UserName=''' + Trim(DName) + ''')');
    end;
    Open;
  end;
  SCreateCDS20(ADOQueryMain, CDS_HZ);
  SInitCDSData20(ADOQueryMain, CDS_HZ);
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid=''' + Trim(CDS_HZ.fieldbyname('KHMainid').asstring) + ''' and isnull(Valid,'''')=''Y''');
    Open;
  end;
  SCreateCDS20(ADOQueryTemp, CDS_HZ3);
  SInitCDSData20(ADOQueryTemp, CDS_HZ3);
end;

procedure TfrmGYSListPB.FormDestroy(Sender: TObject);
begin
  //frmGYSListPB:=nil;
end;

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

procedure TfrmGYSListPB.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('PBGYS11YX', Tv1, '供应商管理');
  WriteCxGrid('PBGYS31YX', Tv3, '供应商管理');
  Close;
end;

procedure TfrmGYSListPB.FormShow(Sender: TObject);
var
  fsj: string;
begin
  fsj := 'select Name=UserName from KH_Owner A inner join KH_Main B on A.KHMainId=B.KHMainId and B.KHFlag=''GYS''' + '  and A.Valid=''Y'' and B.Valid=''Y'' and A.USERID<>''ADMIN''  Group by A.UserName  ';
  SInitComBoxBySql(ADOQueryTemp, FZR, False, fsj);
  ReadCxGrid('PBGYS11YX', Tv1, '供应商管理');
  ReadCxGrid('PBGYS31YX', Tv3, '供应商管理');
  setstatus();
  InitGrid();
end;

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

procedure TfrmGYSListPB.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 TfrmGYSListPB.zjmChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmGYSListPB.cxTabControl1Change(Sender: TObject);
begin
  setstatus();
  InitGrid();
end;

procedure TfrmGYSListPB.TV1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
  InitGridBankMain();
end;

procedure TfrmGYSListPB.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 TfrmGYSListPB.InitGridBankMainID(FID: string);
begin
  with ADOQueryTemp do
  begin
    Close;
    sql.Clear;
    sql.Add('select * from KH_Sub_Bank where KHMainid=''' + Trim(FID) + '''');
    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 TfrmGYSListPB.BankDelClick(Sender: TObject);
begin
  if CDS_HZ3.IsEmpty then
    exit;
  if Trim(canshu1) <> '高权限' then
  begin
    if Trim(CDS_HZ3.fieldbyname('FillerCode').AsString) <> Trim(DCode) then
    begin
      Application.MessageBox('不能操作他人录入的数据!', '提示', 0);
      Exit;
    end;
  end;
  if Application.MessageBox('确定要删除数据吗？', '提示', 32 + 4) <> IDYES then
    Exit;
  with ADOQueryCmd do
  begin
    Close;
    SQL.Clear;
    sql.Add('Update KH_Sub_Bank Set Valid=''N'',DelTime=getdate(),Deler=''' + Trim(DName) + ''',DelerCode=''' + Trim(DCode) + '''');
    sql.add('where BKID=''' + Trim(CDS_HZ3.fieldbyname('BKID').AsString) + '''');
    ExecSQL;
  end;
  CDS_HZ3.Delete;
end;

procedure TfrmGYSListPB.TV3DblClick(Sender: TObject);
begin
  BankView.Click;
end;

procedure TfrmGYSListPB.KHTypeBtnDnClick(Sender: TObject);
begin
  KHType.Text := '';
  KHType.TxtCode := '';
  ToolButton2.Click;
end;

procedure TfrmGYSListPB.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;

end.

