 // 客户端 从数据库中取到的数据级对象
  // --> Delphi StringGrid
// --javascript Query 控件-22
function saveimage(photo_id,pid)
{
  var dbpage="../card2/pid_saveimage.jsp?person_id=&photoNo="+photo_id; 
  var str=getReturnShowModal(dbpage,self,0,0,0,0); 
  if (str!=-1)//取得相片的BASE64编码成功
          { 
            //var jpeg="c:\\tchclient\\"+pid+".jpg";           
			var jpeg=document.all.photo_path.value+"\\"+pid+".jpg";     
             var nRe=document.all.tchImage.saveBase64_ToFile(str,jpeg,"jpg");  
             if (nRe==1)
             {
				 return;
          //     document.all.img1.src="C://tchclient//cutBox64.jpg";//导入图片                
              }
             else
             {
               alert("base64转化失败");
             }
          }
          
	
}
function jsQuery()
{
  this.sql="";	
  this.rowCount=0;
  this.fieldCount=0;
  this.currRowIndex=-1;
  
    //增设翻页效果 在数据量多的情况下使用
  this.pageNo = 0;  //获取页码信息
  this.totalSize = -1;  //查询到得记录数大小
  this.packSize = 200;   //设置数据包
  this.pageSize=10;  //页面大小
  this.packRecordCount=100; //每个数据包大小
  this.searchPage="";   //翻页提交页 
  this.currentPageNo=0;
  this.start=1;
  this.avacount=1;  
  this.totalPageCount=1;
      //状态保存
  this.divName="div"; //显示网格对应的 div 
  this.objName="jsqry";  //类对应的实例名
  this.gridTb="tb";
  this.shooseColor="#a88deb";
     //打印
  this.printTitle="";    //打印标题
  this.openSqlType="openSql";
  

  this.fields=new Array();
  this.queryRows=new Array();
  this.addField=addField;
  this.getField=getField;    
  this.addRow=addRow;
  this.getString=getString;
  this.getStringByIndex=getStringByIndex;
  this.getStringByName=getStringByName;
  this.getFieldCount=getFieldCount;
  this.getRowCount=getRowCount;
  this.next=next;
  this.prior=prior;
  this.first=first;
  this.last=last;
  this.clear=clear;
  this.addSql=addSql;
  this.openSql=openSql;
  this.openSqlNoWin=openSqlNoWin;
  this.drawCheckBox=false;
  this.getHtmlByTable=getHtmlByTable;
  this.getHtmlByTitle_Tr=getHtmlByTitle_Tr;
  this.getHtmlByData_Tr=getHtmlByData_Tr;
  this.getHtmlByData_Tr_print=getHtmlByData_Tr_print;
  this.removeRow=removeRow;
  this.setCells=setCells;
  this.setRowVisible=setRowVisible;
  this.getRowVisible=getRowVisible;
  this.getFieldIndexByName=getFieldIndexByName;
  this.getRowByFieldValue=getRowByFieldValue;
  this.getFieldByName=getFieldByName;
  this.getVisibleQuery=getVisibleQuery;
        //翻页显示
  this.goToSearchPage=goToSearchPage;  
  this.goToSearchPageNoWin=goToSearchPageNoWin;  
  this.openSqlPage=openSqlPage;  
  this.openSqlPageNoWin=openSqlPageNoWin;  
  this.setTotalSize=setTotalSize; //查询到得记录数大小
  this.setPageSize=setPageSize;  //页面大小
  this.setCurrentPageNo=setCurrentPageNo; //设置当前页面
  this.setPackRecordCount=setPackRecordCount;  //设置每个数据包大小
  this.setPackSize=setPackSize;   //设置数据包
  this.getPackSize=getPackSize;
  this.getCurrentPageNo=getCurrentPageNo;
  this.getStart=getStart;
  this.setStart=setStart;
  this.getEnd=getEnd;   
  this.countTotalPageCount=countTotalPageCount;
  this.getHtmlByPage_Tb=getHtmlByPage_Tb;
  this.setHtmlByTable_Page=setHtmlByTable_Page;
  this.setHtmlByTable_PageNoWin=setHtmlByTable_PageNoWin;
  this.getTotalPageCount=getTotalPageCount;
  this.getTotalSize=getTotalSize; 
  this.hasNextPage=hasNextPage;
  this.hasPreviousPage=hasPreviousPage;
  this.setPrintTitle=setPrintTitle;
  this.copySelfNoData=copySelfNoData;
  this.copySelf_WithPrintFieldNoData=copySelf_WithPrintFieldNoData;
  this.setCheckBoxDraw=setCheckBoxDraw;  
  this.replaceAll=replaceAll;
 
  //add by zxh on 2004.11.25
  this.getHtmlByTable_card2=getHtmlByTable_card2;
  this.getHtmlByTable_print=getHtmlByTable_print;//印刷业增加
  this.getHtmlByDataCard2_Tr=getHtmlByDataCard2_Tr;
  this.cadr2pagesize=3;      //专门为二代证抽检时显示设置的每屏大小
  this.card2pageno=1;
  this.card2pagecount=1;
  this.setcard2pagesize=setcard2pagesize;
  this.setcard2pageno=setcard2pageno;
  this.getcard2pageno=getcard2pageno;
  this.getcard2pagecount=getcard2pagecount;
  //end add 
  
}
function setCheckBoxDraw(b)
{
   this.drawCheckBox=b;	
}
function clear()
{
  this.sql="";
}

