/*********************************************************************************************************
 * 프로그램명 : MReportData.java 프로그램설명 : 집계문서에 대해 보고자가 보고한 data처리 작성자 : 강원중 작성일 : 2003.11.30 변경일 : 2004.09.16
 **********************************************************************************************************/

package kr.co.kihyun.moumi.report;

import java.text.NumberFormat;
import java.util.StringTokenizer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import kr.co.kihyun.beans.entity.TotReport;
import kr.co.kihyun.beans.totsys.doc.HttpDocRegister;
import kr.co.kihyun.beans.totsys.doc.table.item.ItemList;
import kr.co.kihyun.io.MultipartRequest;
import kr.co.kihyun.lang.MString;
import kr.co.kihyun.moumi.doc.table.item.MItem;
import kr.co.kihyun.text.html.HtmlUtil;

public class MReportData {
	private static final Logger LOG = LoggerFactory.getLogger(MReportData.class);

	public static String[][] getDataArray(int dataCount, String datas) throws ArrayIndexOutOfBoundsException {
		int rowCount = 1; // total data는 레코드가 1이다.
		return getDataArray(rowCount, dataCount, datas);
	}

	public static String[][] getDataArray(int rowCount, int dataCount, String datas)
			throws ArrayIndexOutOfBoundsException {

		String[] str1 = null;
		String[] str2 = null;
		String[][] dataList = null;
		dataList = new String[rowCount][dataCount];
		// if(datas == null || datas.trim().equals("")){
		if (datas == null) {
			return null;
		}

		str1 = datas.split(MReport.splitStr1);
		int str2Length = 0;

		for (int i = 0, j = 0; i < rowCount && i < str1.length; i++) {
			str2 = str1[i].split(MReport.splitStr2);
			str2Length = str2.length;

			for (j = 0; j < str2Length && str2Length <= dataCount; j++) {
				dataList[i][j] = str2[j];
			}
		}

		return dataList;
	}

	public static String[][] getDataArray2(int rowCount, int dataCount, String datas)
			throws ArrayIndexOutOfBoundsException {

		String[] str1 = null;
		String[] str2 = null;
		String[][] dataList = null;
		dataList = new String[rowCount][dataCount];
		// if(datas == null || datas.trim().equals("")){
		if (datas == null) {
			return null;
		}

		str1 = datas.split(MReport.splitStr2);
		int str2Length = 0;

		for (int i = 0, j = 0; i < rowCount && i < str1.length; i++) {
			str2 = str1[i].split(MReport.splitStr1);
			str2Length = str2.length;

			for (j = 0; j < str2Length && str2Length <= dataCount; j++) {
				dataList[i][j] = str2[j];
			}
		}

		return dataList;
	}

	public static String[] getDataArray(String datas) throws ArrayIndexOutOfBoundsException {
		String[] dataList = null;

		String chDatas = datas;

		// if(datas == null || datas.trim().equals("")){
		if (datas == null) {
			return null;
		}

		StringBuilder delims = new StringBuilder(16).append("(").append(TotReport.COL_DELIMITER).append("|")
				.append(TotReport.ROW_DELIMITER).append("|").append(TotReport.TABLE_DELIMITER).append(")");

		dataList = chDatas.split(delims.toString());
		return dataList;
	}

	public static int[] getColNumList(String datas) throws ArrayIndexOutOfBoundsException {

		// if(datas == null || datas.trim().equals("")){
		if (datas == null) {
			return null;
		}

		String[] collist = null;
		String[] rowlist = null;
		String[] tablelist = datas.split(TotReport.TABLE_DELIMITER);

		int[] colNumList = new int[tablelist.length];

		for (int i = 0; i < tablelist.length; i++) {
			rowlist = tablelist[i].split(MReport.splitStr2);
			collist = rowlist[0].split(MReport.splitStr1);
			colNumList[i] = collist.length;
		}

		return colNumList;
	}

	public static int[] getRowNumList(String datas) throws ArrayIndexOutOfBoundsException {

		// if(datas == null || datas.trim().equals("")){
		if (datas == null) {
			return null;
		}

		String[] rowlist = null;
		String[] tablelist = datas.split(TotReport.TABLE_DELIMITER);

		int[] rowNumList = new int[tablelist.length];

		for (int i = 0; i < tablelist.length; i++) {
			rowlist = tablelist[i].split(MReport.splitStr2);
			rowNumList[i] = rowlist.length;
		}

		return rowNumList;
	}

	/**************************** data ****************************/
	public static String getData(String form, String[] itemDataList, int[] itemIndexList, String[] itemDescList) {

		if (form == null)
			return null;

		StringBuilder sb1 = new StringBuilder();
		StringBuilder sb2 = new StringBuilder();

		String data = "";

		int tableStart = 0;
		int tableEnd = 0;

		while (true) {

			tableStart = form.indexOf("<table");
			if (tableStart == -1)
				break;
			tableEnd = form.indexOf(">", tableStart + 1);
			if (tableEnd == -1)
				break;

			sb1.append(form.substring(0, tableStart + 6));
			sb1.append(">");
			form = form.substring(tableEnd + 1, form.length());

		}

		sb1.append(form);
		data = sb1.toString();

		int tdStart = 0;
		int tdEnd = 0;
		int closetdStart = 0;
		int tdCount = 0;
		int index = 0;
		StringBuilder sb = null;
		String s = "";

		while (true) {

			if (index > itemIndexList.length - 1)
				break;

			tdStart = data.indexOf("<td");
			if (tdStart == -1)
				break;
			tdEnd = data.indexOf(">", tdStart + 1);
			if (tdEnd == -1)
				break;
			closetdStart = data.indexOf("</td>", tdEnd + 1);
			if (closetdStart == -1)
				break;

			if (tdCount == itemIndexList[index]) {

				sb = new StringBuilder();

				if (tdEnd > tdStart + 40) {
					sb.append(data.substring(0, tdStart + 40));
					sb.append(">");
					sb.append(itemDescList[index]);
					sb.append("</td>");

					s = sb.toString();
					s = s.replaceFirst("empty", itemDataList[index]);
					sb2.append(s);
					data = data.substring(closetdStart + 5, data.length());
				} else {
					sb.append(data.substring(0, tdEnd));
					sb.append(" .>");
					sb.append(itemDescList[index]);
					sb.append("</td>");
					s = sb.toString();
					s = s.replaceFirst("empty", itemDataList[index]);
					sb2.append(s);
					data = data.substring(closetdStart + 5, data.length());
				}
				index++;
			} else {
			}
			tdCount++;
		}

		sb2.append(data);
		return sb2.toString();
	}

