分类:
2007-03-17 08:37:10
//By: 公子哥
//E-mail:vxv_-_net2k@126.com
//版权所有,转载请注明作者
extern "C" \
typedef struct START_END_TAG{
int nStart ;
int nEnd ;
} *START_END ;
//表格结构
extern "C" \
typedef struct LINK_TABLE { \
PSTR ptrTableHead;
PSTR ptrTr;
PSTR ptrTd;
PSTR ptrTableHeadEnd;
PSTR ptrTrEnd;
PSTR ptrTdEnd;
//链接文字
PSTR ptrNext; //下一页
PSTR ptrMostend; //最末尾
PSTR ptrMostfront; //最前面
PSTR ptrFront; //前一页
//链接文字说明
PSTR ptrTitleHrefNext;
PSTR ptrTitleHrefMostend; \
PSTR ptrTitleHrefMostfront; \
PSTR ptrTitleHrefFront; \
} SET_LINK_TABLE;
char * StringConn(int argc,char *argv[])
{
size_t nArraySize = 0;
for (int i = 0 ; i < argc ; i++)
nArraySize+=strlen(argv[i]);
char * pBuilder = (char *)malloc(nArraySize);
int n = 0;
for (int i = 0;i
argv[0] = '\0';
argv[0] = (char *)malloc(nArraySize);
return argv[0] = pBuilder;
}
char ** Cler(int argc ,char ** pList)
{
for (int i=0; i < argc ;i++) pList[i] = '\0';
return pList;
}
//初始化表格
SET_LINK_TABLE * InitTable(SET_LINK_TABLE * slt)
{
slt->ptrNext=">";
slt->ptrMostend=">>";
slt->ptrMostfront="<<";
slt->ptrFront="<";
slt->ptrTitleHrefNext="Next page"; //下一页
slt->ptrTitleHrefMostend="End"; //最末尾
slt->ptrTitleHrefMostfront="Start"; //Start
slt->ptrTitleHrefFront="Previous page"; //上一页
slt->ptrTableHead="";
";
slt->ptrTr="";
slt->ptrTd="";
slt->ptrTableHeadEnd="
slt->ptrTrEnd="";
slt->ptrTdEnd="";
return slt;
}
//计算页尺寸
START_END PageSize(START_END pSe , int nTotal, int nPageSize,unsigned long nIndexId, int nPageAmount)
{
int nStart = 0;
__asm
{
mov eax,nPageAmount
cmp eax , 0
je NODE0
mov ecx , 0
mov eax ,nIndexId
cmp eax ,1
jb NODE1
sub eax ,1
NODE1:
mul nPageSize
mov nStart , eax
cmp eax , 0
jb NODE5
NODE2:
mov eax , nIndexId
cmp eax , 1
ja NODE3
jmp NODE7
NODE3:
mov eax ,nIndexId
mul nPageSize
mov ebx , eax
cmp eax , nTotal
ja NODE4
jb NODE4
jmp NODE7
NODE5:
xor eax , eax
mov nStart , eax
mov ecx , offset NODE2
jmp ecx
NODE4:
mov eax , nTotal
sub eax ,ebx
mov ecx , eax
cmp eax , nPageSize
jge NODE6
mov eax , nPageSize
mul nIndexId
sub eax , nPageSize
mov nStart , eax
mov eax , nTotal
mov nPageSize , eax
jmp NODE7
NODE6:
mov eax , nPageSize
mul nIndexId
mov nPageSize , eax
jmp NODE7
NODE0:
mov eax , nTotal
mov nPageSize , eax
jmp NODE7
NODE7:
mov ebx , pSe
mov eax , nStart
mov [ebx]pSe.nStart , eax
mov eax , nPageSize
mov [ebx].nEnd , eax
}
return pSe;
}
/*
数据可视操作界面函数
pLink 页面超级连接
nPageSize 共分成多少页面,
nPageIndex 页索引,即当前第n页
nPageCount 页尺寸,即当前显示的数据总量
public string TableGetLink( string strUrl, int intPnum, int intPage, int intTotnum)
*/
PSTR MarkPage(SET_LINK_TABLE * slt,PSTR pLink,int nPageSize,int nPageIndex,int nPageCount)
{
char buffer[100];
//构造表格
PSTR pList[]={
slt->ptrTableHead ,
slt->ptrTr ,
slt->ptrTd ,
" " ,
itoa(nPageCount,buffer , 10) ,
" " ,
slt->ptrTdEnd ,
slt->ptrTd ,
" " ,
itoa(nPageIndex,buffer , 10) ,
"/" ,
itoa(nPageSize,buffer , 10) ,
" " ,
slt->ptrTdEnd
};
slt->ptrTableHead = (PSTR)malloc(10240);
strcat(slt->ptrTableHead , StringConn(14 , pList));
Cler(14 , pList);
//临时变量
PSTR pStmp = (PSTR)malloc(1024);
if(nPageSize<=11)
{
if(nPageIndex <= nPageSize)//如果请求的页面是<=一页显示的数据总量,那么这样的请求按正常执行
{
// 链接到最前面一页/向前一页
if(nPageIndex != 1) //当前第一页
{
if(nPageIndex != 2)
{
pList[0]=slt->ptrTableHead;
pList[1]=slt->ptrTd;
pList[2]=" pList[7]=slt->ptrMostfront;
pList[8]="";
pList[9]=slt->ptrTdEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
}
pList[0]=slt->ptrTableHead ;
pList[1]=slt->ptrTd ;
pList[2]=" pList[7]=itoa((nPageIndex-1),buffer , 10) ;
pList[8]=">" ;
pList[9]=slt->ptrNext ;
pList[10]="" ;
pList[11]=slt->ptrTdEnd ;
pStmp = StringConn(11 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(12 , pList);
}
// 列出一个页面所有页
for(int i=1; i<=nPageSize; i++)
{
if(i == nPageIndex)
{
pList[0] = slt->ptrTableHead ;
pList[1] = slt->ptrTd ;
pList[2] = "";
pList[3] = itoa(i , buffer , 10);
pList[4] = "" ;
pList[5] = slt->ptrTdEnd ;
pStmp = StringConn(6 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(6 , pList);
}
else
{
pList[0] = slt->ptrTableHead ;
pList[1] = slt->ptrTd ;
pList[2] = " pList[5] = itoa(i , buffer , 10);
pList[6] = ">";
pList[7] = itoa(i , buffer , 10);
pList[8] = "" ;
pList[9] = slt->ptrTdEnd ;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
}
}
// 链接到最后一页/向后移动一页
if(nPageIndex != nPageSize)
{
pList[0] = slt->ptrTableHead ;
pList[1] = slt->ptrTd ;
pList[2] = "";
pList[9] = slt->ptrTdEnd ;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
if((nPageSize+1)!= nPageSize) //查看当前请求页+1后是否不等于总页数
{
pList[0] = slt->ptrTableHead ;
pList[1] = slt->ptrTd ;
pList[2] = " pList[7] = itoa(nPageSize , buffer ,10 );
pList[8] = ">" ;
pList[9] = slt->ptrMostfront ;
pList[10] = "";
pList[11] = slt->ptrTdEnd ;
pStmp = StringConn(12 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(12 , pList);//到最末尾页
}
}
}
else //如果用户有恶意的请求--请求页大于总共页时
{
return ("抱歉,没有找到您请求的内容!");
}
}
else //当总共的页面大于11页时
{
// //如果当前页ID减5还大于或者等于1而且+5小于等于总页数时
if((nPageIndex-5)>=1&&(nPageIndex+5)<=nPageSize)
{
// 链接到最前面一页/向前一页
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[7] = slt->ptrMostfront ;
pList[8] = "" ;
pList[9] = slt->ptrTdEnd; //最前面,即第一页
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "<" ;
pList[8] = slt->ptrTdEnd; //向前移动一页
pStmp = StringConn(9 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(9 , pList);
//列出一个页面所有页
for(int i=nPageIndex-5;i<=nPageIndex+5;i++)//从当前页开始向前延伸5,向后延伸5,一次列出11个链接
{
if(i == nPageIndex)
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[3] = itoa(i , buffer , 10);
pList[4] = "";
pList[5] = slt->ptrTdEnd; //粗体字突显当前页链接文字
pStmp = StringConn(6 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(6 , pList);
}
else
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa(i , buffer , 10);
pList[6] = " >" ;
pList[7] = itoa(i , buffer , 10);
pList[8] = "";
pList[9] = slt->ptrTdEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
}
}
//链接到最后一页/向后移动一页
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[7] = itoa(nPageIndex+1 , buffer ,10);
pList[8] = ">";
pList[9] = slt->ptrNext ;
pList[10] = "";
pList[11] = slt->ptrTdEnd; //向后移动一页
pStmp = StringConn(12 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(12 , pList);
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = slt->ptrTitleHrefMostend;
pList[3] = " href=" ;
pList[4] = pLink ;
pList[5] = "=" ;
pList[6] = itoa(nPageSize,buffer , 10);
pList[7] = ">";
pList[8] = slt->ptrMostend;
pList[9] = "" ;
pList[10] = slt->ptrTdEnd; //最后一页
pStmp = StringConn(11 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(11 , pList);
}
//当到第5页时。。
if((nPageIndex-5)<1)
{
if(nPageIndex!=1)
{
if(nPageIndex!=2)
{
//第一页
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[7] = slt->ptrMostfront ;
pList[8] = "" ;
pList[9] = slt->ptrTdEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
}
//向前移动一页
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[9] = slt->ptrTdEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10 , pList);
}
//列表
for(int i=1;i<=11;i++)
{
if(i == nPageIndex)
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[3] = itoa(i , buffer , 10 );
pList[4] = "";
pList[5] = slt->ptrTdEnd;
pStmp = StringConn(6 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(6 , pList);
}
else
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa(i , buffer ,10) ;
pList[6] = " >" ;
pList[7] = itoa(i , buffer ,10) ;
pList[8] = "";
pList[9] = slt->ptrTdEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10, pList);
}
}
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[6] = itoa((nPageIndex+1) , buffer ,10);
pList[7] = ">";
pList[8] = slt->ptrNext ;
pList[9] = "";
pList[10] = slt->ptrTdEnd ;
pList[11] = slt->ptrTd ;
pList[12] = " pList[17] = itoa(nPageSize , buffer , 10 );
pList[18] = slt->ptrMostend;
pList[19] = "";
pList[20] = slt->ptrTdEnd;
pStmp = StringConn(21 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(21, pList);
}
if((nPageIndex+5)>nPageSize) //大于总页数
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[4] = slt->ptrMostfront ;
pList[5] = "" ;
pList[6] = slt->ptrTdEnd ;
pStmp = StringConn(7 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(7, pList);
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa((nPageIndex-1) , buffer , 10);
pList[6] = slt->ptrFront ;
pList[7] = "" ;
pList[8] = slt->ptrTdEnd ;
pStmp = StringConn(9 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(9, pList);
for(int i=nPageSize-10;i<=nPageSize;i++)
{
if(i==nPageIndex)
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = "" ;
pList[3] = itoa(i , buffer ,10);
pList[4] = "" ;
pList[5] = slt->ptrTdEnd ;
pStmp = StringConn(6 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(6, pList);
}
else
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa(i , buffer ,10);
pList[6] = ">" ;
pList[7] = itoa(i , buffer ,10);
pList[8] = "" ;
pList[9] = slt->ptrTdEnd ;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10, pList);
}
}
if(nPageIndex!=nPageSize&&nPageIndex<=nPageSize) //考虑到恶意用户对页请求是大于总页数的,如果用户是请求页就是大于总页数的 那么就是没有 > >|
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa((nPageIndex+1) , buffer ,10);
pList[6] = ">";
pList[7] = slt->ptrNext ;
pList[8] = "" ;
pList[9] = slt->ptrTdEnd ;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10, pList);
if((nPageIndex+1)!=nPageSize)
{
pList[0] = slt->ptrTableHead;
pList[1] = slt->ptrTd;
pList[2] = " pList[5] = itoa((nPageIndex+1) , buffer , 10);
pList[6] = ">";
pList[7] = slt->ptrMostend;
pList[8] = "" ;
pList[9] = slt->ptrTdEnd ;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10, pList);
}
}
}
}
pList[0] = slt->ptrTableHead ;
pList[1] = slt->ptrTrEnd;
pList[2] = slt->ptrTableHeadEnd;
pStmp = StringConn(10 , pList);
strcat(slt->ptrTableHead ,pStmp );
Cler(10, pList);
return slt->ptrTableHead;
}