function replaceAll(sourceStr,str,replaceStr) //add by fhb on 2004.6.17 修正 get 方法 或取 +号 的bug   	 
{
  while (sourceStr.indexOf(str)>=0)
  {
    sourceStr=sourceStr.replace(str,replaceStr);
  }
  return sourceStr;
}
function openSql(dbpage)
{
  var features =
              'dialogWidth:'  + 10  + 'px;' +
		'dialogHeight:' + 5 + 'px;' +
		'dialogLeft:'   + 1024   + 'px;' +
		'dialogTop:'    + 768 + 'px;' +
		'directories:no; localtion:no; menubar:no; status=no; toolbar=no;scrollbars:yes;Resizeable=no';
 
   //add by fhb on 2004.11.08 转 unicode 

  str=this.replaceAll(dbpage,"+","~~~");  //add by fhb on 2004.6.17 修正 get 方法 或取 +号 的bug 
   
  retval = window.showModalDialog(escapeUrl(str),"getClientSet", features );
  if  (retval)   //add by fhb 0n 2004.8.23
  {
    return retval;       
  }
  else
  {
    alert("访问"+str+"页面时出错！");
    return 0;		
  }
}


function openSqlNoWin(dbpage)  //add by fhb on 2004.8.23 不弹出窗口
{

  dbpage=escapeUrl(dbpage);  //add by fhb on 2004.11.08 转 unicode 

  str=this.replaceAll(dbpage,"+","~~~");  //add by fhb on 2004.6.17 修正 get 方法 或取 +号 的bug 
  var xmlDoc=new ActiveXObject("Msxml2.DOMDocument"); //("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load(str);
  var rootNode = xmlDoc.documentElement;
  if (rootNode!=null)
  {
    var node = rootNode.selectSingleNode("//returns");
    return node.text;
  }
  else 
  {
   alert("访问"+dbpage+"页面出错！");
   return 0;
  }
   
}

function openSqlNoWin1(dbpage)//hzf  
{

  dbpage=escapeUrl(dbpage);  

  str=this.replaceAll(dbpage,"+","~~~");  
  var xmlDoc=new ActiveXObject("Msxml2.DOMDocument");
  xmlDoc.async=false;
  xmlDoc.load(str);
  var rootNode = xmlDoc.documentElement;
  if (rootNode!=null)
  {
    var node = rootNode.selectSingleNode("//returns");
    return node.text;
  }
  else 
  {
   alert("访问"+dbpage+"页面出错！");
   return 0;
  }
   
}


function addSql(str)
{
  this.sql=this.sql+str;
}
function queryField(nIndex,sFieldName,fc,st,git)
{
  this.index=nIndex;
  this.fieldName=sFieldName;   //参数名称
  this.fieldCaption=fc;
  this.sqlType=st;   //java.sql.Types的基本参数 int ,date
  this.gridInputType=git ; //hidden,text,label,nodisplay 不可kan ,
}
function addRow(jsQueryRowObj)
{
  this.rowCount++;
  this.queryRows[this.rowCount-1]=jsQueryRowObj;
}
function removeRow(delRowIndex) //删除行
{  
  for (var i=delRowIndex;i<this.rowCount-1;i++)
     this.queryRows[i]=this.queryRows[i+1];    //行上移  
  this.rowCount=this.rowCount-1;  
   
}

function setRowVisible(nRowIndex,visible)  //将行设置 是否可视 
{
  this.queryRows[nRowIndex].visible=visible;
}	
function getRowVisible(nRowIndex)  //获取 行 是否可视 
{
  return this.queryRows[nRowIndex].visible;
}	

function getRowByFieldValue(sFieldName,sValue)  //通过 域值 来定位 第一次出现的行位置
{
  for (var n=0;n<this.rowCount;n++)
  {
   if (this.getStringByName(sFieldName,n)==sValue)
      return n;
  }  	  	
}
function setCells(nRowIndex,nFieldIndex,svalue)  //给网格对应的行列赋值
{ 
  var n=this.rowCount;
  for (var i=n;i<=nRowIndex;i++)
  {
    var jsRow=new jsQueryRow();
    this.addRow(jsRow);
  }
  this.queryRows[nRowIndex].fieldValues[nFieldIndex]=svalue;  	
  
}	