	public String getOneTotalData(String headLine, String[] totTotData, int[] itemNumber) {
		if (headLine == null)
			return null;
		return getOneTotalData(new StringBuilder(headLine), totTotData, itemNumber);
	}

	public String getOneTotalData(StringBuilder headLine, String[] totTotData, int[] itemNumber) {

		String dataTot = "";
		StringBuilder sInsertedData = new StringBuilder();
		sInsertedData.append("<tr>");

		for (int i = 0; i < totTotData.length; i++) {
			dataTot = totTotData[i];
			if (dataTot.equals("empty")) {
				dataTot = "&nbsp;";
			}

			if (itemNumber[i] == MItem.INT) {// 숫자
				sInsertedData.append("<td align=right><font color=red>");
				dataTot = NumberFormat.getNumberInstance().format(Double.parseDouble(dataTot));
				sInsertedData.append(dataTot);
				sInsertedData.append("&nbsp;&nbsp;");
			} else {
				sInsertedData.append("<td><font color=red>");
				sInsertedData.append(dataTot);
			}
			sInsertedData.append("</font></td>");
		}

		sInsertedData.append("</tr>");

		headLine.append(sInsertedData.toString());
		headLine.append("</table>");
		return headLine.toString();
	}

	// 추출된 값들중 입력되지 않은 값들 중에 item type에 따라 값을 변환해 줌
	public static String[][] getReportData(String[][] inData, int[] itemTypeList) {

		int itemCount = itemTypeList.length;
		int index = 0;

		for (int i = 0, j = 0; i < inData.length; i++) {
			for (j = 0; j < itemCount; j++) {
				if (itemTypeList[j] >= MItem.CHAR) { // 문자, 숫자, 날짜 형식의 아이템이냐..?
					if (itemTypeList[j] == MItem.INT) { // 숫자냐..?
						if (inData[i][index] == null || inData[i][index].trim().equals("")) { // 공백이라면 0을 넣어줌
							inData[i][index] = "0";
						}
					} else { // 문자이거나, 날쨔이거나..?
						if (inData[i][index] == null || inData[i][index].trim().equals("")) { // 공백이라면 " "을 넣어줌
							inData[i][index] = "";
						} else if (inData[i][index] != null & inData[i][index].trim().equals("empty")) {
							inData[i][index] = "";
						}
					}
					index++; // inData의 index으로 사용함
				}
			}
			index = 0; // 하나의 레코드가 끝나면 초기화
		}
		return inData;
	}

	// 추출된 값들중 입력되지 않은 값들 중에 item type에 따라 값을 변환해 줌
	public static String[] getReportData(String[] inData, int[] itemTypeList, int[] tableColNumList,
			String[] tableRowList) {
		int index = 0;
		int itemIdx = 0;
		int tmpItemIdx = 0;
		int here = 0;
		int addt = 0;

		for (int i = 0; i < tableRowList.length && i < tableColNumList.length; i++) {

			for (int stp = 0; stp < Integer.parseInt(tableRowList[i]); stp++) {
				tmpItemIdx = itemIdx;
				addt = 0;

				for (int p = 0; p < tableColNumList[i] && itemIdx + p + addt < itemTypeList.length && index < inData.length; p++) {
					itemIdx = tmpItemIdx;
					if (itemTypeList[itemIdx + p + addt] == MItem.TITLE) {
						for (int x = itemIdx + p + addt; x < itemTypeList.length; x++, addt++) {
							if (itemTypeList[itemIdx + p + addt] != MItem.TITLE)
								break;
						}
					}

					if (itemTypeList[itemIdx + p + addt] >= MItem.CHAR) { // 문자, 숫자, 날짜 형식의 아이템이냐..?
						if (itemTypeList[itemIdx + p + addt] == MItem.INT) { // 숫자냐..?
							if (inData[index] == null || inData[index].trim().equals("")) { // 공백이라면 0을 넣어줌
								inData[index] = "0";
							}
						} else { // 문자이거나, 날짜이거나..?
							if (inData[index] == null || inData[index].trim().equals("")) { // 공백이라면 " "을 넣어줌
								inData[index] = "";
							} else if (inData[index] != null & inData[index].trim().equals("empty")) {
								inData[index] = "";
							}
						}
						index++;
					}
				}
			}
			itemIdx = itemIdx + tableColNumList[i] + addt;
			here = here + tableColNumList[i];
		}

		return inData;
	}

	public static String[] getTotalDataList(int rowCount, ItemList itemList, String[][] dataList, int strInItemNum)
			throws ArrayIndexOutOfBoundsException {
		return getTotalDataList(rowCount, itemList.getTypeList(), itemList.getExprList(), dataList, strInItemNum);
	}

	// 맙소사..
	// 하나의 보고 자료에서 입력된 보고 자료중 숫자는 합해서 집계를 낸다.
	// 정적인 표에서 사용함
	@Deprecated
	public static String[] getTotalDataList(int rowCount, int[] itemTypeList, String[] itemExprList,
			String[][] dataList, int strInItemNum) throws ArrayIndexOutOfBoundsException {

		int inItemCount = 0;
		if (dataList != null) {
			if (dataList.length > 0) {
				inItemCount = dataList[0].length;
			}
		}
		int itemCount = itemTypeList.length;
		String[] dataTotal = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;

		int index = 0;

		for (int c = strInItemNum, r = 0; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (r = 0; r < rowCount; r++) {
					try {
						if (dataList[r][index] != null) {
							floatData = Double.parseDouble(dataList[r][index].replaceAll(",", ""));
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}

					colTotalData = colTotalData + floatData;

				}
				dataTotal[index] = Double.toString(colTotalData);

				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				// if(리스트박스이면)
				if (itemExprList[c + strInItemNum] != null && itemExprList[c + strInItemNum].matches(".+?\\^.+?")) {
					String[] listValList = itemExprList[c + strInItemNum].split("\\^"); // 리스트박스에 올 >수 있는 값들
					int[] valCountList = new int[listValList.length]; // 각 리스트 값의 카운트

					// 각 리스트값의 카운트를 누적
					for (r = 0; r < rowCount; r++) {
						for (int v = 0; v < listValList.length; v++) {
							if (listValList[v].equals(dataList[r][index]))
								valCountList[v]++;
						}
					}

					// 테이블 형태로 출력
					dataTotal[index] = "<table width=\"100%\" border=1>";
					for (int v = 0; v < listValList.length; v++) {
						dataTotal[index] += "<tr>";
						dataTotal[index] += "	<td>" + listValList[v] + "</td>";
						dataTotal[index] += "	<td>" + valCountList[v] + "</td>";
						dataTotal[index] += "</tr>";
					}
					dataTotal[index] += "</table>";
				} else {
					dataTotal[index] = " ";
				}
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[index] = " ";
				index++;
			}
		}

		index = 0;
		for (int c = strInItemNum; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				// dataTotal[index] = NumberFormat.getNumberInstance().format( MInteger.parseInt(dataTotal[index]) );
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				index++;
			}
		}

