unit U_JHDTJ;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ComCtrls, ToolWin, cxStyles, cxCustomData,
  cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, ADODB,
  cxGridCustomPopupMenu, cxGridPopupMenu, cxGridLevel, cxClasses, cxControls,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, DBClient, cxCalendar, cxButtonEdit, cxSplitter, RM_Common, RM_Class,
  RM_e_Xls, RM_Dataset, RM_System, RM_GridReport, cxTextEdit, cxCheckBox,
  BtnEdit, RM_BarCode, cxPC, cxLookAndFeels, cxLookAndFeelPainters, cxNavigator,
  dxDateRanges, dxBarBuiltInMenu, U_BaseList, Vcl.Menus, dxScrollbarAnnotations,
  cxContainer, dxCore, cxDateUtils, cxMaskEdit, cxDropDownEdit, dxSkinsCore,
  dxSkinsDefaultPainters, cxProgressBar, cxGridBandedTableView,
  cxGridDBBandedTableView;

type
  TfrmJHDTJ = class(TfrmBaseList)
    ToolBar1: TToolBar;
    TBRafresh: TToolButton;
    TBClose: TToolButton;
    Panel1: TPanel;
    GPM_1: TcxGridPopupMenu;
    ADOQueryCmd: TADOQuery;
    ADOQueryMain: TADOQuery;
    ADOQueryTemp: TADOQuery;
    Label3: TLabel;
    ConNo: TcxTextEdit;
    ADOQueryPrint: TADOQuery;
    Label2: TLabel;
    C_Name: TcxTextEdit;
    DS_1: TDataSource;
    CDS_1: TClientDataSet;
    Label4: TLabel;
    C_Code: TcxTextEdit;
    ToolButton2: TToolButton;
    Label5: TLabel;
    OrderNo: TcxTextEdit;
    PopupMenu1: TPopupMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    Label8: TLabel;
    Label10: TLabel;
    BegDate: TcxDateEdit;
    EndDate: TcxDateEdit;
    cxGrid1: TcxGrid;
    TV1: TcxGridDBBandedTableView;
    cxGridDBBandedColumn35: TcxGridDBBandedColumn;
    cxGridDBBandedColumn42: TcxGridDBBandedColumn;
    cxGridDBBandedColumn51: TcxGridDBBandedColumn;
    cxGridDBBandedColumn52: TcxGridDBBandedColumn;
    cxGridDBBandedColumn57: TcxGridDBBandedColumn;
    cxGridDBBandedColumn59: TcxGridDBBandedColumn;
    cxGridDBBandedColumn61: TcxGridDBBandedColumn;
    cxGridDBBandedColumn63: TcxGridDBBandedColumn;
    cxGridDBBandedColumn64: TcxGridDBBandedColumn;
    cxGridDBBandedColumn77: TcxGridDBBandedColumn;
    cxGridDBBandedColumn79: TcxGridDBBandedColumn;
    cxGridDBBandedColumn87: TcxGridDBBandedColumn;
    cxGridDBBandedColumn91: TcxGridDBBandedColumn;
    V1Column26: TcxGridDBBandedColumn;
    V1Column4: TcxGridDBBandedColumn;
    V1Column5: TcxGridDBBandedColumn;
    V1Column7: TcxGridDBBandedColumn;
    V1Column3: TcxGridDBBandedColumn;
    V1Column8: TcxGridDBBandedColumn;
    V1Column11: TcxGridDBBandedColumn;
    TV1Column1: TcxGridDBBandedColumn;
    TV1Column2: TcxGridDBBandedColumn;
    TV1Column3: TcxGridDBBandedColumn;
    TV1Column4: TcxGridDBBandedColumn;
    TV1Column7: TcxGridDBBandedColumn;
    TV1Column8: TcxGridDBBandedColumn;
    TV1Column12: TcxGridDBBandedColumn;
    TV1Column13: TcxGridDBBandedColumn;
    TV1Column15: TcxGridDBBandedColumn;
    TV1Column17: TcxGridDBBandedColumn;
    TV1Column6: TcxGridDBBandedColumn;
    TV1Column9: TcxGridDBBandedColumn;
    TV1Column10: TcxGridDBBandedColumn;
    TV1Column11: TcxGridDBBandedColumn;
    TV1Column14: TcxGridDBBandedColumn;
    TV1Column19: TcxGridDBBandedColumn;
    TV1Column5: TcxGridDBBandedColumn;
    TV1Column18: TcxGridDBBandedColumn;
    TV1Column21: TcxGridDBBandedColumn;
    TV1Column22: TcxGridDBBandedColumn;
    TV1Column20: TcxGridDBBandedColumn;
    TV1Column23: TcxGridDBBandedColumn;
    TV1Column24: TcxGridDBBandedColumn;
    TV1Column25: TcxGridDBBandedColumn;
    TV1Column16: TcxGridDBBandedColumn;
    TV1Column27: TcxGridDBBandedColumn;
    TV1Column28: TcxGridDBBandedColumn;
    TV1Column29: TcxGridDBBandedColumn;
    TV1Column26: TcxGridDBBandedColumn;
    TV1Column32: TcxGridDBBandedColumn;
    TV1Column40: TcxGridDBBandedColumn;
    cxGridLevel2: TcxGridLevel;
    ToolButton1: TToolButton;
    TV1Column30: TcxGridDBBandedColumn;
    TV1Column31: TcxGridDBBandedColumn;
    TV1Column33: TcxGridDBBandedColumn;
    TV1Column34: TcxGridDBBandedColumn;
    TV1Column35: TcxGridDBBandedColumn;
    TV1Column36: TcxGridDBBandedColumn;
    TV1Column37: TcxGridDBBandedColumn;
    TV1Column38: TcxGridDBBandedColumn;
    TV1Column39: TcxGridDBBandedColumn;
    TV1Column41: TcxGridDBBandedColumn;
    Label1: TLabel;
    Saleser: TcxTextEdit;
    TV1Column42: TcxGridDBBandedColumn;
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure TBCloseClick(Sender: TObject);
    procedure TBRafreshClick(Sender: TObject);
    procedure ConNoChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure cxTabControl1Change(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure N1Click(Sender: TObject);
    procedure N2Click(Sender: TObject);
    procedure ToolButton1Click(Sender: TObject);
    procedure TV1Column28CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
    procedure ConNoPropertiesChange(Sender: TObject);
  private
    FInt, PFInt: Integer;
    FFMainID, BPFlag: string;
    procedure InitGrid();
    { Private declarations }
  public
    canshu1: string;
    { Public declarations }
  end;

implementation

uses
  U_DataLink, U_RTFun, U_ZDYHelp, U_LabelPrint, U_TatCardInPut1;

{$R *.dfm}

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

end;

procedure TfrmJHDTJ.TBCloseClick(Sender: TObject);
begin
  Close;

end;

procedure TfrmJHDTJ.InitGrid();
var
  fwhere, Pwhere: string;
begin

  Pwhere := SGetFilters(Panel1, 1, 2);

  if trim(Pwhere) <> '' then
  begin
    if fwhere <> '' then
      fwhere := fwhere + ' and ' + trim(Pwhere)
    else
      fwhere := ' and ' + trim(Pwhere);
  end;
  try
    ADOQueryMain.DisableControls;
    with ADOQueryMain do
    begin
      Close;
      SQL.Clear;
      sql.Add(' exec P_View_OrderProgressAll2 @Begdate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', Begdate.Date))));
      sql.Add(',@enddate=' + quotedstr(trim(FormatDateTime('yyyy-MM-dd', EndDate.Date + 1))));
      sql.Add(',@criteria= ' + quotedstr(fwhere));