function addField(sFieldName,fc,st,git)
{
  this.fieldCount++;
  var qField=new queryField(this.fieldCount-1,sFieldName,fc,st,git);
  this.fields[this.fieldCount-1]=qField;
  return qField;

}
function getFieldIndexByName(sFieldName)  //获取字段域 
{
  for (var i=0;i<this.fieldCount;i++)
  {
     if (this.fields[i].fieldName.toLowerCase()==sFieldName.toLowerCase())
        return i;
  }    	 
}	
function getFieldByName(sFieldName)  //获取字段域 
{
  for (var i=0;i<this.fieldCount;i++)
  {
     if (this.fields[i].fieldName.toLowerCase()==sFieldName.toLowerCase())
        return this.fields[i];
  }    	 
}
function getField(nIndex)
{
  return this.fields[nIndex];
}

function getStringByIndex(nRowIndex,nIndex)
{	
   return this.queryRows[nRowIndex].fieldValues[nIndex];
}
  //获取值域的值
function getStringByName(sFieldName,nRowIndex)
{
 //  alert("rows value"+this.queryRows[nRowIndex].value);
  for (var i=0;i<this.fieldCount;i++)
  {
    // alert("getString :"+nRowIndex+":"+i+this.queryRows[nRowIndex].fieldValues[i]);
     if (this.fields[i].fieldName.toLowerCase()==sFieldName.toLowerCase())
        return this.queryRows[nRowIndex].fieldValues[i];
  }
}
   //获取当前行 值域 对应的值
function getString(sFieldName)
{
  return this.getStringByName(sFieldName,this.currRowIndex);
}
  //记录下移
function next()
{
  if (this.rowCount<1)
  {
    return false;
  }
  else
  {
    if (this.currRowIndex==this.rowCount-1)
      return false;
    else
    {
          this.currRowIndex++;
          return true ;
    }
  }
}

function getVisibleQuery(Visible)  //获取可视和不可视两类记录数 add by fhb on 2004.5.24
{
  var myQry=new jsQuery();
  for (var i=0;i<this.getFieldCount();i++)
  {	
    myQry.addField(this.fields[i].fieldName,this.fields[i].fieldCaption,this.fields[i].sqlType,this.fields[i].gridInputType);
  }
  this.first();
  while (this.next())
  {
    if (this.queryRows[this.currRowIndex].visible==Visible)  	
    {
      var  jsRow=new jsQueryRow();
      jsRow= this.queryRows[this.currRowIndex];
      myQry.addRow(jsRow);
    }    	
    
  }
  return myQry;
}


  //记录上移
function prior()
{
  if (this.rowCount<1)
  {
    return false;
  }
  else
  {
    if (this.currRowIndex<=0) //modi by fhb on 2004.5.24
      return false;
    else
    {
          this.currRowIndex=this.currRowIndex-1;
          return true ;
    }
  }
}


  //记录移到首条记录前
function first()
{
  if (this.rowCount<1)
  {
    return false;
  }
  else
  {
      this.currRowIndex=-1;
      return true ;
  }
}

  //记录移到末条记录后
function last()
{
  if (this.rowCount<1)
  {
    return false;
  }
  else
  {
      this.currRowIndex=this.rowCount;
      return true ;
  }
}

function getFieldCount()
{
  return  this.fieldCount;
}
function getRowCount()
{
  return  this.rowCount;
}
//add by fhb on 2004.5.13 生成 StringGrid 

function getHtmlByTable(tb,shooseColor)
{
     var Html="<table width='100%' cellspacing=1 cellpadding=5 class='tab_simple'>" ;
     Html+=this.getHtmlByTitle_Tr();
     
     Html+=this.getHtmlByData_Tr(tb,shooseColor);
     Html+="</table>";
     //alert(Html);
     return Html;
}

function getHtmlByTable_print(tb,shooseColor)
{
     var Html="<table width='100%' border='0' cellspacing=1 cellpadding=5 class='tab_simple'>" ;
     //Html+=this.getHtmlByTitle_Tr();
     
     Html+=this.getHtmlByData_Tr_print(tb,shooseColor);
     Html+="</table>";
     //alert(Html);
     return Html;
}	



function getHtmlByTitle_Tr()
{
    var html="";
    html+="<tr class='ctr_title'> ";
    if (this.drawCheckBox==true)   // checkBox 以支持多选 //add by fhb on 2004.5.13
    {
      html+="<td class='ctd_title'>选择</td>";
    }

   for (var i=0;i<this.fieldCount;i++) //显示标题
   {   
    html+="<td class='ctd_title'";
     if (this.fields[i].gridInputType=="nodisplay")
        html+=" style='display: none'";
    html+=">";
    html+=this.fields[i].fieldCaption;
    html+="</td>";
   }
   html+="</tr>";     
   
   return html;
   
}

  //显示数据，获取数据的Html方法
