Dynamic generator

zhaozj2021-02-16  51

During the recent project development process, due to the needs of the customer, it is necessary to exchange the same type of goods in the database. After many aspects, it is discovered that there is a lack of things online, so I wrote a process to achieve this. Please give more points from the deficiencies, thank you

The third-party control VSFLEXGRID is used in the program, and the variable VSGRID can be replaced with StringGrid but part of the code must be deleted.

Procedure heji (vsgrid: tvsflexgrid);

VAR

COMN_NUM, HEJI, KK, LL: Integer; // COMN_NUM: VSGRID column number heji: Save the matching value KK: The difference between the number of rows read

He: boolean;

Begin

CESHI: = vsgrid.rows-1;

HE: = false;

Try

For record_flag: = conm to ceshi do

Begin

If He = true kiln //

If Record_flag

Begin

HE: = false;

Continue; // Execute the next loop skip this loop

END;

END;

IF (vsgrid.textmatrix [record_flag, 0] <> vsgrid.textmatrix [RECORD_FLAG 1, 0]) THEN / / Decision is the same type of adjacent record

Begin // is different:

He: = true;

vsgrid.additem (vsgrid.textmatrix [record_flag, 0] 'total', Record_Flag 1); // Add a total of total lines at RECORD_FLAG

For co_num: = 5 to vsgrid.cols-1 do // Cycling calculation to be totally field value

Begin heji: = 0;

For record_flag2: = conm to record_flag do // Start calculation from CONM

Begin

IF (Trim (vsgrid.textmatrix [0, col]) = 'week plan') or (Trim (vsgrid.textmatrix [0, comn_num]) = 'last week define') OR (Trim (vsgrid.textmatrix [0, COMN_NUM]) = 'on the day')

OR (Trim (vsgrid.textmatrix [0, comn_num]) = 'Cumulative') OR (Trim (vsgrid.textmtrix [0, comn_num]) = 'Derellar') THEN

Begin

// if (vsgrid.textmatrix [record_flag, 6] = 'direct supply machine') or (vsgrid.textmatrix [record_flag, 6] = 'shooter') THEN

Heji: = start (vsgrid.textmatrix [record_flag2, comn_num]) heji; // save the consolidation value

vsgrid.select (record_flag 1, comn_num); //

vsgrid.cellforecolor: = CLWHITE; / / Give a total color

vsgrid.text: = INTOSTR (HEJI); // Give the cell negative value vsgrid.select (Record_Flag 1, 11);

vsgrid.text: = vsgrid.textMatrix [RECORD_FLAG, 11];

vsgrid.select (Record_flag 1, 12);

vsgrid.text: = vsgrid.textMatrix [RECORD_FLAG, 12];

END;

END;

vsgrid.select (Record_Flag 1, COL);

vsgrid.cellbackcolor: = cahighlight; // change background color

END;

CONM: = Record_flag 2; // Increase the total CONM 2 Skip Total

CESHI: = vsgrid.rows; // vsgrid Added a line, re-negative value

END;

END;

Except

KK: = vsgrid.rows-record_flag;

END;

// Since the record_flag 1 does not exist when it is looped to the last two records, there is a record that cannot be calculated, and the code is processed, the code is as follows:

KK: = vsgrid.rows-record_flag; // The difference between calculation lines and comparison

IF KK> 1 THEN LL: = 1 else ll: = 0;

IF (Record_Flag KK) = vsgrid.rows the

Begin

vsgrid.additem (vsgrid.textmatrix [record_flag kk-1, 0] 'total', Record_Flag KK);

For COMN_NUM: = 5 to vsgrid.cols-1 do

Begin heji: = 0;

For record_flag2: = conm to record_flag ll do

Begin

IF (Trim (vsgrid.textmatrix [0, col]) = 'week plan') or (Trim (vsgrid.textmatrix [0, comn_num]) = 'last week define') OR (Trim (vsgrid.textmatrix [0, COL]) = 'on the day')

OR (Trim (vsgrid.textmatrix [0, col]) = 'cumulative') or (Trim (vsgrid.textmatrix [0, comn_num]) = 'define') THEN

Begin

HEJI: = STRTOINT (vsgrid.textmatrix [record_flag2, comn_num]) heji;

vsgrid.select (record_flag kk, comn_num);

vsgrid.cellforecolor: = CLWHITE;

vsgrid.text: = INTTOSTR (HEJI);

vsgrid.select (Record_Flag KK, 11);

vsgrid.text: = vsgrid.textMatrix [RECORD_FLAG KK-1, 11];

vsgrid.select (Record_Flag KK, 12);

vsgrid.text: = vsgrid.textMatrix [RECORD_FLAG KK-1, 12];

END;

END;

vsgrid.select (record_flag kk, comn_num);

vsgrid.cellbackcolor: = cahighlight;

EXIT;

END;

The above algorithm is simple, first pay the adjacent two ROWS NUMBERs to two variables, then compare the type field value of the two lines, the same words, continue negative, different, inserted on the maximum row of ROWS values And set fields, and then the total field value is taken on this line, after the total is completed, skip the total row and continue to execute. Since the maximum line 1 does not exist when it is looped to the last two records, there is a record that cannot be calculated, and the program is finally processed separately.

Code test in Win2k Server SQL 2000 Enterprise Edition

Write this code out for your reference, if you have any good way, please contact: lsl@haiersoft.com.cn

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

New Post(0)