Есть отчет, который должен печатать access violation records по результатам анализа лога базы данных и таблицы с правами. Есть специальная таблица и форма для работы с этой таблицей, где администратор может определить какие таблицы и какие поля его интересуют в этом отчете. То есть заранее неизвестно сколько будет таблиц и полей выведено в отчет. Администратор не хочет видеть этот отчет в виде вертикальной колбасы, подавай ему табличный вид. Приходится извращаться и создавать массив из таблиц и полей, и печатать этот массив. Вот то и возникает проблема - надо чтобы все поля одной таблицы печатались в одной строчке, отчет масштабировался так, чтобы вписаться в страницу.
А у меня получается какая-то ерунда - не масштабируется отчет и все тут. Уже все свойства подерганы за разные ниточки - не получается. И к тому же работает медленно.
Я не программист, может кто более сведующий подскажет какие нибудь идеи.
А ниже злополучный код fetch, доброжелательные советы будут выслушаны с почтением.
X++:
public boolean fetch()
{
boolean retCode = false;
Issi_tmp_accessvioaltion accessviolation, accessviolation1;
ReportSection reportSection;
Counter i = 0;
QueryRun qrun;
int newtable, oldtable;
str olduser, newuser;
str 50 value[], fieldname[];
int tables[], curtab;
int numberoffields[], fieldwight[], totalwight[], numoftables = 0, maxfileds = 50, shift, t;
reporttextcontrol reportcontrol;
;
qrun = new QueryRun(element);
if (! qrun.prompt())
{
return retCode;
}
olduser = '';
oldtable = 0;
reportcontrol = new reportcontrol();
///////////////////discover tables and fields
numoftables = 0;
while select accessviolation1 group by table
{for (i=1;i<=numoftables; i++)
if (tables[i] == accessviolation1.Table )
break;
if (i> numoftables)
{numoftables++;
tables[numoftables] = accessviolation1.table;
}
}
///////////////////////////////////////////////////////////////////////////
for (curtab = 1; curtab<= numoftables; curtab++)
{
t =maxfileds*(curtab-1);
fieldname[1+t] = 'Com';
fieldwight[1+t] = 3;
fieldname[2+t] = 'Date';
fieldwight[2+t] = 7;
fieldname[3+t] = 'Description';
fieldname[3+t] = 'Type';
fieldwight[4+t] = 7;
numberoffields[curtab] = 4;
while select accessviolation1
where (accessviolation1.Table == tables[curtab]
&& accessviolation1.fieldid != 0)
{
fieldwight[3+t] = max(strlen(accessviolation1.Description),fieldwight[2+t]);
for (i=5; i<=numberoffields[curtab];i++)
{
if (fieldname[i+t] == accessviolation1.FieldN)
break;
}
if (i >numberoffields[curtab])
{
numberoffields[curtab]++;
fieldname[numberoffields[curtab]+t] = accessviolation1.FieldN;
fieldwight[numberoffields[curtab]+t] =strlen(accessviolation1.OldValue) + 4 + strlen(accessviolation1.NewValue);
totalwight[curtab] = totalwight[curtab] + fieldwight[numberoffields[curtab]+t];
}
totalwight[curtab] = totalwight[curtab] + fieldwight[1+t] + fieldwight[2+t] + fieldwight[3+t] + fieldwight[4+t];
// there are description, date and type for each record
} // while select accessviolation1
}// for (curtab = 1; curtab<= numoftables; curtab++)
while (qrun.next())
{
accessviolation = qrun.get(TableNum(Issi_tmp_accessvioaltion));
this.send(accessviolation);
newtable = accessviolation.Table;
newuser = accessviolation.Username;
for (i=1;i<=numoftables; i++)
if (tables[i] == accessviolation.Table )
break;
curtab = i;
t =maxfileds*(curtab-1);
shift = 0;
/////////////// print headers//////////////////////////////////////
if (newuser != olduser) // new user and new table
{
this.execute(1);
this.execute(2);
olduser = newuser;
oldtable = 0;
}
else if (newtable != oldtable)
{
this.execute(2);
oldtable = 0;
}
if (newtable != oldtable) //new table
{
oldtable = newtable;
for (i=1; i<=numoftables;i++)
if (tables[i] == newtable) break;
reportSection = element.design().autoDesignSpecs().addProgrammableSection(4);
reportsection.columnsMode(2);
reportsection.arrangeMethod(0);
// print fields headers
for(i=1; i<=numberoffields[curtab]; i++)
{
reportSection.addTextControl(fieldname[i+t]);
reportcontrol = reportsection.controlNo(i);
reportcontrol.lineRight(1);
reportcontrol.lineBelow(1);
reportcontrol.widthMode(-1);
reportcontrol.width(fieldwight[i+t]*3,Units::pt);
reportcontrol.fontSize(7);
}
reportSection.executeSection();
}// if
/////////////////////////end print headers //////////////////////////////////////
/////////////////////////print that was changed /////////////////////////////////
// define 4 first fields
value[0] = '';
value[1] = accessviolation.LogDataAreaID;
value[2] = date2str(accessviolation.tdate, 213, 2,2,2,0,0);
value[3] = accessviolation.Description;
value[4] = enum2str(accessviolation.LogType);
if (accessviolation.LogType == databaselogtype::Update)
{
while select accessviolation1 where
accessviolation1.LogRecID == accessviolation.LogRecID
&& accessviolation1.TRecID == accessviolation.TRecID
&& accessviolation1.LogType == databaselogtype::Update
&& accessviolation1.fieldid != 0
{
for (i=5; i<=numberoffields[curtab];i++)
if (fieldname[i+t] == accessviolation1.FieldN) break;
value[i] =accessviolation1.OldValue + ' -> ' + accessviolation1.NewValue;
shift ++;
}//WHILE
// move cursor
for (i=1; i < shift; i+=1)
{ qrun.next();
}
} //if
// print field's new value
reportSection = element.design().autoDesignSpecs().addProgrammableSection(7);//this.design().Sectionname('ProgrammableSection_5');
reportsection.columnsMode(2);
reportsection.arrangeMethod(0);
for(i=1; i<=numberoffields[curtab]; i++)
{
reportSection.addTextControl(value[i]);
//design
reportcontrol = reportsection.controlNo(i);
reportcontrol.widthMode(-1);
reportcontrol.width(fieldwight[i+t]*3,Units::pt);
reportcontrol.lineRight(1);
//reportcontrol.rightMarginUnit(units::pt);
//reportcontrol.rightMarginValue(3);
reportcontrol.fontSize(7);
}
reportSection.executeSection();
}// while
retCode = true;
element.printJobSettings().fitToPage(true);
return retCode;
}