function getHtmlByData_Tr(tb,shooseColor)  //表名和选择后的颜色
{
	
  
  var html="";
  html+="<input type='hidden' id='currval_";
       html+=tb;
       html+="'>";
       html+="<tr class='ctr_data'> ";
  var tri=0;  //编号 从 1开始
  try
  {
      var n=this.fieldCount;
      this.first();
      while (this.next())
      {
        if (!this.drawCheckBox) 
          tri = tri+1; //modi by fhb on 2004.5.20
        else 
          tri=this.currRowIndex+1;  //modi  by fhb on 2004.6.16 +1 和dbgrid统一
        
        html+="<tr id='"+tb+"_tr"+tri+"' class=ctr_data bgcolor='#ffffff' ";
        if (this.queryRows[this.currRowIndex].visible)  //
          html+=" style='cursor:hand;'";
        else 
          html+=" style='cursor:hand; display: none;'";
        
        html+=" onclick=\"javascript:chooserow('"+tb+"',"+tri+" ,'"+shooseColor+"')\"> ";
        if (this.drawCheckBox)   // checkBox 以支持多选 //add by fhb on 2004.5.13
        {
              html+="<td class=ctr_data ";
              html+="/><input type=\"checkbox\" id='";
              html+=tb;
              html+="_ck";
              html+=tri-1;  //modi  by fhb on 2004.6.16 -1 和dbgrid统一
              html+="' name='";
              html+=tb;
              html+="_ck";
              html+=tri-1; //modi  by fhb on 2004.6.16 -1 和dbgrid统一
              html+="'></td>";


        }
         for (var i=0;i<n;i++) //显示数据
          {
          	
                  html+="<td  class=ctr_data id='";
                  html+=tb;
                  html+="_td";
                  html+=tri;
                  html+="_";
                  html+=this.fields[i].fieldName.toLowerCase();
                  html+="'";
                  if (this.fields[i].gridInputType=="nodisplay")
                    html+=" style='display: none'";
                  html+=" >";
               
                  html+=this.queryRows[this.currRowIndex].fieldValues[i];
                  html+="</td>";
                  
         }
        html+="</tr>";
    } //end while
  }
  catch(E)
  {
    html+="显示记录数据时出错，错误信息如下："+E;
  }
  return html;
  
}
function getHtmlByData_Tr_print(tb,shooseColor)  //表名和选择后的颜色
{
	
  
  var html="";
  html+="<input type='hidden' id='currval_";
       html+=tb;
       html+="'>";
       html+="<tr class='ctr_data'> ";
  var tri=0;  //编号 从 1开始
  try
  {
      var n=this.fieldCount;
      this.first();
      while (this.next())
      {
        if (!this.drawCheckBox) 
          tri = tri+1; //modi by fhb on 2004.5.20
        else 
          tri=this.currRowIndex+1;  //modi  by fhb on 2004.6.16 +1 和dbgrid统一
        
        html+="<tr id='"+tb+"_tr"+tri+"' class=ctr_data bgcolor='#ffffff' ";
        if (this.queryRows[this.currRowIndex].visible)  //
          html+=" style='cursor:hand;'";
        else 
          html+=" style='cursor:hand; display: none;'";
        
        html+=" onclick=\"javascript:chooserow('"+tb+"',"+tri+" ,'"+shooseColor+"')\"> ";
        if (this.drawCheckBox)   // checkBox 以支持多选 //add by fhb on 2004.5.13
        {
              html+="<td class=ctr_data ";
              html+="/><input type=\"checkbox\" id='";
              html+=tb;
              html+="_ck";
              html+=tri-1;  //modi  by fhb on 2004.6.16 -1 和dbgrid统一
              html+="' name='";
              html+=tb;
              html+="_ck";
              html+=tri-1; //modi  by fhb on 2004.6.16 -1 和dbgrid统一
              html+="'></td>";


        }
         for (var i=0;i<n;i++) //显示数据
          {
          	  if(i%2==0)//alter by hzf on 2005.11.8
          	    html+="<td width='18%' align=\"center\" bgcolor=\"#DAEFFF\" class=ctr_data id='  ";
          	  else  
                    html+="<td width='32%' class=ctr_data id='";
                  html+=tb;
                  html+="_td";
                  html+=tri;
                  html+="_";
                  html+=this.fields[i].fieldName.toLowerCase();
                  html+="'";
                  if (this.fields[i].gridInputType=="nodisplay")
                    html+=" style='display: none'";
                  html+=" >";
               
                  html+=this.queryRows[this.currRowIndex].fieldValues[i];
                  html+="</td>";
                  
         }
        html+="</tr>";
    } //end while
  }
  catch(E)
  {
    html+="显示记录数据时出错，错误信息如下："+E;
  }
  return html;
  
}

