Dataset transfer

xiaoxiao2021-03-06  40

ColumnStr: = TSTRINGLIST.CREATE; PARALLCOLUMNSTR: = TSTRINGLIST.CREATE

ColumnStr.Add ('fsize'); // Rotate Size, its corresponding value is Qty Parallumnstr.Add ('fqty');

DTWHIRLDATA: = WhirlDataSet (DTQuery, Columnstr, PARALLCOLUMNSTR, 0); // Last parameter indicates that the previous column is used as a packet.

Function WhirlDataSet; ColumnTorow, ParallelismrowValue: Tstrings; ifrontgrp: integer: tadodata

VAR

i: integer;

DTGENTMP: TadodataSet;

Oldfixflds: tstrings;

NWFLDSNAME: TSTRINGS;

NWFLDSTYPE: TSTRINGS;

NWFLDSLEN: TSTRINGS;

FieldType: TfieldType;

IColumn, Irow: Integer;

LastValue: TSTRINGS;

Willnewgrp: boolean;

INewfrontgrp: integer;

Begin

/ / This function does not exist if the field of ColumnTorow / ParallelismRowValue is DTSET, so the user handles yourself before calling this function.

IF columnTorow.count <> parallelismrowValue.count then

Begin

IF columnTorow.count> ParallelismrowValue.count then

Begin

For i: = columntorow.count - 1 Downto ParallelismRowValue.count - 1 DO

Begin

ColumnTorow.delete (i);

END;

END ELSE

Begin

For i: = parallelismrowValue.count - 1 Downto ColumnTorow.count - 1 DO

Begin

ParallelismRowValue.delete (i);

END;

END;

END;

IF (columnTorow.count = 0) or (parallelismrowValue.count = 0) THEN

Begin

Result: = dtset;

EXIT;

END;

Oldfixflds: = TSTRINGLIST.CREATE;

NWFLDSNAME: = TSTRINGLIST.CREATE;

NWFLDSTYPE: = TSTRINGLIST.CREATE;

NWFLDSLEN: = TSTRINGLIST.CREATE;

For i: = 0 to dtset.fieldcount - 1 Do // dtset does not need to transpose

Begin

Icolumn: = ColumnTorow.indexof (Trim (dtset.fields [i] .fieldname);

Irow: = ParallelismRowValue.indexof (Trim (dtset.fields [i] .fieldname));

IF (iColumn = -1) and (irow = -1) THEN

Begin

NWFLDSNAME.ADD (dtset.fields [i] .fieldname);

Oldfixflds.add (dtset.fields [i] .fieldname); NWFLDSTYPE.ADD (INTSTR (ORD (DTSET.FIELDS [I] .dattype)));

NWFLDSLEN.ADD (INTSTOT.FIELDS [i] .size);

END;

END;

For i: = 0 to colorow.count - 1 Do // DTSET Requires the column, and set the value as the column name, and ParalleLismRowValue corresponds to the value

Begin

Dtset.first;

While not dtset.eof do

Begin

If NWFLDSNAME.INDEXOF (Trim (dtset.fieldbyname (ColumnTorow [i]). asstring) = -1 THEN

Begin

NWFLDSName.Add (Trim (dtset.fieldbyName); asstring));

NWFLDSTYPE.ADD (INTTOSTR (ORD (DtSet.fieldByname (ParallelismRowValue [i]))))))

NWFLDSlen.Add (INTSTR (DtSet.fieldByname (para]). Size);

END;

DtSet.next;

END;

END;

DTGENTMP: = tadodataset.create (nil);

For i: = 0 to nwfldsname.count - 1 do

Begin

With dtgentmp.fielddefs.addfielddef do

Begin

Name: = nwfldsname [i];

FieldType: = TfieldType (STRTOINT (NWFLDSTYPE [I]));

DataType: = FieldType;

If FIELDTYPE IN [fTString, ftwideString, ftmemo] Then // Here there is bug: main reason is that the length of the ftinteger cannot be set, other data types don't know if you want to set the length.

Size: = start (NWFLDSLEN [i]);

END;

END;

DTGENTMP.CREATEDATASET;

LastValue: = tstringlist.create;

Dtset.first;

IF (Oldfixflds.count - 1)

Begin

inewfrontgrp: = 0;

END ELSE

inewfrontgrp: = IFRONTGRP - 1;

If not dtset.isempty life

Begin

For i: = 0 to inewfrontgrp do

Begin

LastValue.Add ('');

END;

END;

While not dtset.eof do

Begin

DTGENTMP.APPpend;

Willnewgrp: = false;

For i: = 0 to inewfrontgrp do

Begin

If LastValue [i] <> dtset.fieldbyName (Oldfixflds [i]). asstring then

Begin

Willnewgrp: = true;

Break;

END;

END;

IF Willnewgrp Then

LastValue.clear;

For i: = 0 to oldfixflds.count - 1 DO // Unset part of the data

Begin

IF Willnewgrp and (i <= inewfrontgrp) Thenbegin

DTGENTMP.FIELDBYNAME (Oldfixflds [i]). Value: = dtset.fieldByname (Oldfixflds [i]). Value;

LastValue.Add (dtSet.fieldByname (Oldfixflds [i]). Asstring);

END ELSE

IF I> inewfrontgrp

DTGENTMP.FIELDBYNAME (Oldfixflds [i]). Value: = dtset.fieldByname (Oldfixflds [i]). Value;

END;

For i: = 0 to columntorow.count - 1 DO // transpose part of data

Begin

DTGENTMP.FIELDBYNAME (TRIM (dtset.fieldbyName). Value). Value: = dtset.fieldbyName (ParallelismrowValue [i]). Value;

END;

DTGENTMP.POST;

DtSet.next;

END;

DTGENTMP.FIRST;

FreeAndnil (Oldfixflds);

Freeandnil (nwfldsname);

FreeAndnil (nwfldstype);

Freeandnil (NWFLDSLEN);

FreeAndnil (LastValue);

Result: = DTGENTMP;

END;

转载请注明原文地址:https://www.9cbs.com/read-69935.html

New Post(0)