//      ShowMessage(sql.text);
      Open;
    end;
    SCreateCDS(ADOQueryMain, CDS_1);
    SInitCDSData(ADOQueryMain, CDS_1);
//    CDS_HZ.Last;
  finally
    ADOQueryMain.EnableControls;
  end;
end;

procedure TfrmJHDTJ.N1Click(Sender: TObject);
begin
  SelOKNo(cds_1, true)
end;

procedure TfrmJHDTJ.N2Click(Sender: TObject);
begin
  SelOKNo(cds_1, false);
end;

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

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

procedure TfrmJHDTJ.ToolButton2Click(Sender: TObject);
begin
  WriteCxBandedGrid(trim(self.caption) + 'Tv1', Tv1, '统计查询');
end;

procedure TfrmJHDTJ.TV1Column28CompareRowValuesForCellMerging(Sender: TcxGridColumn; ARow1: TcxGridDataRow; AProperties1: TcxCustomEditProperties; const AValue1: Variant; ARow2: TcxGridDataRow; AProperties2: TcxCustomEditProperties; const AValue2: Variant; var AAreEqual: Boolean);
begin
  if ARow1.Values[TV1Column16.Index] = ARow2.Values[TV1Column16.Index] then
    AAreEqual := True
  else
    AAreEqual := False;
end;

procedure TfrmJHDTJ.ConNoChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

procedure TfrmJHDTJ.FormShow(Sender: TObject);
begin
  inherited;
  ReadCxBandedGrid(trim(self.caption) + 'Tv1', Tv1, '统计查询');
  EndDate.Date := SGetServerDate(ADOQueryTemp);
  BegDate.Date := EndDate.Date - 90;
  canshu1 := DParameters1;
  if canshu1 = '业务员' then
  begin
    Saleser.text := DName;
  end;

  InitGrid();
end;

procedure TfrmJHDTJ.ConNoPropertiesChange(Sender: TObject);
begin
  if ADOQueryMain.Active = False then
    Exit;
  SDofilter(ADOQueryMain, SGetFilters(Panel1, 1, 2));
  SCreateCDS(ADOQueryMain, CDS_1);
  SInitCDSData(ADOQueryMain, CDS_1);
end;

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

end.