//add by zxh on 2004.11.25 for card2 DataGrid
function setcard2pagesize(pagesize)
{
    this.card2pagesize = pagesize;
}	
function getcard2pageno()
{
    return this.card2pageno;	
}	
function setcard2pageno(pageno)
{
    this.card2pageno=pageno;	
}
function getcard2pagecount()
{
    var counts=0;	
    this.first();
      while (this.next())
      {
      	if (this.queryRows[this.currRowIndex].visible)
        { 
           counts++;	
        }	
      }	
    if ((counts % this.card2pagesize)>0) 
       return parseInt(counts / this.card2pagesize)+1;
    else    
       return counts/this.card2pagesize;
       
}		

function getHtmlByTable_card2(tb,shooseColor)
{
     var Html="<table width='100%' height='100%' cellspacing=0 cellpadding=5><tr><td>";
     Html+="<table cellspacing=0 cellpadding=0>" ;
     Html+=this.getHtmlByDataCard2_Tr(tb,shooseColor);
     Html+="</table>";
     Html+="</td></tr></table>";
     return Html;          	
}	
function getHtmlByDataCard2_Tr(tb,shooseColor)  //表名和选择后的颜色
{
	
  var html="";
  html+="<input type='hidden' id='currval_";
       html+=tb;
       html+="'>";

       html+="<tr class=ctd_fzcss bgcolor='#ffffff' align='top' >";       

  var tri=0;  //编号 从 1开始
  var counts=0;  //第几个记录数
  var row_counts=0;//一行显示几个
  
  
  try
  {
      var n=this.fieldCount;
      this.first();
      while (this.next())
      {
        if (!this.drawCheckBox) 
          tri = tri+1; //modi by fhb on 2004.5.20
        else 
          tri=this.currRowIndex+1;  //modi  by fhb on 2004.6.16 +1 和dbgrid统一
        if (this.queryRows[this.currRowIndex].visible)  //只显示可见的记录
        {
          counts++;           		
          if ((counts>((this.card2pageno-1)*this.card2pagesize))&&(counts<=(this.card2pageno*this.card2pagesize))){
			  //modify by lsq 20050810
            if (counts%10==6)	//modify by lsq on 2005.3.16 分行显示十张图片||
            {  html+="</tr>";	        
              html+="<tr class=ctr_data bgcolor='#ffffff'>";   
              } 
            html+="<td id='"+tb+"_tr"+tri+"' valign=top";
           // html+=" style='cursor:hand;'";
            html+=" style=''";
            html+=" onclick=\"javascript:chooserow('"+tb+"',"+tri+" ,'"+shooseColor+"')\"";
            html+="> ";
            
            html+=" <table align=top cellspacing=0 cellpadding=1 class='tab_simple' style='border:1px solid #999999'>";
        
            if (this.drawCheckBox)   // checkBox 以支持多选 //add by fhb on 2004.5.13
            {
              html+="<tr class=ctr_title><td class=ctd_title ";
              html+="/><table cellpadding=1 cellspacing=0><tr><td><input type=\"checkbox\" id='";
              html+=tb;
              html+="_ck";
              html+=tri-1;  //modi  by fhb on 2004.6.16 -1 和dbgrid统一
              html+="' name='";
              html+=tb;
              html+="_ck";
              html+=tri-1;  //modi  by fhb on 2004.6.16 -1 和dbgrid统一
             // html+="'></td><td> 选择</td></tr></table></td></tr>";
			 //modify by lsq  20050817
	
			  if ((this.queryRows[this.currRowIndex].fieldValues[3].trim()=="已审核")||(this.queryRows[this.currRowIndex].fieldValues[3].trim()=="已抽检"))
                html+="' disabled ></td><td> 选择</td>";
			  else 
			     html+="'></td><td> 选择</td>";
              html+="<td style='color: #006600'>["+this.queryRows[this.currRowIndex].fieldValues[2]+"]</td><td style='color: #990000'>"+this.queryRows[this.currRowIndex].fieldValues[3]+"</td></tr></table></td></tr>";
            }
        
            //显示照片
			
            var photo_id=this.getString("IMAGE_ID");
			var pid=this.getString("pid");
			//调用tchimg.ocx保存本地图像
			//modify by lsq 20050812 如果未设置相片导出目录,就不进行相片导出,修改后可以跟莆田南平二代证共用
			if (document.all.photo_path.value!="")
               saveimage(photo_id,pid);
            html+="<tr class=card2_data>";
            html+="<td class=card2_data align=center>";     
			var imgpath=document.all.photo_path.value+"\\"+pid+".jpg";
			//alert(imgpath);
	        if (document.all.photo_path.value!="")
		      html+="<img src='"+imgpath+"' width='100' height='130' title='点击进行相片比对' id='img_"+photo_id+"' onclick=\"showphtotbd(\'img_"+photo_id+"\')\">";
		    else 
		      html+="<img src='../photo/showimagebyphotoid.jsp?photo_id="+photo_id+"' width='100' height='130'  title='点击进行相片比对' id='img_"+photo_id+"' onclick=\"showphtotbd(\'img_"+photo_id+"\')\">";
          // prompt('',html);
		   html+="</td></tr>";        
		//return;
            for (var i=0;i<n;i++) //显示数据
            {
                  html+="<tr class=card2_data align=center";
                  if (this.fields[i].gridInputType=="nodisplay")
                    html+=" style='display: none'";
                  if (this.queryRows[this.currRowIndex].fieldValues[i]=="与户籍信息不一致")
                    html+=" style='color: #FF0000'";                    
                  html+=">";
                  html+="<td class=card2_data id='";
                  html+=tb;
                  html+="_td";
                  html+=tri;
                  html+="_";
                  html+=this.fields[i].fieldName.toLowerCase();
                  html+="'";
                  html+=" title='"+this.fields[i].fieldCaption+"'>";
                  
                  html+=this.queryRows[this.currRowIndex].fieldValues[i];
                  
                  html+="</td></tr>";
                  
            }
            html+="</table></td>";
			
          }
                
      }  //end if (visible)  
    } //end while
  }
  catch(E)
  {
    html+="显示记录数据时出错，错误信息如下："+E;
  }
  html+="</tr>";
  return html;
  
  
}
//end add on 2004.11.25



  //翻页效果 add by fhb on 2004.6.4 