		return dataTotal;
	}

	public static String[] getTotalDataList(int rowCount, int[] itemTypeList, String[] itemExprList,
			String[] itemNameList, String[][] dataList, int strInItemNum) throws ArrayIndexOutOfBoundsException {

		int inItemCount = 0;
		if (dataList != null) {
			if (dataList.length > 0) {
				inItemCount = dataList[0].length;
			}
		}
		int itemCount = itemTypeList.length;
		String[] dataTotal = new String[inItemCount];

		String[] dataName = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;

		int index = 0;

		for (int c = strInItemNum, r = 0; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (r = 0; r < rowCount; r++) {
					try {
						if (dataList[r][index] != null) {
							floatData = Double.parseDouble(dataList[r][index].replaceAll(",", ""));
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}

					colTotalData = colTotalData + floatData;

				}
				dataTotal[index] = Double.toString(colTotalData);
				dataName[index] = itemNameList[c];

				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				// if(리스트박스이면)
				if (itemExprList[c + strInItemNum] != null && itemExprList[c + strInItemNum].matches(".+?\\^.+?")) {
					String[] listValList = itemExprList[c + strInItemNum].split("\\^"); // 리스트박스에 올 >수 있는 값들
					int[] valCountList = new int[listValList.length]; // 각 리스트 값의 카운트

					// 각 리스트값의 카운트를 누적
					for (r = 0; r < rowCount; r++) {
						for (int v = 0; v < listValList.length; v++) {
							if (listValList[v].equals(dataList[r][index]))
								valCountList[v]++;
						}
					}

					// 테이블 형태로 출력
					dataTotal[index] = "<table width=\"100%\" border=1>";
					for (int v = 0; v < listValList.length; v++) {
						dataTotal[index] += "<tr>";
						dataTotal[index] += "	<td>" + listValList[v] + "</td>";
						dataTotal[index] += "	<td>" + valCountList[v] + "</td>";
						dataTotal[index] += "</tr>";
					}
					dataTotal[index] += "</table>";
				} else {
					dataTotal[index] = " ";
				}

				dataName[index] = itemNameList[c];

				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[index] = " ";

				dataName[index] = itemNameList[c];

				index++;
			}
		}

		/****************************** 수식계산을 위한 추가부분 **********************************/
		index = 0;
		for (int c = strInItemNum; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				String expr = itemExprList[c];
				char[] exprList = expr.toCharArray();

				/**************************** 후위식으로 변경 ****************************/
				String[] newEx = new String[100];
				char[] stack = new char[100];

				int exPos = 0;
				int stPos = 0;

				for (int i = 0; i < expr.length(); i++) {
					if (exprList[i] >= 'A' && exprList[i] <= 'Z') {
						StringBuilder variable = new StringBuilder();
						variable.append(exprList[i]);
						for (int j = i + 1; j < expr.length(); j++) {
							if ((exprList[j] >= 'A' && exprList[j] <= 'Z')
									|| (exprList[j] >= '0' && exprList[j] <= '9')) {
								variable.append(exprList[j]);
								i = j;
								continue;
							} else {
								break;
							}
						}

						newEx[exPos] = variable.toString();
						exPos++;
					} else if (exprList[i] >= '0' && exprList[i] <= '9') {
						StringBuilder variable = new StringBuilder();
						variable.append(exprList[i]);
						for (int j = i + 1; j < expr.length(); j++) {
							if (exprList[j] >= '0' && exprList[j] <= '9') {
								variable.append(exprList[j]);
								i = j;
								continue;
							} else {
								break;
							}
						}
						newEx[exPos] = variable.toString();
						exPos++;
					} else {
						if (stPos > 0) {
							if (exprList[i] == '*' || exprList[i] == '/' || exprList[i] == '%') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '+' || stack[stPos - 1] == '-' || stack[stPos - 1] == '(') {
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
								stack[stPos] = exprList[i];
								stPos++;
							} else if (exprList[i] == '+' || exprList[i] == '-') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '(') {
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
								stack[stPos] = exprList[i];
								stPos++;
							} else if (exprList[i] == ')') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '(') {
										stPos--;
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
							} else if (exprList[i] == '(') {
								stack[stPos] = exprList[i];
								stPos++;
							} else {
								return dataTotal; // error : return (orginal)dataTotal
							}
						} else if (stPos == 0) {
							stack[stPos] = exprList[i];
							stPos++;
						} else {
							return dataTotal; // error : return (orginal)dataTotal
						}
					}
				}

				for (; stPos > 0; stPos--) {
					newEx[exPos] = String.valueOf(stack[stPos - 1]);
					exPos++;
				}
				/***************** A B 등을 알맞는 데이터 등으로 만들어 준다 ************************/

				for (int i = 0; i < exPos; i++) {
					if (newEx[i].charAt(0) >= 'A' && newEx[i].charAt(0) <= 'Z') {
						int k = 0;
						for (k = 0; k < dataName.length; k++) {
							if (newEx[i].equals(dataName[k])) {
								newEx[i] = dataTotal[k];
								break;
							}
						}
						if (k == dataName.length)
							newEx[i] = "0.0";
					}
				}

				double[] dstk = new double[10];
				int dpos = 0;

				for (int i = 0; i < exPos; i++) {
					if (newEx[i].equals("+")) {
						dstk[dpos - 2] = dstk[dpos - 2] + dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("-")) {
						dstk[dpos - 2] = dstk[dpos - 2] - dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("*")) {
						dstk[dpos - 2] = dstk[dpos - 2] * dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("/")) {
						dstk[dpos - 2] = dstk[dpos - 2] / dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("%")) {
						dstk[dpos - 2] = dstk[dpos - 2] % dstk[dpos - 1];
						dpos--;
					} else {
						dstk[dpos] = Double.parseDouble(newEx[i]);
						dpos++;
					}
				}
				if (exPos > 0) {
					dataTotal[index] = Double.toString(dstk[0]);
				}

				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				index++;
			}
		}
		index = 0;
		for (int c = strInItemNum; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				index++;
			}
		}
		return dataTotal;
	}

	public static String[] getTotalDataList(int rowCount, int[] itemTypeList, String[][] dataList, int strInItemNum)
			throws ArrayIndexOutOfBoundsException {

		int inItemCount = 0;
		if (dataList != null) {
			if (dataList.length > 0) {
				inItemCount = dataList[0].length;
			}
		}
		int itemCount = itemTypeList.length;
		String[] dataTotal = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;

		int index = 0;

		for (int c = strInItemNum, r = 0; c < itemCount; c++) {
			if (itemTypeList[c] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (r = 0; r < rowCount; r++) {
					try {
						if (dataList[r][index] != null) {
							floatData = Double.parseDouble(dataList[r][index]);
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}
					colTotalData = colTotalData + floatData;
				}
				// dataTotal[index] = Double.toString(colTotalData);
				dataTotal[index] = NumberFormat.getNumberInstance().format(colTotalData);
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				dataTotal[index] = " ";
				index++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[index] = " ";
				index++;
			}
		}
		return dataTotal;
	}

	// 하나의 보고 자료에서 입력된 보고 자료중 숫자는 합해서 집계를 낸다.
	/********************************** 동적인표 **********************************/
	public static String[] getTotalDataList(int rowCount, int inItemCount, int[] itemTypeList, String[] itemExprList,
			String[][] dataList, String[][] totDataList, int strInItemNum) throws ArrayIndexOutOfBoundsException {
		String[] dataTotal = null;

		dataTotal = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;
		int index = 0; // itemTypeList 접근 index
		int count = 0; // 실제 data저장 count

		for (int c = 0; count < inItemCount; c++) {
			// index = c+strInItemNum;
			index = c + strInItemNum;
			if (index >= itemTypeList.length) {
				break;
			}

			if (itemTypeList[index] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (int r = 0; r < rowCount; r++) {
					try {
						if (totDataList[r][count] != null) {
							floatData = Double.parseDouble(totDataList[r][count]);
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}
					colTotalData = colTotalData + floatData;
				}

				dataTotal[count] = Double.toString(colTotalData);
				count++;
			} else if (itemTypeList[index] == MItem.CHAR) {
				dataTotal[count] = " ";
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[count] = " ";
				count++;
			}
		}

		/*********************** 수식계산을 위해 추가된 부분 ***************************/
		index = 0;
		count = 0;

		// A2+B2 -> A+B 등으로 변환
		for (int c = 0; count < inItemCount; c++) {
			index = c + strInItemNum;

			if (itemTypeList[index] == MItem.INT) {
				if (!(itemExprList[index].equals("")) && !(itemExprList[index].substring(0, 4).equals("sum("))
						&& !(itemExprList[index].substring(0, 4).equals("SUM("))) {
					String expr = itemExprList[index];
					char[] exprList = expr.toCharArray();

					// 수식 : (A2+B2)/100 을 (A +B )/100으로 수정

for(int ii=0;ii<expr.length();ii++)
    //System.out.println("exprList["+ii+"]=====================================================================>"+exprList[ii]);
					for (int i = 0; i < expr.length(); i++)
                    {
						if (exprList[i] >= 'A' && exprList[i] <= 'Z')
                        {
							for (int j = i + 1; j < expr.length(); j++)
                            {
								if (exprList[j] >= 'A' && exprList[j] <= 'Z')  continue;
								else if (exprList[j] < '0' || exprList[j] > '9') break;
								else if (exprList[j] >= '0' && exprList[j] <= '9') exprList[j] = ' ';
								else break;
							}
						}
					}
for(int ii=0;ii<expr.length();ii++)
    //System.out.println("exprList["+ii+"]##########################################################################=>"+exprList[ii]);
					expr = String.valueOf(exprList);
					expr = expr.replaceAll(" ", "");
					exprList = expr.toCharArray();

					/**************************** 후위식으로 변경 ****************************/
					String[] newEx = new String[100];
					char[] stack = new char[100];

					int exPos = 0;
					int stPos = 0;

					for (int i = 0; i < expr.length(); i++) {
						if (exprList[i] >= 'A' && exprList[i] <= 'Z') {
							StringBuilder variable = new StringBuilder();
							variable.append(exprList[i]);
							for (int j = i + 1; j < expr.length(); j++) {
								if (exprList[j] >= 'A' && exprList[j] <= 'Z') {
									variable.append(exprList[j]);
									i = j;
									continue;
								} else {
									break;
								}
							}

							newEx[exPos] = variable.toString();
							exPos++;
						} else if (exprList[i] >= '0' && exprList[i] <= '9') {
							StringBuilder variable = new StringBuilder();
							variable.append(exprList[i]);
							for (int j = i + 1; j < expr.length(); j++) {
								if (exprList[j] >= '0' && exprList[j] <= '9') {
									variable.append(exprList[j]);
									i = j;
									continue;
								} else {
									break;
								}
							}
							newEx[exPos] = variable.toString();
							exPos++;
						} else {
							if (stPos > 0) {
								if (exprList[i] == '*' || exprList[i] == '/' || exprList[i] == '%') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '+' || stack[stPos - 1] == '-'
												|| stack[stPos - 1] == '(') {
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
									stack[stPos] = exprList[i];
									stPos++;
								} else if (exprList[i] == '+' || exprList[i] == '-') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '(') {
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
									stack[stPos] = exprList[i];
									stPos++;
								} else if (exprList[i] == ')') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '(') {
											stPos--;
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
								} else if (exprList[i] == '(') {
									stack[stPos] = exprList[i];
									stPos++;
								} else {
									return dataTotal; // error : return (orginal)dataTotal
								}
							} else if (stPos == 0) {
								stack[stPos] = exprList[i];
								stPos++;
							} else {
								return dataTotal; // error : return (orginal)dataTotal
							}
						}
					}

					for (; stPos > 0; stPos--) {
						newEx[exPos] = String.valueOf(stack[stPos - 1]);
						exPos++;
					}
					/***************** A B 등을 알맞는 데이터 등으로 만들어 준다 ************************/

					for (int i = 0; i < exPos; i++) {
						if (newEx[i].charAt(0) >= 'A' && newEx[i].charAt(0) <= 'Z') {
							int pos = 0;
							StringBuilder variable = new StringBuilder();
							variable.append(newEx[i]);

							for (int k = (variable.length() - 1); k >= 0; k--) {
								int tm = (int) (variable.charAt(k) - 'A') + 1;
								for (int l = 0; l < k; l++) {
									tm = tm * 26;
								}
								pos = pos + tm;
							}
							pos = pos - 1;

							newEx[i] = dataTotal[pos];
						}
					}
					/**********************************************************************************/

					/****************************** 후위식으로 계산해 준다 *****************************/

					double[] dstk = new double[10];
					int dpos = 0;

					for (int i = 0; i < exPos; i++) {
						if (newEx[i].equals("+")) {
							dstk[dpos - 2] = dstk[dpos - 2] + dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("-")) {
							dstk[dpos - 2] = dstk[dpos - 2] - dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("*")) {
							dstk[dpos - 2] = dstk[dpos - 2] * dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("/")) {
							dstk[dpos - 2] = dstk[dpos - 2] / dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("%")) {
							dstk[dpos - 2] = dstk[dpos - 2] % dstk[dpos - 1];
							dpos--;
						} else {
							dstk[dpos] = Double.parseDouble(newEx[i]);
							dpos++;
						}
					}

					dataTotal[count] = Double.toString(dstk[0]);

				}
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				count++;
			}
		}

		return dataTotal;
	}

	public static String[] getTotalDataList(int rowCount, int inItemCount, int[] itemTypeList, String[][] dataList,
			int strInItemNum) throws ArrayIndexOutOfBoundsException {
		String[] dataTotal = null;

		dataTotal = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;
		int index = 0; // itemTypeList 접근 index
		int count = 0; // 실제 data저장 count

		for (int c = 0; count < inItemCount; c++) {
			index = c + strInItemNum;
			if (index >= itemTypeList.length) {
				break;
			}

			if (itemTypeList[index] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (int r = 0; r < rowCount; r++) {
					try {
						if (dataList[r][count] != null) {
							floatData = Double.parseDouble(dataList[r][count]);
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}
					colTotalData = colTotalData + floatData;
				}

				dataTotal[count] = Double.toString(colTotalData);
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				dataTotal[count] = " ";
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[count] = " ";
				count++;
			}
		}
		return dataTotal;
	}

	public static String[] getTotalDataList(int rowCount, int inItemCount, int[] itemTypeList, String[] itemExprList,
			String[][] dataList, int strInItemNum) throws ArrayIndexOutOfBoundsException {
		String[] dataTotal = null;

		dataTotal = new String[inItemCount];

		double floatData = 0.0D;
		double colTotalData = 0.0D;
		int index = 0; // itemTypeList 접근 index
		int count = 0; // 실제 data저장 count

		for (int c = 0; count < inItemCount; c++) {
			index = c + strInItemNum;
			if (index >= itemTypeList.length) {
				break;
			}

			if (itemTypeList[index] == MItem.INT) {
				floatData = 0.0D;
				colTotalData = 0.0D;

				for (int r = 0; r < rowCount; r++) {
					try {
						if (dataList[r][count] != null) {
							floatData = Double.parseDouble(dataList[r][count]);
						} else {
							floatData = Double.parseDouble("0");
						}
					} catch (NumberFormatException ex) {
						floatData = Double.parseDouble("0");
					}
					colTotalData = colTotalData + floatData;
				}

				dataTotal[count] = Double.toString(colTotalData);
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				dataTotal[count] = " ";
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				dataTotal[count] = " ";
				count++;
			}
		}
		/*********************** 수식계산을 위해 추가된 부분 ***************************/
		index = 0;
		count = 0;

		// A2+B2 -> A+B 등으로 변환
		for (int c = 0; count < inItemCount; c++) {
			index = c + strInItemNum;

			if (itemTypeList[index] == MItem.INT) {
				if (!(itemExprList[index].equals("")) && !(itemExprList[index].substring(0, 4).equals("sum("))
						&& !(itemExprList[index].substring(0, 4).equals("SUM("))) {
					String expr = itemExprList[index];
					char[] exprList = expr.toCharArray();

					// 수식 : (A2+B2)/100 을 (A +B )/100으로 수정
					for (int i = 0; i < expr.length(); i++) {
						if (exprList[i] >= 'A' && exprList[i] <= 'Z') {
							for (int j = i + 1; j < expr.length(); j++) {
								if (exprList[j] >= 'A' && exprList[j] <= 'Z') {
									continue;
								} else if (exprList[j] < '0' || exprList[j] > '9') {
									break;
								} else if (exprList[j] >= '0' && exprList[j] <= '9') {
									exprList[j] = ' ';
								} else {
									break;
								}
							}
						}
					}

					expr = String.valueOf(exprList);
					expr = expr.replaceAll(" ", "");
					exprList = expr.toCharArray();

					/**************************** 후위식으로 변경 ****************************/
					String[] newEx = new String[100];
					char[] stack = new char[100];

					int exPos = 0;
					int stPos = 0;

					for (int i = 0; i < expr.length(); i++) {
						if (exprList[i] >= 'A' && exprList[i] <= 'Z') {
							StringBuilder variable = new StringBuilder();
							variable.append(exprList[i]);
							for (int j = i + 1; j < expr.length(); j++) {
								if (exprList[j] >= 'A' && exprList[j] <= 'Z') {
									variable.append(exprList[j]);
									i = j;
									continue;
								} else {
									break;
								}
							}

							newEx[exPos] = variable.toString();
							exPos++;
						} else if (exprList[i] >= '0' && exprList[i] <= '9') {
							StringBuilder variable = new StringBuilder();
							variable.append(exprList[i]);
							for (int j = i + 1; j < expr.length(); j++) {
								if (exprList[j] >= '0' && exprList[j] <= '9') {
									variable.append(exprList[j]);
									i = j;
									continue;
								} else {
									break;
								}
							}
							newEx[exPos] = variable.toString();
							exPos++;
						} else {
							if (stPos > 0) {
								if (exprList[i] == '*' || exprList[i] == '/' || exprList[i] == '%') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '+' || stack[stPos - 1] == '-'
												|| stack[stPos - 1] == '(') {
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
									stack[stPos] = exprList[i];
									stPos++;
								} else if (exprList[i] == '+' || exprList[i] == '-') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '(') {
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
									stack[stPos] = exprList[i];
									stPos++;
								} else if (exprList[i] == ')') {
									for (; stPos > 0; stPos--) {
										if (stack[stPos - 1] == '(') {
											stPos--;
											break;
										} else {
											newEx[exPos] = String.valueOf(stack[stPos - 1]);
											exPos++;
										}
									}
								} else if (exprList[i] == '(') {
									stack[stPos] = exprList[i];
									stPos++;
								} else {
									return dataTotal; // error : return (orginal)dataTotal
								}
							} else if (stPos == 0) {
								stack[stPos] = exprList[i];
								stPos++;
							} else {
								return dataTotal; // error : return (orginal)dataTotal
							}
						}
					}

					for (; stPos > 0; stPos--) {
						newEx[exPos] = String.valueOf(stack[stPos - 1]);
						exPos++;
					}
					/***************** A B 등을 알맞는 데이터 등으로 만들어 준다 ************************/

					for (int i = 0; i < exPos; i++) {
						if (newEx[i].charAt(0) >= 'A' && newEx[i].charAt(0) <= 'Z') {
							int pos = 0;
							StringBuilder variable = new StringBuilder();
							variable.append(newEx[i]);

							for (int k = (variable.length() - 1); k >= 0; k--) {
								int tm = (int) (variable.charAt(k) - 'A') + 1;
								for (int l = 0; l < k; l++) {
									tm = tm * 26;
								}
								pos = pos + tm;
							}
							pos = pos - 1;

							newEx[i] = dataTotal[pos];
						}
					}

					/****************************** 후위식으로 계산해 준다 *****************************/

					double[] dstk = new double[10];
					int dpos = 0;

					for (int i = 0; i < exPos; i++) {
						if (newEx[i].equals("+")) {
							dstk[dpos - 2] = dstk[dpos - 2] + dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("-")) {
							dstk[dpos - 2] = dstk[dpos - 2] - dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("*")) {
							dstk[dpos - 2] = dstk[dpos - 2] * dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("/")) {
							dstk[dpos - 2] = dstk[dpos - 2] / dstk[dpos - 1];
							dpos--;
						} else if (newEx[i].equals("%")) {
							dstk[dpos - 2] = dstk[dpos - 2] % dstk[dpos - 1];
							dpos--;
						} else {
							dstk[dpos] = Double.parseDouble(newEx[i]);
							dpos++;
						}
					}

					dataTotal[count] = Double.toString(dstk[0]);

				}
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.CHAR) {
				count++;
			} else if (itemTypeList[c + strInItemNum] == MItem.DATE) {
				count++;
			}
		}
		/*********************** 수식계산을 위해 추가된 부분 끝 ***************************/

		return dataTotal;
	}

	/***********************************************************
	 **** 다수 동적표등 포함된 것을 처리하기 위해 만들어진 함수 ****
	 ***********************************************************/
	public static String[] getTotalDataList(int itemSize, int inItemCount, int[] tableColNumList,
			String[] tableRowList, int[] itemTypeList, String[] itemExprList, String[] dataList, String[] itemNameList)
			throws ArrayIndexOutOfBoundsException {


		String[] dataTotal = null;

		dataTotal = new String[inItemCount];

		int[] transTypeList = new int[inItemCount];
		String[] transExprList = new String[inItemCount];
		String[] transNameList = new String[inItemCount];

		int translength = 0;
		for (int i = 0; i < itemTypeList.length; i++) {
			if (itemTypeList[i] != MItem.TITLE) {
				transTypeList[translength] = itemTypeList[i];
				transExprList[translength] = itemExprList[i];
				transNameList[translength] = itemNameList[i];
				translength++;
			}
		}

		/**************** 각 셀 위치별 세로로의 합계 *****************/
		int index = 0; // itemTypeList 접근 index
		int here = 0;
		for (int t = 0; t < tableRowList.length && t < tableColNumList.length; t++) {
			for (int tr = 0; tr < Integer.parseInt(tableRowList[t]); tr++) {
				for (int tc = 0; tc < tableColNumList[t] && index + tc < dataTotal.length && here + tc < dataList.length; tc++) {
					if (transTypeList[index + tc] == MItem.INT) {
						String data = dataList[here + tc];
						if (data.equals(" ") || data == null || data.equals(""))
							data = "0";

						if (dataTotal[index + tc] == null || dataTotal[index + tc].equals(" ")
								|| dataTotal[index + tc].equals("")) {
							dataTotal[index + tc] = dataList[here + tc];
						} else {
							dataTotal[index + tc] = Double.toString(Double.parseDouble(dataList[here + tc])
									+ Double.parseDouble(dataTotal[index + tc]));
						}
					} else {
						//콤보도 계산될수 있도록 수정
						//dataTotal[index + tc] = " ";
						dataTotal[index + tc] = dataList[here + tc];
					}
				}
				here = here + tableColNumList[t];
			}
			index = index + tableColNumList[t];
		}

		/****************************** 수식계산을 위한 추가부분 **********************************/
		index = 0;

		for (int c = 0; c < inItemCount; c++) {
			if (transTypeList[c] == MItem.INT) {
				if (transExprList[c].indexOf("sum(") > -1 || transExprList[c].indexOf("SUM(") > -1) {
					transExprList[c] = "";
				}
				String expr = transExprList[c];
				char[] exprList = expr.toCharArray();

				/**************************** 후위식으로 변경 ****************************/
				String[] newEx = new String[100];
				char[] stack = new char[100];

				int exPos = 0;
				int stPos = 0;

				for (int i = 0; i < expr.length(); i++) {
					if (exprList[i] >= 'A' && exprList[i] <= 'Z') {
						StringBuilder variable = new StringBuilder();
						variable.append(exprList[i]);
						for (int j = i + 1; j < expr.length(); j++) {
							if ((exprList[j] >= 'A' && exprList[j] <= 'Z')
									|| (exprList[j] >= '0' && exprList[j] <= '9')) {
								variable.append(exprList[j]);
								i = j;
								continue;
							} else {
								break;
							}
						}

						newEx[exPos] = variable.toString();
						exPos++;
					} else if (exprList[i] >= '0' && exprList[i] <= '9') {
						StringBuilder variable = new StringBuilder();
						variable.append(exprList[i]);
						for (int j = i + 1; j < expr.length(); j++) {
							if (exprList[j] >= '0' && exprList[j] <= '9') {
								variable.append(exprList[j]);
								i = j;
								continue;
							} else {
								break;
							}
						}
						newEx[exPos] = variable.toString();
						exPos++;
					} else {
						if (stPos > 0) {
							if (exprList[i] == '*' || exprList[i] == '/' || exprList[i] == '%') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '+' || stack[stPos - 1] == '-' || stack[stPos - 1] == '(') {
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
								stack[stPos] = exprList[i];
								stPos++;
							} else if (exprList[i] == '+' || exprList[i] == '-') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '(') {
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
								stack[stPos] = exprList[i];
								stPos++;
							} else if (exprList[i] == ')') {
								for (; stPos > 0; stPos--) {
									if (stack[stPos - 1] == '(') {
										stPos--;
										break;
									} else {
										newEx[exPos] = String.valueOf(stack[stPos - 1]);
										exPos++;
									}
								}
							} else if (exprList[i] == '(') {
								stack[stPos] = exprList[i];
								stPos++;
							} else {
								return dataTotal; // error : return (orginal)dataTotal
							}
						} else if (stPos == 0) {
							stack[stPos] = exprList[i];
							stPos++;
						} else {
							return dataTotal; // error : return (orginal)dataTotal
						}
					}
				}

				for (; stPos > 0; stPos--) {
					newEx[exPos] = String.valueOf(stack[stPos - 1]);
					exPos++;
				}
				/***************** A B 등을 알맞는 데이터 등으로 만들어 준다 ************************/

				for (int i = 0; i < exPos; i++) {
					if (newEx[i].charAt(0) >= 'A' && newEx[i].charAt(0) <= 'Z') {
						int k = 0;
						for (k = 0; k < transNameList.length; k++) {
							if (newEx[i].equals(transNameList[k])) {
								newEx[i] = dataTotal[k];
								break;
							}
						}
						if (k == transNameList.length)
							newEx[i] = "0.0";
					}
				}
				/**********************************************************************************/

				/****************************** 후위식으로 계산해 준다 *****************************/

				double[] dstk = new double[10];
				int dpos = 0;

				for (int i = 0; i < exPos; i++) {

					if (newEx[i].equals("+")) {
						dstk[dpos - 2] = dstk[dpos - 2] + dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("-")) {
						dstk[dpos - 2] = dstk[dpos - 2] - dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("*")) {
						dstk[dpos - 2] = dstk[dpos - 2] * dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("/")) {
						dstk[dpos - 2] = dstk[dpos - 2] / dstk[dpos - 1];
						dpos--;
					} else if (newEx[i].equals("%")) {
						dstk[dpos - 2] = dstk[dpos - 2] % dstk[dpos - 1];
						dpos--;
                    } else if (newEx[i].equals("=")) {
                        continue;
                    } else {
						dstk[dpos] = Double.parseDouble(newEx[i]);
						dpos++;
					}
				}
				if (exPos > 0) {
					dataTotal[index] = Double.toString(dstk[0]);
				}

				/***********************************************************************************/
				index++;
			} else if (transTypeList[c] == MItem.CHAR) {
				index++;
			} else if (transTypeList[c] == MItem.DATE) {
				index++;
			}
		}
		/****************************** 수식계산을 위한 추가부분 끝 ********************************/
		return dataTotal;
	}

	public static String[][] getDataList(MultipartRequest multi, int[] itemInTypeList, int rowCount, int inItemCount,
			String[] inItemNameList, int strInItemNum) throws NullPointerException {

		String[][] dataArray = new String[rowCount][inItemCount];
		String inData = "";
		int index = 0;
		int itemInTypeListLength = itemInTypeList.length;

		for (int i = 0, j = 0; i < rowCount; i++) {
			for (j = 0; j < inItemCount && j < itemInTypeListLength; j++) {
				inData = multi.getParameter(inItemNameList[index]);

				if (MString.isNull(inData)) { // 아무런 값이 없을때 기본값 입력
					if (itemInTypeList[j] == MItem.CHAR) { // 문자
						inData = " ";// 꼭 공백을 넣어 줘야함..
					} else if (itemInTypeList[j] == MItem.INT) { // 숫자
						inData = "0";
					} else if (itemInTypeList[j] == MItem.DATE) { // 날짜
						inData = " ";
					}
				}

				dataArray[i][j] = inData.trim();
				index++;
			}
		}

		return dataArray;
	}

	public static String[] getDataList(MultipartRequest multi, int[] itemInTypeList, String[] inItemNameList,
			int[] tableColNumList, String[] tableRowList) throws NullPointerException {
		String[] dataArray = new String[inItemNameList.length];
		String inData = "";
		int index = 0;

		int here = 0;
		for (int t = 0; t < tableRowList.length && t < tableColNumList.length; t++) {
			for (int r = 0; r < Integer.parseInt(tableRowList[t]); r++) {
				for (int tc = 0; tc < tableColNumList[t] && index < inItemNameList.length && index < dataArray.length && here + tc < itemInTypeList.length; tc++) {
					inData = multi.getParameter(inItemNameList[index]);
					if (MString.isNull(inData)) { // 아무런 값이 없을때 기본값 입력
						LOG.debug("null data for {}", inItemNameList[index]);
						if (itemInTypeList[here + tc] == MItem.CHAR) { // 문자
							inData = " ";// 꼭 공백을 넣어 줘야함..
						} else if (itemInTypeList[here + tc] == MItem.INT) { // 숫자
							inData = "0";
						} else if (itemInTypeList[here + tc] == MItem.DATE) { // 날짜
							inData = " ";
						}
					}

					dataArray[index] = inData.trim();
					index++;
				}
			}
			here = here + tableColNumList[t];
		}

		return dataArray;
	}

	// 배열로 되어있는 보고 data를 String으로 변환 함
	public static String getDatas(int rowCount, int inItemCount, String[][] dataList) throws Exception {
		StringBuilder dataBuf = new StringBuilder();

		String inData = "";
		for (int i = 0, j = 0; i < rowCount; i++) {
			if (i != 0) {
				dataBuf.append(MReport.splitStr2);
			}

			for (j = 0; j < inItemCount; j++) {
				if (dataList[i][j] == null || (dataList[i][j] != null && dataList[i][j].trim().equals(""))) { // String.split()메소드
																												// 사용할때
																												// 값이
																												// 없으면
																												// 공백으로
																												// 만들어야함
					inData = " ";
				} else {
					inData = dataList[i][j];
				}

				if (j == 0) {
					dataBuf.append(inData);
				} else {
					dataBuf.append(MReport.splitStr1 + inData);
				}
			}
		}
		return dataBuf.toString();
	}

	// 배열로 되어있는 보고 data를 String으로 변환 함
	public static String getDatas(int[] tableColNumList, String[] tableRowList, String[] dataList) throws Exception {
		StringBuilder dataBuf = new StringBuilder();

		int here = 0;
		for (int t = 0; t < tableRowList.length && t < tableColNumList.length; t++) {
			if (t != 0) {
				dataBuf.append(MReport.splitStr3);
			}

			for (int r = 0; r < Integer.parseInt(tableRowList[t]); r++) {
				if (r != 0) {
					dataBuf.append(MReport.splitStr2);
				}

				for (int tc = 0; tc < tableColNumList[t] && here < dataList.length; tc++) {
					if (tc != 0) {
						dataBuf.append(MReport.splitStr1);
					}
					if (dataList[here] == null || (dataList[here] != null && dataList[here].trim().equals(""))) { // String.split()메소드
																													// 사용할때
																													// 값이
																													// 없으면
																													// 공백으로
																													// 만들어야함
						dataBuf.append(" ");
					} else {
						dataBuf.append(dataList[here]);
					}
					here++;
				}
			}
		}

		return dataBuf.toString();
	}

	public static String getTotDatas(int inItemCount, String[] totDataList) throws Exception {
		StringBuilder dataBuf = new StringBuilder();

		String inData = "";

		for (int j = 0; j < inItemCount; j++) {

			if (totDataList[j] == null) {
				inData = " ";
			} else {
				inData = totDataList[j];
			}

			if (j == 0) {
				dataBuf.append(inData);
			} else {
				dataBuf.append(MReport.splitStr2 + inData);
			}
		}

		return dataBuf.toString();
	}

	// 다수 동적행을 위해 새로 추가된 함수
	public static String getTotDatas(int[] tableColNumList, String[] totDataList) throws Exception {
		StringBuilder dataBuf = new StringBuilder();

		String inData = "";
		int index = 0;

		for (int i = 0; i < tableColNumList.length; i++) {
			if (i != 0) {
				dataBuf.append(MReport.splitStr3);
			}

			for (int j = 0; j < tableColNumList[i]; j++) {
				if (totDataList[index] == null) {
					inData = " ";
				} else {
					inData = totDataList[index];
				}

				if (j == 0) {
					dataBuf.append(inData);
				} else {
					dataBuf.append(MReport.splitStr1 + inData);
				}
				index++;
			}
		}

		return dataBuf.toString();
	}

	public String getTotalLineData(String aData, String reportTotData, int[] itemNumber) {
		if (aData == null)
			return null;
		StringBuilder sInsertedData = new StringBuilder();
		String tmp = reportTotData;
		String data = "";
		int i = 0;
		double dValue;
		String sValue;

		tmp = tmp.replace('{', ' ');
		tmp = tmp.replace('}', ' ');

		sInsertedData.append("<tr>");
		StringTokenizer st = new StringTokenizer(tmp.trim(), ",");
		while (st.hasMoreTokens()) {
			data = st.nextToken();
			if (data.equals("empty")) {
				data = "&nbsp;";
			}

			if (itemNumber[i] == 1) {
				sInsertedData.append("<td align=right><font color=red>");
				dValue = Double.parseDouble(data);
				sValue = NumberFormat.getNumberInstance().format(dValue);
				sInsertedData.append(sValue + "&nbsp;&nbsp;");
			} else {
				sInsertedData.append("<td><font color=red>");
				sInsertedData.append(data);
			}
			sInsertedData.append("</font></td>");
			i++;
		}
		sInsertedData.append("</tr>");

		aData = aData + sInsertedData.toString() + "</table>";
		return aData;
	}

	public String getAddLineData(String sunLine, String reportData, int[] itemNumber) throws Exception {

		if (sunLine == null)
			return null;
		StringBuilder sInsertedData = new StringBuilder();
		String data = "";
		String tmp = reportData;
		int i = 0;
		StringTokenizer st2 = null;
		double dValue;
		String sValue;

		tmp = tmp.replace('{', ' ');
		tmp = tmp.replaceAll(", ", " ");

		StringTokenizer st1 = new StringTokenizer(tmp, "}");
		while (st1.hasMoreTokens()) {
			tmp = st1.nextToken();
			sInsertedData.append("<tr>");
			st2 = new StringTokenizer(tmp.trim(), ",");
			while (st2.hasMoreTokens()) {
				data = st2.nextToken();
				if (data.equals("empty")) {
					data = "&nbsp;";
				}

				if (itemNumber[i] == 1) {// 숫자이면
					sInsertedData.append("<td align=right>");
					dValue = Double.parseDouble(data);
					sValue = NumberFormat.getNumberInstance().format(dValue);
					sInsertedData.append(sValue + "&nbsp;&nbsp;");
				} else {
					sInsertedData.append("<td>");
					sInsertedData.append(data);
				}
				i++;
				sInsertedData.append("</td>");
			}
			i = 0;
			sInsertedData.append("</tr>");
		}
		sunLine = sunLine + sInsertedData.toString();
		return sunLine;
	}

	public String getSumData(String form, String[] itemDataList, int[] itemIndexList, int[] itemBNW) {
		if (form == null)
			return null;
		StringBuilder inBuf = new StringBuilder();
		int tdCount = 0;
		int tdStart;
		int tdEnd;
		int index = 0;
		String itemDatas = "";
		String tmp = "";
		while (true) {
			if (index > itemIndexList.length - 1)
				break;

			tdStart = form.indexOf("<td");
			if (tdStart == -1)
				break;
			tdEnd = form.indexOf(">", tdStart + 1);
			if (tdEnd == -1)
				break;
			if (tdCount == itemIndexList[index]) {// 입력값이 있는 셀의 경우
				if (itemBNW[index] == 1) {
					itemDatas = HtmlUtil.toBR(itemDataList[index]);
					inBuf.append(form.substring(0, tdEnd + 1) + itemDatas); // // 출력되는 값들이 생성되는 곳
				} else {
					tmp = form.substring(0, tdEnd + 1) + itemDataList[index];
					inBuf.append(tmp);
				}

				form = form.substring(tdEnd + 1, form.length());
				index++;
			} else {
				tmp = form.substring(0, tdEnd + 1);

				inBuf.append(tmp);
				form = form.substring(tdEnd + 1, form.length());
			}
			tdCount++;
		}

		inBuf.append(form);
		return inBuf.toString();
	}

}
