2008-05-30 16:56:23 +00:00
|
|
|
|
unit uGridClipboardUtils;
|
|
|
|
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
|
|
|
|
|
Dialogs, cxGrid;
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
procedure PegarAlGridDesdePortapapeles (AGrid : TcxGrid);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
procedure CopiarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
|
|
|
|
|
|
procedure CortarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
|
2008-09-30 12:12:40 +00:00
|
|
|
|
function HayDatosEnPortapapeles(AFormat: Cardinal = 0): Boolean;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesRTF (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesHTML (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesTXT (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesExcel (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
var
|
|
|
|
|
|
CF_FACTUGES : Cardinal;
|
|
|
|
|
|
CF_RTF : Cardinal;
|
|
|
|
|
|
CF_HTML: Cardinal;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
implementation
|
|
|
|
|
|
|
|
|
|
|
|
uses
|
|
|
|
|
|
cxVariants, CtlToRTF, Clipbrd, DB, cxExport, cxGridExportLink, cxCustomData,
|
|
|
|
|
|
uSistemaFunc, ClipboardUtils, cxDBData, cxGridLevel, uStringsUtils,
|
|
|
|
|
|
cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
|
2010-02-08 17:38:24 +00:00
|
|
|
|
cxGridTableView, cxGridDBTableView, cxGridDBDataDefinitions, uGridStatusUtils,
|
|
|
|
|
|
uDADataTable, uCalculosUtils, uControllerDetallesBase;
|
2008-10-08 11:20:38 +00:00
|
|
|
|
|
|
|
|
|
|
type
|
|
|
|
|
|
TTipoAnadir = (taAnadir, taInsertar);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
procedure RegistrarFormatos;
|
|
|
|
|
|
begin
|
|
|
|
|
|
CF_FACTUGES := RegisterClipboardFormat ('FactuGES Format');
|
|
|
|
|
|
if CF_FACTUGES = 0 then
|
|
|
|
|
|
raise Exception.Create('Error al registrar formato CF_FACTUGES');
|
|
|
|
|
|
|
|
|
|
|
|
CF_HTML := RegisterClipboardFormat ('HTML Format');
|
|
|
|
|
|
if CF_HTML = 0 then
|
|
|
|
|
|
raise Exception.Create('Error al registrar formato CF_HTML');
|
|
|
|
|
|
|
|
|
|
|
|
CF_RTF := RegisterClipboardFormat('Rich Text Format');
|
|
|
|
|
|
if CF_RTF = 0 then
|
|
|
|
|
|
raise Exception.Create('Error al registrar formato CF_RTF (CopiarSeleccionGridAlPortapapelesRTF)');
|
|
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
2008-10-08 11:20:38 +00:00
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
function _BuscarColumna (AView: TcxGridDBTableView;
|
|
|
|
|
|
const AName, ATypeValue : String; var AIndex : Integer) : Boolean;
|
|
|
|
|
|
var
|
|
|
|
|
|
i : Integer;
|
|
|
|
|
|
bNombreOk : Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
AIndex := -1;
|
|
|
|
|
|
Result := False;
|
|
|
|
|
|
for i := 0 to AView.ItemCount - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if (AView.Items[i].DataBinding is TcxGridItemDBDataBinding) then
|
|
|
|
|
|
with (AView.Items[i].DataBinding as TcxGridItemDBDataBinding) do
|
|
|
|
|
|
bNombreOk := (FieldName = AName)
|
|
|
|
|
|
else
|
|
|
|
|
|
bNombreOk := (AView.Items[i].Caption = AName);
|
|
|
|
|
|
|
|
|
|
|
|
if bNombreOk and (AView.Items[i].DataBinding.ValueType = ATypeValue) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
AIndex := i;
|
|
|
|
|
|
Result := True;
|
|
|
|
|
|
Break;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
{$REGION 'LoadGridRowsFromStream'}
|
|
|
|
|
|
procedure LoadGridRowsFromStream(AView : TcxGridDBTableView; AStream: TStream;
|
|
|
|
|
|
var ACaption : String);
|
|
|
|
|
|
var
|
|
|
|
|
|
AValueNameList: TStringList;
|
|
|
|
|
|
AValueTypeList: TStringList;
|
|
|
|
|
|
ARecordID : Integer;
|
|
|
|
|
|
ARecordIndex : Integer;
|
|
|
|
|
|
bEstabaVacia : Boolean;
|
|
|
|
|
|
|
|
|
|
|
|
iContador : Integer;
|
|
|
|
|
|
AValueName, AValueType : String;
|
|
|
|
|
|
iCols, NumCols : integer;
|
|
|
|
|
|
NumFilas: Integer;
|
|
|
|
|
|
AReader: TcxReader;
|
|
|
|
|
|
AValue : Variant;
|
|
|
|
|
|
AIndex : integer;
|
|
|
|
|
|
|
2010-02-08 17:38:24 +00:00
|
|
|
|
//Se adapta para que se utilicen las mismas funciones que en el controllerbase
|
|
|
|
|
|
AControllerDetallesBase: IControllerDetallesBase;
|
|
|
|
|
|
ADataTable: IDAStronglyTypedDataTable;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AView) then
|
|
|
|
|
|
raise Exception.Create('Vista no asignada (SaveGridViewToStream)');
|
|
|
|
|
|
|
|
|
|
|
|
if not Assigned(AStream) then
|
|
|
|
|
|
raise Exception.Create('Stream no asignado (SaveGridViewToStream)');
|
|
|
|
|
|
|
2010-02-08 17:38:24 +00:00
|
|
|
|
if not Supports((AView.DataController.DataSource as TDADataSource).DataTable, IDAStronglyTypedDataTable, ADataTable) then
|
|
|
|
|
|
raise Exception.Create('DataTable asignado no soporta IDAStronglyTypedDataTable)');
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
AReader := TcxReader.Create(AStream);
|
|
|
|
|
|
AValueNameList := TStringList.Create;
|
|
|
|
|
|
AValueTypeList := TStringList.Create;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase:= TControllerDetallesBase.Create;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
AIndex := -1;
|
2009-03-05 12:18:48 +00:00
|
|
|
|
ACaption := AReader.ReadAnsiString;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
NumCols := AReader.ReadInteger; // n<> de columnas
|
|
|
|
|
|
for iContador := 0 to NumCols - 1 do
|
|
|
|
|
|
begin
|
2009-03-05 12:18:48 +00:00
|
|
|
|
AValueName := AReader.ReadAnsiString;
|
|
|
|
|
|
AValueType := AReader.ReadAnsiString;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
AValueNameList.Add(AValueName);
|
|
|
|
|
|
AValueTypeList.Add(AValueType);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
NumFilas := AReader.ReadInteger;
|
2010-02-08 17:38:24 +00:00
|
|
|
|
bEstabaVacia := ADataTable.IsEmpty;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
AView.DataController.BeginUpdate;
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
|
|
|
|
// Localizar el punto donde se empieza a insertar
|
|
|
|
|
|
if not bEstabaVacia then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ARecordIndex := AView.DataController.FocusedRecordIndex;
|
|
|
|
|
|
if ARecordIndex >= 0 then
|
2008-06-02 18:12:24 +00:00
|
|
|
|
begin
|
2008-05-30 16:56:23 +00:00
|
|
|
|
ARecordID := AView.DataController.GetRecordId(ARecordIndex);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Locate(AView.DataController.KeyFieldNames, ARecordID, []);
|
2008-06-02 18:12:24 +00:00
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
for iContador := 0 to NumFilas - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// Insertar una tupla de la forma adecuada
|
|
|
|
|
|
if bEstabaVacia then
|
2010-02-08 17:38:24 +00:00
|
|
|
|
begin
|
|
|
|
|
|
AControllerDetallesBase.Add(ADataTable,TIPO_DETALLE_CONCEPTO);
|
|
|
|
|
|
ADataTable.Edit;
|
|
|
|
|
|
end
|
2008-05-30 16:56:23 +00:00
|
|
|
|
else begin
|
2008-10-06 13:54:35 +00:00
|
|
|
|
if iContador = 0 then
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Edit
|
2008-10-06 13:54:35 +00:00
|
|
|
|
else begin
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase.Add(ADataTable,TIPO_DETALLE_CONCEPTO);
|
|
|
|
|
|
ADataTable.Edit;
|
2008-10-06 13:54:35 +00:00
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
for iCols := 0 to NumCols - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
AValue := AReader.ReadVariant;
|
2008-10-08 11:20:38 +00:00
|
|
|
|
if (Pos(AValueNameList[iCols], AView.DataController.KeyFieldNames) = 0) then
|
2008-10-06 13:54:35 +00:00
|
|
|
|
begin
|
2010-02-08 17:38:24 +00:00
|
|
|
|
if (AValueNameList[iCols] <> CAMPO_POSICION) then
|
|
|
|
|
|
if _BuscarColumna(AView, AValueNameList[iCols], AValueTypeList[iCols], AIndex) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
if AIndex <> -1 then
|
|
|
|
|
|
ADataTable.DataTable.FieldByName(AView.DataController.GetItemField(AIndex).FieldName).Value := AValue;
|
|
|
|
|
|
end;
|
2008-10-06 13:54:35 +00:00
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
finally
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Post;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
AView.DataController.EndUpdate;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(AReader);
|
|
|
|
|
|
FreeANDNIL(AValueNameList);
|
|
|
|
|
|
FreeANDNIL(AValueTypeList);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase := Nil;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
|
|
|
|
{$REGION 'SaveGridRowsToStream'}
|
|
|
|
|
|
procedure SaveGridRowsToStream(AView : TcxGridDBTableView; AStream: TStream;
|
|
|
|
|
|
const ACaption : String; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
var
|
|
|
|
|
|
AWriter: TcxWriter;
|
|
|
|
|
|
i, j : integer;
|
|
|
|
|
|
AName, AValueType : String;
|
|
|
|
|
|
|
|
|
|
|
|
procedure _CopyForEachRowProc(ARowIndex: Integer; ARowInfo: TcxRowInfo);
|
|
|
|
|
|
var
|
|
|
|
|
|
iCols: Integer;
|
|
|
|
|
|
begin
|
|
|
|
|
|
for iCols := 0 to AView.ItemCount - 1 do
|
|
|
|
|
|
AWriter.WriteVariant(AView.DataController.GetRowValue(ARowInfo, iCols));
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AView) then
|
|
|
|
|
|
raise Exception.Create('Vista no asignada (SaveGridViewToStream)');
|
|
|
|
|
|
|
|
|
|
|
|
if not Assigned(AStream) then
|
|
|
|
|
|
raise Exception.Create('Stream no asignado (SaveGridViewToStream)');
|
|
|
|
|
|
|
|
|
|
|
|
if EsCadenaVacia(ACaption) then
|
|
|
|
|
|
raise Exception.Create('Etiqueta no asignada (SaveGridViewToStream)');
|
|
|
|
|
|
|
|
|
|
|
|
AWriter := TcxWriter.Create(AStream);
|
|
|
|
|
|
try
|
2009-03-05 12:18:48 +00:00
|
|
|
|
AWriter.WriteAnsiString(ACaption);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
AWriter.WriteInteger(AView.ItemCount);
|
|
|
|
|
|
for i := 0 to AView.ItemCount - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
AName := '';
|
|
|
|
|
|
AValueType := '';
|
|
|
|
|
|
|
|
|
|
|
|
if AView.Items[i].DataBinding is TcxGridItemDBDataBinding then
|
|
|
|
|
|
AName := (AView.Items[i].DataBinding as TcxGridItemDBDataBinding).FieldName;
|
|
|
|
|
|
|
|
|
|
|
|
if EsCadenaVacia(AName) then
|
|
|
|
|
|
AName := AView.Items[i].Caption;
|
|
|
|
|
|
|
|
|
|
|
|
AValueType := AView.Items[i].DataBinding.ValueType;
|
|
|
|
|
|
|
2009-03-05 12:18:48 +00:00
|
|
|
|
AWriter.WriteAnsiString(AName);
|
|
|
|
|
|
AWriter.WriteAnsiString(AValueType);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
with AView.DataController do
|
|
|
|
|
|
begin
|
|
|
|
|
|
if ASoloSeleccion then
|
|
|
|
|
|
begin
|
|
|
|
|
|
AWriter.WriteInteger(GetSelectedCount);
|
|
|
|
|
|
for I := 0 to GetSelectedCount - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
J := GetSelectedRowIndex(I);
|
|
|
|
|
|
_CopyForEachRowProc(J, GetRowInfo(J));
|
|
|
|
|
|
end;
|
|
|
|
|
|
end
|
|
|
|
|
|
else begin
|
|
|
|
|
|
AWriter.WriteInteger(GetRowCount);
|
|
|
|
|
|
for I := 0 to GetRowCount - 1 do
|
|
|
|
|
|
_CopyForEachRowProc(I, GetRowInfo(I));
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(AWriter);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
{$ENDREGION}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function HTMLToClipFmt(const AHTML: string): string;
|
|
|
|
|
|
const
|
|
|
|
|
|
CR = #13#10;
|
|
|
|
|
|
DescriptionSize = 105;
|
|
|
|
|
|
HeaderSize = 47;
|
|
|
|
|
|
FooterSize1 = 58;
|
|
|
|
|
|
FooterSize2 = 24;
|
|
|
|
|
|
|
|
|
|
|
|
function GetHeader: string;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := 'Version:0.9' + CR;
|
|
|
|
|
|
Result := Result + Format('StartHTML:%.10d', [DescriptionSize]) + CR;
|
|
|
|
|
|
Result := Result + Format('EndHTML:%.10d', [DescriptionSize + HeaderSize + Length(AHTML) + FooterSize1]) + CR;
|
|
|
|
|
|
Result := Result + Format('StartFragment:%.10d', [DescriptionSize + HeaderSize]) + CR;
|
|
|
|
|
|
Result := Result + Format('EndFragment:%.10d', [DescriptionSize + HeaderSize + Length(AHTML) + FooterSize2]) + CR;
|
|
|
|
|
|
Result := Result + '<html>' + CR + '<head></head>' + '<body>' + '<!--StartFragment-->' + '<code><pre>';
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function GetFooter: string;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := '</pre></code><!--EndFragment-->';
|
|
|
|
|
|
Result := Result + '</body>' + CR + '</html>'
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := GetHeader + AHTML + GetFooter;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function FormatHTMLClipboardHeader(HTMLText: string): string;
|
|
|
|
|
|
{http://www.swissdelphicenter.ch/torry/showcode.php?id=1391}
|
|
|
|
|
|
const
|
|
|
|
|
|
CrLf = #13#10;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := 'Version:0.9' + CrLf;
|
|
|
|
|
|
Result := Result + 'StartHTML:-1' + CrLf;
|
|
|
|
|
|
Result := Result + 'EndHTML:-1' + CrLf;
|
|
|
|
|
|
Result := Result + 'StartFragment:000081' + CrLf;
|
|
|
|
|
|
Result := Result + 'EndFragment:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>' + CrLf;
|
|
|
|
|
|
Result := Result + HTMLText + CrLf;
|
|
|
|
|
|
Result := StringReplace(Result, '<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>', Format('%.6d', [Length(Result)]), []);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesHTML (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
const
|
|
|
|
|
|
CR = #13#10;
|
|
|
|
|
|
DescriptionSize = 105;
|
|
|
|
|
|
HeaderSize = 47;
|
|
|
|
|
|
FooterSize1 = 58;
|
|
|
|
|
|
FooterSize2 = 24;
|
|
|
|
|
|
|
|
|
|
|
|
function GetHeader(const AHTML: string): string;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := 'Version:0.9' + CR;
|
|
|
|
|
|
Result := Result + Format('StartHTML:%.10d', [DescriptionSize]) + CR;
|
|
|
|
|
|
Result := Result + Format('EndHTML:%.10d', [DescriptionSize + HeaderSize + Length(AHTML) + FooterSize1]) + CR;
|
|
|
|
|
|
Result := Result + Format('StartFragment:%.10d', [DescriptionSize + HeaderSize]) + CR;
|
|
|
|
|
|
Result := Result + Format('EndFragment:%.10d', [DescriptionSize + HeaderSize + Length(AHTML) + FooterSize2]) + CR;
|
|
|
|
|
|
Result := Result + '<html>' + CR + '<head></head>' + '<body>' + '<!--StartFragment-->' + '<code><pre>';
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function GetFooter: string;
|
|
|
|
|
|
begin
|
|
|
|
|
|
Result := '</pre></code><!--EndFragment-->';
|
|
|
|
|
|
Result := Result + '</body>' + CR + '</html>'
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
var
|
|
|
|
|
|
AFicheroTMP : String;
|
|
|
|
|
|
AStringList : TStringList;
|
|
|
|
|
|
HTMLText : String;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Vista no asignada (CopiarSeleccionGridAlPortapapelesTXT)');
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
RegistrarFormatos;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
AFicheroTMP := DarFicheroHTMLTemporal;
|
|
|
|
|
|
ExportGridToHTML(AFicheroTMP, AGrid, True, not ASoloSeleccion);
|
|
|
|
|
|
|
|
|
|
|
|
if FileExists(AFicheroTMP) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
AStringList := TStringList.Create;
|
|
|
|
|
|
try
|
|
|
|
|
|
AStringList.LoadFromFile(AFicheroTMP);
|
|
|
|
|
|
HTMLText := AStringList.Text;
|
|
|
|
|
|
AStringList.Insert(0, GetHeader(HTMLText));
|
|
|
|
|
|
AStringList.Add(GetFooter);
|
|
|
|
|
|
CopyStringsToClipboard(CF_HTML, AStringList);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(AStringList);
|
|
|
|
|
|
DeleteFile(AFicheroTMP)
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesRTF (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
var
|
|
|
|
|
|
ARTFConv : TCtrlToRTF;
|
|
|
|
|
|
AStringList : TStringList;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Grid no asignado (CopiarSeleccionGridAlPortapapelesTXT)');
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
RegistrarFormatos;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
ARTFConv := TCtrlToRTF.Create(NIL);
|
|
|
|
|
|
try
|
|
|
|
|
|
ARTFConv.cxGridViewToRTF(TcxGridTableView(AGrid.ActiveView));
|
|
|
|
|
|
|
|
|
|
|
|
AStringList := TStringList.Create;
|
|
|
|
|
|
try
|
|
|
|
|
|
AStringList.Add(ARTFConv.RTFText);
|
|
|
|
|
|
CopyStringsToClipboard(CF_RTF, AStringList);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(AStringList);
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(ARTFConv);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesTXT (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
{var
|
|
|
|
|
|
iFilas, iCols : Integer;}
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Grid no asignado (CopiarSeleccionGridAlPortapapelesTXT)');
|
|
|
|
|
|
|
|
|
|
|
|
TcxGridTableView(AGrid.ActiveView).CopyToClipboard(not ASoloSeleccion);
|
|
|
|
|
|
|
|
|
|
|
|
{ for iFilas := 0 to AGrid.ActiveView.Controller.SelectedRowCount-1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
for iCols := 0 to cxGridView.VisibleColumnCount-1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
|
StreamWriteStr(RTF, cxGridView.DataController.DisplayTexts[cxGridView.Controller.SelectedRows[i].RecordIndex, cxGridView.VisibleColumns[j].Index] +'\cell ');
|
|
|
|
|
|
}
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopiarGridAlPortapapelesExcel (AGrid : TcxGrid; const ASoloSeleccion : Boolean = false);
|
|
|
|
|
|
var
|
|
|
|
|
|
AFicheroTMP : String;
|
|
|
|
|
|
AStream : TFileStream;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Vista no asignada (CopiarSeleccionGridAlPortapapelesTXT)');
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
RegistrarFormatos;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
AFicheroTMP := DarFicheroExcelTemporal;
|
|
|
|
|
|
ExportGridToExcel(AFicheroTMP, AGrid, True, not ASoloSeleccion);
|
|
|
|
|
|
|
|
|
|
|
|
if FileExists(AFicheroTMP) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
AStream := TFileStream.Create(AFicheroTMP, fmOpenRead);
|
|
|
|
|
|
try
|
|
|
|
|
|
CopyStreamToClipboard(CF_HTML, AStream);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(AStream);
|
|
|
|
|
|
DeleteFile(AFicheroTMP)
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure CopiarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
|
|
|
|
|
|
var
|
|
|
|
|
|
AMemStream : TMemoryStream;
|
|
|
|
|
|
AGridStatus : TcxGridStatus;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Grid no asignado (CopiarSeleccionGridAlPortapapelesTXT)');
|
|
|
|
|
|
|
2009-06-02 10:52:07 +00:00
|
|
|
|
ShowHourglassCursor;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
try
|
2009-06-02 10:52:07 +00:00
|
|
|
|
RegistrarFormatos;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
2009-06-02 10:52:07 +00:00
|
|
|
|
AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
Clipboard.Open;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
try
|
2010-02-08 18:38:14 +00:00
|
|
|
|
CopiarGridAlPortapapelesTXT(AGrid, True);
|
|
|
|
|
|
CopiarGridAlPortapapelesRTF(AGrid, True);
|
|
|
|
|
|
CopiarGridAlPortapapelesHTML(AGrid, True);
|
2009-06-02 10:52:07 +00:00
|
|
|
|
|
|
|
|
|
|
AMemStream := TMemoryStream.Create;
|
|
|
|
|
|
try
|
|
|
|
|
|
SaveGridRowsToStream(TcxGridDBTableView(AGrid.ActiveView), AMemStream, AGrid.ActiveView.Name, True);
|
|
|
|
|
|
CopyStreamToClipboard(CF_FACTUGES, AMemStream);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeAndNil(AMemStream);
|
|
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
finally
|
2009-06-02 10:52:07 +00:00
|
|
|
|
Clipboard.Close;
|
|
|
|
|
|
AGridStatus.Restore(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
FreeAndNil(AGridStatus);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
finally
|
2009-06-02 10:52:07 +00:00
|
|
|
|
HideHourglassCursor;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure CortarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
var
|
|
|
|
|
|
//Se adapta para que se utilicen las mismas funciones que en el controllerbase
|
|
|
|
|
|
AControllerDetallesBase: IControllerDetallesBase;
|
|
|
|
|
|
ADataTable : TDADataTable;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
begin
|
2010-02-08 17:38:24 +00:00
|
|
|
|
if Assigned(AGrid) then
|
|
|
|
|
|
ADataTable := ((AGrid.ActiveView as TcxGridDBTableView).DataController.DataSource as TDADataSource).DataTable;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase := TControllerDetallesBase.Create;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
CopiarSeleccionGridAlPortapapeles(AGrid);
|
|
|
|
|
|
AGrid.ActiveView.DataController.DeleteSelection;
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase.Renumerar(ADataTable, ADataTable.FieldByName(CAMPO_POSICION).AsInteger);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
finally
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase := Nil;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
HideHourglassCursor;
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure PegarSeleccionGridDesdePortapapeles (AGrid : TcxGrid);
|
|
|
|
|
|
var
|
|
|
|
|
|
AMemStream : TMemoryStream;
|
|
|
|
|
|
ACaption : String;
|
|
|
|
|
|
AGridStatus : TcxGridStatus;
|
|
|
|
|
|
begin
|
|
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Grid no asignado (PegarSeleccionGridDesdePortapapeles)');
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
RegistrarFormatos;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
|
|
|
|
|
|
if not Clipboard.HasFormat(CF_FACTUGES) then
|
|
|
|
|
|
raise Exception.Create('No hay nada en el portapapeles');
|
|
|
|
|
|
|
|
|
|
|
|
AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
Clipboard.Open;
|
|
|
|
|
|
try
|
|
|
|
|
|
AMemStream := TMemoryStream.Create;
|
|
|
|
|
|
try
|
|
|
|
|
|
CopyStreamFromClipboard(CF_FACTUGES, AMemStream);
|
|
|
|
|
|
LoadGridRowsFromStream(TcxGridDBTableView(AGrid.ActiveView), AMemStream, ACaption);
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeAndNil(AMemStream);
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
Clipboard.Close;
|
|
|
|
|
|
AGridStatus.Restore(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
FreeAndNil(AGridStatus);
|
|
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
|
|
|
|
|
|
procedure PegarTextoDesdePortapapeles (AGrid : TcxGrid);
|
2008-05-30 16:56:23 +00:00
|
|
|
|
var
|
2008-09-30 12:12:40 +00:00
|
|
|
|
AGridStatus : TcxGridStatus;
|
|
|
|
|
|
ATextList : TStringList;
|
|
|
|
|
|
|
|
|
|
|
|
ARecordID : Integer;
|
|
|
|
|
|
ARecordIndex : Integer;
|
|
|
|
|
|
bEstabaVacia : Boolean;
|
|
|
|
|
|
AView : TcxGridDBTableView;
|
|
|
|
|
|
|
|
|
|
|
|
iContador : Integer;
|
2010-02-08 17:38:24 +00:00
|
|
|
|
|
|
|
|
|
|
//Se adapta para que se utilicen las mismas funciones que en el controllerbase
|
|
|
|
|
|
AControllerDetallesBase: IControllerDetallesBase;
|
|
|
|
|
|
ADataTable: IDAStronglyTypedDataTable;
|
|
|
|
|
|
|
2008-05-30 16:56:23 +00:00
|
|
|
|
begin
|
2010-02-08 17:38:24 +00:00
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
if not Assigned(AGrid) then
|
|
|
|
|
|
raise Exception.Create('Grid no asignado (PegarTextoDesdePortapapeles)');
|
|
|
|
|
|
|
2010-02-08 17:38:24 +00:00
|
|
|
|
if not Supports(((AGrid.ActiveView as TcxGridDBTableView).DataController.DataSource as TDADataSource).DataTable, IDAStronglyTypedDataTable, ADataTable) then
|
|
|
|
|
|
raise Exception.Create('DataTable asignado no soporta IDAStronglyTypedDataTable)');
|
|
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
RegistrarFormatos;
|
|
|
|
|
|
|
|
|
|
|
|
if not Clipboard.HasFormat(CF_TEXT) then
|
|
|
|
|
|
raise Exception.Create('No hay nada en el portapapeles');
|
|
|
|
|
|
|
|
|
|
|
|
AView := TcxGridDBTableView(AGrid.ActiveView);
|
|
|
|
|
|
|
|
|
|
|
|
AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
Clipboard.Open;
|
|
|
|
|
|
try
|
|
|
|
|
|
ATextList := TStringList.Create;
|
|
|
|
|
|
try
|
|
|
|
|
|
CopyStringsFromClipboard(CF_TEXT, ATextList);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase := TControllerDetallesBase.Create;
|
|
|
|
|
|
bEstabaVacia := ADataTable.IsEmpty;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
AView.DataController.BeginUpdate;
|
|
|
|
|
|
try
|
|
|
|
|
|
// Localizar el punto donde se empieza a insertar
|
|
|
|
|
|
if not bEstabaVacia then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ARecordIndex := AView.DataController.FocusedRecordIndex;
|
|
|
|
|
|
if ARecordIndex >= 0 then
|
|
|
|
|
|
begin
|
|
|
|
|
|
ARecordID := AView.DataController.GetRecordId(ARecordIndex);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Locate(AView.DataController.KeyFieldNames, ARecordID, []);
|
2008-09-30 12:12:40 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
for iContador := 0 to ATextList.Count - 1 do
|
|
|
|
|
|
begin
|
|
|
|
|
|
// Insertar una tupla de la forma adecuada
|
|
|
|
|
|
if bEstabaVacia then
|
2010-02-08 17:38:24 +00:00
|
|
|
|
begin
|
|
|
|
|
|
AControllerDetallesBase.Add(ADataTable,TIPO_DETALLE_CONCEPTO);
|
|
|
|
|
|
ADataTable.Edit;
|
|
|
|
|
|
end
|
2008-09-30 12:12:40 +00:00
|
|
|
|
else begin
|
2008-10-06 13:54:35 +00:00
|
|
|
|
if iContador = 0 then
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Edit
|
2008-10-06 13:54:35 +00:00
|
|
|
|
else begin
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase.Add(ADataTable,TIPO_DETALLE_CONCEPTO);
|
|
|
|
|
|
ADataTable.Edit;
|
2008-10-06 13:54:35 +00:00
|
|
|
|
end;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
try
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Edit;
|
|
|
|
|
|
ADataTable.DataTable.FieldByName('CONCEPTO').AsString := ATextList[iContador];
|
2008-09-30 12:12:40 +00:00
|
|
|
|
finally
|
2010-02-08 17:38:24 +00:00
|
|
|
|
ADataTable.Post;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
2008-10-08 11:20:38 +00:00
|
|
|
|
|
2008-09-30 12:12:40 +00:00
|
|
|
|
finally
|
|
|
|
|
|
AView.DataController.EndUpdate;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
FreeANDNIL(ATextList);
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
Clipboard.Close;
|
|
|
|
|
|
AGridStatus.Restore(TcxGridDBTableView(AGrid.ActiveView));
|
|
|
|
|
|
FreeAndNil(AGridStatus);
|
2010-02-08 17:38:24 +00:00
|
|
|
|
AControllerDetallesBase := Nil;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
end;
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function HayDatosEnPortapapeles(AFormat: Cardinal): Boolean;
|
|
|
|
|
|
begin
|
|
|
|
|
|
RegistrarFormatos;
|
|
|
|
|
|
|
|
|
|
|
|
if AFormat = 0 then
|
|
|
|
|
|
Result := Clipboard.HasFormat(CF_FACTUGES) or Clipboard.HasFormat(CF_TEXT)
|
|
|
|
|
|
else
|
|
|
|
|
|
Result := Clipboard.HasFormat(AFormat);
|
|
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
procedure PegarAlGridDesdePortapapeles (AGrid : TcxGrid);
|
|
|
|
|
|
begin
|
|
|
|
|
|
{ Aqui se determina qu<EFBFBD> hacer. Si en el portapapeles hay datos en formato...
|
|
|
|
|
|
1. CF_FACTUGES -> pegar conceptos
|
|
|
|
|
|
2. CF_TEXT -> tratar y pegar texto plano
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2009-06-02 10:52:07 +00:00
|
|
|
|
ShowHourglassCursor;
|
|
|
|
|
|
try
|
|
|
|
|
|
RegistrarFormatos;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
|
2009-06-02 10:52:07 +00:00
|
|
|
|
if Clipboard.HasFormat(CF_FACTUGES) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
PegarSeleccionGridDesdePortapapeles(AGrid);
|
|
|
|
|
|
Exit;
|
|
|
|
|
|
end;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
|
2009-06-02 10:52:07 +00:00
|
|
|
|
if Clipboard.HasFormat(CF_TEXT) then
|
|
|
|
|
|
begin
|
|
|
|
|
|
PegarTextoDesdePortapapeles(AGrid);
|
|
|
|
|
|
Exit;
|
|
|
|
|
|
end;
|
|
|
|
|
|
finally
|
|
|
|
|
|
HideHourglassCursor;
|
2008-09-30 12:12:40 +00:00
|
|
|
|
end;
|
2008-05-30 16:56:23 +00:00
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
end.
|