unit U_TradePlanProfit1;

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, cxGridBandedTableView, cxGridDBBandedTableView,
  cxLookAndFeels, cxLookAndFeelPainters, cxNavigator, dxDateRanges,
  dxBarBuiltInMenu, U_BaseList, dxScrollbarAnnotations, FrameDateSel,
  cxContainer, cxCurrencyEdit, dxSkinsCore, dxSkinsDefaultPainters,
  cxProgressBar;

type
  TfrmTradePlanProfit1 = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    ADOQueryTemp: TADOQuery;
    ADOQueryCmd: TADOQuery;
    Panel1: TPanel;
    TBFind: TToolButton;
    ToolButton1: TToolButton;
    cxGridPopupMenu2: TcxGridPopupMenu;
    ADOQueryMain: TADOQuery;
    DataSource1: TDataSource;
    cxStyleRepository1: TcxStyleRepository;
    cxStyle1: TcxStyle;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    frmFrameDateSel1: TfrmFrameDateSel;
    Label1: TLabel;
    Label4: TLabel;
    BuyName: TcxTextEdit;
    ConNo: TcxTextEdit;
    Label2: TLabel;
    Saleser: TcxTextEdit;
    ToolButton2: TToolButton;
    ToolButton6: TToolButton;
    cxGrid1: TcxGrid;
    Tv1: TcxGridDBTableView;
    v1conno: TcxGridDBColumn;
    v1CustomerNoName: TcxGridDBColumn;
    Tv1Column85: TcxGridDBColumn;
    Tv1Column14: TcxGridDBColumn;
    Tv1Column15: TcxGridDBColumn;
    v1OrdDate: TcxGridDBColumn;
    Tv1Column1: TcxGridDBColumn;
    Tv1Column79: TcxGridDBColumn;
    Tv1Column83: TcxGridDBColumn;
    Tv1Column2: TcxGridDBColumn;
    Tv1Column3: TcxGridDBColumn;
    Tv1Column4: TcxGridDBColumn;
    Tv1Column5: TcxGridDBColumn;
    Tv1Column6: TcxGridDBColumn;
    Tv1Column80: TcxGridDBColumn;
    Tv1Column7: TcxGridDBColumn;
    Tv1Column9: TcxGridDBColumn;
    Tv1Column8: TcxGridDBColumn;
    Tv1Column10: TcxGridDBColumn;
    cxGrid1Level1: TcxGridLevel;
    ToolButton7: TToolButton;
    procedure FormDestroy(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure TBFindClick(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton4Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure CustNamePropertiesChange(Sender: TObject);
    procedure ToolButton6Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton7Click(Sender: TObject);
    procedure cxButton4Click(Sender: TObject);
    procedure cxButton1Click(Sender: TObject);
    procedure cxButton5Click(Sender: TObject);
    procedure cxButton2Click(Sender: TObject);
    procedure cxButton3Click(Sender: TObject);
  private

    { Private declarations }

    procedure InitGrid();
  public
    fkhType: string;
    Fmanage: string;
    canshu1: string;
  end;

var
  frmTradePlanProfit1: TfrmTradePlanProfit1;

implementation

uses
  U_DataLink, U_RTFun, U_RPFun, U_ZDYHelp, U_TradePlanProfitDetails,
  U_LabelPrint;

{$R *.dfm}

procedure TfrmTradePlanProfit1.InitGrid();
var
  SqlStr: string;
begin
  SqlStr := ' exec P_Trade_Profit_Plan1 @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.Begdate.Date)));
  SqlStr := SqlStr + ' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.EndDate.Date + 1)));

  InitADOData(ADOQueryMain, Tv1, SqlStr, SGetFilters(Panel1, 1, 2), 'conno');
end;

procedure TfrmTradePlanProfit1.FormDestroy(Sender: TObject);
begin
  inherited;
  frmTradePlanProfit1 := nil;
end;

procedure TfrmTradePlanProfit1.CustNamePropertiesChange(Sender: TObject);
begin
  TBFind.Click;
end;

procedure TfrmTradePlanProfit1.cxButton1Click(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.cxButton1Click(Sender);
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmTradePlanProfit1.cxButton2Click(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.cxButton2Click(Sender);
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmTradePlanProfit1.cxButton3Click(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.cxButton3Click(Sender);
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmTradePlanProfit1.cxButton4Click(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.cxButton4Click(Sender);
  ToolBar1.SetFocus;
  InitGrid();
end;

procedure TfrmTradePlanProfit1.cxButton5Click(Sender: TObject);
begin
  inherited;
  frmFrameDateSel1.cxButton5Click(Sender);
  ToolBar1.SetFocus;
  InitGrid();
end;

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

procedure TfrmTradePlanProfit1.TBCloseClick(Sender: TObject);
begin

  Close;
end;

procedure TfrmTradePlanProfit1.FormShow(Sender: TObject);
var
  fsj: string;
begin
  inherited;
  ReadCxGrid(trim(self.caption), Tv1, '合同利润表');

  InitGrid();
end;

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

procedure TfrmTradePlanProfit1.TBFindClick(Sender: TObject);
begin
  if ADOQueryMain.Active then
  begin
    SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
//    SCreateCDS(ADOQueryMain, CDS_1);
//    SInitCDSData(ADOQueryMain, CDS_1);
  end;
end;

procedure TfrmTradePlanProfit1.ToolButton3Click(Sender: TObject);
begin
  WriteCxGrid(trim(self.caption), Tv1, '合同利润表');
end;

procedure TfrmTradePlanProfit1.ToolButton4Click(Sender: TObject);
begin
  try
    frmTradePlanProfitDetails := TfrmTradePlanProfitDetails.Create(Application);
    with frmTradePlanProfitDetails do
    begin

      FConNo := Trim(Self.ADOQueryMain.fieldbyname('ConNo').AsString);
      if ShowModal = 1 then
      begin
        InitGrid();
      end;
    end;
  finally
    frmTradePlanProfitDetails.Free;
  end;
end;

procedure TfrmTradePlanProfit1.ToolButton5Click(Sender: TObject);
var
  WSql: string;
  MPrintJson: string;
begin
  WSql := ' ,@ConNo=' + quotedstr(Trim(Self.ADOQueryMain.fieldbyname('ConNo').AsString));
  MPrintJson := '              {"LMType": "TradePlanProfit1"    ';
  MPrintJson := MPrintJson + ' ,"PreviewPrint": true      ';
  MPrintJson := MPrintJson + ' ,"PrtArgs": [ { "IsSql": true, "Filtration":" @CXType=''总计'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''销售'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''成本'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''费用'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''利润'' ' + WSql + '"  } ] }    ';
  FromPrintFr3(Application, PChar(DConString), PChar(MPrintJson));
end;

procedure TfrmTradePlanProfit1.ToolButton6Click(Sender: TObject);
var
  WSql: string;
  MPrintJson: string;
begin

  WSql := ' ,@SellName=' + quotedstr(Trim(Self.ADOQueryMain.fieldbyname('SellName').AsString));
  WSql := WSql + ' ,@Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.Begdate.Date)));
  WSql := WSql + ' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.EndDate.Date + 1)));

  MPrintJson := '              {"LMType": "TradePlanProfit2"    ';
  MPrintJson := MPrintJson + ' ,"PreviewPrint": true      ';
  MPrintJson := MPrintJson + ' ,"PrtArgs": [ { "IsSql": true, "Filtration":" @CXType=''总计'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''销售'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''成本'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''费用'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''利润'' ' + WSql + '"  } ] }    ';
  FromPrintFr3(Application, PChar(DConString), PChar(MPrintJson));

end;

procedure TfrmTradePlanProfit1.ToolButton7Click(Sender: TObject);
var
  WSql: string;
  MPrintJson: string;
begin
  WSql := ' ,@Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.Begdate.Date)));
  WSql := WSql + ' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.EndDate.Date + 1)));

  MPrintJson := '              {"LMType": "TradePlanProfit4"    ';
  MPrintJson := MPrintJson + ' ,"PreviewPrint": true      ';
  MPrintJson := MPrintJson + ' ,"PrtArgs": [ { "IsSql": true, "Filtration":" @CXType=''总计'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''销售'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''成本'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''费用'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''利润'' ' + WSql + '"  } ] }    ';
  FromPrintFr3(Application, PChar(DConString), PChar(MPrintJson));

end;

procedure TfrmTradePlanProfit1.ToolButton1Click(Sender: TObject);
begin
  if ADOQueryMain.IsEmpty then
    Exit;
  TcxGridToExcel(self.Caption, cxgrid1);
end;

procedure TfrmTradePlanProfit1.ToolButton2Click(Sender: TObject);
var
  WSql: string;
  MPrintJson: string;
begin
  WSql := '  ,@Saleser=' + quotedstr(Trim(Self.ADOQueryMain.fieldbyname('Saleser').AsString));
  WSql := WSql + ' ,@Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.Begdate.Date)));
  WSql := WSql + ' ,@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', frmFrameDateSel1.EndDate.Date + 1)));

  MPrintJson := '              {"LMType": "TradePlanProfit3"    ';
  MPrintJson := MPrintJson + ' ,"PreviewPrint": true      ';
  MPrintJson := MPrintJson + ' ,"PrtArgs": [ { "IsSql": true, "Filtration":" @CXType=''总计'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''销售'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''成本'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''费用'' ' + WSql + '" }, ';
  MPrintJson := MPrintJson + '               { "IsSql": true, "Filtration":" @CXType=''利润'' ' + WSql + '"  } ] }    ';
  FromPrintFr3(Application, PChar(DConString), PChar(MPrintJson));

end;

procedure TfrmTradePlanProfit1.FormCreate(Sender: TObject);
begin
  inherited;
  canshu1 := Trim(DParameters1);
  frmFrameDateSel1.EndDate.Date := SGetServerDate(ADOQueryTemp);
  frmFrameDateSel1.BegDate.Date := frmFrameDateSel1.EndDate.Date - 365;

end;

end.

