git-svn-id: https://192.168.0.254/svn/Proyectos.AlonsoYSal_FactuGES/trunk@12 9a1d36f3-7752-2d40-8ccb-50eb49674c68
322 lines
8.5 KiB
ObjectPascal
322 lines
8.5 KiB
ObjectPascal
unit uEditorGrid;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
Dialogs, uEditorBase, ToolWin, ComCtrls, JvExControls, JvComponent,
|
|
JvNavigationPane, ActnList, TB2Dock, TB2Toolbar, TBX, TB2Item,
|
|
ImgList, PngImageList, StdActns, TB2ExtItems, TBXExtItems, uViewGrid,
|
|
uEditorDBBase, DB, uDADataTable, Menus, JvFormAutoSize,
|
|
uDAScriptingProvider, uDACDSDataTable, AppEvnts, JvAppStorage,
|
|
JvAppRegistryStorage, JvFormPlacement, pngimage, ExtCtrls,
|
|
JvComponentBase;
|
|
|
|
type
|
|
IEditorGrid = interface(IEditorDBBase)
|
|
['{CB8CDE00-B225-4A1D-9A5C-EC6FBE2C854B}']
|
|
end;
|
|
|
|
TfEditorGrid = class(TfEditorDBBase, IEditorGrid)
|
|
tbxEditFiltro: TTBXEditItem;
|
|
tbxFiltro: TTBXToolbar;
|
|
TBXItem7: TTBXItem;
|
|
GridPopupMenu: TPopupMenu;
|
|
Modificar1: TMenuItem;
|
|
Eliminar1: TMenuItem;
|
|
N1: TMenuItem;
|
|
Nuevo1: TMenuItem;
|
|
TBXLabelItem1: TTBXLabelItem;
|
|
actQuitarFiltro: TAction;
|
|
N2: TMenuItem;
|
|
Previsualizar1: TMenuItem;
|
|
Imprimir1: TMenuItem;
|
|
TBXSeparatorItem14: TTBXSeparatorItem;
|
|
TBXItem33: TTBXItem;
|
|
actDuplicar: TAction;
|
|
TBXSeparatorItem15: TTBXSeparatorItem;
|
|
TBXItem34: TTBXItem;
|
|
Duplicar1: TMenuItem;
|
|
actAnchoAuto: TAction;
|
|
TBXItem35: TTBXItem;
|
|
actFiltrar: TAction;
|
|
TBXItem37: TTBXItem;
|
|
lblAno: TTBXLabelItem;
|
|
cbxListaAnos: TTBXComboBoxItem;
|
|
sepAno: TTBXSeparatorItem;
|
|
procedure tbxEditFiltroChange(Sender: TObject; const Text: String);
|
|
procedure FormShow(Sender: TObject);
|
|
procedure actPrevisualizarExecute(Sender: TObject);
|
|
procedure actConfPaginaExecute(Sender: TObject);
|
|
procedure actImprimirExecute(Sender: TObject);
|
|
procedure actQuitarFiltroExecute(Sender: TObject);
|
|
procedure actModificarExecute(Sender: TObject);
|
|
procedure actEliminarExecute(Sender: TObject);
|
|
procedure actDuplicarUpdate(Sender: TObject);
|
|
procedure actDuplicarExecute(Sender: TObject);
|
|
procedure JvFormStorageSavePlacement(Sender: TObject);
|
|
procedure JvFormStorageRestorePlacement(Sender: TObject);
|
|
procedure actRefrescarExecute(Sender: TObject);
|
|
procedure actAnchoAutoExecute(Sender: TObject);
|
|
procedure actFiltrarExecute(Sender: TObject);
|
|
procedure actFiltrarUpdate(Sender: TObject);
|
|
private
|
|
FListaAnos: TStringList;
|
|
FViewGrid : IViewGrid;
|
|
FWhereDataTable: WideString;
|
|
|
|
function GetListaAnos: TStringList;
|
|
procedure SetListaAnos(const Value: TStringList);
|
|
|
|
function GetWhereDataTable: String;
|
|
procedure SetWhereDataTable(const Value: String);
|
|
|
|
protected
|
|
procedure SetViewGrid(const Value : IViewGrid); virtual;
|
|
function GetViewGrid: IViewGrid;
|
|
|
|
public
|
|
property ListaAnos: TStringList read GetListaAnos write SetListaAnos;
|
|
property WhereDataTable: String read GetWhereDataTable write SetWhereDataTable;
|
|
property ViewGrid: IViewGrid read GetViewGrid write SetViewGrid;
|
|
constructor Create(AOwner : TComponent); override;
|
|
destructor Destroy; override;
|
|
|
|
end;
|
|
|
|
implementation
|
|
|
|
uses
|
|
uDataModuleBase, uCustomEditor, cxGridTableView;
|
|
|
|
{$R *.dfm}
|
|
|
|
{
|
|
********************************* TfEditorGrid *********************************
|
|
}
|
|
destructor TfEditorGrid.Destroy;
|
|
begin
|
|
FWhereDataTable := '';
|
|
FViewGrid := NIL;
|
|
if Assigned(FListaAnos) then
|
|
FlistaAnos.Free;
|
|
|
|
inherited;
|
|
end;
|
|
|
|
function TfEditorGrid.GetViewGrid: IViewGrid;
|
|
begin
|
|
Result := FViewGrid;
|
|
end;
|
|
|
|
procedure TfEditorGrid.SetViewGrid(const Value: IViewGrid);
|
|
begin
|
|
FViewGrid := Value;
|
|
if Assigned(FViewGrid) then
|
|
begin
|
|
FViewGrid.PopupMenu := GridPopupMenu;
|
|
FViewGrid.OnDblClick := actModificar.OnExecute;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorGrid.tbxEditFiltroChange(Sender: TObject; const Text: String);
|
|
begin
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.Filter := Text;
|
|
end;
|
|
|
|
procedure TfEditorGrid.FormShow(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
cbxListaAnos.ItemIndex := 0; //OJO EL ORDEN PORQUE EL ShowEmbedded hace el open de la tabla
|
|
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.ShowEmbedded(Self);
|
|
end;
|
|
|
|
procedure TfEditorGrid.actPrevisualizarExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ViewGrid.Preview;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actConfPaginaExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ViewGrid.PrintSetup;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actImprimirExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ViewGrid.Print;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actQuitarFiltroExecute(Sender: TObject);
|
|
begin
|
|
if Assigned(ViewGrid) then
|
|
begin
|
|
tbxEditFiltro.Text := '';
|
|
ViewGrid.Filter := '';
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actModificarExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
ViewGrid.SyncFocusedRecordsFromGrid;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actEliminarExecute(Sender: TObject);
|
|
begin
|
|
ViewGrid.SyncFocusedRecordsFromGrid; // Esto va ANTES del inherited. No cambiar.
|
|
inherited;
|
|
end;
|
|
|
|
constructor TfEditorGrid.Create(AOwner: TComponent);
|
|
begin
|
|
inherited;
|
|
actModificar.ShortCut := ShortCut(VK_RETURN, []);
|
|
end;
|
|
|
|
procedure TfEditorGrid.actDuplicarUpdate(Sender: TObject);
|
|
begin
|
|
if Assigned(dsDataTable.DataTable) then
|
|
(Sender as TAction).Enabled := (not dsDataTable.DataTable.IsEmpty)
|
|
and not (dsDataTable.DataTable.State = dsInsert)
|
|
else
|
|
(Sender as TAction).Enabled := False;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actDuplicarExecute(Sender: TObject);
|
|
begin
|
|
ViewGrid.SyncFocusedRecordsFromGrid; // Esto va ANTES del inherited. No cambiar.
|
|
inherited;
|
|
end;
|
|
|
|
procedure TfEditorGrid.JvFormStorageSavePlacement(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.StoreToRegistry;
|
|
end;
|
|
|
|
procedure TfEditorGrid.JvFormStorageRestorePlacement(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.RestoreFromRegistry;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actRefrescarExecute(Sender: TObject);
|
|
var
|
|
FocusedRow, TopRow : Integer;
|
|
begin
|
|
ViewGrid.SyncFocusedRecordsFromGrid;
|
|
|
|
TopRow := (ViewGrid.Grid.ActiveView.Controller as TcxGridTableController).TopRowIndex;
|
|
FocusedRow := ViewGrid.Grid.ActiveView.DataController.FocusedRowIndex;
|
|
|
|
inherited;
|
|
|
|
ViewGrid.Grid.ActiveView.DataController.FocusedRowIndex := FocusedRow;
|
|
(ViewGrid.Grid.ActiveView.Controller as TcxGridTableController).TopRowIndex := TopRow;
|
|
// ViewGrid.Grid.ActiveView.Controller.TopRowIndex := TopRow;
|
|
|
|
// ViewGrid.SyncFocusedRecordsFromDataSet;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actAnchoAutoExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.AjustarAncho;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actFiltrarExecute(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if Assigned(ViewGrid) then
|
|
ViewGrid.ActivarDesactivarFiltros;
|
|
|
|
if Assigned(ViewGrid) then
|
|
if ViewGrid.EstanFiltrosVisible then
|
|
begin
|
|
tbxEditFiltro.Visible := False;
|
|
TBXItem7.Visible := False;
|
|
end
|
|
else
|
|
begin
|
|
tbxEditFiltro.Text := '';
|
|
tbxEditFiltro.Visible := True;
|
|
TBXItem7.Visible := True;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorGrid.actFiltrarUpdate(Sender: TObject);
|
|
begin
|
|
inherited;
|
|
if Assigned(ViewGrid) then
|
|
(Sender as TAction).Checked := ViewGrid.EstanFiltrosVisible
|
|
end;
|
|
|
|
function TfEditorGrid.GetListaAnos: TStringList;
|
|
begin
|
|
Result := FListaAnos;
|
|
end;
|
|
|
|
function TfEditorGrid.GetWhereDataTable: String;
|
|
begin
|
|
Result := FWhereDataTable;
|
|
end;
|
|
|
|
procedure TfEditorGrid.SetListaAnos(const Value: TStringList);
|
|
var
|
|
i: Integer;
|
|
AStringAnterior: String;
|
|
|
|
begin
|
|
AStringAnterior := '';
|
|
if Assigned(FListaAnos) then
|
|
begin
|
|
AStringAnterior := FListaAnos.ValueFromIndex[cbxListaAnos.ItemIndex];
|
|
FListaAnos.Free;
|
|
end;
|
|
|
|
//Se asigna el nuevo TStringList
|
|
FListaAnos := Value;
|
|
|
|
if Assigned(FListaAnos) then
|
|
begin
|
|
cbxListaAnos.Strings.BeginUpdate;
|
|
cbxListaAnos.Strings.Clear;
|
|
for i := 0 to FListaAnos.Count - 1 do
|
|
cbxListaAnos.Strings.Append(FListaAnos.Names[i]);
|
|
|
|
//Se posiciona en el elemento que habia anteriormente
|
|
if Length(AStringAnterior) > 0 then
|
|
begin
|
|
if FListaAnos.IndexOfName(AStringAnterior) <> -1 then
|
|
cbxListaAnos.ItemIndex := FListaAnos.IndexOfName(AStringAnterior)
|
|
else
|
|
cbxListaAnos.ItemIndex := 0;
|
|
end;
|
|
|
|
cbxListaAnos.Strings.EndUpdate;
|
|
end;
|
|
end;
|
|
|
|
procedure TfEditorGrid.SetWhereDataTable(const Value: String);
|
|
begin
|
|
FWhereDataTable := Value;
|
|
end;
|
|
|
|
initialization
|
|
RegisterClass(TfEditorGrid);
|
|
|
|
finalization
|
|
UnRegisterClass(TfEditorGrid);
|
|
|
|
end.
|
|
|