function setHtmlByTable_Page(divName,objName,tb,shooseColor) //add by fhb on 2004.6.7 
{
     this.divName=divName; //显示网格对应的 div 
     this.objName=objName;  //类对应的实例名	
     this.gridTb=tb;
     this.shooseColor=shooseColor;
     
     this.countTotalPageCount();  //计算页码
     	
     var Html="<table width='100%' cellspacing=1 cellpadding=5 class='tab_simple'>" ;
     
     Html+="<tr><td>";
     Html+=this.getHtmlByTitle_Tr();
     Html+=this.getHtmlByData_Tr(tb,shooseColor);
     Html+="</td></tr>";
     Html+="<tr><td colspan='388'>";
     Html+=this.getHtmlByPage_Tb(objName+".goToSearchPage","jsPageNo");
     Html+="</td></tr>";
     Html+="</table>";     
     
     eval("document.all."+divName+".innerHTML=Html;");//写入网格
}	
  
  
function setHtmlByTable_PageNoWin(divName,objName,tb,shooseColor) //add by fhb on 2004.8.25 没有弹出窗口 
{
     this.divName=divName; //显示网格对应的 div 
     this.objName=objName;  //类对应的实例名	
     this.gridTb=tb;
     this.shooseColor=shooseColor;
     
     this.countTotalPageCount();  //计算页码
     	
     var Html="<table width='100%' cellspacing=1 cellpadding=5 class='tab_simple'>" ;
     
     Html+="<tr><td>";
     Html+=this.getHtmlByTitle_Tr();
     Html+=this.getHtmlByData_Tr(tb,shooseColor);
     Html+="</td></tr>";
     Html+="<tr><td colspan='388'>";
     Html+=this.getHtmlByPage_Tb(objName+".goToSearchPageNoWin","jsPageNo");
     Html+="</td></tr>";
     Html+="</table>";     
     
     eval("document.all."+divName+".innerHTML=Html;");//写入网格
}	  

function openSqlPage(dbpage)
{
  var features =
              'dialogWidth:'  + 10  + 'px;' +
		'dialogHeight:' + 5 + 'px;' +
		'dialogLeft:'   + 200   + 'px;' +
		'dialogTop:'    + 200 + 'px;' +
		'directories:no; localtion:no; menubar:no; status=no; toolbar=no;scrollbars:yes;Resizeable=no';

  
  this.searchPage=dbpage;
  var str=dbpage+"&pageNo="+this.pageNo;
  str=str+"&totalSize="+this.totalSize;
  str=str+"&packSize="+this.packSize;
  str=str+"&pageSize="+this.pageSize;
  str=str+"&packRecordCount="+this.packRecordCount;

  

  str=this.replaceAll(str,"+","~~~");  //add by fhb on 2004.6.17 修正 get 方法 或取 +号 的bug 

    //add by fhb on 2004.11.08 转 unicode   
  
  retval = window.showModalDialog(escapeUrl(str),"getClientSet", features );
  if  (retval)   //add by fhb 0n 2004.8.23
  {
    return retval;       
  }
  else
  {
    alert("访问"+str+"页面时出错！");
    return 0;		
  }
    
}


