Arreglado un fallo de renumerar la posición al copiar y pegar texto desde el portapapeles (2º intento)

git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES2/trunk@668 0c75b7a4-871f-7646-8a2f-f78d34cc349f
This commit is contained in:
David Arranz 2008-10-08 11:20:38 +00:00
parent 676a4e1439
commit a05aa3f5b8

View File

@ -29,6 +29,15 @@ uses
cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView, cxClasses, cxControls, cxGridCustomView, cxGridCustomTableView,
cxGridTableView, cxGridDBTableView, cxGridDBDataDefinitions, uGridStatusUtils; cxGridTableView, cxGridDBTableView, cxGridDBDataDefinitions, uGridStatusUtils;
const
TIPO_DETALLE_CONCEPTO = 'Concepto';
CAMPO_ID = 'ID';
CAMPO_POSICION = 'POSICION';
CAMPO_TIPO = 'TIPO_DETALLE';
CAMPO_CONCEPTO = 'CONCEPTO';
type
TTipoAnadir = (taAnadir, taInsertar);
procedure RegistrarFormatos; procedure RegistrarFormatos;
begin begin
@ -45,11 +54,139 @@ begin
raise Exception.Create('Error al registrar formato CF_RTF (CopiarSeleccionGridAlPortapapelesRTF)'); raise Exception.Create('Error al registrar formato CF_RTF (CopiarSeleccionGridAlPortapapelesRTF)');
end; end;
procedure RenumerarCampoPosicion(ADataSet : TDataSet);
function _DesplazarNPosiciones(ADataSet: TDataSet; NumOrdenIni: Variant; NPosiciones: Variant): Integer;
{
Función que desplaza NPosiciones el numero de orden a partir del elemento con el
número de orden dado. Devuelve el numero de orden del primer elemento del hueco
generado
}
var
AuxNumOrden: Integer;
AuxNumPos: Integer;
AField: TField;
begin
AField := ADataSet.FindField(CAMPO_POSICION);
if not Assigned(AField) then
raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (DesplazarNPosiciones)');
if VarIsNull(NPosiciones) then
AuxNumPos := 1
else
AuxNumPos := NPosiciones;
if VarIsNull(NumOrdenIni) then
AuxNumOrden := 0
else
AuxNumOrden := NumOrdenIni + 1; //Añadimos por abajo siempre
Result := AuxNumOrden;
with ADataSet do
begin
First;
while not EOF do
begin
if (FieldByName(CAMPO_POSICION).AsInteger >= AuxNumOrden) then
begin
if not (State in dsEditModes) then
Edit;
FieldByName(CAMPO_POSICION).AsInteger := FieldByName(CAMPO_POSICION).AsInteger + AuxNumPos;
Post;
end;
Next;
end;
end;
end;
procedure _NuevaTupla(ADataSet: TDataSet; ATipoAnadir: TTipoAnadir = taInsertar);
var
AuxNumOrden : Integer;
begin
ADataSet.DisableControls;
try
with ADataSet do
begin
AuxNumOrden := _DesplazarNPosiciones(ADataSet, FieldByName(CAMPO_POSICION).AsVariant, 1);
case ATipoAnadir of
taAnadir: Append;
taInsertar: Insert;
end;
FieldByName(CAMPO_POSICION).AsInteger := AuxNumOrden;
FieldByName(CAMPO_TIPO).AsVariant := TIPO_DETALLE_CONCEPTO;
end;
finally
ADataSet.EnableControls;
end;
end;
procedure _Renumerar(ADataSet: TDataSet);
{
procedimiento que renumera todos los conceptos de la tabla dada por parametro
}
var
i, j : Integer;
AField: TField;
begin
AField := ADataSet.FindField(CAMPO_POSICION);
if not Assigned(AField) then
raise Exception.Create('Campo ' + CAMPO_POSICION + ' no encontrado (renumerar)');
with ADataSet do
begin
for i:=0 to RecordCount-1 do
begin
First;
if not Locate(CAMPO_POSICION, i, []) then
begin
j := i;
First;
while not Locate(CAMPO_POSICION, j, []) do
begin
Inc(j);
First;
end;
if not (State in dsEditModes) then
Edit;
FieldByName(CAMPO_POSICION).AsInteger := i;
Post;
end;
end;
end;
end;
{procedure RenumerarCampoPosicion(ADataSet : TDataSet);
var var
i, j : Integer; i, j : Integer;
AField : TField; AField : TField;
AList : TStringList;
begin begin
AList := TStringList.Create;
try
ADataSet.First;
for i:=0 to ADataSet.RecordCount-1 do
begin
AList.Add(ADataSet.FieldByName('POSICION').AsString);
ADataSet.Next;
end;
ShowMessage(AList.Text);
finally
FreeANDNIL(AList);
end;
AField := ADataSet.FindField('POSICION'); AField := ADataSet.FindField('POSICION');
if Assigned(AField) and not (ADataSet.IsEmpty) then if Assigned(AField) and not (ADataSet.IsEmpty) then
begin begin
@ -67,15 +204,15 @@ begin
Inc(j); Inc(j);
First; First;
end; end;
Edit;
FieldByName('POSICION').AsInteger := i;
Post;
end; end;
Edit;
FieldByName('POSICION').AsInteger := i;
Post;
end; end;
end; end;
end; end;
end; end;}
function _BuscarColumna (AView: TcxGridDBTableView; function _BuscarColumna (AView: TcxGridDBTableView;
const AName, ATypeValue : String; var AIndex : Integer) : Boolean; const AName, ATypeValue : String; var AIndex : Integer) : Boolean;
@ -168,16 +305,16 @@ begin
begin begin
// Insertar una tupla de la forma adecuada // Insertar una tupla de la forma adecuada
if bEstabaVacia then if bEstabaVacia then
ADataSet.Append _NuevaTupla(ADataSet, taAnadir)
else begin else begin
if iContador = 0 then if iContador = 0 then
ADataSet.Edit ADataSet.Edit
else begin else begin
ADataSet.Next; ADataSet.Next;
if ADataSet.EOF then if ADataSet.EOF then
ADataSet.Append _NuevaTupla(ADataSet, taAnadir)
else else
ADataSet.Insert; _NuevaTupla(ADataSet, taInsertar)
end; end;
end; end;
@ -185,14 +322,16 @@ begin
for iCols := 0 to NumCols - 1 do for iCols := 0 to NumCols - 1 do
begin begin
AValue := AReader.ReadVariant; AValue := AReader.ReadVariant;
if (Pos(AValueNameList[iCols], AView.DataController.KeyFieldNames) = 0) and if (Pos(AValueNameList[iCols], AView.DataController.KeyFieldNames) = 0) then
(AValueNameList[iCols] <> 'POSICION') then
begin begin
if _BuscarColumna(AView, AValueNameList[iCols], AValueTypeList[iCols], AIndex) then if (AValueNameList[iCols] = 'POSICION') then
begin ADataSet.FieldByName('POSICION').Value := ADataSet.RecNo
if AIndex <> -1 then else
ADataSet.FieldByName(AView.DataController.GetItemField(AIndex).FieldName).Value := AValue; if _BuscarColumna(AView, AValueNameList[iCols], AValueTypeList[iCols], AIndex) then
end; begin
if AIndex <> -1 then
ADataSet.FieldByName(AView.DataController.GetItemField(AIndex).FieldName).Value := AValue;
end;
end; end;
end; end;
finally finally
@ -200,7 +339,7 @@ begin
end; end;
end; end;
RenumerarCampoPosicion(ADataSet); _Renumerar(ADataSet);
finally finally
AView.DataController.EndUpdate; AView.DataController.EndUpdate;
@ -490,7 +629,7 @@ begin
try try
CopiarSeleccionGridAlPortapapeles(AGrid); CopiarSeleccionGridAlPortapapeles(AGrid);
AGrid.ActiveView.DataController.DeleteSelection; AGrid.ActiveView.DataController.DeleteSelection;
RenumerarCampoPosicion(TcxGridDBTableView(AGrid.ActiveView).DataController.DataSet); _Renumerar(TcxGridDBTableView(AGrid.ActiveView).DataController.DataSet);
finally finally
HideHourglassCursor; HideHourglassCursor;
end; end;
@ -531,12 +670,10 @@ end;
procedure PegarTextoDesdePortapapeles (AGrid : TcxGrid); procedure PegarTextoDesdePortapapeles (AGrid : TcxGrid);
var var
ACaption : String;
AGridStatus : TcxGridStatus; AGridStatus : TcxGridStatus;
ATextList : TStringList; ATextList : TStringList;
ADataSet : TDataSet; ADataSet : TDataSet;
AColumnID: Integer;
ARecordID : Integer; ARecordID : Integer;
ARecordIndex : Integer; ARecordIndex : Integer;
@ -555,17 +692,14 @@ begin
AView := TcxGridDBTableView(AGrid.ActiveView); AView := TcxGridDBTableView(AGrid.ActiveView);
AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView)); AGridStatus := TcxGridStatus.Create(TcxGridDBTableView(AGrid.ActiveView));
Clipboard.Open; Clipboard.Open;
try try
ATextList := TStringList.Create; ATextList := TStringList.Create;
try try
CopyStringsFromClipboard(CF_TEXT, ATextList); CopyStringsFromClipboard(CF_TEXT, ATextList);
ADataSet := AView.DataController.DataSource.DataSet; ADataSet := AView.DataController.DataSource.DataSet;
bEstabaVacia := ADataSet.IsEmpty; bEstabaVacia := ADataSet.IsEmpty;
AView.DataController.BeginUpdate; AView.DataController.BeginUpdate;
try try
// Localizar el punto donde se empieza a insertar // Localizar el punto donde se empieza a insertar
@ -583,16 +717,16 @@ begin
begin begin
// Insertar una tupla de la forma adecuada // Insertar una tupla de la forma adecuada
if bEstabaVacia then if bEstabaVacia then
ADataSet.Append _NuevaTupla(ADataSet, taAnadir)
else begin else begin
if iContador = 0 then if iContador = 0 then
ADataSet.Edit ADataSet.Edit
else begin else begin
ADataSet.Next; ADataSet.Next;
if ADataSet.EOF then if ADataSet.EOF then
ADataSet.Append _NuevaTupla(ADataSet, taAnadir)
else else
ADataSet.Insert; _NuevaTupla(ADataSet, taInsertar)
end; end;
end; end;
@ -603,7 +737,8 @@ begin
ADataSet.Post; ADataSet.Post;
end; end;
end; end;
RenumerarCampoPosicion(ADataSet);
_Renumerar(ADataSet);
finally finally
AView.DataController.EndUpdate; AView.DataController.EndUpdate;
end; end;
@ -649,7 +784,6 @@ begin
PegarTextoDesdePortapapeles(AGrid); PegarTextoDesdePortapapeles(AGrid);
Exit; Exit;
end; end;
end; end;
end. end.