unit U_YGCL_BZ;

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;

type
  TfrmYGCL_BZ = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    v2GXName: TcxGridDBColumn;
    v2BZName: TcxGridDBColumn;
    v2SYRName: TcxGridDBColumn;
    cxGridLevel1: TcxGridLevel;
    Label6: TLabel;
    ADOQuery1: TADOQuery;
    Panel1: TPanel;
    Label5: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    GXName: TEdit;
    BZName: TEdit;
    SYRName: TEdit;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBDelClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ZdyNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
  private
    { Private declarations }
    procedure InitGrid();

  public
    fDEFstr5:string;
  end;

var
  frmYGCL_BZ: TfrmYGCL_BZ;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_YGCL_BZInput;

{$R *.dfm}

procedure TfrmYGCL_BZ.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select * from OA_YG_BZ ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
  //ToolButton2.Click;
end;


procedure TfrmYGCL_BZ.FormDestroy(Sender: TObject);
begin
  frmYGCL_BZ:=nil;
end;

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

procedure TfrmYGCL_BZ.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid('供应商资料',Tv2,'客户自定义');
  Close;
end;

procedure TfrmYGCL_BZ.TBDelClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if Trim(CDS_HZ.fieldbyname('BZID').AsString)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete OA_YG_BZ where BZID='''+Trim(CDS_HZ.fieldbyname('BZID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmYGCL_BZ.FormShow(Sender: TObject);
begin
  ReadCxGrid('供应商资料',Tv2,'客户自定义');
  InitGrid();
end;

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

procedure TfrmYGCL_BZ.ZdyNameChange(Sender: TObject);
begin
  ToolButton2.Click;
end;


procedure TfrmYGCL_BZ.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then Exit;
    TcxGridToExcel(self.Caption,cxgrid2);
//  SelExportData(Tv2,ADOQueryMain,'供应商资料列表');
end;

procedure TfrmYGCL_BZ.ToolButton4Click(Sender: TObject);
begin
  try
    frmYGCL_BZInput:=TfrmYGCL_BZInput.Create(Application);
    with frmYGCL_BZInput do
    begin
      FCYID:=Trim(Self.CDS_HZ.fieldbyname('BZID').AsString);
      fDEFstr5:=self.fDEFstr5;
      if ShowModal=1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmYGCL_BZInput.Free;
  end;
end;

procedure TfrmYGCL_BZ.ToolButton3Click(Sender: TObject);
begin
  try
    frmYGCL_BZInput:=TfrmYGCL_BZInput.Create(Application);
    with frmYGCL_BZInput do
    begin
      FCYID:='';
      fDEFstr5:=self.fDEFstr5;
      if ShowModal=1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmYGCL_BZInput.Free;
  end;
end;

end.


