home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Visual Basic 4 Unleashed
/
Visual_Basic_4_Unleashed_SAMS_Publishing_1995.iso
/
repease
/
rep_sec.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-05-03
|
16KB
|
438 lines
/*==============================================================================
REP_SEC.C
Report Ease: Section related functions.
ReportEase Plus
Sub Systems, Inc.
ReportEase Plus, Copyright (c) 1993, Sub Systems, Inc. All Rights Reserved.
159 Main Street, #8C, Stoneham, MA 02180
(617) 438-8901.
Software License Agreement (1993)
----------------------------------
This license agreement allows the purchaser the right to modify the
source code to incorporate in their application.
The target application must not be distributed as a standalone report writer
or a mail merge product.
Sub Systems, Inc. reserves the right to prosecute anybody found to be
making illegal copies of the executable software or compiling the source
code for the purpose of selling there after.
===============================================================================*/
#include "windows.h"
#if defined (_WIN32)
#if !defined(WIN32)
#define WIN32
#endif
#endif
#if !defined(WIN32)
#include "print.h"
#endif
#include "stdio.h"
#include "stdlib.h"
#include "ctype.h"
#include "fcntl.h"
#include "io.h"
#include "sys\types.h"
#include "sys\stat.h"
#include "string.h"
#include "setjmp.h"
#include "rep.h"
#define PREFIX extern
#include "rep1.h"
/******************************************************************************
NewSection:
Insert a new section in the report.
******************************************************************************/
NewSection()
{
LPSTR SecName[MAX_SECTIONS];
int count=0,i,select,SecIdx[MAX_SECTIONS],SecHdr,NewSection,
CurItem,PrevSec,PrevItem;
int FieldIndex;
struct StrField GroupField;
if (TotalItems>=MAX_ITEMS) { // check for item table space
MessageBox(hFrWnd,"Item Table Full!",NULL,MB_OK);
return TRUE;
}
// deselect currently selected item
if (SelItem>=0) DeselectItem();// deselect the current item
// build an array of sections to choose from
for (i=0;i<MAX_SECTIONS;i++) {
if (!section[i].InUse) {
// Select the header sections
if (i>SEC_HDR_LVL1 && i<=SEC_HDR_LVL9) {
if (section[i-1].InUse) { // select only if lower section selected
SecIdx[count]=i; // selected index
SecName[count]=(LPSTR)SectionName[i];
count++;
}
continue;
}
// Select the detail sections
if (i>SEC_DETAIL1 && i<=SEC_DETAIL9) {
if (section[i-1].InUse && section[i-1].columns==1) { // select only if previous detail selected and uses one column only
SecIdx[count]=i; // selected index
SecName[count]=(LPSTR)SectionName[i];
count++;
}
continue;
}
// Select the footer sections
if (i>=SEC_FTR_LVL9 && i<=SEC_FTR_LVL1) {
SecHdr=SEC_HDR_LVL1+8-(i-SEC_FTR_LVL9);
if (section[SecHdr].InUse) { // select only if the section header selected
SecIdx[count]=i; // selected index
SecName[count]=SectionName[i];
count++;
}
continue;
}
SecIdx[count]=i; // selected index
SecName[count]=SectionName[i];
count++;
}
}
SecName[count]=NULL;
if ((select=CallDialogBox("NewSecParam",NewSecParam,(DWORD)(LPSTR)SecName))<0) return FALSE;
NewSection=SecIdx[select]; // section number to insert
//*** get the sorting field for a group break sections ***
if (NewSection>=SEC_HDR_LVL1 && NewSection<=SEC_HDR_LVL9) { // select a group sort field
// ACCEPT GROUP FIELD
InitField(&GroupField); // initialize the field variables
GroupField.section=NewSection;
if (!(FormArg.UserSelection)(hFrWnd,&GroupField,NewSection-SEC_HDR_LVL1+1)) return FALSE; // call a user routine to select a data field
//****************** Find room for the Sort field *********
if (END_OF_EXP==(FieldIndex=FindFieldSlot())) {
MessageBox(hFrWnd,"Ran out of field table!",NULL,MB_OK);
return FALSE;
}
// copy the field into the current array position
field[FieldIndex]=GroupField;
BreakField[TotalBreakFields].SortField=FieldIndex;
//****************** Find room for the Comparision field *********
if (END_OF_EXP==(FieldIndex=FindFieldSlot())) {
MessageBox(hFrWnd,"Ran out of field table!",NULL,MB_OK);
return FALSE;
}
// copy the field into the current array position
field[FieldIndex]=GroupField;
BreakField[TotalBreakFields].CompField=FieldIndex;
// update the break field structure
BreakField[TotalBreakFields].section=NewSection;
TotalBreakFields++;
}
// find the item number before which to insert this section
for (i=0;i<TotalItems;i++) if (item[i].section>NewSection) break;
if (i<TotalItems) {
CurItem=i;
MoveItemArray(CurItem,1,'B'); // scoll down other items;
}
else {
CurItem=TotalItems;
TotalItems++;
}
// create the section item
InitItem(&item[CurItem]);
item[CurItem].type=SECTION;
item[CurItem].section=NewSection;
item[CurItem].x=(int)(FormHdr.LeftMargin*UNITS_PER_INCH);
if (CurItem==0) item[CurItem].y=0;
else { // locate the previous section to get the current Y
PrevSec=item[CurItem-1].section;
PrevItem=section[PrevSec].ScrItem; // item number for the previous section
item[CurItem].y=item[PrevItem].y+item[PrevItem].height;
}
item[CurItem].width=FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin));
item[CurItem].height=DEF_SEC_HEIGHT;
// set the current section array element
section[NewSection].InUse=TRUE; // define the page header
section[NewSection].ScrItem=CurItem; // reference to the item
section[NewSection].SelExp[0]=END_OF_EXP;
section[NewSection].flags=0;
// adjust the Y position of the remaining items
for (i=CurItem+1;i<TotalItems;i++) {
item[i].y+=item[CurItem].height;
}
FrHeight+=item[CurItem].height; // adjust the form height
SelItem=CurItem; // select the current section
FrWinOrgY=item[CurItem].y-(FrWinHeight-item[CurItem].height)/2; // show new section at the center
FrPaint();
FrModified=TRUE;
return TRUE;
}
/******************************************************************************
EditSection:
Edit Section Parameters.
******************************************************************************/
EditSection()
{
if (SelItem<0) return TRUE;
DlgIndex=item[SelItem].section; // pass the section number to the dialog box
if (CallDialogBox("EditSecParam",EditSecParam,0L)) {
// recalculate the section width
if (DlgIndex==SEC_DETAIL1) item[SelItem].width=(FrWidth-(int)(UNITS_PER_INCH*(FormHdr.LeftMargin+FormHdr.RightMargin)))/section[DlgIndex].columns;
FrPaint();
}
return TRUE;
}
/******************************************************************************
DeleteSection:
Delete the current section from the report.
******************************************************************************/
DeleteSection()
{
int CurSec,CurItem,height,i,count,HdrBreakNo,FtrBreakNo;
CurSec=item[SelItem].section; // section to delete
// Last section check
count=0;
for (i=0;i<MAX_SECTIONS;i++) if (i!=CurSec && section[i].InUse) count++;
if (count==0) {
MessageBox(hFrWnd,"Can not delete the last section!",NULL,MB_OK);
return FALSE;
}
// Detail section check
if (CurSec>=SEC_DETAIL1 && CurSec<SEC_DETAIL9 && section[CurSec+1].InUse) {
MessageBox(hFrWnd,"Must Delete all Higher Detail Sections First!",NULL,MB_OK);
return FALSE;
}
// Validate for group header fields
if (CurSec>=SEC_HDR_LVL1 && CurSec<=SEC_HDR_LVL9) {
HdrBreakNo=CurSec-SEC_HDR_LVL1;
FtrBreakNo=SEC_FTR_LVL1-HdrBreakNo;
if (section[FtrBreakNo].InUse) {
MessageBox(hFrWnd,"Must Delete the Group Footer Before Deleting the Group Header Section!",NULL,MB_OK);
return FALSE;
}
if (BreakField[TotalBreakFields-1].section!=CurSec) {
MessageBox(hFrWnd,"Must Delete all Higher Group Sections Before Deleting This Section",NULL,MB_OK);
return FALSE;
}
}
// Delete confirmation
wsprintf(msg,"Delete Current Section: %s? ",(LPSTR)SectionName[CurSec]);
if (IDNO==MessageBox(hFrWnd,msg,"Confirmation",MB_YESNO)) return FALSE;
// Delete all items within the section
PaintEnabled=FALSE; // suspend painting until the whole operation is over
while (TRUE) {
for (i=0;i<TotalItems;i++) {
if (item[i].type!=SECTION && item[i].type!=GROUP && item[i].section==CurSec) break;
}
if (i==TotalItems) break; // items deleted
SelItem=i;
DeleteItem(); // delete this item;
}
// Delete the section item
for (i=0;i<TotalItems;i++) if (item[i].type==SECTION && item[i].section==CurSec) break;
if (i==TotalItems) AbortFr("Section Not Found!(DeleteSection)",ERR_OTHER);
CurItem=i;
height=item[CurItem].height; // save the section height
FrEraseFocusRect(hFrDC,&CursRect);
MoveItemArray(CurItem,1,'D'); // delete and scroll the item array
// scroll up the remaining items;
for (i=CurItem;i<TotalItems;i++) {
item[i].y-=height;
if (item[i].y<0) item[i].y=0;
}
FrHeight-=height; // reduce the form height
// relocate the group item to the first section
for (i=0;i<TotalItems;i++) if (item[i].type==GROUP) break;
if (i==TotalItems) AbortFr("Group Item Not Found!(DeleteSection)",ERR_OTHER);
if (item[i].section==CurSec) { // relocate to the top of the form
MoveEachItem(i,item[0].x-item[i].x,item[0].y-item[i].y+FormHdr.SecBannerHeight);
}
//*** delete the group sort and comparision fields **
if (CurSec>=SEC_HDR_LVL1 && CurSec<=SEC_HDR_LVL9) {
DeleteField(BreakField[TotalBreakFields-1].SortField);
DeleteField(BreakField[TotalBreakFields-1].CompField);
TotalBreakFields--;
}
//***** Release the selection expression symbols ****
ReleaseSymbols(section[CurSec].SelExp);
section[CurSec].SelExp[0]=END_OF_EXP;
section[CurSec].InUse=FALSE;
SelItem=-1; // Deselect all items
PaintEnabled=TRUE; // refresh the screen
FrPaint();
return TRUE;
}
/******************************************************************************
EditSectionFilter:
Edit section selection criteria.
******************************************************************************/
EditSectionFilter()
{
int CurSec,i;
int NewExp[NAME_WIDTH+2];
CurSec=item[SelItem].section;
if (ModifyExp(section[CurSec].SelExp,NewExp,"Section Selection Criteria",EXP_PARM)!=-1) {
i=0;
while(NewExp[i]!=END_OF_EXP) {
section[CurSec].SelExp[i]=NewExp[i];
i++;
}
section[CurSec].SelExp[i]=NewExp[i];
}
return TRUE;
}
/******************************************************************************
EditSectionSort:
Edit section sort field. Section sort fields are application for
sort header sections only.
******************************************************************************/
EditSectionSort()
{
int i,CurSec,SortFieldIndex,BreakFieldIndex;
BOOL IdenticalFields;
CurSec=item[SelItem].section;
if (CurSec<SEC_HDR_LVL1 || CurSec>SEC_HDR_LVL9) return FALSE;
for (i=0;i<TotalBreakFields;i++) if (BreakField[i].section==CurSec) {
SortFieldIndex=BreakField[i].SortField;
BreakFieldIndex=BreakField[i].CompField;
break;
}
if (i==TotalBreakFields) {
AbortFr("Invalid Section, File Corruption Detected!",10);
}
DlgIndex=SortFieldIndex; // pass the section sort field number using the global variable
//***** check if sort and break field are identical *****
IdenticalFields=FALSE;
if (lstrcmp(field[SortFieldIndex].name,field[BreakFieldIndex].name)==0) IdenticalFields=TRUE;
if (CallDialogBox("SecSortParam",SecSortParam,(DWORD)CurSec)) {
if (IdenticalFields) { // change the break field as well
lstrcpy(field[BreakFieldIndex].name,field[SortFieldIndex].name);
field[BreakFieldIndex].type=field[SortFieldIndex].type;
field[BreakFieldIndex].width=field[SortFieldIndex].width;
field[BreakFieldIndex].DecPlaces=field[SortFieldIndex].DecPlaces;
field[BreakFieldIndex].FileId=field[SortFieldIndex].FileId;
field[BreakFieldIndex].FieldId=field[SortFieldIndex].FieldId;
}
}
return TRUE;
}
/******************************************************************************
EditSectionBreak:
Edit section break field. A section break occurs when the corresponding
section break field value changes.
******************************************************************************/
EditSectionBreak()
{
int i,CurSec,BreakFieldIndex,SortFieldIndex,SecLevel,ExpType,ResultType;
int NewExp[NAME_WIDTH+2];
CurSec=item[SelItem].section;
if (CurSec<SEC_HDR_LVL1 || CurSec>SEC_HDR_LVL9) return FALSE;
for (i=0;i<TotalBreakFields;i++) if (BreakField[i].section==CurSec) {
BreakFieldIndex=BreakField[i].CompField;
SortFieldIndex=BreakField[i].SortField;
SecLevel=i+1;
break;
}
if (i==TotalBreakFields) {
AbortFr("Invalid Section, File Corruption Detected!",10);
}
DlgTempField=field[BreakFieldIndex]; // make a working copy of the field
while (TRUE) {
if (DlgTempField.source==SRC_CALC) {
if (CurSec>=SEC_FTR_LVL9) ExpType=EXP_FOOTER;
else ExpType=EXP_OTHER;
if ((ResultType=ModifyExp(DlgTempField.CalcExp,NewExp,DlgTempField.name,ExpType))<0) {
DlgTempField=field[SortFieldIndex];
continue;
}
i=0;
while(NewExp[i]!=END_OF_EXP) {
DlgTempField.CalcExp[i]=NewExp[i];
i++;
}
DlgTempField.CalcExp[i]=NewExp[i];
DlgTempField.type=ResultType;
if (i==0) { // a calculatio field not specified
DlgTempField=field[SortFieldIndex];
continue;
}
else break; // a valid calculation field provided
}
else {
DlgIndex=BreakFieldIndex; // pass the section break field number using the global variable
if (!CallDialogBox("SecBreakParam",SecBreakParam,(DWORD)CurSec)) return TRUE;
if (DlgTempField.name[0]==0) { // create a calculation field
DlgTempField.source=SRC_CALC;
DlgTempField.type=TYPE_NUM;
wsprintf(DlgTempField.name,"COMP_EXP%d",SecLevel);
DlgTempField.CalcExp[0]=END_OF_EXP;
}
else break; // a valid data field provided
}
}
field[BreakFieldIndex]=DlgTempField;
return TRUE;
}