function openSqlPageNoWin(dbpage)  // add by fhb on 2004.8.25 翻页显示 ,不弹出窗体
{
  this.searchPage=dbpage;
  var str=dbpage+"&pageNo="+this.pageNo;
  str=str+"&totalSize="+this.totalSize;
  str=str+"&packSize="+this.packSize;
  str=str+"&pageSize="+this.pageSize;
  str=str+"&packRecordCount="+this.packRecordCount;
 
  str=escapeUrl(str);  //add by fhb on 2004.11.08 转 unicode  

  str=this.replaceAll(str,"+","~~~");  //add by fhb on 2004.6.17 修正 get 方法 或取 +号 的bug 
  
  var xmlDoc=new ActiveXObject("Msxml2.DOMDocument"); //("Microsoft.XMLDOM");
  xmlDoc.async=false;
  xmlDoc.load(str);
  var rootNode = xmlDoc.documentElement;
  if (rootNode!=null)
  {
    var node = rootNode.selectSingleNode("//returns");
    return node.text;
  }
  else 
  {
   alert("访问"+dbpage+"页面出错！");
   return 0;
  }
  
}

function goToSearchPageNoWin(size,packSize)  //跳转页面
{	
  this.setCurrentPageNo(size);
  this.setPackSize(packSize);  
  
  var str=this.openSqlPageNoWin(this.searchPage+"&needField=0");  
    //重画网格
  if (str!=0)
  {
     this.queryRows=new Array(); //删除原有数据
     this.rowCount=0;
     this.currRowIndex=-1;
     eval(str);  //动态执行以获取记录集     
     this.setHtmlByTable_PageNoWin(this.divName,this.objName,this.gridTb,this.shooseColor);
  }
  else
  {
     return;
  }
  
}

function goToSearchPage(size,packSize)  //跳转页面
{	
  this.setCurrentPageNo(size);
  this.setPackSize(packSize);  
  
  var str=this.openSqlPage(this.searchPage+"&needField=0");  
    //重画网格
  if (str!=0)
  {
     this.queryRows=new Array(); //删除原有数据
     this.rowCount=0;
     this.currRowIndex=-1;
     eval(str);  //动态执行以获取记录集     
     this.setHtmlByTable_Page(this.divName,this.objName,this.gridTb,this.shooseColor);
  }
  else
  {
     alert("查询数据库中的其他页数据出错！");
     return;
  }
  
}

function setTotalSize(size) //查询到得记录数大小
{
  this.totalSize =size;  //查询到得记录数大小
}
function setPageSize(size)  //页面大小
{
  this.pageSize=size;  //页面大
}
function setCurrentPageNo(size) //设置当前页面
{
  this.pageNo =size;  //获取页码信息
  this.currentPageNo=size; 
}
function setPackRecordCount(size)  //设置每个数据包大小
{
  this.packRecordCount=size; //每个数据包大小
}	
function setPackSize(size)   //设置数据包
{
  this.packSize = size;   //设置数据包
}
function getCurrentPageNo()
{  
  return this.currentPageNo;
}
     /** 是否有下一页 */
function hasNextPage() {
	//alert(this.getCurrentPageNo()+":"+this.getTotalPageCount());
     return (this.getCurrentPageNo()<this.getTotalPageCount());
}
     /* 是否有上一页   */
function hasPreviousPage() {
       return (this.getCurrentPageNo()>1);
}
function  getStart(){
    return this.start;
 }
function  setStart(size){
   this.start=size;
 }

    /** 获取当前页最后一条数据在数据库中的位置  */
function getEnd(){
   var end = this.start + this.avaCount-1;
   if (end<0) {
       end = 0;        }
   return end;
 }

function countTotalPageCount()
{
   this.totalPageCount = Math.floor((this.totalSize + this.pageSize - 1) / this.pageSize);
   var n=this.totalSize-this.start;
   if (n>this.pageSize)
      this.avaCount=this.pageSize;
   else
      this.avaCount=n+1;
      
        
}

function getTotalPageCount()
{
  return this.totalPageCount;
}
function getPackSize()
{
  return this.packSize;
}
function getTotalSize()
{
  return this.totalSize;
}
  //增设页码 
