unit uViewInfVentasArticulo; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, uViewInformeBase, ActnList, ImgList, PngImageList, uViewGrid, uViewInformeBaseGrid, uViewSumarios, TBXDkPanels, StdCtrls, uViewAgrupaciones, uCustomView, uViewBase, uViewColumnas, ComCtrls, TB2Dock, uViewInformeBaseParametros, uBizInformes, cxStyles, cxCustomData, cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DB, cxDBData, cxGridLevel, cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxGrid, cxTextEdit, uViewFiltros, uBizInfVentasArticulo, uInfVentasArticuloController, uViewPeriodoFechas, uViewInfVentasArticuloGrid, uDADataTable, uViewFiltroBase, uDAInterfaces; type IViewInfVentasArticulo = interface(IViewInformeBase) ['{B8B9105B-E833-4E7D-BA36-EB9A7EBDCE69}'] function GetDatos : IBizInfVentasArticulo; procedure SetDatos (const Value : IBizInfVentasArticulo); property Datos : IBizInfVentasArticulo read GetDatos write SetDatos; function GetController : IInfVentasArticuloController; procedure SetController (const Value : IInfVentasArticuloController); property Controller: IInfVentasArticuloController read GetController write SetController; end; TfrViewInfVentasArticulo = class(TfrViewInformeBase, IViewInfVentasArticulo) frViewPeriodoFechas1: TfrViewPeriodoFechas; actPeriodoFechas: TAction; frViewInfVentasArticuloGrid1: TfrViewInfVentasArticuloGrid; dsVentasTerminadas: TDADataSource; procedure actRefrescarExecute(Sender: TObject); procedure actPeriodoFechasExecute(Sender: TObject); procedure frViewInfVentasArticuloGrid1cxGridViewIMPORTE_TOTAL_VENTAHeaderClick(Sender: TObject); procedure frViewInfVentasArticuloGrid1cxGridViewCANTIDADHeaderClick(Sender: TObject); protected FDatos : IBizInfVentasArticulo; FController : IInfVentasArticuloController; FModificado : Boolean; procedure OnViewInformeBaseGridChanged(Sender : TObject); procedure OnFilterChanged(Sender : TObject); procedure ActivarTarea(const ATarea: Integer); override; function GetFocusedView: TcxGridDBTableView; override; function GetDatos : IBizInfVentasArticulo; procedure SetDatos (const Value : IBizInfVentasArticulo); function GetController : IInfVentasArticuloController; procedure SetController (const Value : IInfVentasArticuloController); public property Controller: IInfVentasArticuloController read GetController write SetController; property Datos : IBizInfVentasArticulo read GetDatos write SetDatos; constructor Create(AOwner: TComponent); override; procedure Refresh; override; end; implementation {$R *.dfm} { TfrViewInfVentasArticulo } uses schInfVentasArticuloClient_Intf, StrUtils; const PERIODO = 0; constructor TfrViewInfVentasArticulo.Create(AOwner: TComponent); begin inherited; frViewInfVentasArticuloGrid1.OnViewChanged := OnViewInformeBaseGridChanged; frViewInfVentasArticuloGrid1.OnFilterChanged := OnFilterChanged; frViewColumnas1.ViewInformeBaseGrid := frViewInfVentasArticuloGrid1; frViewAgrupaciones1.ViewInformeBaseGrid := frViewInfVentasArticuloGrid1; frViewSumarios1.ViewInformeBaseGrid := frViewInfVentasArticuloGrid1; frViewFiltros1.ViewInformeBaseGrid := frViewInfVentasArticuloGrid1; pcParametros.ActivePage := TabSheet5; end; procedure TfrViewInfVentasArticulo.frViewInfVentasArticuloGrid1cxGridViewCANTIDADHeaderClick(Sender: TObject); begin inherited; frViewInfVentasArticuloGrid1.cxGridView.DataController.Groups.DataController.BeginUpdate; frViewInfVentasArticuloGrid1.cxGridView.GetColumnByFieldName(fld_InfVentasArticuloCANTIDAD).SortIndex := 1; frViewInfVentasArticuloGrid1.cxGridView.GetColumnByFieldName(fld_InfVentasArticuloCANTIDAD).Summary.SortByGroupFooterSummary := True; frViewInfVentasArticuloGrid1.cxGridView.DataController.Groups.DataController.EndUpdate; end; procedure TfrViewInfVentasArticulo.frViewInfVentasArticuloGrid1cxGridViewIMPORTE_TOTAL_VENTAHeaderClick(Sender: TObject); begin inherited; frViewInfVentasArticuloGrid1.cxGridView.DataController.Groups.DataController.BeginUpdate; frViewInfVentasArticuloGrid1.cxGridView.GetColumnByFieldName(fld_InfVentasArticuloIMPORTE_TOTAL_VENTA).SortOrder := soAscending; frViewInfVentasArticuloGrid1.cxGridView.GetColumnByFieldName(fld_InfVentasArticuloIMPORTE_TOTAL_VENTA).Summary.SortByGroupFooterSummary := True; frViewInfVentasArticuloGrid1.cxGridView.DataController.Groups.DataController.EndUpdate; end; function TfrViewInfVentasArticulo.GetController: IInfVentasArticuloController; begin Result := FController; end; function TfrViewInfVentasArticulo.GetDatos: IBizInfVentasArticulo; begin Result := FDatos; end; function TfrViewInfVentasArticulo.GetFocusedView: TcxGridDBTableView; begin Result := frViewInfVentasArticuloGrid1.cxGridView; end; procedure TfrViewInfVentasArticulo.Refresh; var AColumns : TStringList; AColumnsGroup : TStringList; i: Integer; Condicion: TDAWhereExpression; AWhere : String; begin inherited; ShowHourglassCursor; actRefrescar.Enabled := False; AWhere := ' ( ' + fld_InfVentasArticuloFECHA_FACTURA + ' between ''' + ReplaceStr(DateToStr(frViewPeriodoFechas1.FechaInicial),'/','.') + ''' and ''' + ReplaceStr(DateToStr(frViewPeriodoFechas1.FechaFinal),'/','.') + ''') '; frViewInfVentasArticuloGrid1.OnViewChanged := nil; frViewInfVentasArticuloGrid1.OnFilterChanged := nil; try // Calcular las columnas a pedir al servidor AColumns := frViewColumnas1.GetCheckedColumns; AColumns.sorted := true; AColumns.Duplicates := dupIgnore; //Aņadimos el nombre de los campos a los que referencia los captions de agrupacion AColumnsGroup := frViewAgrupaciones1.GetAgrupaciones; for i:= 0 to AColumnsGroup.Count - 1 do AColumns.Add((frViewInfVentasArticuloGrid1 as IViewInformeBaseGrid).GetColumnByCaption(AColumnsGroup.Strings[i]).DataBinding.FieldName); FDatos := FController.BuscarTodos(AColumns.CommaText, Awhere); dsVentasTerminadas.DataTable := FDatos.Datatable; frViewInfVentasArticuloGrid1.FocusedView.DataController.DataSource := dsVentasTerminadas; with Datos.DataTable do begin DisableControls; try Active := False; // LoadSchema; { // Filtrar por fecha with Datos.DataTable.DynamicWhere do begin // (FECHAINI >= ) Condicion := NewBinaryExpression(NewField('', fld_InfVentasArticuloFECHA_FACTURA), NewConstant(frViewPeriodoFechas1.FechaInicial, datDateTime), dboGreaterOrEqual); Condicion := NewBinaryExpression(NewBinaryExpression(NewField('', fld_InfVentasArticuloFECHA_FACTURA), NewConstant(frViewPeriodoFechas1.FechaFinal, datDateTime), dboLessOrEqual), Condicion, dboAnd); if IsEmpty then Expression := Condicion else Expression := NewBinaryExpression(Expression, Condicion, dboAnd); end; } { Tbl := DynWhere_ClientDataForm.tbl_Data; if Pan_Cond.Visible then begin Tbl.Active := False; XML := GetXML(); if XML = '' then Tbl.DynamicWhere.Clear() else Tbl.DynamicWhere.Xml := GetXML(); Tbl.Active := True; end } //showmessage(DateToStr(frViewPeriodoFechas1.FechaInicial)); //showmessage(DateToStr(frViewPeriodoFechas1.FechaFinal)); // ParamByName('FECHAINI').AsDateTime := frViewPeriodoFechas1.FechaInicial; // ParamByName('FECHAFIN').AsDateTime := frViewPeriodoFechas1.FechaFinal; Active := True; frViewColumnas1.Execute; frViewAgrupaciones1.Execute; frViewSumarios1.Refresh; frViewFiltros1.Refresh; pnlTareas.Visible := True; if Assigned(FOnViewChanged) then FOnViewChanged(Self); finally EnableControls; frViewInfVentasArticuloGrid1.Refresh; frViewInfVentasArticuloGrid1.ExpandirTodo; frViewInfVentasArticuloGrid1.GotoFirst; end; end; finally FreeAndNil(AColumns); // ViewInfVentasArticuloGrid.OnViewChanged := OnViewInformeBaseGridChanged; // ViewInfVentasArticuloGrid.OnFilterChanged := OnFilterChanged; actRefrescar.Enabled := True; HideHourglassCursor; end; end; procedure TfrViewInfVentasArticulo.SetController(const Value: IInfVentasArticuloController); begin FController := Value; end; procedure TfrViewInfVentasArticulo.SetDatos(const Value: IBizInfVentasArticulo); begin FDatos := Value; end; procedure TfrViewInfVentasArticulo.actRefrescarExecute(Sender: TObject); begin inherited; Refresh; end; procedure TfrViewInfVentasArticulo.OnViewInformeBaseGridChanged( Sender: TObject); begin if Assigned(Self.OnViewChanged) then Self.OnViewChanged(Self); end; procedure TfrViewInfVentasArticulo.OnFilterChanged(Sender: TObject); begin frViewFiltros1.Refresh; end; procedure TfrViewInfVentasArticulo.actPeriodoFechasExecute( Sender: TObject); begin inherited; ActivarTarea(PERIODO); end; procedure TfrViewInfVentasArticulo.ActivarTarea(const ATarea: Integer); begin inherited; case ATarea of PERIODO : pcParametros.ActivePage := TabSheet5; end; end; end.