You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

716 lines
26 KiB

TotForm = function(instanceName, tableCount, itemCount) {
this.name = instanceName;
this.isTotDoc = false;
this.tableCount = tableCount;
this.itemCount = itemCount;
this.itemList = new Array();
this.tableList = new Array();
for(var j=1; j <= tableCount && tableCount > 0 ; j++)
this.tableList[j]= new TotTable(1);
for(var i=0;i<itemCount;i++)
this.itemList[i] = new TotItem('', 0, 0, 0, 0,
'', '', '',
false, false);
};
TotForm.prototype.Class = 'TotForm';
TotTable = function(type) {
this.type = type;
};
TotItem = function(name, tableNum, rowNum, colNum, size,
desc, type, expr,
dataItem, setWin) {
this.itemName = name;
this.tableNum = tableNum;
this.rowNum = rowNum;
this.colNum = colNum;
this.size = size;
this.desc = desc;
this.type = type;
this.expr = expr;
this.dataItem = dataItem;
this.setWin = setWin;
};
TotForm.prototype.isValid = function() {
return this.isTotDoc;
};
// change all cell types in 'cellRange' to 'type'
TotForm.prototype.changeTypes = function (cellRange, type) {
if(cellRange == null)
return false;
if(/[A-Z]+\d+\s*:\s*[A-Z]+\d+/ig.test(cellRange)) { // cellName:cellName 형태
for(var i = 0; i < this.itemCount; i++) {
if(isContainedIn(this.itemList[i].itemName, cellRange)) {
this.itemList[i].type = type;
this.reShowValue(i);
}
}
} else if(/[A-Z]+\d+(?:\s*[,\+\-\*\/=]\s*[A-Z]+\d+)*/ig.test(cellRange)) { // cellName, cellName, ... 형태
var cellNameArray = cellRange[0].split(/\s*[,\+\-\*\/=]\s*/g);
for(var i = 0; i < this.itemCount; i++) {
for(var j = 0; j < cellNameArray.length; j++) {
if(this.itemList[i].itemName.toUpperCase() == cellNameArray[j].toUpperCase().trim()) {
this.itemList[i].type = type;
this.reShowValue(i);
}
}
}
} else {
alert('unexpected condition');
// FIXME : unexpected condition
}
};
TotForm.prototype.correctCellTypes = function() {
for(var i = 0; i < this.itemCount; i++) {
if(this.itemList[i].expr != '' && this.itemList[i].expr != null) { // if has formula
//FIXME : this regexp can handle with neither incorrect cell range expression
//nor composite expression like 'cellName:cellName, cellName:cellName'
var cellRange = this.itemList[i].expr.match(/[A-Z]+\d+\s*:\s*[A-Z]+\d+|[A-Z]+\d+(?:\s*[,\+\-\*\/=]\s*[A-Z]+\d+)+/ig);
this.itemList[i].type = '숫자';
this.reShowValue(i);
this.changeTypes(cellRange, '숫자');
}
}
};
TotForm.prototype.exprCheck = function(){
for(var i=0; i < this.itemList.length; i++){
if(isErrorExpr(this.itemList[i].expr, this.itemList[i].type)) {
return true;
}
}
};
function isErrorExpr(expr, type){
//SUM안에 +가 있는 경우 check
if(expr != ""){
var sumIndex = expr.indexOf("SUM");
var plusIndex = 0;
plusIndex += expr.indexOf("+");
plusIndex += expr.indexOf("-");
plusIndex += expr.indexOf("*");
plusIndex += expr.indexOf("/");
plusIndex += expr.indexOf("=");
if(expr.indexOf("=")>-1)
{
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요. \n정의한 수식중 SUM()안에 '+', '-', '*', '/', '='가 있는지 다시 확인해 주세요. ");
return true;
}
if(sumIndex > -1 && plusIndex > -1){
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요. \n정의한 수식중 SUM()안에 '+', '-', '*', '/', '='가 있는지 다시 확인해 주세요. ");
return true;
}
var colonIndex = expr.indexOf(":");
var alphabetCount = 0;
var alphaBeforeCount = 0;
var alphaAfterCount = 0;
//SUM안에 아이템이 하나만 존재할때..
var roundInStr = "";
var charCount = 0;
var alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
// if(sumIndex > -1){
// roundInStr = expr.substring(sumIndex+3, expr.length);
// charCount = roundInStr.length;
// var isErrorExpr = false;
// for(var i=0; i < charCount; i++){
// alert(roundInStr.substring(i, i+1));
// if(alphabet.indexOf(roundInStr.substring(i, i+1)) > -1 && isErrorExpr){
// isErrorExpr = false;
// break;
// }else{
// isErrorExpr = true;
// }
// }
// }
// if(isErrorExpr){
// alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요. \n정의한 수식중 SUM()안에 셀 이름이 하나만 있는지 확인해 주세요. ");
// return true;
// }
if(sumIndex > -1){
//콜론이 없는 경우에는 알파벳+숫자가 2개 있어야 한다.
if(colonIndex <= -1) {
roundInStr = expr.substring(sumIndex+4, expr.length-1);
charCount = roundInStr.length;
for(var i=0; i < charCount; i++){
if(alphabet.indexOf(roundInStr.substring(i, i+1)) > -1){
if(alphabetCount == 1) { alphabetCount = 0; }
alphabetCount = alphabetCount + 1;
} else {
if(alphabetCount == 2) { alphabetCount = 1; }
alphabetCount = alphabetCount + 1;
}
}
if(alphabetCount != 2){
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요.");
return true;
}
//콜론이 1개 있는 경우에는 알파벳+숫자가 2개 있어야 한다.
} else {
//콜론의 앞쪽
roundInStr = expr.substring(sumIndex+4, colonIndex);
charCount = roundInStr.length;
for(var i=0; i < charCount; i++){
if(alphabet.indexOf(roundInStr.substring(i, i+1)) > -1){
if(alphaBeforeCount == 1) { alphaBeforeCount = 0; }
alphaBeforeCount = alphaBeforeCount + 1;
} else {
if(alphaBeforeCount == 2) { alphaBeforeCount = 1; }
alphaBeforeCount = alphaBeforeCount + 1;
}
}
//콜론의 뒤쪽
roundInStr = expr.substring(colonIndex+1, expr.length-1);
charCount = roundInStr.length;
for(var i=0; i < charCount; i++){
if(alphabet.indexOf(roundInStr.substring(i, i+1)) > -1){
if(alphaAfterCount == 1) { alphaAfterCount = 0; }
alphaAfterCount = alphaAfterCount + 1;
} else {
if(alphaAfterCount == 2) { alphaAfterCount = 1; }
alphaAfterCount = alphaAfterCount + 1;
}
}
if((alphaBeforeCount == 2 && alphaAfterCount != 2) || (alphaBeforeCount != 2 && alphaAfterCount == 2)) {
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요. \n정의한 수식중 SUM()안에 셀 이름이 하나만 있는지 확인해 주세요. ");
return true;
} else if(alphaBeforeCount != 2 || alphaAfterCount != 2){
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요.");
return true;
}
}
}
// 셀을 '숫자'로 선택하고, 계산식을 입력할 경우 입력가능한 문자외에는 등록하지 못하도록 체크한다. 2014.11.21 by YOUNGJUN,CHO
//alert(SetCell.itemType.value);
if (type === "숫자") {
// 아래 문자가 아닌 경우(정규식 앞에 ^ 으로 아닌 경우를 체크)가 존재할 경우 true 로 리턴.
// 영문 대문자 A-Z
// 숫자 0-9
// 괄호 ( )
// 사칙연산 + - * /
// 콜론 :
var regexp = /[^A-Z|0-9|\(|\)|\+|\-|\/|\*|\:]/;
//alert(regexp.test(expr));
if (regexp.test(expr) === true) {
alert(expr+" 수식이 잘못 되었습니다.\n\n셀을 '숫자'로 선택하신 경우에는 수식에 소수점을 사용할 수 없으며\n\r아래 문자만 사용할 수 있습니다.\n\
\n** 알파벳(대문자), 숫자, 괄호, 사칙연산기호(+,-,*,/), 콜론(:) **\n\n수식을 다시 설정해 주십시오!");
return true;
}
}
}
//SUM없이 ','만 사용할때 사용불가
var comaIndex;
if(sumIndex == -1){
comaIndex = expr.indexOf(",");
if(comaIndex > -1){
alert(expr+" 수식이 잘못 되었습니다. 다시확인해 주세요. \n정의한 수식중 ','가 있는지 확인해주세요. \n','를 '+'로 바꿔 사용하면 정상적으로 작동합니다.");
return true;
}
}
//수식에 자기자신을 연산하는 경우 사용불가
if(expr.indexOf("+")==-1||expr.indexOf("-")==-1||expr.indexOf("*")==-1||expr.indexOf("/")==-1||expr.indexOf("SUM(")==-1){
var cellname=$(SetWin).find('td:first').text();
try{
cellname=cellname.trim();
}catch(e){}
if(expr.indexOf(cellname)>-1&&cellname!=''){
alert('수식에는 자기 자신을 연산할 수 없습니다.');
return true;
}
}
//셀 서식 적용 중 콤보박스와 연산이 있을 경우 콤보박스 값 중에 숫자값이 아닌 값이 있는지 체크
//수식 일 때 숫자가 아닌 셀 이 있는 지 확인
var temp=expr.replace('+',',').replace('-',',').replace('*',',').replace('/',',').replace('SUM(',',').replace(':',',').replace(')',',').split(',');
if(temp.length>1){
for(var i=0;i<temp.length;i++){
for(var j=0;j<totForm.itemList.length;j++){
if(temp[i]==totForm.itemList[j].itemName){
var exp=totForm.itemList[j].expr;
if(exp.indexOf('^')>-1){
var explist=exp.split('^');
for(var k=0;k<explist.length;k++){
if(isNaN(explist[k])){
alert(totForm.itemList[j].itemName+' 의 콤보 값 중에 숫자가 아닌값이 있습니다.');
return true;
}
}
}
if(totForm.itemList[j].type!='숫자'&&exp.indexOf('^')==-1){
alert(totForm.itemList[j].itemName+' 은 숫자가 아니므로 수식을 적용할 수 없습니다.');
return true;
}
}
}
}
}
if(expr.indexOf('+')>-1||expr.indexOf('-')>-1||expr.indexOf('*')>-1||expr.indexOf('/')>-1||expr.indexOf('SUM(')>-1){
for(var i=0;j<totForm.itemList.length;i++){
}
}
}
function isErrorCalculate(expr) {
}
//설정
function setValue(totForm, index){
if(isErrorExpr(SetCell.itemExpr.value, SetCell.itemType.value)) return; //수식 오류 check
totForm.itemList[index].type = SetCell.itemType.value;
totForm.itemList[index].size = SetCell.itemSize.value;
totForm.itemList[index].expr = SetCell.itemExpr.value;
totForm.reShowValue(index);
}
function getNumber(itemName) {
var num = itemName.substring(1, itemName.length);
if(isNaN(num))
num = itemName.substring(2, itemName.length);
return num;
}
function getCharter(itemName, number) {
/*
var charter = itemName.substring(0, 1);
if(isNaN(number))
charter = itemName.substring(0, 2);
return charter;
*/
var ret;
if(itemName.length==2)
{
var charter = itemName.substring(0, 1);
if(isNaN(number)) charter = itemName.substring(0, 2);
ret=charter;
}
else
{
var charter1 = itemName.substring(0, 1);
var charter2 = itemName.substring(1, 2);
if(!isNaN(charter2)) { ret=charter1; }
else { ret=itemName.substring(0,2); }
}
return ret;
}
function horApply(totForm, ItemName, index) {
if(isErrorExpr(SetCell.itemExpr.value, SetCell.itemType.value)) return; //수식 오류 체크
var TableSu = totForm.itemList[index].tableNum;
var Number = getNumber(ItemName);
var Charter = getCharter(ItemName, Number);
for (i=0;i<totForm.itemCount;i++){
if(totForm.itemList[i].itemName != undefined
&& totForm.itemList[i].desc == 'empty'
&& totForm.itemList[i].tableNum == TableSu
&& totForm.itemList[i].type != '타이틀') {
var ChangeNumber = getNumber(totForm.itemList[i].itemName);
var ChangeCharter = getCharter(totForm.itemList[i].itemName, ChangeNumber);
if(Number == ChangeNumber){
var ItemExpr = (SetCell.itemExpr.value).toUpperCase();
if(ItemExpr.indexOf("^") < 0)
totForm.itemList[i].expr = ItemExpr.replace(eval('/'+Charter+'/g'), ChangeCharter);
else
totForm.itemList[i].expr = ItemExpr;
totForm.itemList[i].type = SetCell.itemType.value; //숫자, 문자, 날짜 수평 설정
totForm.itemList[i].size = SetCell.itemSize.value; //셀 크기 수평 설정
totForm.reShowValue(i);
}
}
}
SetWin.style.visibility="hidden";
}
function verApply(totForm, ItemName, index){
if(isErrorExpr(SetCell.itemExpr.value, SetCell.itemType.value)) return; //수식 오류 체크
var TableSu = totForm.itemList[index].tableNum;
var Number = getNumber(ItemName);
var Charter = getCharter(ItemName, Number);
for (i=0;i<totForm.itemCount;i++){
if(totForm.itemList[i].itemName != undefined
&& totForm.itemList[i].desc == 'empty'
&& totForm.itemList[i].tableNum == TableSu
&& totForm.itemList[i].type != '타이틀') {
var ChangeNumber = getNumber(totForm.itemList[i].itemName);
var ChangeCharter = getCharter(totForm.itemList[i].itemName, ChangeNumber);
if(Charter == ChangeCharter){
var ItemExpr = (SetCell.itemExpr.value).toUpperCase();
if(ItemExpr.indexOf("^") < 0)
totForm.itemList[i].expr = ItemExpr.replace(eval('/'+Number+'/g'), ChangeNumber);
else
totForm.itemList[i].expr = ItemExpr;
totForm.itemList[i].type = SetCell.itemType.value; //숫자, 문자, 날짜 수직 설정
totForm.itemList[i].size = SetCell.itemSize.value; //셀 크기 수직 설정
totForm.reShowValue(i);
}
}
}
SetWin.style.visibility="hidden";
}
TotForm.prototype.setTypeAll = function(typeName) {
for (i=0;i<this.itemCount;i++){
if(this.itemList[i].itemName != undefined
&& this.itemList[i].type != '타이틀'
&& this.itemList[i].desc == 'empty'){
this.itemList[i].type = typeName;
this.reShowValue(i);
}
}
};
TotForm.prototype.setTypeByIndex = function(typeName, index) {
for (i=0;i<this.itemCount;i++){
if(this.itemList[i].itemName != undefined
&& this.itemList[i].desc == 'empty'
&& this.itemList[i].type != '타이틀'
&& this.itemList[i].tableNum == index){
this.itemList[i].type = typeName;
this.reShowValue(i);
}
}
};
TotForm.prototype.setSum = function(index, expr){
this.itemList[index].setWin = true;
this.itemList[index].desc = 'AutoSum';
this.itemList[index].size = 10;
this.itemList[index].expr = expr;
this.itemList[index].type = 0;
};
TotForm.prototype.closeValue = function(index) {
var el=document.getElementById("cell_"+index);
if(el) eval('cell_'+index).innerHTML="";
};
TotForm.prototype.reShowValue = function(i){
if(this.itemList[i].type != '타이틀' && this.itemList[i].desc == 'empty'){
this.isTotDoc = true; //입력셀이 하나라도 있는지..?
this.showValue(i);
}else{
this.closeValue(i);
this.itemList[i].expr = '';
}
};
TotForm.prototype.showValue = function(index) {
var htmlStr =
"<table width=100% border=0 cellspacing=0 cellspacing=1>\
<tr>\
<td align=left width=40%>\
<a href=\"javascript:inExp('"+ this.itemList[index].itemName +"');\"><b><font face='Courier' color='brown'>"+ this.itemList[index].itemName +"</font></a></b></td><td align=right>";
htmlStr+="<img src=\"/totsys/common/inc/documents/tot_doc/images/";
if(this.itemList[index].expr == '' || this.itemList[index].expr == null){
if(this.itemList[index].type == '타이틀')
htmlStr+="set4.gif\" ";
else if(this.itemList[index].type == '문자')
htmlStr+="set2.gif\" ";
else if(this.itemList[index].type == '숫자')
htmlStr+="set1.gif\" ";
else if(this.itemList[index].type == '날짜')
htmlStr+="set3.gif\" ";
}else if(this.itemList[index].expr.indexOf('^') != -1) {
this.itemList[index].type = '문자';
htmlStr+="set_on5.gif\" ";
}else if(this.itemList[index].expr.indexOf('~') != -1) {
this.itemList[index].type = '문자';
htmlStr+="set_on2.gif\" ";
}else{
if(this.itemList[index].type == '타이틀')
htmlStr+="set_on4.gif\" ";
else if(this.itemList[index].type== '문자')
htmlStr+="set_on2.gif\" ";
else if(this.itemList[index].type== '숫자')
htmlStr+="set_on1.gif\" ";
else if(this.itemList[index].type== '날짜')
htmlStr+="set_on3.gif\" ";
}
htmlStr+="border=0 align=center onclick=\"showSetWinForCell("+this.name+", "+index+");\" alt='"+this.itemList[index].expr+"' height=15>";
htmlStr+="</td>\
</tr>\
</table>";
eval('cell_'+index).innerHTML = htmlStr;
};
function showSetWinForCell(totForm, index){
totForm.itemList[index].setWin = true;
SetWin.style.visibility='visible';
SetWin.style.width='auto';
//SetWin.style.top = window.event.y + document.body.scrollTop;
//SetWin.style.left = window.event.x + document.body.scrollLeft;
// 2014.08.21 by YoungJun Cho. 셀 서식지정 레이어 팝업 위치조절
SetWin.style.top = (window.event.clientY + document.body.scrollTop - 30) + "px"; // 위로 30px 밀기
SetWin.style.left = (window.event.clientX + document.body.scrollLeft + 20) + "px"; // 우측으로 20px 밀기
SetWin.innerHTML =
"<table nowrap border=0 cellpadding=4 cellspacing=0 bgcolor=#eeeeee>\
<tr nowrap bgcolor='#BBBBBB' style='cursor:hand;' id='ForDrag'>\
<td nowrap><font color='brown'><b>"+totForm.itemList[index].itemName+"</b></font></td>\
<td nowrap align=right><right><img src='/totsys/common/inc/documents/tot_doc/images/close.gif' onmouseDown=\"this.src='/totsys/common/inc/documents/tot_doc/images/close1.gif';\" onclick=\"SetWin.style.visibility='hidden';\"></right></td>\
</tr>\
<tr nowrap>\
<td nowrap colspan=2>\
<form name='SetCell'>\
<table nowrap border=0 cellpadding=2 cellspacing=0>\
<tr nowrap >\
<td nowrap>\
<input type='hidden' name=itemSize value='3'>\
<select name='itemType' onchange=\"SetCell.itemType.value=this.value;\" style='vertical-align: middle;'>\
<option value='숫자'>숫자</option>\
<option value='문자'>문자</option>\
<option value='날짜'>날짜</option>\
<!--option value='타이틀'>표제</option-->\
</select>\
<input type=\"button\" style=\"cursor: hand; padding: 0 2px;\" onClick=\"inExp('+');\" value=\"+\" />\
<input type=\"button\" style=\"cursor: hand; padding: 0 2px;\" onClick=\"inExp('-');\" value=\"-\" />\
<input type=\"button\" style=\"cursor: hand; padding: 0 2px;\" onClick=\"inExp('*');\" value=\"*\" />\
<input type=\"button\" style=\"cursor: hand; padding: 0 2px;\" onClick=\"inExp('/');\" value=\"/\" />\
<input type=\"button\" style=\"cursor: hand; padding: 0 2px;\" onClick=\"inExp('SUM(:)');\" value=\"SUM(:)\" />\
</td>\
</tr>\
<tr nowrap>\
<td nowrap><input name='itemExpr' type='text' style='width:100%' class=inputtxt onkeydown='enter_catch("+totForm.name+", "+index+")'></td>\
</tr>\
<input type=hidden name=itemDesc>\
<tr nowrap>\
<td nowrap colspan=10 align=center>\
<input type=button value='설정' style=\"cursor: hand; padding: 0 2px;\" onclick=\"setValue("+totForm.name+", "+index+");SetWin.style.visibility='hidden';\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\
<input type=button value='행적용' style=\"cursor: hand; padding: 0 2px;\" onClick=\"horApply("+totForm.name+", '"+totForm.itemList[index].itemName+"', "+index+");\">\
<input type=button value='열적용' style=\"cursor: hand; padding: 0 2px;\" onClick=\"verApply("+totForm.name+", '"+totForm.itemList[index].itemName+"', "+index+");\">\
</td>\
</tr>\
</table>\
</form>\
</td>\
</tr>\
</table>";
SetCell.itemSize.value = totForm.itemList[index].size;
SetCell.itemExpr.value = totForm.itemList[index].expr;
SetCell.itemType.value = totForm.itemList[index].type;
SetCell.itemExpr.focus();
}
function inExp(v1){
if(SetWin.style.visibility=='hidden'){
}else{
SetCell.itemExpr.focus();
//ie10,11 호환성 수정
var range;
var txt=SetCell.itemExpr.value;
try{
range = window.document.selection.createRange();
range.text=v1;
if (v1.match('\\(\\)$')) {
range.moveStart ('character', -1);
range.moveEnd ('character', -1);
range.select();
} else if (v1.match('\\(:\\)$')) {
range.moveStart ('character', -2);
range.moveEnd ('character', -2);
range.select();
}else if(txt.substr(txt.length-2,2)==':)'){
range.moveStart ('character', 1);
range.moveEnd ('character', 0);
range.select();
}
}catch(e){
range=SetCell.itemExpr.createTextRange();
var pos=SetCell.itemExpr.selectionStart;
txt=txt.substring(0,pos)+v1+txt.substring(pos,txt.length);
SetCell.itemExpr.value=txt;
if (v1.match('\\(:\\)$')) {
range.moveStart('character', SetCell.itemExpr.value.length-2);
range.moveEnd('character',-2);
range.select();
}else if(txt.substring(txt.length-2)==':)'&&txt.substring(txt.length-6)!='SUM(:)'){
range.moveStart('character', SetCell.itemExpr.value.length-1);
range.moveEnd('character', -1);
range.select();
}
}
}
}
function enter_catch(totForm, index){
if(event.keyCode==13){
setValue(totForm, index);
SetWin.style.visibility='hidden';
totForm.reShowValue(index);
}
}
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};
function compareColName(col1, col2) {
col1 = col1.toUpperCase();
col2 = col2.toUpperCase();
if(col1.length != col2.length)
return col2.length - col1.length;
else {
for(var x = 0; x < col1.length; x++) {
if(col1.charCodeAt(x) == col2.charCodeAt(x))
continue;
else
return col2.charCodeAt(x) - col1.charCodeAt(x);
}
return 0;
}
}
function isContainedIn(cellName, cellRange) {
var cellNameArray = cellRange[0].split(/\s*:\s*/g);
var cellName1 = cellNameArray[0].toUpperCase();
var cellName2 = cellNameArray[1].toUpperCase();
var colName1 = cellName1.match(/[A-Z]+/g);
var colName2 = cellName2.match(/[A-Z]+/g);
var rowNum1 = cellName1.match(/\d+/g);
var rowNum2 = cellName2.match(/\d+/g);
var startColName, endColName, startRowNum, endRowNum;
if( (compareColName(colName1[0], colName2[0]) < 0) ||
(compareColName(colName1[0], colName2[0]) == 0 && rowNum1[0] - rowNum2[0] < 0)
) {
startColName = colName1[0];
endColName = colName2[0];
startRowNum = rowNum1[0];
endRowNum = rowNum2[0];
} else /*if( (compareColName(colName1[0], colName2[0]) > 0) ||
(compareColName(colName1[0], colName2[0]) == 0 && rowNum1[0] - rowNum2[0] >= 0)
)*/ {
startColName = colName2[0];
endColName = colName1[0];
startRowNum = rowNum2[0];
endRowNum = rowNum1[0];
}
var colNameTmp = cellName.toUpperCase().match(/[A-Z]+/g);
var rowNumTmp = cellName.match(/\d+/g);
var colName = colNameTmp[0];
var rowNum = rowNumTmp[0];
return compareColName(startColName, colName) <= 0 && compareColName(colName, endColName) <= 0 && startRowNum <= rowNum && rowNum <= endRowNum;
}
function getCalculationForm(str, rowNum, type){
//필요없는 EXPR ^
if(isSearch(str, "^")) return str;
//"SUM", "(", ")", ":", ",", "+", "-", "*", "/"
//SUM(B9:F99)
var alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var integer = '0123456789';
var charCount = str.length;
var charList = new Array(charCount);
var numList = new Array(charCount);
var befoChar = "";
var currChar = "";
var afterChar = "";
if(charCount < 1) return str;
//String array analysis
//expr의 item name의 number add
var exprbuf = "";
var isItemNum = false;
var tmpNum = "";
var sumNum = "";
for(var i=0; i < charCount; i++){
currChar = str.substring(i, i+1);
if(isSearch(alphabet, currChar)){ //문자 일때~~~~
if(currChar == 's' || currChar == 'S'){
sumNum = 1;
isItemNum = true;
}else if(sumNum == 1 && i > 0 && (currChar == 'u' || currChar == 'U')){
sumNum = 2;
isItemNum = true;
}else if(sumNum == 2 && i > 1 && (currChar == 'm' || currChar == 'M')){
sumNum = 3;
isItemNum = false;
}else{
sumNum = 0;
isItemNum = true;
}
exprbuf += currChar;
}else if(isSearch(integer, currChar)){ //숫자 일때~~~~
if(i > 0 && isSearch(alphabet, befoChar) && isItemNum == true){ //Item name의 첫번째 숫자라면
tmpNum = currChar;
isItemNum = true;
}else if(i > 0 && isSearch(integer, befoChar) && isItemNum == true){ //Item name의 두번째 이상의 숫자라면
tmpNum += currChar;
isItemNum = true;
}else{ //나머지
exprbuf += currChar;
isItemNum = false;
}
afterChar = str.substring(i+1, i+2);
if((i == (charCount-1) || !isSearch(integer, afterChar)) && isItemNum){ //Item name의 숫자 끝이라면
if(type == "add"){ //동적표에서 보가자료 보기시 보고한 행에 따라 수식을 변경해줌
exprbuf += (parseInt(tmpNum)+parseInt(rowNum));
isItemNum = false;
}else if(type == "sub"){ //두개의 표를 등록할때 Form에 적용되는 수식사용
exprbuf += (parseInt(tmpNum)-parseInt(rowNum));
isItemNum = false;
}
}
}else{
exprbuf += currChar;
isItemNum = false;//수식 일때~~~
}
befoChar = currChar;
}
return exprbuf;
}
function isSearch(strs, str){
var count = strs.length;
var strList = new Array(count);
for(var i=0; i < count; i++){
if(strs.substring(i, i+1) == str)
return true;
}
return false;
}