function getHtmlByPage_Tb(queryJSFunctionName,pageNoParamName){	
	
   if (this.getTotalPageCount()<1){
      return "<input type='hidden' name='"+pageNoParamName+"' value='1' >";
   }
      
   var  gotoPage =queryJSFunctionName;  //类的跳转事件
    
   var html="";
   
   html+= "<table align=left border=0 cellspacing=0 cellpadding=0 align=center width=600>  ";
   html+= "  <tr class='ctr_page'>  "; 
       //drawCheckBox  add by fhb on 2004.6.18    
   if (this.drawCheckBox==true)
   {
        html+="<td class=ctr_data ";
        html+="/>&nbsp;<input type=\"checkbox\" name='";
        html+=this.objName;
        html+="_ck' onClick=\"setAllInputValueOnGrid('"+this.gridTb+"','checkbox',this.checked)\">全选</td>";
	
   }
   html+= "    <td class='ctd_page' valign='bottom' > " ;
   
   if (this.getTotalSize()!=this.packSize) //add by fhb on 2004.7.5
     html+=   "       共"; 
   else 
     html+=   "       前"; 	
      
   html+= this.getTotalPageCount() ;
   html+= "页" ;
   html+=  "       [";
       html+= this.getStart();
       html+= "..";
       html+= this.getEnd();
       html+= "/";
       html+= this.getTotalSize();
       html+= "]  ";
   html+= "    </td>  " ;   
   
   html+= "<td valign='bottom'> <a href=\"javascript:gridPrint('"+this.objName+"','"+this.openSqlType+"')\"> 打印列表</a></td>"
   
   html+= "    <td class='ctd_page' align=right>  ";
    if (this.hasPreviousPage()){
        html+=  "[<a href='javascript:";
            html+= gotoPage;
           html+= "(";
           html+= this.getCurrentPageNo()-1;
           html+= ",";
           html+= this.getPackSize();
       html+= ")'>上一页</a>]   ";
     }
   html+=   "       第";
   html+=   "        <select name='";
       html+= pageNoParamName;
       html+= "' onChange='javascript:";
       html+= gotoPage;
       html+= "(this.value,";
       html+= this.getPackSize();
       html+= ")'>";

  var  s_selected = "selected";
  for(var i=1;i<=this.getTotalPageCount();i++){
  if( i == this.getCurrentPageNo() )
     s_selected = "selected";
    else s_selected = "";
      html+=  "      <option value='";
     html+= i;
     html+= "' ";
     html+= s_selected;
     html+= ">";
     html+= i;
     html+= "</option>  ";        }
     if (this.getCurrentPageNo()>this.getTotalPageCount()){
          html+=  "      <option value='";
              html+= this.getCurrentPageNo();
              html+= "' selected>";
              html+= this.getCurrentPageNo();
              html+= "</option>  ";        }
        html+=  "    </select>页  ";
if (this.hasNextPage()){
       html+=  "    [<a href='javascript:";
           html+= gotoPage;
           html+= "(";
           html+= (this.getCurrentPageNo()+1);
           html+= ",";
           html+= this.getPackSize();
       html+= ")'>下一页</a>]   ";
     }

if (this.getTotalSize()==this.packSize) //add by fhb on 2004.4.27 数据包
{
       html+=  "    [<a href='javascript:";
           html+= gotoPage;
           html+= "(";
           html+= this.getTotalPageCount()+1;
           html+= ",";
           html+=(this.packSize+this.packRecordCount);
       html+= ")'>下一包</a>]   ";
}
if (this.getTotalSize()==this.packSize) //add by fhb on 2004.4.27 数据包 取所有数据包
{
            html+=  "    [<a href='javascript:";
                html+= gotoPage;
                html+= "(";
                html+= this.getTotalPageCount()+1;
                html+= ",";
                html+= "99999999";
            html+= ")'>所有包</a>]   ";
}

      html+=  "</td></tr></table>  ";
       //数据包显示



   return html;
}
   //打印   //add by fhb on 2004.6.10
function setPrintTitle(printtitle,opensqltype)
{ 
  this.printTitle=printtitle;
  this.openSqlType=opensqltype;
}
function copySelfNoData()  //复制自身，防止直接用= 赋值产生的错误
{
  var myQry=new jsQuery();
  for (var i=0;i<this.getFieldCount();i++)
  {	
    myQry.addField(this.fields[i].fieldName,this.fields[i].fieldCaption,this.fields[i].sqlType,this.fields[i].gridInputType);
  }
   myQry.sql=this.sql;
   myQry.setTotalSize(this.totalSize); //查询到得记录数大小
   myQry.setPageSize(this.pageSize);  //页面大小
   myQry.setCurrentPageNo(this.currentPageNo); //设置当前页面
   myQry.setPackRecordCount(this.packRecordCount);  //设置每个数据包大小
   myQry.setPackSize(this.packSize);   //设置数据包
   myQry.setPrintTitle(this.printTitle,this.openSqlType);
   
  return  myQry;
 
}

function copySelf_WithPrintFieldNoData()  //复制自身， 用于打印
{
  var myQry=new jsQuery();
  for (var i=0;i<this.getFieldCount();i++)
  {	
    if (this.fields[i].gridInputType!="nodisplay") 
      myQry.addField(this.fields[i].fieldName,this.fields[i].fieldCaption,this.fields[i].sqlType,this.fields[i].gridInputType);
  }
   myQry.sql=this.sql;
   myQry.setTotalSize(this.totalSize); //查询到得记录数大小
   myQry.setPageSize(this.pageSize);  //页面大小
   myQry.setCurrentPageNo(this.currentPageNo); //设置当前页面
   myQry.setPackRecordCount(this.packRecordCount);  //设置每个数据包大小
   myQry.setPackSize(this.packSize);   //设置数据包
   myQry.setPrintTitle(this.printTitle,this.openSqlType);
   
   return  myQry;
 
}
