unit U_YSCRMXList;

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, cxLookAndFeels, cxLookAndFeelPainters,
  dxBarBuiltInMenu, cxNavigator, DateUtils, dxSkinsCore,
  dxSkinsDefaultPainters, dxSkinscxPCPainter;

type
  TfrmYSCRMXList = class(TForm)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    ToolButton2: TToolButton;
    Label1: TLabel;
    YFName: TEdit;
    ADOQueryMain: TADOQuery;
    ToolButton1: TToolButton;
    RM1: TRMGridReport;
    RMDB_Main: TRMDBDataSet;
    Label3: TLabel;
    FactoryName: TEdit;
    Label2: TLabel;
    Label6: TLabel;
    begdate: TDateTimePicker;
    Enddate: TDateTimePicker;
    cxGridPopupMenu2: TcxGridPopupMenu;
    DS_HZ: TDataSource;
    CDS_HZ: TClientDataSet;
    cxTabControl1: TcxTabControl;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1Column4: TcxGridDBColumn;
    v1Column3: TcxGridDBColumn;
    v1Column2: TcxGridDBColumn;
    v1Column5: TcxGridDBColumn;
    v1Qty: TcxGridDBColumn;
    v1QtyUnit: TcxGridDBColumn;
    v1Price: TcxGridDBColumn;
    v1Money: TcxGridDBColumn;
    v1note: TcxGridDBColumn;
    cxGridLevel2: TcxGridLevel;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    CDS_YFS: TClientDataSet;
    DS_YFS: TDataSource;
    cxGridPopupMenu1: TcxGridPopupMenu;
    v1Column6: TcxGridDBColumn;
    v1Column7: TcxGridDBColumn;
    v1Column8: TcxGridDBColumn;
    v1Column9: TcxGridDBColumn;
    v1Column10: TcxGridDBColumn;
    v1Column11: TcxGridDBColumn;
    v1Column13: TcxGridDBColumn;
    v1Column14: TcxGridDBColumn;
    v1Column15: TcxGridDBColumn;
    chk1: TCheckBox;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    Tv1Column1: 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 FactoryNameChange(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure YFGSTypeChange(Sender: TObject);
    procedure Tv1DblClick(Sender: TObject);
    procedure chk1Click(Sender: TObject);
  private
    { Private declarations }

    procedure InitGrid();
    procedure SetStatus();
  public

    { Public declarations }
    FCYID: string;
    fmanage: string;
  end;

var
  frmYSCRMXList: TfrmYSCRMXList;

implementation

uses
  U_DataLink, U_Fun, U_SXCKNewList, U_YSSCList, U_YsScXsList, U_YSKInput,
  U_XXFPHXList;

{$R *.dfm}
procedure TfrmYSCRMXList.SetStatus();
begin

end;

procedure TfrmYSCRMXList.InitGrid();
begin
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' select A.*,B.* from YF_Money_CR A');
      sql.Add(' inner join  YF_Money_CR_SUB B on A.yfid=B.yfid');
      sql.Add(' where A.CRTime>=''' + FormatDateTime('yyyy-MM-dd', begdate.DateTime) + ''' ');
      sql.Add(' and CRTime<''' + FormatDateTime('yyyy-MM-dd', Enddate.DateTime + 1) + ''' ');
      sql.Add(' and A.CRType=''应收款登记''  ');
      if chk1.Checked then
      begin
        sql.Add(' and B.Price=0  ');
      end;
      if cxTabControl1.TabIndex < 2 then
        sql.Add(' and A.status=''' + inttostr(cxTabControl1.TabIndex) + ''' ');
      Open;
    end;
    SCreateCDS20(ADOQueryMain, CDS_YFS);
    SInitCDSData20(ADOQueryMain, CDS_YFS);
  finally
    ADOQueryMain.EnableControls;
    ToolButton2.Click;
  end;
end;

procedure TfrmYSCRMXList.FormDestroy(Sender: TObject);
begin
  frmYSCRMXList := nil;
end;

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

procedure TfrmYSCRMXList.TBCloseClick(Sender: TObject);
begin
  WriteCxGrid(trim(self.Caption) + 'Tv11', Tv1, '财务管理');

  Close;
end;

procedure TfrmYSCRMXList.FormShow(Sender: TObject);
begin

  ReadCxGrid(trim(self.Caption) + 'Tv11', Tv1, '财务管理');

  Enddate.DateTime := SGetServerDate(ADOQueryTemp);
  begdate.DateTime := StartOfTheMonth(Now());

  SetStatus();
  InitGrid();
end;

procedure TfrmYSCRMXList.TBRafreshClick(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

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

procedure TfrmYSCRMXList.FactoryNameChange(Sender: TObject);
begin
  ToolButton2.Click;

end;

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

procedure TfrmYSCRMXList.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  SelExportData(Tv1, ADOQueryMain, '应收款列表');
end;

procedure TfrmYSCRMXList.cxTabControl1Change(Sender: TObject);
begin
  SetStatus();
  InitGrid();
end;

procedure TfrmYSCRMXList.N1Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := TRUE;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYSCRMXList.N2Click(Sender: TObject);
begin
  if CDS_HZ.IsEmpty then
    exit;
  with CDS_HZ do
  begin
    DisableControls;
    first;
    while not eof do
    begin
      edit;
      fieldbyname('ssel').Value := FALSE;
      post;
      next;
    end;
    First;
    EnableControls;
  end;

end;

procedure TfrmYSCRMXList.YFGSTypeChange(Sender: TObject);
begin
  ToolButton2.Click;
end;

procedure TfrmYSCRMXList.Tv1DblClick(Sender: TObject);
begin
  frmXXFPHXList := TfrmXXFPHXList.create(self);
  with frmXXFPHXList do
  begin
    FTONO := TRIM(CDS_YFS.Fieldbyname('YFSID').AsString);
    FFromNo := '';
    if showmodal = 1 then
    begin

    end;
    free;
  end;
end;

procedure TfrmYSCRMXList.chk1Click(Sender: TObject);
begin
  begdate.SetFocus;
  InitGrid();
end;

end.

