';
+ end;
+
+ function GetFooter: string;
+ begin
+ Result := '
';
+ Result := Result + '' + CR + ''
+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:°°°°°°' + CrLf;
+ Result := Result + HTMLText + CrLf;
+ Result := StringReplace(Result, '°°°°°°', 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 + '' + CR + '' + '' + '' + '';
+ end;
+
+ function GetFooter: string;
+ begin
+ Result := '
';
+ Result := Result + '' + CR + ''
+ end;
+
+var
+ AFicheroTMP : String;
+ AStringList : TStringList;
+ HTMLText : String;
+ CF_HTML : Cardinal;
+begin
+ if not Assigned(AGrid) then
+ raise Exception.Create('Vista no asignada (CopiarSeleccionGridAlPortapapelesTXT)');
+
+ 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);
+
+ CF_HTML := RegisterClipboardFormat ('HTML Format');
+ if CF_HTML = 0 then
+ raise Exception.Create('Error al registrar formato CF_HTML (CopiarSeleccionGridAlPortapapelesHTML)');
+
+ 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;
+ CF_RTF : Cardinal;
+begin
+ if not Assigned(AGrid) then
+ raise Exception.Create('Grid no asignado (CopiarSeleccionGridAlPortapapelesTXT)');
+
+ ARTFConv := TCtrlToRTF.Create(NIL);
+ try
+ ARTFConv.cxGridViewToRTF(TcxGridTableView(AGrid.ActiveView));
+
+ CF_RTF := RegisterClipboardFormat('Rich Text Format');
+ if CF_RTF = 0 then
+ raise Exception.Create('Error al registrar formato CF_RTF (CopiarSeleccionGridAlPortapapelesRTF)');
+
+ 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;
+ CF_HTML : Cardinal;
+begin
+ if not Assigned(AGrid) then
+ raise Exception.Create('Vista no asignada (CopiarSeleccionGridAlPortapapelesTXT)');
+
+ AFicheroTMP := DarFicheroExcelTemporal;
+ ExportGridToExcel(AFicheroTMP, AGrid, True, not ASoloSeleccion);
+
+ if FileExists(AFicheroTMP) then
+ begin
+ AStream := TFileStream.Create(AFicheroTMP, fmOpenRead);
+ try
+ CF_HTML := RegisterClipboardFormat ('HTML Format');
+ if CF_HTML = 0 then
+ raise Exception.Create('Error al registrar formato CF_HTML (CopiarSeleccionGridAlPortapapelesHTML)');
+
+ CopyStreamToClipboard(CF_HTML, AStream);
+ finally
+ FreeANDNIL(AStream);
+ DeleteFile(AFicheroTMP)
+ end;
+ end;
+end;
+
+
+procedure CopiarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
+var
+ AMemStream : TMemoryStream;
+ CF_FACTUGES : Cardinal;
+ AGridStatus : TcxGridStatus;
+begin
+ if not Assigned(AGrid) then
+ raise Exception.Create('Grid no asignado (CopiarSeleccionGridAlPortapapelesTXT)');
+
+ AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView));
+ Clipboard.Open;
+ try
+ CopiarGridAlPortapapelesTXT(AGrid);
+ CopiarGridAlPortapapelesRTF(AGrid);
+ CopiarGridAlPortapapelesHTML(AGrid);
+
+ AMemStream := TMemoryStream.Create;
+ try
+ SaveGridRowsToStream(TcxGridDBTableView(AGrid.ActiveView), AMemStream, AGrid.ActiveView.Name, True);
+ CF_FACTUGES := RegisterClipboardFormat ('FactuGES Format');
+ if CF_FACTUGES = 0 then
+ raise Exception.Create('Error al registrar formato CF_HTML (CopiarSeleccionGridAlPortapapelesHTML)');
+ CopyStreamToClipboard(CF_FACTUGES, AMemStream);
+ finally
+ FreeAndNil(AMemStream);
+ end;
+ finally
+ Clipboard.Close;
+ AGridStatus.Restore(TcxGridDBTableView(AGrid.ActiveView));
+ FreeAndNil(AGridStatus);
+ end;
+end;
+
+
+procedure CortarSeleccionGridAlPortapapeles (AGrid : TcxGrid);
+begin
+ ShowHourglassCursor;
+ try
+ CopiarSeleccionGridAlPortapapeles(AGrid);
+ AGrid.ActiveView.DataController.DeleteSelection;
+ RenumerarCampoPosicion(TcxGridDBTableView(AGrid.ActiveView).DataController.DataSet);
+ finally
+ HideHourglassCursor;
+ end;
+end;
+
+
+procedure PegarSeleccionGridDesdePortapapeles (AGrid : TcxGrid);
+var
+ AMemStream : TMemoryStream;
+ CF_FACTUGES : Cardinal;
+ ACaption : String;
+ AGridStatus : TcxGridStatus;
+begin
+ if not Assigned(AGrid) then
+ raise Exception.Create('Grid no asignado (PegarSeleccionGridDesdePortapapeles)');
+
+ CF_FACTUGES := RegisterClipboardFormat ('FactuGES Format');
+ if CF_FACTUGES = 0 then
+ raise Exception.Create('Error al registrar formato CF_FACTUGES (PegarSeleccionGridDesdePortapapeles)');
+
+ 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;
+
+function HayDatosEnPortapapeles: Boolean;
+var
+ CF_FACTUGES : Cardinal;
+begin
+ CF_FACTUGES := RegisterClipboardFormat ('FactuGES Format');
+ if CF_FACTUGES = 0 then
+ raise Exception.Create('Error al registrar formato CF_FACTUGES (HayDatosEnPortapapeles)');
+
+ Result := Clipboard.HasFormat(CF_FACTUGES);
+end;
+
+end.
diff --git a/Source/Base/Utiles/uGridUtils.pas b/Source/Base/Utiles/uGridStatusUtils.pas
similarity index 92%
rename from Source/Base/Utiles/uGridUtils.pas
rename to Source/Base/Utiles/uGridStatusUtils.pas
index abcffa37..1eecac80 100644
--- a/Source/Base/Utiles/uGridUtils.pas
+++ b/Source/Base/Utiles/uGridStatusUtils.pas
@@ -1,4 +1,4 @@
-unit uGridUtils;
+unit uGridStatusUtils;
interface
@@ -56,11 +56,11 @@ procedure SeleccionarFilasDesdeGrid(const AView : TcxGridDBTableView;
implementation
-
uses
uDADataTable, uDAInterfaces, cxVariants;
+{$REGION 'TRecordInfos'}
procedure TRecordInfos.Notify(Ptr: Pointer; Action: TListNotification);
begin
if Action in [lnExtracted, lnDeleted] then
@@ -188,12 +188,15 @@ procedure TcxGridStatus.LoadGridViewTopFocusedRecords(AView: TcxGridDBTableView)
var
ARecord: TcxCustomGridRecord;
begin
- ARecord := FindRecordEx(AView, AFocusedRow);
- if Assigned(ARecord) then
- ARecord.Focused := True;
- ARecord := FindRecordEx(AView, TopRow);
- if Assigned(ARecord) then
- AView.Controller.TopRowIndex := ARecord.Index;
+ if Assigned(AFocusedRow) then
+ begin
+ ARecord := FindRecordEx(AView, AFocusedRow);
+ if Assigned(ARecord) then
+ ARecord.Focused := True;
+ ARecord := FindRecordEx(AView, TopRow);
+ if Assigned(ARecord) then
+ AView.Controller.TopRowIndex := ARecord.Index;
+ end;
end;
type
@@ -289,9 +292,10 @@ begin
finally
AView.EndUpdate;
AGridStatus.Restore(AView);
+ FreeANDNIL(AGridStatus);
HideHourglassCursor;
end;
end;
-
+{$ENDREGION}
end.
diff --git a/Source/Base/Utiles/uIntegerListUtils.pas b/Source/Base/Utiles/uIntegerListUtils.pas
index 62994ac7..b5caef0a 100644
--- a/Source/Base/Utiles/uIntegerListUtils.pas
+++ b/Source/Base/Utiles/uIntegerListUtils.pas
@@ -20,7 +20,7 @@ implementation
function TIntegerList.GetInteger(Index: integer): integer;
begin
- result := Integer(Items[index]);
+ Result := Integer(Items[index]);
end;
procedure TIntegerList.SetInteger(Index: integer; Value: integer);
diff --git a/Source/Base/Utiles/uRTFUtils.pas b/Source/Base/Utiles/uRTFUtils.pas
new file mode 100644
index 00000000..cecd2584
--- /dev/null
+++ b/Source/Base/Utiles/uRTFUtils.pas
@@ -0,0 +1,203 @@
+unit uRTFUtils;
+
+interface
+
+function RtfToText(ARTFText: String): String;
+
+implementation
+
+uses
+ Forms, Classes, SysUtils, StdCtrls, ComCtrls;
+
+
+{
+ Convert RTF enabled text to plain.
+ http://www.delphipraxis.net/topic45179.html
+}
+
+// HAY QUE LIMPIAR LA CADENA DE ENTRADA DE SALTOS DE LÍNEA (#$D#$A) POR QUE
+// SI NO, NO ES UNA CADENA CON TEXTO RTF VÁLIDO
+
+function RtfToText(ARTFText: String): String;
+const
+ SaltoLinea = #13#10; //--> #$D#$A
+var
+ aSource: string; // <- Para almacenar la cadena de entrada sin saltos de línea
+ Source: string;
+ NChar: Integer;
+
+ function ProcessGroupRecursevly: string;
+
+ function HexToInt(HexStr: String): Integer;
+ begin
+ result := StrToInt('$' + HexStr);
+ end;
+
+ procedure SkipStar;
+ var
+ BracesOpened: Integer;
+ Escaped: Boolean;
+ begin
+ BracesOpened:=1;
+ Escaped:=false;
+ while BracesOpened>0
+ do begin
+ Inc (NChar);
+ case Source [NChar] of
+ '{': if Escaped
+ then Escaped:=false
+ else Inc (BracesOpened);
+ '}': if Escaped
+ then Escaped:=false
+ else Dec (BracesOpened);
+ '\': Escaped:=not Escaped;
+ else Escaped:=false;
+ end;
+ end;
+ end;
+
+ function UnicodeCharCode2ANSIChar (aCode: LongInt): Char;
+ type
+ TUnicode2ANSITable=array [$0410..$044f] of Char;
+ const
+ Unicode2ANSITable: TUnicode2AnsiTable=('À', 'Á', 'Â', 'Ã', 'Ä', 'Å', 'Æ', 'Ç', 'È', 'É', 'Ê', 'Ë', 'Ì', 'Í', 'Î', 'Ï', 'Ð', 'Ñ', 'Ò', 'Ó', 'Ô', 'Õ', 'Ö', '×', 'Ø', 'Ù', 'Ú', 'Û', 'Ü', 'Ý', 'Þ', 'ß',
+ 'à', 'á', 'â', 'ã', 'ä', 'å', 'æ', 'ç', 'è', 'é', 'ê', 'ë', 'ì', 'í', 'î', 'ï', 'ð', 'ñ', 'ò', 'ó', 'ô', 'õ', 'ö', '÷', 'ø', 'ù', 'ú', 'û', 'ü', 'ý', 'þ', 'ÿ');
+ begin
+ if (Low (Unicode2ANSITable)<=aCode) and (aCode<=High (Unicode2ANSITable)) then
+ UnicodeCharCode2ANSIChar:=Unicode2ANSITable [aCode]
+ else UnicodeCharCode2ANSIChar:='?';
+ end;
+
+ var
+ Control, NumericValue, TextValue: string;
+ begin
+ Result:='';
+ Inc (NChar);
+ while NChar<=Length (Source)
+ do case Source [NChar] of
+ '{': Result:=Result+ProcessGroupRecursevly;
+ '}': begin
+ Inc (NChar);
+ Break;
+ end;
+ '\': begin
+ Inc (NChar);
+ case Source [NChar] of
+ '''': begin
+ Result:=Result+Chr (HexToInt (Copy (Source, NChar+1, 2)));
+ Inc (NChar, 3);
+ end;
+ '~': Result:=Result+#$20;
+ '*': SkipStar;
+ 'a'..'z': begin
+ Control:='';
+ while Source [NChar] in ['a'..'z']
+ do begin
+ Control:=Control+Source [NChar];
+ Inc (NChar);
+ end;
+ if Source [NChar]='-'
+ then begin
+ NumericValue:=Source [NChar];
+ Inc (NChar);
+ end
+ else NumericValue:='';
+ while Source [NChar] in ['0'..'9']
+ do begin
+ NumericValue:=NumericValue+Source [NChar];
+ Inc (NChar);
+ end;
+ if Source [NChar]='{'
+ then ProcessGroupRecursevly;
+ TextValue:='';
+ if not (Source [NChar] in ['a'..'z', '{', '}', '\'])
+ then begin
+ Inc (NChar);
+ while not (Source [NChar] in ['{', '}', '\'])
+ do begin
+ TextValue:=TextValue+Source [NChar];
+ Inc (NChar);
+ end;
+ end;
+ if (Control='line') or (Control='par')
+ then Result:=Result+#$0D#$0A
+ else if Control='tab'
+ then Result:=Result+#$09
+ else if Control='u'
+ then Result:=Result+UnicodeCharCode2ANSIChar (StrToInt (NumericValue))
+ else if Control='colortbl'
+ then TextValue:='';
+ if Length (TextValue)>0
+ then if (not ((TextValue [Length (TextValue)]=';') and (Source [NChar]='}')))
+ then begin
+ Result:=Result+TextValue;
+ TextValue:='';
+ end;
+ end;
+ else begin
+ Result:=Result+Source [NChar];
+ Inc (NChar);
+ end;
+ end;
+ end;
+ else begin
+ Result:=Result+Source [NChar];
+ Inc (NChar);
+ end;
+ end;
+ end;
+
+ function InitSource: Boolean;
+ var
+ BracesCount: Integer;
+ Escaped: Boolean;
+ begin
+ if Copy (aSource, 1, 5) <> '{\rtf' then
+ InitSource:=false
+ else begin
+ Source:='';
+ BracesCount:=0;
+ Escaped:=false;
+ NChar:=1;
+ while (NChar<=Length (aSource)) and (BracesCount>=0)
+ do begin
+ if not (aSource [NChar] in [#$0D, #$0A])
+ then begin
+ Source:=Source+aSource [NChar];
+ case aSource [NChar] of
+ '{': if not Escaped
+ then Inc (BracesCount)
+ else Escaped:=false;
+ '}': if not Escaped
+ then Dec (BracesCount)
+ else Escaped:=false;
+ '\': Escaped:=true;
+ else Escaped:=false;
+ end;
+ end;
+ Inc (NChar);
+ end;
+ InitSource:=BracesCount=0;
+ end;
+ end;
+
+begin
+ // Hay que quitar el salto de línea al final de la aSource RTF
+ aSource := StringReplace(ARTFText, SaltoLinea, '', [rfReplaceAll]);
+
+ // o bien:
+ //
+ //aSource := Copy( cLinea, 1, length(cLinea)-2) );
+
+ if InitSource then
+ begin
+ NChar:=1;
+ Result:= PChar(ProcessGroupRecursevly);
+ end
+ else
+ Result := PChar(aSource);
+end;
+
+end.
+
+
diff --git a/Source/Base/Utiles/uSistemaFunc.pas b/Source/Base/Utiles/uSistemaFunc.pas
index fcce8117..a5749625 100644
--- a/Source/Base/Utiles/uSistemaFunc.pas
+++ b/Source/Base/Utiles/uSistemaFunc.pas
@@ -33,6 +33,8 @@ function DarFicheroTemporal : String;
function DarFicheroJPGTemporal : String;
function DarFicheroBMPTemporal : String;
function DarFicheroTIFFTemporal : String;
+function DarFicheroHTMLTemporal : String;
+function DarFicheroExcelTemporal : String;
function DarFicheroWordExportar (var Fichero : String) : Boolean;
function DarVersionFichero (Executable : String) : String;
function DarFechaFichero (Executable : String) : String;
@@ -145,6 +147,22 @@ begin
Result := Copy(Cadena, 0, (Length(Cadena)-3)) + 'bmp';
end;
+function DarFicheroExcelTemporal : String;
+var
+ Cadena : String;
+begin
+ Cadena := DarFicheroTemporal;
+ Result := Copy(Cadena, 0, (Length(Cadena)-3)) + 'xls';
+end;
+
+function DarFicheroHTMLTemporal : String;
+var
+ Cadena : String;
+begin
+ Cadena := DarFicheroTemporal;
+ Result := Copy(Cadena, 0, (Length(Cadena)-3)) + 'html';
+end;
+
function DarFicheroJPGTemporal : String;
var
Cadena : String;
diff --git a/Source/Cliente/FactuGES.dproj b/Source/Cliente/FactuGES.dproj
index 2d4ad558..ad5bddc4 100644
--- a/Source/Cliente/FactuGES.dproj
+++ b/Source/Cliente/FactuGES.dproj
@@ -75,42 +75,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-