unit U_ZdyAttachment_Help;

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, cxDBLookupComboBox, cxLookAndFeels,
  cxLookAndFeelPainters, cxNavigator;

type
  TfrmZdyAttachment_Help = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBDel: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    ZdyName: TEdit;
    cxGrid2: TcxGrid;
    Tv2: TcxGridDBTableView;
    cxGridLevel1: TcxGridLevel;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    ToolButton3: TToolButton;
    v2Column6: TcxGridDBColumn;
    v2Column1: TcxGridDBColumn;
    v2Column2: TcxGridDBColumn;
    v2Column3: TcxGridDBColumn;
    v2Column5: TcxGridDBColumn;
    v2Column7: TcxGridDBColumn;
    v2Column8: TcxGridDBColumn;
    v2Column9: TcxGridDBColumn;
    Label1: TLabel;
    ZdyCode: TEdit;
    v2Column10: TcxGridDBColumn;
    ToolButton4: TToolButton;
    Label2: TLabel;
    Filler: TEdit;
    v2Column11: TcxGridDBColumn;
    v2DEFStr7: TcxGridDBColumn;
    v2Column12: TcxGridDBColumn;
    v2Column13: TcxGridDBColumn;
    v2Column14: TcxGridDBColumn;
    DEFStr7: TEdit;
    Label4: TLabel;
    v2Column15: TcxGridDBColumn;
    v2Column16: TcxGridDBColumn;
    TBuser: TToolButton;
    Label5: TLabel;
    begdate: TDateTimePicker;
    Label6: TLabel;
    enddate: TDateTimePicker;
    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 ToolButton2Click(Sender: TObject);
    procedure ZdyNameChange(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure TBuserClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Tv2CellDblClick(Sender: TcxCustomGridTableView;
      ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
      AShift: TShiftState; var AHandled: Boolean);
  private

    { Private declarations }
    procedure InitGrid();

  public
    fkhType:string;
    Fmanage:string;
  end;

var
  frmZdyAttachment_Help: TfrmZdyAttachment_Help;

implementation
uses
  U_DataLink,U_Fun,U_ZDYHelp,U_ZdyAttInput,U_ZdyInput;

{$R *.dfm}



procedure TfrmZdyAttachment_Help.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Filtered:=False;
      Close;
      SQL.Clear;
      sql.Add(' select * from KH_Zdy_Attachment where Type=''KHName'' ');
      IF begdate.Checked then
      sql.Add(' and FillTime>='''+formatdateTime('yyyy-MM-dd',begdate.DateTime)+'''');
      IF enddate.Checked then
      sql.Add(' and FillTime<'''+formatdateTime('yyyy-MM-dd',enddate.DateTime+1)+'''');
    //  sql.Add(' and isnull(khType,'''')='+quotedstr(trim(fkhType)));
      IF trim(Fmanage)='业务员'then
      sql.Add(' and Filler='+quotedstr(trim(DName)));
      Open;
    end;
    SCreateCDS20(ADOQueryMain,CDS_HZ);
    SInitCDSData20(ADOQueryMain,CDS_HZ);
  finally
    ADOQueryMain.EnableControls;
  end;
end;


procedure TfrmZdyAttachment_Help.FormDestroy(Sender: TObject);
begin
  frmZdyAttachment_Help:=nil;
end;

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

procedure TfrmZdyAttachment_Help.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(self.Caption,Tv2,'客户自定义');
  Close;
end;
procedure TfrmZdyAttachment_Help.TBDelClick(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then Exit;
  if Application.MessageBox('确定要删除数据吗？','提示',32+4)<>IDYES then Exit;
  if Trim(CDS_HZ.fieldbyname('ATID').AsString)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('delete KH_Zdy_Attachment where ATID='''+Trim(CDS_HZ.fieldbyname('ATID').AsString)+'''');
      sql.Add('delete KH_Zdy where ZdyNo='''+Trim(CDS_HZ.fieldbyname('ATID').AsString)+'''');
      ExecSQL;
    end;
  end;
  CDS_HZ.Delete;
end;

procedure TfrmZdyAttachment_Help.FormShow(Sender: TObject);
begin
  ReadCxGrid(self.Caption,Tv2,'客户自定义');
  InitGrid();
  IF trim(Fmanage)='业务员'then
  TBuser.Visible:=false;
end;

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

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


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

procedure TfrmZdyAttachment_Help.ToolButton4Click(Sender: TObject);
begin
  IF CDS_HZ.IsEmpty then exit;
  try
    frmZdyAttInput:=TfrmZdyAttInput.Create(Application);
    with frmZdyAttInput do
    begin
      FCYID:=Trim(Self.CDS_HZ.fieldbyname('ATID').AsString);
      fkhType:=self.fkhType;
      IF trim(Fmanage)='业务员'then
      begin
        v2Column6.Options.Editing:=false;
        v2Column14.Options.Editing:=false;
      end;
      if ShowModal=1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmZdyAttInput.Free;
  end;
end;

procedure TfrmZdyAttachment_Help.ToolButton3Click(Sender: TObject);
begin
  try
    frmZdyAttInput:=TfrmZdyAttInput.Create(Application);
    with frmZdyAttInput do
    begin
      fkhType:=self.fkhType;
      FCYID:='';
      if ShowModal=1 then
      begin
        TBRafresh.Click;
      end;
    end;
  finally
    frmZdyAttInput.Free;
  end;
end;

procedure TfrmZdyAttachment_Help.TBuserClick(Sender: TObject);
var
  FuserName:string;
begin
  IF CDS_HZ.IsEmpty then exit;
  frmZDYHelp:=TfrmZDYHelp.Create(self);
  with frmZDYHelp do
  begin
    flag:='UserName';
    FlagName:='操作员';
    IF showmodal=1 then
    begin
      FuserName:=ClientDataSet1.fieldbyname('zdyName').AsString;
    end;
    free;
  end;
  IF trim(FuserName)<>'' then
  begin
    with ADOQueryCmd do
    begin
      Close;
      SQL.Clear;
      sql.Add('update  KH_Zdy_Attachment SET filler='''+trim(FuserName)+''' where ATID='''+Trim(CDS_HZ.fieldbyname('ATID').AsString)+'''');
      ExecSQL;
    end;
    TBRafresh.Click;
  end;
end;

procedure TfrmZdyAttachment_Help.FormCreate(Sender: TObject);
begin
  enddate.Date:=date();
  begdate.Date:=strtodate(formatdateTime('yyyy-MM',enddate.Date)+'-01');
end;

procedure TfrmZdyAttachment_Help.Tv2CellDblClick(
  Sender: TcxCustomGridTableView;
  ACellViewInfo: TcxGridTableDataCellViewInfo; AButton: TMouseButton;
  AShift: TShiftState; var AHandled: Boolean);
begin
  IF cds_hz.IsEmpty then exit;
  self.ModalResult:=1;
end;

end.


