fcRep.js
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:128k
- {
- SaveoUndoOneRecord()
- //从外部复制来的数据
- var arrRow,arrCol
- arrRow=clipboard.split("n")
- for (var i=0 ;i<arrRow.length;i++) {
- arrCol=arrRow[i].split("t")
- for (var j=0;j<arrCol.length;j++) {
- var arr=PhyToLog(i+sRowSort,j+sColSort)
- var curTD=t.rows(arr[0]).cells(arr[1])
- //var logCol=physicalToLogic(i+sRow,j+sCol)
- try {
- curTD.innerText=arrCol[j]
- }
- catch (e) {}
- }
- }
- SaveoRedoOneRecord()
- clearBlueScale()
- }
- return
- //}
- //如果是选定单个单元格则用平铺的方法粘贴
- var blnBlockTile=false//块平铺
- var lngStatus=SelStatus(sRow,sCol,eRow,eCol)
- if (lngStatus==1){
- blnBlockTile=true
- }
- else{
- //检查区域是否匹配
- if ((eRowSort-sRowSort+1)*(eColSort-sColSort+1)!=(blockObjAry.length-2) || (eRowSort-sRowSort)!=blockObjAry[0] || (eColSort-sColSort)!=blockObjAry[1]){
- alert("复制的区域与粘贴的区域形状不同,不能完成粘贴,请选定一区域使该区域与源区域的大小和形状一致,再粘贴!")
- return
- }
- }
- //检查粘贴的区域中是否有合并的单元格
- /*
- if (oRect.documentElement.xml.length>13)
- {
- var eRowno,eColno
- if (blnBlockTile==false)
- eRowno=eRow
- else
- eRowno=sRow+blockObjAry[0]
-
- if (blnBlockTile==false)
- eColno=eCol
- else
- eColno=sCol+blockObjAry[1]
- var oSel=oRect.documentElement.selectSingleNode("//record[row0='" + sRow + "' and col0='" + sCol+ "' and row1='" + eRowno + "' and col1='" + eColno+ "']")
- if (oSel!=null)
- {
- //alert("重合拆分")
- //处理重合,拆分的情况,选中一个合并后的大格
- alert("粘贴的区域中有合并单元格,不能完成粘贴,请选定一区域使该区域与源区域的大小和形状一致,再粘贴!")
- return
- }
- else
- {
- for (i=0;i<=oRect.documentElement.childNodes.length-1;i++)
- {
- var oChild=oRect.documentElement.childNodes.item(i)
- if (parseInt(oChild.childNodes.item(0).text)>eRowno||parseInt(oChild.childNodes.item(1).text)>eColno||parseInt(oChild.childNodes.item(2).text)<sRow||parseInt(oChild.childNodes.item(3).text)<sCol)
- {//没有相交
- }
- else
- {//有相交
- alert("粘贴的区域中有合并单元格,不能完成粘贴,请选定一区域使该区域与源区域的大小和形状一致,再粘贴!")
- return
- }
- }
- }
- }
- */
- //块粘贴
- SaveoUndoOneRecord()//在改变之前保存住位置,备undo时装入
- var i,j
- var inx=2
- var sColno,eColno
- var eRowno//结束行
- if (blnBlockTile==false)
- eRowno=eRowSort
- else
- eRowno=sRowSort+blockObjAry[0]
- for (i=sRowSort;i<=eRowno;i++){
- if (i>=t.rows.length)
- break
- sColno=sColSort
- if (blnBlockTile==false)
- eColno=eColSort
- else
- eColno=sColSort+blockObjAry[1]
- /*
- var osFind=oCoor.documentElement.selectNodes("//record[row='" + i + "' and col='" +sCol +"']")
- if (osFind.length>=1)
- sColno=parseInt(osFind.item(0).childNodes.item(2).text)
- var osFind=oCoor.documentElement.selectNodes("//record[row='" + i + "' and col='" +eColno +"']")
- if (osFind.length>=1)
- eColno=parseInt(osFind.item(0).childNodes.item(2).text)
- */
- for (j=sColno;j<=eColno;j++){
- var arr=PhyToLog(i,j)
- var curTD=t.rows(arr[0]).cells(arr[1])
- if (j>=t.rows(0).cells.length){
- inx=inx+sColno+blockObjAry[1]-j
- break
- }
- curTD.innerText=blockObjAry[inx]
- //curTD.replaceNode(blockObjAry[inx])
- //将粘贴的单元格的行高与列宽修改成本单元格的行高与列宽
-
- inx=inx+1
- }
- }
- //块删除
- blockObjAry=new Array()
- SaveoRedoOneRecord()//在改变之后保存住位置,备redo时装入
- //将选择单元的值给文本框tdtotxt
- /* var arr=PhyToLog(sRow,sCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- txtMyGrid.value=curTD.innerText
- ExitMe()
- */
- clearBlueScale()
- txtMyGrid.style.display="none"
- }
- /**
- *工具栏上的格式刷按钮的点击事件
- **/
- function cmdFormatBrush() {
- if(blnRunMode)return
- if (cmdBrush.getAttribute("fcDown")=="1") {
- cmdBrush.setAttribute("fcDown","0")
- cmdBrush.className="tblclassup"
- }
- else {
- cmdCopyFormat()
- cmdBrush.setAttribute("fcDown","1")
- cmdBrush.className="divmenutrue"
- }
- }
- /**
- *工具栏上的复制按钮的点击事件
- **/
- function cmdCopyFormat() {
- if (tc.style.display =="none")
- return
-
- // if (lngStatus==3 || lngStatus==4 ){
- // alert("选择的区域内有合并单元格,不能做块复制!")
- // return
- // }
- FormatRow=sRow
- FormatCol=sCol
- }
- /**
- *工具栏上的粘贴按钮的点击事件
- **/
- function cmdPasteFormat() {
- SaveoUndoOneRecord()
- var arrFormat=PhyToLog(FormatRow,FormatCol)
-
- var i,j
- for (i=sRowSort;i<=eRowSort;i++)
- {
- for (j=sColSort;j<=eColSort;j++) {
- var arr=PhyToLog(i,j)
- var curTD=t.rows(arr[0]).cells(arr[1])
- var gNodeTD=t.rows(arrFormat[0]).cells(arrFormat[1]).cloneNode(true)
- gNodeTD.rowSpan=curTD.rowSpan
- gNodeTD.colSpan=curTD.colSpan
- var sTmp=curTD.innerText
- curTD.replaceNode(gNodeTD)
- t.rows(arr[0]).cells(arr[1]).innerText=sTmp
- }
- }
-
- SaveoRedoOneRecord()
- }
- /**
- *删除所有的oUndo与oRedo对象中的节点
- **/
- function initoUndooRedo(){
- lngUndo=-1//childNodes.item(0)从0开始
- lngRedo=-1
- cmdUndo.disabled =true
- cmdRedo.disabled =true
- oUndo.loadXML("<root></root>")
- oRedo.loadXML("<root></root>")
- }
- /**
- *增加一行oRedo对象的记录,按先进先出的规则,保持只有8条记录
- **/
- function SaveoRedoOneRecord(){
- var root = oRedo.documentElement
- var newNode = oRedo.createNode (1, "record", "")
- root.appendChild(newNode)
- var newElem = oRedo.createElement("cell") //表格
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(t.outerHTML )
- var newElem = oRedo.createElement("cellcopy") //表格Copy
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(tCopy.outerHTML )
- var newElem = oRedo.createElement("oFormula")
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(oFormula.documentElement.xml)
- if (oRedo.documentElement.childNodes.length >8) {
- DeleteoRedoOneRecord(0)
- }
- }
- /**
- *增加一行oUndo对象的记录,按先进先出的规则,保持只有8条记录
- **/
- function SaveoUndoOneRecord(){
- var root = oUndo.documentElement
- var newNode = oUndo.createNode (1, "record", "")
- root.appendChild(newNode)
- var newElem = oUndo.createElement("cell") //表格
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(t.outerHTML )
- var newElem = oUndo.createElement("cellcopy") //表格
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(tCopy.outerHTML )
- var newElem = oUndo.createElement("oFormula")
- newNode.appendChild(newElem)
- newNode.lastChild.text = escape(oFormula.documentElement.xml)
-
- lngUndo=lngUndo+1
- cmdUndo.disabled =false//可以undo
- if (oUndo.documentElement.childNodes.length >8) {
- DeleteoUndoOneRecord(0)
- lngUndo=7//从0-7
- }
- }
- /**
- *读出一行oUndo对象的记录
- **/
- function ReadoRedoOneRecord(lngKey){
- t.outerHTML=unescape(oRedo.documentElement.childNodes.item(lngKey).childNodes.item(0).childNodes.item(0).xml)
- grid.reload(t.outerHTML)
- tCopy.outerHTML=unescape(oRedo.documentElement.childNodes.item(lngKey).childNodes.item(1).childNodes.item(0).xml)
- oFormula.loadXML (unescape(oRedo.documentElement.childNodes.item(lngKey).childNodes.item(2).childNodes.item(0).xml))
- }
- /**
- *读出一行oUndo对象的记录
- **/
- function ReadoUndoOneRecord(lngKey){
- t.outerHTML=unescape(oUndo.documentElement.childNodes.item(lngKey).childNodes.item(0).childNodes.item(0).xml)
- grid.reload(t.outerHTML)
- tCopy.outerHTML=unescape(oUndo.documentElement.childNodes.item(lngKey).childNodes.item(1).childNodes.item(0).xml)
- oFormula.loadXML (unescape(oUndo.documentElement.childNodes.item(lngKey).childNodes.item(2).childNodes.item(0).xml))
- }
- /**
- *删除Redo一行记录,按先进先删的规则,保持只有8条记录
- * intR=0删除第一个节点
- **/
- function DeleteoRedoOneRecord(intR){
- oRedo.documentElement.removeChild(oRedo.documentElement.childNodes.item(intR))
- }
- /**
- *删除Undo一行记录,按先进先删的规则,保持只有8条记录
- * intR=0删除第一个节点
- **/
- function DeleteoUndoOneRecord(intR){
- oUndo.documentElement.removeChild(oUndo.documentElement.childNodes.item(intR))
- }
- /**
- *工具栏上的Redo按钮的点击事件
- **/
- function cmdRedo(){
- var intMaxR=oRedo.documentElement.childNodes.length - 1//当前oRedo对象中的最大记录数
- if (lngRedo>=0 && lngRedo<=intMaxR){
- ReadoRedoOneRecord(lngRedo)//读出当前undo对应的值
- lngUndo=lngRedo
- lngRedo=lngRedo+1
- cmdUndo.disabled =false//做了一步redo则undo肯定可以做
- //强制表格宽高同步
- if(grid.autosize){
- grid.autosize=true
- }
- //clearBlueScale()
- }
- if (lngRedo>intMaxR && lngRedo<0){
- cmdRedo.disabled =true //肯定不能做redo的功能
- }
- }
- /**
- *工具栏上的Undo按钮的点击事件
- **/
- function cmdUndo(){
- var intMaxR=oUndo.documentElement.childNodes.length - 1//当前oRedo对象中的最大记录数
- if (lngUndo>=0 && lngUndo<=intMaxR){
- ReadoUndoOneRecord(lngUndo)
- lngRedo=lngUndo
- lngUndo=lngUndo - 1
- cmdRedo.disabled =true//做了一步undo则redo肯定可以做
-
- //强制表格宽高同步
- if(grid.autosize){
- grid.autosize=true
- }
- //clearBlueScale()
- }
- if (lngUndo<=0 && lngUndo>intMaxR){
- cmdUndo.disabled =true//undo肯定不可以做
- }
- if (lngUndo>=intMaxR && lngUndo<0){
- cmdRedo.disabled =true//redo肯定不可以做
- }
- }
- /**
- *公式处理
- *预处理公式,将公式中的B5 等标记变成GetCell(5,2)
- *公式中的SUM(A2:F8)等展开成一个个单元格的形式.
- *getcell(row(),2)之类的公式,将它的坐标中的公式值计算出来
- **/
- function replaceFormula(strFormula){
- var r
- var re
- var strSearch//
- var strReplace
- var lngPrePos
- var j
- var blnEnd=false
- //下面这行先不变大写20020627
- //strFormula=strFormula.toUpperCase()
- //下面将公式中的SUM(A2:F8)等展开成一个个单元格的形式.
- strFormula=getFunctionValue(strFormula)
- //------------------
- //getcell(row(),2)之类的公式,将它的坐标中的公式值计算出来
- //ROW() COL() + - * / 只支持前面这些操作符
- /*
- var sExp=/GETCELL((ROW()|COL()|d|+|-|*|/)*,(ROW()|COL()|d|+|-|*|/)*[,|)]/ig //new RegExp("S","ig")
- var re=strFormula.match(sExp)
- if (re!=null) {
- for (var i=0;i<=re.length-1;i++){
- var s1=re[i]
- var endS=s1.substring(s1.length-1,s1.length)
- s1=s1.substring(8,s1.length-1)
- var arr=s1.split(",")
-
-
- s1="GETCELL("+eval(arr[0])+","+eval(arr[1])+endS
-
- strFormula=strFormula.replace(re[i],s1)
- //alert(strFormula)
- // alert("length:"+re.length+" "+re[0]+" "+re[1])
- }
- }
- */
- //-------------------
-
- strFormula=" " +strFormula+" "
- re=/(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9]))[^0-9]/ig
- r=strFormula.match(re)
- if(r!=null){
- var lngPrePos=0
- var lngPrePos1=0
- var strRet="" //返回公式
- //加此循环是为了替代一个公式中的多个A2
- for (var i=0;i<=r.length-1;i++){
- strSearch=trim(r[i].substring(0,r[i].length-1))//取出的一个标志符
- var strChar,strInt
- var iLength=strSearch.length-1
- var sCurRow,sCurCol
- var lngA
- for (var ii=0;ii<=iLength;ii++){
- lngA=parseInt(strSearch.charCodeAt(ii))
- if (lngA>=49 && lngA<=57){
- var strChar=strSearch.substring(0,ii)
- var strInt=strSearch.substring(ii,iLength+1)
- break;
- }
- }
- //由B5==>行和列数
- sCurRow=strInt
- sCurCol=LblToInt(strChar)
-
- //-----------
- //将GetCellValue函数用getCell取代
- strReplace="GETCELL("+sCurRow+","+sCurCol+")"
- lngPrePos1=strFormula.indexOf(strSearch,lngPrePos)
- if (lngPrePos1>0){
- //替换字符
- strRet=strRet+strFormula.substring(lngPrePos,lngPrePos1)+strReplace
- lngPrePos=lngPrePos1+strSearch.length
- }
- else {
- //此行可能无用
- strRet=strRet+strFormula.substring(lngPrePos,strFormula.length-1)
- }
- }
- strRet=strRet+strFormula.substring(lngPrePos,strFormula.length-1)
- return trim(strRet)
- }
- return trim(strFormula)
- }
- /**
- *找本表页的单元格的值
- **/
- function GETCELL(iRow,iCol) {
- return GetCellData(iRow,iCol)
- }
- /**
- *设置单元值
- *@param iRow 物理行值
- *@param iCol 列值
- *@param vData 要设置单元值
- **/
- function SetCellData(iRow,iCol,vData) {
- //先计算出逻辑列,因逻辑行和物理行相同
- var arr=PhyToLog(iRow,iCol)
- var curObj1=t.rows(arr[0]).cells(arr[1])
- //给值时做小数位处理
- CellPoint(curObj1,vData)
- /*
- if (isSpace(curObj1.getAttribute("dec"))==false)
- curObj1.innerText=ContDec(vData,curObj1.getAttribute("dec"))
- else
- curObj1.innerText=vData
- */
- }
- /**
- *取得单元值
- *@param iRow 物理行值
- *@param iCol 列值
- *@return 单元值
- **/
- function GetCellData(iRow,iCol) {
- //先计算出逻辑列,因逻辑行和物理行相同
-
- var arr=PhyToLog(iRow,iCol)
- var s1=t.rows(arr[0]).cells(arr[1]).innerText
- //alert(s1)
- //让返回null是为了计算公式时""会使数值变成字符
- if(s1=="") return null
- //-----------
- if (isNaN(parseFloat(s1)))
- return s1
- else
- return parseFloat(s1)
- }
- /**
- //求出自定义公式的值
- **/
- function getFunctionValue(strFormula,strLblSelf){
- //strFormula=computeFunctionValue(strFormula,"getreportcell")//求表间取数
- strFormula=computeFunctionValue(strFormula,"sum")//求和
- strFormula=computeFunctionValue(strFormula,"avg")//求平均
- strFormula=computeFunctionValue(strFormula,"max")//求最大值
- strFormula=computeFunctionValue(strFormula,"min")//求最小值
- return strFormula
- }
- /**
- //求出自定义公式的值
- **/
- function computeFunctionValue(strFormula,strKey){
- //最大最小值未处理2001.12.21
- var i,j
- strKey=trim(strKey.toUpperCase())
- //if (strKey=="GETREPORTCELL")
- // var re=new RegExp(strKey+".([1-9]|([1-9][0-9])|([1-9][0-9][0-9])|([1-9][0-9][0-9][0-9]))"+","+"(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9]))[^0-9]","ig")
- //else
- var re=new RegExp(strKey+".(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9])):(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9]))[^0-9]","ig")
- var r=strFormula.match(re)
- if (r==null)
- return strFormula
- var dblSum=""
- switch (strKey){
- /*case "GETREPORTCELL":
- for (i=0;i<=r.length-1;i++){
- var strQuote=r[i].substring(0,14)+"'"+r[i].substring(14,r[i].length -1) + "')" //插入单引号
- var strExpr=replaceString(r[i],r[i],strQuote)
- var dblCellValue=DealPoint(strExpr)
- //var dblCellValue=eval(strExpr)
- strFormula=replaceString(strFormula,r[i],dblCellValue)
- }
- break;*/
- case "SUM":
- for (i=0;i<=r.length-1;i++){
- var retAry=getAllLabelAry(r[i])//得到所有标签的公式的数组
- dblSum="("
- for (j=0;j<retAry.length;j++ ){
- // dblSum=dblSum+parseFloat(retAry[j])
- dblSum=dblSum+retAry[j]+"+"
- }
- dblSum=dblSum+"0)"
- strFormula=replaceString(strFormula,r[i],dblSum)
- }
- break;
- case "AVG":
- for (i=0;i<=r.length-1;i++){
- var retAry=getAllLabelAry(r[i])//得到所有标签的值的数组
- dblSum="(("
- for (j=0;j<retAry.length;j++ ){
- dblSum=dblSum+retAry[j]+"+"
- }
- var dblAvg=dblSum+"0)/"+retAry.length+")"
- strFormula=replaceString(strFormula,r[i],dblAvg)
- }
- break;
- case "MAX":
- for (i=0;i<=r.length-1;i++){
- var retAry=getAllLabelAry(r[i])//得到所有标签的值的数组
- if (retAry.length==1){
- strFormula=replaceString(strFormula,r[i],retAry[0])
- break;
- }
- for (j=1;j<retAry.length;j++ ){
- if (parseFloat(retAry[j-1])>parseFloat(retAry[j])){
- retAry[j]=retAry[j-1]
- }
- }
- var dblMax=retAry[j-1]
- strFormula=replaceString(strFormula,r[i],dblMax)
- }
- break;
- case "MIN":
- for (i=0;i<=r.length-1;i++){
- var retAry=getAllLabelAry(r[i])//得到所有标签的值的数组
- if (retAry.length==1){
- strFormula=replaceString(strFormula,r[i],retAry[0])
- break;
- }
- for (j=1;j<retAry.length;j++ ){
- if (parseFloat(retAry[j-1])<parseFloat(retAry[j])){
- retAry[j]=retAry[j-1]
- }
- }
- var dblMin=retAry[j-1]
- strFormula=replaceString(strFormula,r[i],dblMin)
- }
- break;
- }
- return strFormula
- }
- /**
- //返回取得所有标签公式的数组
- **/
- function getAllLabelAry(strExp){
- //strExp="Sum(A1:C2)"
-
- var ReturnArr=new Array()
- var strF,lngA,strL
- strExp=" " +strExp+" "
- var re=/(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9]))[^0-9]/ig
- var r=strExp.match(re)
- if (r==null)
- return
- strF=trim(r[0].substring(0,r[0].length-1))//取出第一个标志符
- var iLength=strF.length
- for (var i=0;i<iLength;i++){
- lngA=parseInt(strF.charCodeAt(i))
- if (lngA>=49 && lngA<=57){
- var strFChar=strF.substring(0,i)
- var strFInt=parseInt(strF.substring(i,iLength+1))
- break;
- }
- }
- strL=trim(r[1].substring(0,r[1].length-1))//取出第二个标志符
- iLength=strL.length
- for (var i=0;i<iLength;i++){
- lngA=parseInt(strL.charCodeAt(i))
- if (lngA>=49 && lngA<=57){
- var strLChar=strL.substring(0,i)
- var strLInt=parseInt(strL.substring(i,iLength+1))
- break;
- }
- }
- var iIndex=0
- for (var j=LblToInt(strFChar);j<=LblToInt(strLChar);j++){
- for (var i=strFInt;i<=strLInt;i++){
- var strCol=IntToLbl(j)
- var strSearch=trim(strCol)+i
- var strRe=new RegExp(strSearch,"i")
- //-----------将getCellValue函数的内容插入此
- var strChar1,strInt1
- var iLength1=strSearch.length-1
- var sCurRow,sCurCol
- var lngA1
- for (var ii=0;ii<=iLength1;ii++){
- lngA1=parseInt(strSearch.charCodeAt(ii))
- if (lngA1>=49 && lngA1<=57){
- var strChar1=strSearch.substring(0,ii)
- var strInt1=strSearch.substring(ii,iLength1+1)
- break;
- }
- }
- sCurRow=strInt1
- sCurCol=LblToInt(strChar1)
-
- //-----------
- //将GetCellValue函数用getCell取代
- strReplace="GETCELL("+sCurRow+","+sCurCol+")"
- //var strReplace="getCellValue('"+strSearch+"')"
- var retR=strSearch.replace(strRe,strReplace)
- //var retValue=DealPoint(retR)
- //改为返回GETCELL()样的公式,而不是值
- ReturnArr[iIndex]=retR//retValue
- iIndex=iIndex+1
- }
- }
-
- return ReturnArr
- }
- /**
- //处理小数点
- **/
- function DealPoint(strExpress){
- var dblResult
- //try{
- strExpress=trim(strExpress)
- dblResult=eval(strExpress)
- //}
- //catch (exception)
- //{
- // dblResult="#无效值"
- //}
- return dblResult
- }
- /**
- *宏函数
- **/
- function IF(strExpr,strTrue,strFalse) {
- if (strExpr)
- return strTrue
- else
- return strFalse
- }
- /**
- //sGetcell为要计算的单元串GETCELL(2,3)
- //计算GETCELL(2,3)此单元改动后的级联计算
- **/
- function SumOneCell(sGetcell) {
- var oFind=oFormula.documentElement.selectNodes("//record")
- for (var i=0;i<oFind.length;i++){
- var strRow=oFind.item(i).childNodes.item(0).text
- var strCol=oFind.item(i).childNodes.item(1).text
- var strPos="GETCELL("+trim(strRow)+","+trim(strCol)+")"
- bCheckFormula=false
- arrCheckFormula.length=0
- var sFor=ExpandFormula(strPos)
-
- if(bCheckFormula==true && arrCheckFormula.length>0){
- var s1=""
- for(var i=0;i<arrCheckFormula.length;i++){
- s1=s1+arrCheckFormula[i].RC+"="+arrCheckFormula[i].sFormula+" "
- }
- alert("公式循环调用:"+s1)
- break
- }
- if (sFor.indexOf(sGetcell)>-1) {
- // alert(sFor+" "+sGetcell)
- SetCellData(parseInt(strRow),parseInt(strCol),DealPoint(sFor))
- }
- }
- }
- /**
- //返回此单元r,c的展开后的公式串.
- **/
- function ExpandFormula(sGetcell) {
- //sGetcell="GETCELL(2,3)"
-
- var r,c
- var i=sGetcell.indexOf(",")
- if (i>0) {
- r=sGetcell.substring(8,i)
- c=sGetcell.substring(i+1,sGetcell.length-1)
- }
- //上面是将"GETCELL(2,3)"===>2 3
- var strFormula,initFormula
- var oFind=oFormula.documentElement.selectNodes("//record[row='" + r + "' and col='" + c + "']")
- if (oFind.length>0){
- //找到2 3单元的公式
- strFormula=oFind.item(0).childNodes.item(2).text
- initFormula=oFind.item(0).childNodes.item(4).text
- }
- else {
- //如无公式则返回"GETCELL(2,3)"
- return sGetcell
- }
- //查找公式中是否有GETCELL(x,y)
- var strR=strFormula
- var sExp=new RegExp("GETCELL.([1-9][0-9]*"+","+"[1-9][0-9]*).","ig")
- var re=strFormula.match(sExp)
- //如没有则返回"GETCELL(2,3)"
- if (re==null) return sGetcell
-
- for (var i=0;i<=re.length-1;i++){
- //先找此单元在数组中是否存在,不存在的话才加入
- var mRC=IntToLbl(c)+r
- var bFind=false
- for(var j=0;j<arrCheckFormula.length;j++){
- if(arrCheckFormula[j].RC==mRC){
- bFind=true
- }
- }
- if(bFind==false)
- arrCheckFormula[arrCheckFormula.length]=new ErrorFormula(sGetcell,initFormula,mRC)
- //---------------------
- for(var j=0;j<arrCheckFormula.length;j++){
- if (re[i]==arrCheckFormula[j].sGetcell ) {
- //自己调用自己
- bCheckFormula=true
- return ""
- }
- }
- //当单元串不等于最开始的单元串时才处理,以解决当改动的单元本身就是一个调用了其它单元的公式单元时的情况
- //利用递归找到公式中的GETCELL公式进行展开后的公式串
- var strReplace=ExpandFormula(re[i])
- //替代源串.
- strR=replaceString(strR,re[i],"("+strReplace+")")
- }
- return strR
- }
- /**
- //全表重算时检查公式是否有第归的情况
- //返回真表示可以进行公式计算
- **/
- function checkFormula(){
- if (oFormula.documentElement.childNodes.length <=0)
- return false;
- var oFind=oFormula.documentElement.selectNodes("//record")
- for (var i=0;i<oFind.length;i++){
- var strRow=oFind.item(i).childNodes.item(0).text
- var strCol=oFind.item(i).childNodes.item(1).text
- var strPos="GETCELL("+trim(strRow)+","+trim(strCol)+")"
- bCheckFormula=false
- arrCheckFormula.length=0
- var sFor=ExpandFormula(strPos)
- if(bCheckFormula==true && arrCheckFormula.length>0){
- var s1=""
- for(var i=0;i<arrCheckFormula.length;i++){
- s1=s1+arrCheckFormula[i].RC+"="+arrCheckFormula[i].sFormula+" "
- }
- alert("公式循环调用:"+s1)
- return false
- }
- }
- return true
- }
- /**
- //将选中格的每行的起始列和结束列号位置增加到oPos中
- //strFormula为原始输入的公式
- //preFormula为预处理过后的公式
- **/
- function addoFormulaNodes(rowno,colno,preFormula,strFormula)
- {
- //删除保存在oFormula中的公式
- var oFind=oFormula.documentElement.selectNodes("//record[row='" + rowno + "' and col='" + colno + "']")
- if (oFind.length==1)
- oFormula.documentElement.removeChild(oFind.item(0))//删除找到的节点
- var root = oFormula.documentElement
- var newNode = oFormula.createNode (1, "record", "")
- root.appendChild(newNode)
-
- var newElem = oFormula.createElement("row") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = rowno
- var newElem = oFormula.createElement("col") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = colno
- var newElem = oFormula.createElement("formula") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = preFormula
- var newElem = oFormula.createElement("level") //重算的级别数
- newNode.appendChild(newElem)
- newNode.lastChild.text = "1"
- var newElem = oFormula.createElement("source") //处理前的公式
- newNode.appendChild(newElem)
- newNode.lastChild.text = strFormula
-
- }
- /**
- //装入所有的公式到oFormula对象
- **/
- function LoadAllFormula() {
-
- var sFormula="<root>"
- for(var i=1;i<t.rows.length;i++){
- for(var j=1;j<t.rows(0).cells.length;j++){
- var arr=PhyToLog(i,j)
- var s1=t.rows(arr[0]).cells(arr[1]).getAttribute("formula")
- if(s1!=null){
- var preFormula=replaceFormula(s1)
- sFormula=sFormula+"<record><row>"+i+"</row><col>"
- +j+"</col><formula>"+preFormula
- +"</formula><level></level><source>"
- +s1+"</source></record>"
- }
- }
- }
- sFormula=sFormula+"</root>"
- //装入DOM
- oFormula=new ActiveXObject("Microsoft.XMLDOM")
- oFormula.async ="false";
- oFormula.loadXML(sFormula)
-
- }
- /**
- *全表重算的按钮的点击事件
- //公式计算的工作:1 全表重算,2 当改动一个单元格的值时自动执行调用此单元的公式
- //(即设置为自动重算时要做的工作).3 三级以上级联公式的处理.
- //重算
- **/
- function cmdCompute(){
- // if (SetReadOnly()) return
- var i,j,iLevel
- var strFormula
- if (checkFormula()==false){
- return;
- }
- window.status="正在重算整个表,请稍候..."
- // SaveoUndoOneRecord()
- //将上一当前行列保存进来以便恢复
- // curFormulaRow=presRow
- // curFormulaCol=presCol
- //先让所有的水平都为1
- for(i=0;i<oFormula.documentElement.childNodes.length;i++){
- oFormula.documentElement.childNodes(i).childNodes(3).text=1
- }
- //alert(oFormula.documentElement.xml)
- iLevel=1
- var oFind=oFormula.documentElement.selectNodes("//record[level='" + iLevel + "']") //
- while (oFind.length>0){
- for (i=0;i<oFind.length;i++){
- strFormula=oFind.item(i).childNodes.item(2).text
- for (j=0;j<oFind.length;j++){
- var strRow=oFind.item(j).childNodes.item(0).text
- var strCol=oFind.item(j).childNodes.item(1).text
- //注COL在前
- var strPos="GETCELL("+trim(strRow)+","+trim(strCol)+")"
- //查找公式中是否有GETCELL()之类的,如有则表示级别应加大.
- //查找公式中是否有B5之类的,如有则表示级别应加大.
-
- if (strFormula.indexOf(strPos)>-1){
- oFind.item(i).childNodes.item(3).text=parseInt(iLevel)+1
- break;
- }
- }
- }
- iLevel=iLevel+1
- var oFind=oFormula.documentElement.selectNodes("//record[level='" + iLevel + "']")
- //再在高一级的公式中查找更高一级的.
- }
- var colno
- //按oFormula对象中的层次关系由最低层的开始计算
- iLevel=1
- oFind=oFormula.documentElement.selectNodes("//record[level='" + iLevel + "']")
- while (oFind.length>0){
- for (i=0;i<oFind.length;i++){
- var strRow=oFind.item(i).childNodes.item(0).text
- var strCol=oFind.item(i).childNodes.item(1).text
- var strLblSelf=trim(IntToLbl(strCol))+trim(strRow)
- strFormula=oFind.item(i).childNodes.item(2).text
-
- //if (NotIsInRect(parseInt(strRow),parseInt(strCol))==true)//false在矩形之内的无对应td值的单元格;true不在矩形之内
- //{
- //带模版的公式的当前行列用此两个变量跟踪
- presRow=parseInt(strRow)
- presCol=parseInt(strCol)
- SetCellData(parseInt(strRow),parseInt(strCol),DealPoint(strFormula))
- //}
- oFind.item(i).childNodes.item(3).text="1"
- }
- iLevel=iLevel+1
- oFind=oFormula.documentElement.selectNodes("//record[level='" + iLevel + "']")
- }
- blnChange=true
- //将上一当前行列恢复
- //presRow=curFormulaRow
- //presCol=curFormulaCol
-
- //SaveoRedoOneRecord()
- window.status="计算完成!"
- }
- /**
- //增删列时要移动公式相对引用的
- **/
- function MoveFormula(startCol,iCols,iTag){
- var strFormula
- for (var k=0;k<oFormula.documentElement.childNodes.length;k++){
- strFormula=trim(oFormula.documentElement.childNodes(k).childNodes(4).text)
- strFormula=" " +strFormula+" "
- re=/(([a-z]|[A-Z])|([a-z]|[A-Z])([a-z]|[A-Z]))([1-9]|([1-9][0-9])|([1-9][0-9][0-9]))[^0-9]/ig
- r=strFormula.match(re)
- if(r!=null){
- var lngPrePos=0
- var lngPrePos1=0
- var strRet="" //返回公式
- //加此循环是为了替代一个公式中的多个A2
- for (var i=0;i<=r.length-1;i++){
- strSearch=trim(r[i].substring(0,r[i].length-1))//取出的一个标志符
- //alert(strSearch)
- var strChar,strInt
- var iLength=strSearch.length-1
- var sCurRow,sCurCol
- var lngA
- for (var ii=0;ii<=iLength;ii++){
- lngA=parseInt(strSearch.charCodeAt(ii))
- if (lngA>=49 && lngA<=57){
- var strChar=strSearch.substring(0,ii)
- var strInt=strSearch.substring(ii,iLength+1)
- break;
- }
- }
- //由B5==>行和列数
- sCurRow=parseInt(strInt)
- sCurCol=LblToInt(strChar)
-
- if(sCurCol>startCol) {
- //=1表示移行,否则移动列
- if(iTag==1)
- sCurRow=sCurRow+iCols
- else
- sCurCol=sCurCol+iCols
-
- //-----------替代 B5===>F5
- strReplace=IntToLbl(sCurCol)+sCurRow
- //alert(strReplace)
- lngPrePos1=strFormula.indexOf(strSearch,lngPrePos)
- if (lngPrePos1>0){
- //替换字符
- strRet=strRet+strFormula.substring(lngPrePos,lngPrePos1)+strReplace
- lngPrePos=lngPrePos1+strSearch.length
- }
- else {
- strRet=strRet+strFormula.substring(lngPrePos,strFormula.length-1)
- }
- //alert(i+":"+strRet)
- }
- }
- //alert(strRet)
- var iRow=parseInt(trim(oFormula.documentElement.childNodes(k).childNodes(0).text))
- var iCol=parseInt(trim(oFormula.documentElement.childNodes(k).childNodes(1).text))
- var arr=PhyToLog(iRow,iCol)
- t.rows(arr[0]).cells(arr[1]).setAttribute("formula",trim(strRet))
- }
- }
- }
- //表函数
- /**
- *表函数,取当前列号
- **/
- function COL() {
- return sCol
- }
- /**
- *表函数,取当前行号
- **/
- function ROW() {
- return sRow
- }
- /**
- *表函数,取总列数
- **/
- function COLS() {
- return t.rows(0).cells.length
- }
- /**
- *表函数,取总行数
- **/
- function ROWS() {
- return t.rows.length
- }
- function col() {
- return COL()
- }
- function cols() {
- return COLS()
- }
- function row() {
- return ROW()
- }
- function rows() {
- return ROWS()
- }
- /**
- *表函数,取SQL语句的返回值
- **/
- function getdb(strConnection,strSql){
- return GETDB(strConnection,strSql)
- }
- /**
- *输入公式按扭的点击事件
- **/
- function cmdFormula(){
- //输入公式
- var arySend=new Array()
- arySend[0]=IntToLbl(sCol)+sRow //当前单元格的位置
- var arr=PhyToLog(sRow,sCol)
- arySend[1]=t.rows(arr[0]).cells(arr[1]).getAttribute("formula") //公式串
- if(arySend[1]==null)arySend[1]=""
- var strReturn=window.showModalDialog("dsnsetformula.htm",arySend,"status:no;dialogHeight:265px;dialogWidth:405px;dialogTop:200;dialogLeft:150px")
- if (isSpace(strReturn)==false){
- txtMyGrid.value ="="+strReturn//返回的公式串
- grid.txtTotd()
- blnChange=true
- }
- }
- //*****************************************************************************************
- //公式处理 end
- //*****************************************************************************************
- /**
- //设置固定行列
- **/
- function FixRowsCols() {
- var arr=new Array()
- arr[0]=grid.FixRows
- arr[1]=grid.FixCols
- arr[2]=t.getAttribute("queryorder")
- if(arr[2]==null)arr[2]="0"
- var sRet=window.showModalDialog("fixrowscols.htm",arr,"status:no;dialogHeight:180px;dialogWidth:300px;dialogTop:180;dialogLeft:250px")
- grid.FixRows=sRet[0]
- grid.FixCols=sRet[1]
- //存入表格属性中
- t.setAttribute("fixrows",sRet[0])
- t.setAttribute("fixcols",sRet[1])
- t.setAttribute("queryorder",sRet[2])
- blnChange=true
- }
- /**
- *调用设置事件的页面
- **/
- function InputRunPara() {
- //输入报表运行时设置的参数
- var sRet=window.showModalDialog("setevent.htm",t,"status:no;scroll:no;dialogHeight:270px;dialogWidth:300px;center:yes;")
- blnChange=true
-
- return
- var arySend=t.getAttribute("runpara")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsninputrunpara.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("runpara",sRet)
- blnChange=true
- }
- }
- function AfterRunSql() {
- //设置运行查询之后要运行的命令
- var arySend=t.getAttribute("afterrunsql")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsnafterrunsql.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("afterrunsql",sRet)
- blnChange=true
- }
- }
- function PageRun() {
- //输入报表翻页时运行的命令
- var arySend=t.getAttribute("pagerun")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsnpagerun.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("pagerun",sRet)
- blnChange=true
- }
- }
- function AddLineRun() {
- //输入自动加行后要运行的命令
- var arySend=t.getAttribute("addlinerun")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsnaddlinerun.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("addlinerun",sRet)
- blnChange=true
- }
- }
- function SetReportUserData() {
- //输入报表的用户数据
- var arySend=t.getAttribute("userdata")
- if(arySend==null)arySend=""
- arySend=unescape(arySend)
- var sRet=window.showModalDialog("dsnuserdata.htm",arySend,"status:no;scroll:no;dialogHeight:200px;dialogWidth:280px;dialogTop:20;dialogLeft:20px")
- if(isSpace(sRet)==false && typeof sRet!="undefined"){
- t.setAttribute("userdata",escape(sRet))
- blnChange=true
- }
- }
- /**
- *设置单元格只读或可写
- //设置按回车键后进入哪个单元格
- **/
- function PressEnter() {
- if(tc.style.display=="none") return
- var arr=PhyToLog(sRow,sCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- var s1=curTD.getAttribute("pressenter")
- if(s1==null)s1=""
- var s2=curTD.getAttribute("cellreadonly")
- if(s2==null)s2=""
- //alert(s1+" : "+s2)
- var arr1=new Array()
- arr1[0]=s1
- arr1[1]=s2
- var sRet=window.showModalDialog("dsnsetenter.htm",arr1,"status:no;dialogHeight:160px;dialogWidth:400px;dialogTop:180;dialogLeft:100px")
- if(sRet!=null){
- if(isSpace(sRet[0])==false)
- curTD.setAttribute("pressenter",sRet[0])
- else
- curTD.removeAttribute("pressenter")
- if(sRet[1]==1)
- curTD.setAttribute("cellreadonly",sRet[1])
- else
- curTD.removeAttribute("cellreadonly")
-
- blnChange=true
- }
-
- }
- /**
- //设置小数位数
- **/
- function SetPointNum() {
- if(tc.style.display=="none") return
- SaveoUndoOneRecord()
- var arr=PhyToLog(sRow,sCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- var s1=curTD.getAttribute("pointnum")
- if(s1==null)s1=""
- var sRet=window.showModalDialog("dsnpointnum.htm",s1,"status:no;dialogHeight:110px;dialogWidth:250px;dialogTop:180;dialogLeft:250px")
- for(var i=sRowSort;i<=eRowSort;i++){
- for(var j=sColSort;j<=eColSort;j++){
- arr=PhyToLog(i,j)
- curTD=t.rows(arr[0]).cells(arr[1])
- if(isSpace(sRet)==false){
- curTD.setAttribute("pointnum",sRet)
- curTD.innerText=ContDec(curTD.innerText,sRet)
- }
- else {
- curTD.removeAttribute("pointnum")
- }
- }
- }
- hideTxt()
- SaveoRedoOneRecord()
- blnChange=true
- }
- /**
- //设置超级链接
- **/
- function SetHref() {
- if(tc.style.display=="none") return
- var arr=PhyToLog(sRow,sCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- var s1=curTD.getAttribute("sethref")
- if(s1==null)s1=""
- var sRet=window.showModalDialog("dsnhref.htm",s1,"status:no;dialogHeight:110px;dialogWidth:350px;dialogTop:180;dialogLeft:250px")
- if(typeof sRet=="undefined") return
- SaveoUndoOneRecord()
- if(isSpace(sRet)==false){
- //alert(sRet)
- curTD.setAttribute("sethref",sRet)
- curTD.innerHTML="<a href="+sRet+">"+curTD.innerText+"</a>"
- }
- else {
- curTD.removeAttribute("sethref")
- curTD.innerHTML=""
- }
- alert(curTD.innerHTML)
- SaveoRedoOneRecord()
- blnChange=true
- }
- /**
- //输入数据装入的Sql条件
- **/
- function ShowSetSql() {
- var arySend=new Array()
- arySend[0]=t.getAttribute("buttonxml")
- if(arySend[0]==null)
- arySend[0]=""
- else
- arySend[0]=unescape(arySend[0])
- arySend[1]=t.getAttribute("initwhere")
- if(arySend[1]==null)
- arySend[1]=""
- else
- arySend[1]=unescape(arySend[1])
- arySend[2]=t.getAttribute("recordsetxml")
- if(arySend[2]==null)
- arySend[2]=""
- else
- arySend[2]=unescape(arySend[2])
-
- var sRet=window.showModalDialog("dsnsetsql.htm",arySend,"status:no;scroll:no;dialogHeight:450px;dialogWidth:600px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- var arr=sRet.split(";")
- t.setAttribute("buttonxml",arr[0])
- t.setAttribute("initwhere",arr[1])
- t.setAttribute("recordsetxml",arr[2])
- blnChange=true
- }
- }
- /**
- //装入HTML表格
- **/
- function LoadHtml() {
- var sRet=window.showModalDialog("dsnloadhtml.htm","","status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){ //下面的内容和newreport类似
- //先检查是否要保存当前报表
- CheckReportChange()
- var sTab=sRet
- t.outerHTML=sTab
- CopytHtml()
- document.title=""
- grid.reload(sTab)
-
- initoUndooRedo()
-
- oFormula=new ActiveXObject("Microsoft.XMLDOM")
- oFormula.async ="false";
- oFormula.loadXML("<root></root>")
- oGraph=new ActiveXObject("Microsoft.XMLDOM")
- oGraph.async ="false";
- oGraph.loadXML("<root></root>")
- blnChange=false
- //另加,内有滚动条的处理
- grid.initGrid()
- }
- }
- function InputCheck() {
- //输入检查条件
- var arySend=t.getAttribute("check")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsninputcheck.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("check",sRet)
- blnChange=true
- }
- }
- /**
- //执行检查条件
- **/
- function ExecCheck() {
- var arySend=t.getAttribute("check")
- if(arySend==null) {
- alert("无检查条件!")
- return
- }
- else {
- eval(unescape(arySend))
- }
- }
- /**
- //重算此表的所有图形
- **/
- function setAllGraph(){
- for(var i=1;i<t.rows.length;i++){
- for(var j=1;j<t.rows(i).cells.length;j++){
- var curTD=t.rows(i).cells(j)
- var s1=curTD.getAttribute("graph")
- if(s1!=null){
- s1=unescape(s1)
- if(isSpace(s1)==false){
- setGraph(1,s1)
- }
- }
- }
- }
- }
- /**
- //设置新的图形
- //iRun==1表示不出现对话框,重算此表的所有图形
- //iRun==0表示出现对话框,
- //生成的图形自动放到当前TD中
- //取值范围,标签范围只能采用命令来写,且应存入TD的属性中.其它用属性窗的方式.将所有的属性拼成一个XML串存在TD的属性中.
- //然后由此XML串得到一个图形串.
- //有一个可扩充的参数,将它插入到</applet>前面.
- //参数: samplevalues:B1:B5,samplelabels:B1:B5,graphposition:C4,width:100,height:200,
- //TD:graphxml:
- <root>
- <type>直方图</type>
- <samplevalues>B1:B5</samplevalues>
- <samplelabels>B1:B5</samplelabels>
- <graphposition>C4</graphposition>
- <width>100</width>
- <height>200</height>
- <other></other> //其它属性,要先escape
- <opt>行</opt> //填行/列两个值,用于控制循环拼数时是先行后列还是先列后行
- </root>
- **/
- function setGraph(iRun,sGraphAttribute) {
- var sXml=sGraphAttribute
- if(iRun==0) {
- if(tc.style.display=="none") return
- var arr=PhyToLog(sRow,sCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- var arySend=curTD.getAttribute("graph")
- if(arySend==null)arySend=""
- arySend=unescape(arySend)
-
- sXml=window.showModalDialog("dsnsetgraph.htm",arySend,"status:no;scroll:no;dialogHeight:500px;dialogWidth:700px;dialogTop:20;dialogLeft:20px")
- if(sXml==null || sXml=="") return
- }
- //alert(sXml)
- var oXml=new ActiveXObject("Microsoft.XMLDOM")
- oXml.async="false";
- oXml.loadXML(sXml)
- //-----------------------------------------------------------------------------------
- //计算放图的TD
- var iPosRow,iPosCol //放图形的单元的行列
-
- var arr1=TransAto1(oXml.documentElement.childNodes(3).text) //C3,放图的单元格
- iPosRow=arr1[0]
- iPosCol=arr1[1]
- var arr=PhyToLog(iPosRow,iPosCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- //-----------------------------------------------------------------------------------
- //计算samplevalues串和samplelabels串
- var sRowTmp,sColTmp,eRowTmp,eColTmp //放数据的起止单元
- var sData=oXml.documentElement.childNodes(1).text //A1:C2
- var s1=""
- if(isSpace(sData)==false){
- var arrData=sData.split(":")
- var arrS=TransAto1(arrData[0])
- sRowTmp=parseInt(arrS[0])
- sColTmp=parseInt(arrS[1])
- var arrE=TransAto1(arrData[1])
- eRowTmp=parseInt(arrE[0])
- eColTmp=parseInt(arrE[1])
-
- var iRows=eRowTmp-sRowTmp+1
- var iCols=eColTmp-sColTmp+1
- var ssamplevalue="sampleValues"
- var ss1='<param name="'
- var ii=0
- s1=''
- if(oXml.documentElement.childNodes(7).text=="行"){
- if(sColTmp<eColTmp){
- ssamplevalue="sampleValues_0"
- //多列时加上列数属性
- //s1+='<param name=seriesCount value="'+(eRowTmp-sRowTmp+1)+'">'
-
- }
- for (var j=sColTmp;j<=eColTmp;j++) {
- s1+='<param name="'+ssamplevalue+'" value=" '
- for (var i=sRowTmp;i<=eRowTmp ;i++) {
- var arr3=PhyToLog(i,j)
- s1+=t.rows(arr3[0]).cells(arr3[1]).innerText+ ","
- }
- s1=s1.substring(0,s1.length-1); //去掉最后的,号
- s1+='">'
-
- ii++;
- ssamplevalue="sampleValues_"+ii;
- }
- }else{
-
- if(sRowTmp<eRowTmp){
- ssamplevalue="sampleValues_0"
- //多列时加上列数属性
- //s1+='<param name=seriesCount value="'+(eColTmp-sColTmp+1)+'">'
-
- }
- for (var i=sRowTmp;i<=eRowTmp ;i++) {
- s1+='<param name="'+ssamplevalue+'" value=" '
- for (var j=sColTmp;j<=eColTmp;j++) {
- var arr3=PhyToLog(i,j)
- s1+=t.rows(arr3[0]).cells(arr3[1]).innerText+ ","
- }
- s1=s1.substring(0,s1.length-1); //去掉最后的,号
- s1+='">'
-
- ii++;
- ssamplevalue="sampleValues_"+ii;
- }
-
- }
- }
- //计算samplelabels
- var s2=""
- var sData=oXml.documentElement.childNodes(2).text //A1:C2
- if(isSpace(sData)==false){
- var arrData=sData.split(":")
- var arrS=TransAto1(arrData[0])
- sRowTmp=parseInt(arrS[0])
- sColTmp=parseInt(arrS[1])
- var arrE=TransAto1(arrData[1])
- eRowTmp=parseInt(arrE[0])
- eColTmp=parseInt(arrE[1])
-
- var iRows=eRowTmp-sRowTmp+1
- var iCols=eColTmp-sColTmp+1
- s2='<param name="sampleLabels" value=" '
- for (var i=sRowTmp;i<=eRowTmp ;i++) {
- for (var j=sColTmp;j<=eColTmp;j++) {
- var arr3=PhyToLog(i,j)
- s2+=t.rows(arr3[0]).cells(arr3[1]).innerText+ ","
- }
- }
- s2=s2.substring(0,s2.length-1)
- s2+='">'
- }
- //-----------------------------------------------------------------------------------
- var sType=""
- switch (oXml.documentElement.childNodes(0).text) {
- case "折线图" :
- sType=" code=cn.com.fcsoft.chart.LineChartApplet "
- break;
- case "圆饼图" :
- sType=" code=cn.com.fcsoft.chart.PieChartApplet "
- break;
- default :
- sType=" code=cn.com.fcsoft.chart.BarChartApplet "
- }
- var sAll='<Applet archive=chart.jar '
- if(isSpace(oXml.documentElement.childNodes(4).text)==false)
- sAll+=" width=" +oXml.documentElement.childNodes(4).text+" "
- if(isSpace(oXml.documentElement.childNodes(5).text)==false)
- sAll+=" height=" +oXml.documentElement.childNodes(5).text+" "
-
- sAll+=sType
- sAll+=' >'
- sAll+=s1+s2
- sAll+=unescape(oXml.documentElement.childNodes(6).text) //其它属性
- sAll+='</Applet>'
- curTD.setAttribute("graph",escape(sXml))
- //alert(sAll)
- curTD.innerHTML=sAll
- //t.rows(3).cells(2).innerHTML='<applet code=cn.com.fcsoft.chart.BarChartApplet archive=chart.jar width=200 height=140><param name=sampleValues value="'+t.rows(3).cells(1).innerText+',20,30,40,50"><param name=chartTitle value="chart title"><param name=titleFont value="Courier, bold, 20"></Applet>'
- return
- }
- //--------------------------------------------------------------------------------------
- function showGraph(strGraph,iRun) {
- setGraph(0,"")
- return
- //sRet为选择对话框后的返回值 0:标题 1:图形类型 2:放图的单元格 3 为0表示垂直方向
- //graph.Labeltext="车间名称";//X轴标题的内容
- //type=4
-
- graph.top="1"
- graph.left="1"
- graph.ArcLeft=100
- graph.ArcTop=150
- graph.ArcRadius=50
- graph.ImgWidth=450
- graph.ImgHeight=300
- graph.ImgMargin=40
-
- var hostname=location.hostname
- //显示设置界面
- var ary=""
- if(arguments.length>0)
- ary=strGraph
- if(arguments.length==2)
- var strReturn=strGraph //直接运行
- else
- var strReturn=window.showModalDialog("dsngraph.htm",ary,"status:no;scroll:no;dialogHeight:365px;dialogWidth:405px;dialogTop:100;dialogLeft:150px")
- if (isSpace(strReturn)) return
- if (strReturn=="del"){
- //删除当前图形
- if(arguments.length==0) return
- //从表格的双击事件进入
- var o=event.srcElement
- if(o.tagName=="IMG"){
- o=o.parentNode
- if(o.tagName=="TD"){
- o.removeAttribute("graph")
- o.innerHTML=""
- }
- }
- return
- }
- var arrWin=strReturn.split(";")
- var sTitle=arrWin[0] //graph title
- var iType=parseInt(arrWin[1])// graph type
- if (isNaN(iType)) iType=1
- var sRowTmp,sColTmp,eRowTmp,eColTmp //放数据的起止单元
- var sData=arrWin[6] //A1:C2
- var arrData=sData.split(":")
- var arrS=TransAto1(arrData[0])
- sRowTmp=parseInt(arrS[0])
- sColTmp=parseInt(arrS[1])
- var arrE=TransAto1(arrData[1])
- eRowTmp=parseInt(arrE[0])
- eColTmp=parseInt(arrE[1])
- //alert(sRowTmp+" "+sColTmp+" "+eRowTmp+" "+eColTmp)
- var iPosRow,iPosCol //放图形的单元的行列
-
- var arr1=TransAto1(arrWin[2])
- iPosRow=arr1[0]
- iPosCol=arr1[1]
- var arr=PhyToLog(iPosRow,iPosCol)
- var curTD=t.rows(arr[0]).cells(arr[1])
- graph.imgWidth=curTD.offsetWidth //-20
- if (graph.imgWidth<10)graph.imgWidth=10
- graph.imgHeight=curTD.offsetHeight //-20
- if (graph.imgHeight<10)graph.imgHeight=10
- var s1="<r>"
- if (arrWin[3]=="0") {
- //垂直方向
- var iCols=eRowTmp-sRowTmp+1
- var iRows=eColTmp-sColTmp+1
- for (var j=sColTmp;j<=eColTmp ;j++) {
- s1=s1+"<a" + j + ">"
- for (var i=sRowTmp;i<=eRowTmp;i++) {
- var arr3=PhyToLog(i,j)
- s1=s1+"<a" + j+""+i + ">"+t.rows(arr3[0]).cells(arr3[1]).innerText+"</a" + j+""+i + ">"
- }
- s1=s1+"</a" + j + ">"
- }
- }
- else {
- var iRows=eRowTmp-sRowTmp+1
- var iCols=eColTmp-sColTmp+1
- for (var i=sRowTmp;i<=eRowTmp ;i++) {
- s1=s1+"<a" + i + ">"
- for (var j=sColTmp;j<=eColTmp;j++) {
- var arr3=PhyToLog(i,j)
- s1=s1+"<a" + i+""+j + ">"+t.rows(arr3[0]).cells(arr3[1]).innerText+"</a" + i+""+j + ">"
- }
- s1=s1+"</a" + i + ">"
- }
- }
- s1=s1+"</r>"
- //建IMG标记
- curTD.innerHTML="<IMG></IMG>"
- var img1=curTD.childNodes.item(0)
- img1.style.width=graph.imgWidth
- img1.style.height=graph.imgHeight
-
- img1.src=graph.ShowGraphXml(img1,s1,iType,sTitle,iRows,iCols)
-
- //将画图参数保存
- curTD.setAttribute("graph",strReturn)
- addoGraph(iPosRow,iPosCol,strReturn)
-
- blnChange=true
- }
- /**
- //将选中格的每行的起始列和结束列号位置增加到oPos中
- //strFormula为原始输入的公式
- //preFormula为预处理过后的公式
- **/
- function addoGraph(rowno,colno,strGraph)
- {
- //删除保存在oFormula中的公式
- var oFind=oGraph.documentElement.selectNodes("//record[row='" + rowno + "' and col='" + colno + "']")
- if (oFind.length==1)
- oGraph.documentElement.removeChild(oFind.item(0))//删除找到的节点
- var root = oGraph.documentElement
- var newNode = oGraph.createNode (1, "record", "")
- root.appendChild(newNode)
-
- var newElem = oGraph.createElement("row") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = rowno
- var newElem = oGraph.createElement("col") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = colno
- var newElem = oGraph.createElement("graph") //物理行
- newNode.appendChild(newElem)
- newNode.lastChild.text = strGraph
- }
- /**
- //装入显示图形
- **/
- function LoadGraph(iTag){
- if(iTag==1){ //装入报表时装入
- var sGraph=t.getAttribute("graph")
- if(sGraph==null )return
- oGraph.loadXML(unescape(sGraph))
- }
- for(var i=0;i<oGraph.documentElement.childNodes.length;i++){
- var s1=oGraph.documentElement.childNodes(i).childNodes(2).text
- showGraph(s1,1) //1为一个标志,表示不出现对话框
-
- return //暂时这样
- //延时
- //for(var j=0;j<100000;j++){
- // var s="s";
- //}
- }
-
- }
- /**
- //用于拖动修改行高时删除图形
- **/
- function DelAllGraphTag(){
- for(var i=0;i<oGraph.documentElement.childNodes.length;i++){
- var sRowTmp=oGraph.documentElement.childNodes(i).childNodes(0).text
- var sColTmp=oGraph.documentElement.childNodes(i).childNodes(1).text
- var arr=PhyToLog(parseInt(sRowTmp),parseInt(sColTmp))
- t.rows(arr[0]).cells(arr[1]).innerHTML=""
- }
- }
- function SetCondition() {
- //设置查询窗口的条件串
- var arySend=t.getAttribute("condition")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsnsetcondition.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("condition",sRet)
- blnChange=true
- }
- }
- function SetConditionAct() {
- //设置查询条件的处理方式
- var arySend=t.getAttribute("conditionact")
- if(arySend==null)arySend=""
- var sRet=window.showModalDialog("dsnsetconditionact.htm",arySend,"status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- t.setAttribute("conditionact",sRet)
- blnChange=true
- }
- }
- /**
- *装入查询条件对话框
- **/
- function fc_getwhere() {
- var arr=new Array()
- // arr[0]=t.getAttribute("condition")
- arr[0]=t.getAttribute("filter")
- if(isSpace(arr[0])){
- alert("请设置条件对话框!")
- return
- }
- if(arr[0]!=null)
- arr[0]=unescape(arr[0])
- else
- arr[0]=""
- arr[1]=fc_wherexml
- //得到此表的条件串
- var sRet=window.showModalDialog("fc_condition.htm",arr,"status:no;dialogHeight:330px;dialogWidth:655px;dialogTop:50;dialogLeft:50px")
- if (sRet!=null) {
- // alert(sRet)
- fc_wherexml=sRet //保存到全局变量中
- //fc_wherexml的节点格式为:字段中文名,值1,值2
- fc_curpage=1
- fc_executesql(1,sRet)//1 为页号,sRet为条件数据的XML串
- }
- }
- // no use
- function LoadWhereToSql() {
- //用于打开统计表时,需要装入缺省条件进行查询
- if(isSpace(t.getAttribute("initwhere")))
- fc_wherexml=""
- else
- fc_wherexml=t.getAttribute("initwhere")
- fc_wherexml=unescape(fc_wherexml)
-
- fc_curpage=1
- fc_executesql(1,fc_wherexml)//1 为页号,fc_wherexml为条件数据的XML串
- }
- /**
- //下一页
- **/
- function fc_nextpage() {
- if(fc_curpage<fc_allpages) {
- fc_curpage++
- fc_executesql(fc_curpage,fc_wherexml)
- var arySend=t.getAttribute("pagerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- }
- }
- /**
- //下一页0,最后一页
- **/
- function fc_nextpage0() {
- if(fc_allpages>0) {
- fc_curpage=fc_allpages
- fc_executesql(fc_curpage,fc_wherexml)
- var arySend=t.getAttribute("pagerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- }
- }
- /**
- //上一页
- **/
- function fc_prevpage() {
- if(fc_curpage>1) {
- fc_curpage--
- fc_executesql(fc_curpage,fc_wherexml)
- var arySend=t.getAttribute("pagerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- }
- }
- /**
- //上一页
- **/
- function fc_prevpage0() {
- if(fc_curpage>0) {
- fc_curpage=1
- fc_executesql(fc_curpage,fc_wherexml)
- var arySend=t.getAttribute("pagerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- }
- }
- /**
- //保存用户报表
- **/
- function SaveUserReport() {
- t.setAttribute("initwhere",escape(fc_wherexml)) //在打开用户报表时应将"initwhere"属性值给变量fc_wherexml
- SaveAsReport()
- }
- /**
- *执行SQL语句查询
- //将表属性中的结果集串一个个取出来运行.
- //PageNo当前要显示的数据页号,=-1表示要显示所有数据页
- //curWhereXml当前条件框中生成的条件XML节点串,不含根节点
- **/
- function fc_executesql(PageNo,curWhereXml) {
- //加上根节点
- curWhereXml="<root>"+curWhereXml+"</root>"
-
- hideTxt()
- //用于保存条件对话窗中的三种条件。
- var sSql2000=""
- var sSql2001=""
- var sSql2002=""
-
- var sXml=t.getAttribute("recordsetxml")
- if (isSpace(sXml)) return
- sXml=unescape(sXml)
- var oData=new ActiveXObject("Microsoft.XMLDOM")
- oData.async="false";
- oData.loadXML("<root>"+sXml+"</root>")
-
-
- //--------------------------------------------------------------
- //取节点名为record的节点:表格记录
- var oRec=oData.documentElement.selectNodes("//record")
- for (var iii=0;iii<oRec.length;iii++) {
- var curNode=oRec.item(iii)
- //alert(curNode.xml)
- var curRow=curNode.childNodes.item(0).text
- var curCol=curNode.childNodes.item(1).text
- var oGroup=curNode.selectNodes("group")
- //fcnull表示此XML节点为空,因为直接空会影响JAVA节点取数
- var curGroup1="fcnull"
- var curGroupField1="fcnull"
- var curGroup2="fcnull"
- var curGroupField2="fcnull"
- if(oGroup.length>0){
- curGroup1=oGroup.item(0).childNodes(0).text
- curGroupField1=oGroup.item(0).childNodes(1).text
- }
- if(oGroup.length>1){
- curGroup2=oGroup.item(1).childNodes(0).text
- curGroupField2=oGroup.item(1).childNodes(1).text
- }
- // var curSql=curNode.childNodes.item(5).childNodes(0).text
- var oMain=curNode.selectNodes("mainsql")
- var curSql=oMain.item(0).childNodes(0).text
- //3 为页尺寸 4 为在字段值--->表格中的值之间的转换的节点
- //暂时注释,等做小计行时再做
- /*if (curNode.childNodes.length>4 && curNode.childNodes.item(4).tagName=="events" ) {
- var oEvent=curNode.childNodes.item(4)
- if (oEvent.childNodes.length>0) {
- var iFieldNo=oEvent.childNodes(0).text
- var iFieldNo=oEvent.childNodes(1).text
- }
- }*/
- //----------------------
- /*
- //找到curSql的表名
- var sExp=/s(from|join)s+[A-Za-z0-9]+s* /ig
- var re=curSql.match(sExp)
- if (re!=null) {
- var arrTab=new Array()//保存表名的数组
- for (var i=0;i<=re.length-1;i++){
- var s1=re[i]
- arrTab[i]=trim(s1.substring(5,s1.length))
- //alert(arrTab[i])
- }
- }
- else {
- //Sql语句中无表名,有错,待处理
- }
- //curWhereXml为保存对话框中条件的XML串
- if (curWhereXml!="" && curWhereXml!="<root></root>") {
- //如条件中有2000=2000 则要替代成条件框中生成的条件
- var newWhere=""//保存结果SQL串
- var oX=new ActiveXObject("Microsoft.XMLDOM")
- oX.async="false";
- oX.loadXML(curWhereXml)
- for (var ii=0;ii<oX.documentElement.childNodes.length;ii++) {
- var sField=oX.documentElement.childNodes.item(ii).childNodes.item(0).text
- for (var jj=0;jj<arrTab.length;jj++) {
- if (fc_FieldInTable(sField,arrTab[jj])=="") {
- //多次用带表名的字段名替代条件串中的字段名
- var sAfterReplace=fc_RepStr(oX.documentElement.childNodes.item(ii).childNodes.item(1).text,sField,arrTab[jj]+"."+trim(sField))
-
- newWhere=newWhere+" and "+sAfterReplace
- break
- }
- }
-
- }
- //去掉前面的" and "
- if (newWhere.length>6)
- newWhere =newWhere.substring(5,newWhere.length)
- //如条件中有fcsoft=fcsoft 则要替代成条件框中生成的条件
- curSql=fc_RepStr(curSql,"2000=2000",newWhere)
- }
- */
- if (curWhereXml!="" && curWhereXml!="<root></root>") {
- //如条件中有2000=2000 则要替代成条件框中生成的条件
- var newWhere=""//保存结果SQL串
- //给输入参数的值
- //alert(curWhereXml)
-
- sActFieldIn=curWhereXml
- ConditionAct()
- //var sActField=t.getAttribute("conditionact")
- //if(sActField!=null)
- // sActField=unescape(sActField)
- //else
- // sActField=""
-
- //运行用户定义的字段拼条件的方式,参数为sActFieldIn,将结果放入sActFieldOut变量中
- //eval(sActField)
-
- //alert(sActFieldOut)
- var oX=new ActiveXObject("Microsoft.XMLDOM")
- oX.async="false";
- oX.loadXML("<root>"+sActFieldOut+"</root>")
- newWhere=unescape(oX.documentElement.childNodes(0).text)
- if(isSpace(newWhere)==false){
- var tmp1=newWhere
- sSql2000=tmp1
- //alert(sSql2000+curSql)
- curSql=fc_RepStr(curSql,"2000=2000",tmp1)
- //alert("qqq"+curSql)
- curGroup1=fc_RepStr(curGroup1,"2000=2000",tmp1)
- curGroup2=fc_RepStr(curGroup2,"2000=2000",tmp1)
- }
- newWhere=unescape(oX.documentElement.childNodes(1).text)
- if(isSpace(newWhere)==false){
- var tmp1=newWhere
- sSql2001=tmp1
- curSql=fc_RepStr(curSql,"2001=2001",tmp1)
- curGroup1=fc_RepStr(curGroup1,"2001=2001",tmp1)
- curGroup2=fc_RepStr(curGroup2,"2001=2001",tmp1)
- }
- newWhere=unescape(oX.documentElement.childNodes(2).text)
- if(isSpace(newWhere)==false){
- var tmp1=newWhere
- sSql2002=tmp1
- //alert(sSql2002)
- curSql=fc_RepStr(curSql,"2002=2002",tmp1)
- curGroup1=fc_RepStr(curGroup1,"2002=2002",tmp1)
- curGroup2=fc_RepStr(curGroup2,"2002=2002",tmp1)
- }
- }
- //show(curSql+"OOOOOOOO"+curGroup1+"oooooooo"+curGroup2)
- //alert("ddd:"+curSql)
- //----------------------
- if(PageNo==-1){
- var blnNoPages=true //分页标志,供后使用
- var curPageSize=99999999 //表示不分页,尽可能最大值
- PageNo=1
- //设置的页尺寸要供后使用
- var curPageSizeOld=parseInt(curNode.childNodes.item(2).text)
- if (isNaN(curPageSizeOld) || curPageSizeOld==0)
- curPageSizeOld=10 //如页尺寸不合法则置为10
- }
- else {
- var blnNoPages=false
- var curPageSize=parseInt(curNode.childNodes.item(2).text)
- if (isNaN(curPageSize) || curPageSize==0)
- curPageSize=10 //如页尺寸不合法则置为10
- }
- if(curGroup1=="fcnull") {
- //无分组
- //此XML串的SQL节点顺序决定返回数据的顺序
- var allXml="<page><pageno>"+PageNo+"</pageno><pagesize>"+curPageSize+"</pagesize></page>"
- allXml+="<source><datasource>webgrid</datasource><username>sa</username><password></password></source>"
- //找开始的SQL语句,
- //<mainsql><sql>...</sql>...<start>...<sql>...</sql><sql>...</sql></start></mainsql>
- var oEnd=oMain.item(0).selectNodes("start")
- if (oEnd.length>0){
- var oEndSql=oEnd.item(0).selectNodes("sql")
- if(oEndSql.length>0){
- for(var iEndSql=0;iEndSql<oEndSql.length;iEndSql++){
- var sEndSql=oEndSql.item(iEndSql).text
- if(isSpace(sSql2000)==false)
- sEndSql=fc_RepStr(sEndSql,"2000=2000",sSql2000)
- if(isSpace(sSql2001)==false)
- sEndSql=fc_RepStr(sEndSql,"2001=2001",sSql2001)
- if(isSpace(sSql2002)==false)
- sEndSql=fc_RepStr(sEndSql,"2002=2002",sSql2002)
- allXml=allXml+"<sql>"+TransXml(sEndSql)+"</sql>"
- }
- }
- }
- allXml=allXml+"<sql>"+TransXml(curSql)+"</sql>"
- //找结束的SQL语句,
- //<mainsql><sql>...</sql>...<end>...<sql>...</sql><sql>...</sql></end></mainsql>
- var oEnd=oMain.item(0).selectNodes("end")
- if (oEnd.length>0){
- var oEndSql=oEnd.item(0).selectNodes("sql")
- if(oEndSql.length>0){
- for(var iEndSql=0;iEndSql<oEndSql.length;iEndSql++){
- var sEndSql=oEndSql.item(iEndSql).text
- if(isSpace(sSql2000)==false)
- sEndSql=fc_RepStr(sEndSql,"2000=2000",sSql2000)
- if(isSpace(sSql2001)==false)
- sEndSql=fc_RepStr(sEndSql,"2001=2001",sSql2001)
- if(isSpace(sSql2002)==false)
- sEndSql=fc_RepStr(sEndSql,"2002=2002",sSql2002)
- allXml=allXml+"<sql>"+TransXml(sEndSql)+"</sql>"
- }
- }
- }
- //alert(allXml)
- var curDataXml=fc_select1(allXml)
- //alert(curDataXml)
- //var curDataXml=fc_select(curSql,PageNo,curPageSize)
- }
- else {
- //有分组
- var allXml="<page><pageno>"+PageNo+"</pageno><pagesize>"+curPageSize+"</pagesize></page>"
- allXml+="<source><datasource>webgrid</datasource><username>sa</username><password></password></source>"
- allXml+="<mainsql><sql>"+TransXml(curSql)+"</sql>"
- //找开始的SQL语句,
- //<mainsql><sql>...</sql>...<start>...<sql>...</sql><sql>...</sql></start></mainsql>
- allXml+="<start>"
- var oEnd=oMain.item(0).selectNodes("start")
- if (oEnd.length>0){
- var oEndSql=oEnd.item(0).selectNodes("sql")
- if(oEndSql.length>0){
- for(var iEndSql=0;iEndSql<oEndSql.length;iEndSql++){
- var sEndSql=oEndSql.item(iEndSql).text
- if(isSpace(sSql2000)==false)
- sEndSql=fc_RepStr(sEndSql,"2000=2000",sSql2000)
- if(isSpace(sSql2001)==false)
- sEndSql=fc_RepStr(sEndSql,"2001=2001",sSql2001)
- if(isSpace(sSql2002)==false)
- sEndSql=fc_RepStr(sEndSql,"2002=2002",sSql2002)
- allXml=allXml+"<sql>"+TransXml(sEndSql)+"</sql>"
- }
- }
- }
- allXml+="</start>"
- //找结束的SQL语句,
- //<mainsql><sql>...</sql>...<start>...<sql>...</sql><sql>...</sql></start></mainsql>
- allXml+="<end>"
- var oEnd=oMain.item(0).selectNodes("end")
- if (oEnd.length>0){
- var oEndSql=oEnd.item(0).selectNodes("sql")
- if(oEndSql.length>0){
- for(var iEndSql=0;iEndSql<oEndSql.length;iEndSql++){
- var sEndSql=oEndSql.item(iEndSql).text
- if(isSpace(sSql2000)==false)
- sEndSql=fc_RepStr(sEndSql,"2000=2000",sSql2000)
- if(isSpace(sSql2001)==false)
- sEndSql=fc_RepStr(sEndSql,"2001=2001",sSql2001)
- if(isSpace(sSql2002)==false)
- sEndSql=fc_RepStr(sEndSql,"2002=2002",sSql2002)
- allXml=allXml+"<sql>"+TransXml(sEndSql)+"</sql>"
- }
- }
- }
- allXml+="</end>"
-
- allXml+="</mainsql>"
- allXml+="<group><sql>"+TransXml(curGroup1)+"</sql><groupfield>"
- +curGroupField1+"</groupfield></group>"
- allXml=allXml+"<group><sql>"+TransXml(curGroup2)+"</sql><groupfield>"
- +curGroupField2+"</groupfield></group>"
- //alert(allXml)
- var curDataXml=fc_select2(allXml)
- }
-
- if(curDataXml=="<root></root>") {
- alert("无符合条件的记录!")
- return
- }
- //alert(curDataXml)
- //在换页时将表格的界面恢复,注意:全局变量没恢复
- //div1.innerHTML=LoadDiv1Html()
- //----------------------
-
- //将数据给表格中
- var oD=new ActiveXObject("Microsoft.XMLDOM")
- oD.async="false";
- oD.loadXML(curDataXml)
- var allRows=parseInt(oD.documentElement.childNodes.item(oD.documentElement.childNodes.length-1).text)
- var intCols=oD.documentElement.childNodes(0).childNodes.length
- if(blnNoPages){ //不分页显示,一次把数据都显示出来
- //curPageSizeOld
- var blnInsertRow=false
- for (var j=0;j<oD.documentElement.childNodes.length-1;j++) {
- if(j>=curPageSizeOld && blnInsertRow==false){
- //插入空行
- AutoAddLines=oD.documentElement.childNodes.length-1-curPageSizeOld
- for(var kk=0;kk<AutoAddLines;kk++){
- grid.InsertRow(parseInt(curRow)+j)
- }
- CopytHtml()
- //运行外部设置的命令
- //AutoAddLines为此命令的参数
- var arySend=t.getAttribute("addlinerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- //---------------
-
- blnInsertRow=true
- }
- if(j<curPageSizeOld)
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"")
- var curO=oD.documentElement.childNodes.item(j)
- //如当前行为汇总行,则给底色
- if(curO.tagName=="recordsum1"){
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"yellow")
- }
- else if(curO.tagName=="recordsum2"){
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"gray")
- }
- for (var k=0;k<oD.documentElement.childNodes.item(0).childNodes.length;k++) {
- //如标记名为fcnull,则此列不能给值
- if (curO.childNodes.item(k).tagName!="fcnull") {
- //从XML串中往界面上给值
- SetCellData(parseInt(curRow)+j,parseInt(curCol)+k,curO.childNodes.item(k).text)
- }
- }
- } //for end
- //
- var arySend=t.getAttribute("pagerun")
- if(arySend!=null){
- eval(unescape(arySend))
- }
-
- }
- else { //分页显示
- if (isNaN(allRows))
- fc_allpages=0
- else
- fc_allpages=Math.ceil(allRows/curPageSize) //给页尺寸
- //加上当前页和总页数的显示,如1/3
- fcPage.childNodes(2).value=fc_curpage+"/"+fc_allpages
- //------------
- //最后一个子节点为行数
- for (var j=0;j<curPageSize;j++) {
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"")
- if(j<oD.documentElement.childNodes.length-1){
- var curO=oD.documentElement.childNodes.item(j)
- //如当前行为汇总行,则给底色
- if(curO.tagName=="recordsum1"){
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"yellow")
- }
- else if(curO.tagName=="recordsum2"){
- SetRowbgColor(parseInt(curRow)+j,parseInt(curCol),intCols,"gray")
- }
- for (var k=0;k<oD.documentElement.childNodes.item(0).childNodes.length;k++) {
- //如标记名为fcnull,则此列不能给值
- if (curO.childNodes.item(k).tagName!="fcnull") {
- //从XML串中往界面上给值
- SetCellData(parseInt(curRow)+j,parseInt(curCol)+k,curO.childNodes.item(k).text)
- }
- }
- }
- else { //清空,以免数据重叠
- for (var k=0;k<oD.documentElement.childNodes.item(0).childNodes.length;k++) {
- //如标记名为fcnull,则此列不能给值
- if (curO.childNodes.item(k).tagName!="fcnull") {
- //从XML串中往界面上给值
- SetCellData(parseInt(curRow)+j,parseInt(curCol)+k,"")
- }
- }
-
- }
- } //for end
- } //分页显示if end
-
- } //record node for end
- //--------------------------------------------------------------
- //alert(fc_wherexml)
- var arySend=t.getAttribute("afterrunsql")
- if(arySend!=null){
- eval(unescape(arySend))
- }
- }
- /**
- //点显示全部页数据的自定义按钮时运行此
- **/
- function fc_ShowAll() {
- fc_executesql(-1,fc_wherexml)
- }
- /**
- //装入用于开发的一排按钮
- **/
- function LoadButton() {
- var sR='<table border=1 id=queryToolbar bordercolordark="#ffe5d5" bordercolorlight="#808080" style="display:none;LEFT: 5px; POSITION: absolute; TOP: 3px" cellpadding=0 cellspacing=0><tr>'
- sR=sR+'<td style="display:none" id=fcPage >'
- sR=sR+'<INPUT class="buttonpage" type=button value="|<" onclick=fc_prevpage0()>'
- sR=sR+'<INPUT class="buttonpage" type=button value="<" onclick=fc_prevpage()>'
- sR=sR+'<INPUT class="buttonpageno" disabled style="width:40" value="">'
- sR=sR+'<INPUT class="buttonpage" type=button value=">" onclick=fc_nextpage()>'
- sR=sR+'<INPUT class="buttonpage" type=button value=">|" onclick=fc_nextpage0()>'
- sR=sR+'</td>'
- sR=sR+'<td style="display:none" id=fcShowAll><INPUT class="button" type=button value="显示全部" onclick=fc_ShowAll() ></td>'
- var s1='<td><INPUT id=fcButton class="button" style="display:none" type=button ></td>'
- for(var i=0;i<5;i++) {sR=sR+s1}
- sR=sR+'</tr></table>'
- document.write(sR)
- }
- /**
- //初始化功能按钮
- **/
- function initButton() {
- var s1=t.getAttribute("buttonxml")
- if(isSpace(s1)==false) {
- var ii=0
- s1=unescape(s1)
- var oXml=new ActiveXObject("Microsoft.XMLDOM")
- oXml.async="false";
- oXml.loadXML(s1)
- for(var i=0;i<oXml.documentElement.childNodes.length;i++) {
- if (oXml.documentElement.childNodes(i).childNodes(0).text=="fcpage"){
- fcPage.style.display="block"
- }
- else if (oXml.documentElement.childNodes(i).childNodes(0).text=="fcshowall"){
- fcShowAll.style.display="block"
- }
- else {
- fcButton[ii].outerHTML='<INPUT id=fcButton class="button" type=button '
- +' onclick='+oXml.documentElement.childNodes(i).childNodes(1).text
- +' value='+oXml.documentElement.childNodes(i).childNodes(0).text+'>'
- ii++
- }
- }
-
- }
- }
- /**
- //设行背景色
- **/
- function SetRowbgColor(iRow,iCol,intCols,vColor) {
- for(var i=0;i<intCols;i++){
- t.rows(iRow).cells(i+iCol).bgColor=vColor
- }
-
- }
- /**
- //直接运行输入的命令,可用于设置表格背景等功能
- **/
- function RunCommand() {
- var sRet=window.showModalDialog("dsncommand.htm","","status:no;scroll:no;dialogHeight:340px;dialogWidth:695px;dialogTop:20;dialogLeft:20px")
- if(sRet!=""){
- eval(sRet)
- blnChange=true
- }
- }
- /**
- //检查报表是否变化了,提示保存
- **/
- function CheckReportChange() {
- if(blnRunMode)return
- if(blnChange){
- var ret = window.confirm("报表内容已改变,需要保存吗?");
- if (ret) {
- SaveReport()
- }
- else {
- blnChange=false
- }
- }
-
- }
- /**
- //从fcRep.htm中移过来的
- *表格的cellchange事件
- **/
- function grid_onCellChange() {
- var curTD=event.oldTD //当前修改的TD
- var newValue=curTD.innerText
- var strV=trim(newValue)
- if(curTD.innerText==event.BeforeChangeText && trim(strV.substring(0,1))!="=") return
- curTD.innerText=event.BeforeChangeText
- SaveoUndoOneRecord()
- curTD.innerText=newValue
-
- //检查左边是否有"="
- var strFormula
- var curRow,curCol
- if (trim(strV.substring(0,1))=="="){
-
- //计算公式的结果和保存公式至oFormula对象中
- strFormula=strV.substring(1,strV.length)
- //保存公式
- curTD.setAttribute("formula",strFormula)
- //preFormula为预处理过后的公式
- var preFormula=trim(replaceFormula(strFormula))
-
- addoFormulaNodes(curTD.parentNode.rowIndex,curTD.cellIndex,preFormula,strFormula)
- var v=DealPoint(preFormula)
- CellPoint(curTD,v)
- }
- else {
- //清空公式
- curTD.removeAttribute("formula")
- //删除保存在oFormula中的公式
- var oFind=oFormula.documentElement.selectNodes("//record[row='" + curTD.parentNode.rowIndex + "' and col='" + curTD.cellIndex + "']")
- if (oFind.length==1)
- oFormula.documentElement.removeChild(oFind.item(0))//删除找到的节点
-
-
- }
- //将调用此单元的所有单元格重算一遍
- SumOneCell("GETCELL("+curTD.parentNode.rowIndex+","+LogToPhy(curTD.parentNode.rowIndex,curTD.cellIndex)+")")
- SaveoRedoOneRecord()
- blnChange=true
-
- }
- /**
- *查询条件的处理函数,将curWhereXml中的条件串,根据字段表达式拼成SQL语句
- *@date 2003-06-06
- *@param sActFieldIn 输入参数,条件串, =curWhereXml
- *@return sActFieldOut 输出参数,
- **/
- function ConditionAct(){
- var sFilter=t.getAttribute("filter")
- if(isSpace(sFilter)) return
- sFilter=unescape(sFilter)
- //alert(sFilter)
- var oFilter=new ActiveXObject("Microsoft.XMLDOM");
- oFilter.async ="false";
- oFilter.loadXML("<root>"+sFilter+"</root>");
- var sRet="";
- var sRet2000="";
- var sRet2001="";
- var sRet2002="";
- // var s1=" format(fintYear,'0000')+'.'+format(fintPeriod,'00') ";
- oXml=new ActiveXObject("Microsoft.XMLDOM");
- oXml.async ="false";
- oXml.loadXML(sActFieldIn);
- for (var i=0;i<oXml.documentElement.childNodes.length;i++) {
- var sValue1=oXml.documentElement.childNodes(i).childNodes(1).text;
- var sValue2=oXml.documentElement.childNodes(i).childNodes(2).text;
- if (isSpace(sValue1)==false || isSpace(sValue2)==false) {
- for (var j=0;j<oFilter.documentElement.childNodes.length;j++) {
- //名称相同
- if(oFilter.documentElement.childNodes(j).childNodes(0).text == oXml.documentElement.childNodes(i).childNodes(0).text ) {
- var oField =oFilter.documentElement.childNodes(j).childNodes(2) //字段表达式节点
- if(oField.childNodes(0).childNodes(0).text=="否" || isSpace(sValue1)==false ){
- var sF=" and "+fc_RepStr(oField.childNodes(0).childNodes(1).text,":get_value1",sValue1)
-
- for(var k=0;k<oField.childNodes(0).childNodes(2).childNodes.length;k++){
- if(oField.childNodes(0).childNodes(2).childNodes(k).text=="2000=2000"){
- sRet2000+=sF
- }
- if(oField.childNodes(0).childNodes(2).childNodes(k).text=="2001=2001"){
- sRet2001+=sF
- }
- if(oField.childNodes(0).childNodes(2).childNodes(k).text=="2002=2002"){
- sRet2002+=sF
- }
- }
- }
- //处理第二个字段表达式
- if(oField.childNodes.length>1){
- if(oField.childNodes(1).childNodes(0).text=="否" || isSpace(sValue2)==false ){
- var sF=" and "+fc_RepStr(oField.childNodes(1).childNodes(1).text,":get_value2",sValue2)
-
- for(var k=0;k<oField.childNodes(1).childNodes(2).childNodes.length;k++){
- if(oField.childNodes(1).childNodes(2).childNodes(k).text=="2000=2000"){
- sRet2000+=sF
- }
- if(oField.childNodes(1).childNodes(2).childNodes(k).text=="2001=2001"){
- sRet2001+=sF
- }
- if(oField.childNodes(1).childNodes(2).childNodes(k).text=="2002=2002"){
- sRet2002+=sF
- }
- } // end for k
- }
- }
- break;
- } //end if
- } //end for j
- } //end if
- } //end for i
- if(sRet2000.length>5){
- sRet2000=sRet2000.substring(5,sRet2000.length);
- }
- if(sRet2001.length>5){
- sRet2001=sRet2001.substring(5,sRet2001.length);
- }
- if(sRet2002.length>5){
- sRet2002=sRet2002.substring(5,sRet2002.length);
- }
- //alert(sRet2000)
- sActFieldOut="<fc>"+escape(sRet2000)+"</fc>"+"<fc>"+escape(sRet2001)+"</fc>"+"<fc>"+escape(sRet2002)+"</fc>";
- }
- /**
- *另存Excel文件
- *@date 2003-11-30
- **/
- function SaveAsExcel(){
- var sRet=window.showModalDialog("saveasexcel.htm",s1,"status:no;dialogHeight:120px;dialogWidth:400px;dialogTop:180;dialogLeft:250px")
- if(typeof sRet=="undefined") return
- var s1=sRet+".csv"
- grid.SaveExcel(s1)
- //alert("报表成功的另存到"+s1)
- }