본문 바로가기
프로그래밍/Nexacro 17

2022년 2월 11일 - Dataset 구조, 데이터 찾기, 데이터 통계처리, 데이터 필터 기능

by 철제백조 2022. 2. 11.

http://demo.nexacro.com/EduPlay/_web_/index.html?version= 

 

http://demo.nexacro.com/EduPlay/_web_/index.html?version=

 

demo.nexacro.com

 

 

 

 

//데이터셋의 컬럼 개수와 레코드(Row) 개수, 컬럼명을 구하기
this.Button00_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//컬럼 개수 구하기
	var nColCount = this.Dataset1.getColCount();
	var nRowCount = this.Dataset1.getRowCount();
	
	//ID가 txt_result인 Text Area에서 결과확인
	var sText = "Column Count : " + nColCount;
	sText += "\n"+"Row Count : " + nRowCount;
	
	
	//컬럼명 구하기(컬럼 갯수만큼 for문 출력)
	for(var i=0; i<nColCount; i++){
		
		//Syntax: Dataset.getColID(nColIdx)
		var sColId = this.Dataset1.getColID(i);
		
		sText += "\n" + "Column ID(" + i + ") : " + sColId;
	}
	
	//this.TextArea_ID값
	this.TextArea00.set_value(sText);
};


//컬럼추가 : ID가 COL_CHK인 컬럼을 추가
this.Button01_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//ID와 Type 지정
	this.Dataset1.addColumn("COL_CHK","String");
	
	//Grid 새로 그리기 - 새로운 포멧으로 설정해주기
	this.Grid00.createFormat();
};

this.Static02_onclick = function(obj:nexacro.Static,e:nexacro.ClickEventInfo)
{
	
};


//사원번호가 BB001인 사람의 이름구하기 - 결과값이 하나
this.Button02_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//행의 번호를 찾음 - EMPL_ID가 BB001인 행
	var nRow = this.Dataset1.findRow("EMPL_ID","BB001");
	
	//해당 행번호에서 FULL_NAME 값을 담는다
	var sVal = this.Dataset1.getColumn(nRow, "FULL_NAME");
	
	//!!!lookup 방식!!!
	//비교할 컬럼명, 찾을것, 반환값
	var sVal2 = this.Dataset1.lookup("EMPL_ID","BB001","FULL_NAME");
	
	var sText = "사원번호: BB001, 사원명: " + sVal2;
	this.TextArea00.set_value(sText);
};


//복합조건 데이터 찾기
//DEPT_CD가 01이고, POS_CD가 04인 사람
this.Button03_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//findRowExpr은 조건표현식을 만족하는 첫번째 로우 인덱스를 찾는다 ( )안에는 조건식이 들어간다
	var nRow =  this.Dataset1.findRowExpr("DEPT_CD=='01' && POS_CD=='04'");
	
	//구한 행 번호에서 이름을 찾는다
	var sVal = this.Dataset1.getColumn(nRow, "FULL_NAME");
	
	var sText = "DEPT_CD가 01이고, POS_CD가 04인 사람: " + sVal;
	
	this.TextArea00.set_value(sText);
};


//데이터 가치를 목록으로 출력하기 : POS_CD가 03인 사람
//findRow vs ExtractRows
this.Button04_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//extraRows는 범위에서 조건표현식을 만족하는 로우의 인덱스 배열을 전부 출력함
	var arrRow = this.Dataset1.extractRows("POS_CD=='03'");
	
	var sText="";
	
	//만족하는 Row의 수만큼 for문 돌면서 이름 저장하기
	for(var i=0; i<arrRow.length; i++){
		
		//
		var sVal = this.Dataset1.getColumn(arrRow[i], "FULL_NAME");
		sText += sVal + "\n";
	}
	
	this.TextArea00.set_value(sText);
};



//남성과 여성의 평균 급여 계산
this.Button05_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//getCaseAvg는 조건을 만족하는 값 또는 계산값의 평균값을 구하는 메서드
	//남자의 평균급여
	//조건식 + 구해올 컬럼 설정
	var nAvgM = this.Dataset1.getCaseAvg("GENDER=='M'", "SALARY");
	
	//여자의 평균급여
	var nAvgW1 = this.Dataset1.getCaseAvg("GENDER=='W'", "SALARY");
	
	//NULL을 분모에서 제외한 여자 평균 급여구하기
	//3번째 인자 : 시작 인덱스
	//4번째 인자 : 종료 인덱스
	//5번째 인자 : NULL값의 분모를 포함할지 정하는 것 - true 일 경우, 평균값 계산에서 포함, false일 경우 제외
	var nAvgW2 = this.Dataset1.getCaseAvg("GENDER=='W'", "SALARY", 0, -1, false);
	
	//Math Object
	var sText = "Man Avg = " + Math.round(nAvgM,2) + "\n";
		sText += "Woman Avg = " + Math.round(nAvgW1) + "\n";
		sText += "Woman Avg without NULL = " + Math.round(nAvgW2,2);
		
	this.TextArea00.set_value(sText);
};


//급여와 보너스를 합친 금액의 평균 계산
this.Button06_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//급여와 보너스를 합친 금액의 평균
	var nAvg = this.Dataset1.getAvg("SALARY+BONUS");
	var sText = "Salary + Bonus : " + nAvg;
	
	this.TextArea00.set_value(sText);
};


//입사일을 기준으로 내림차순 정렬
this.Button07_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//Keystring은 데이터를 그룹핑하거나 정렬할 때 사용
	//속성값에 G는 그룹핑, S는 정렬작업을 나타내며 생략시 G(정렬)로 적용된다
	//+는 오름차순, - 내림차순
	this.Dataset1.set_keystring("S:-HIRE_DATE");
};



//남성이고 미혼인 데이터만 필터하여 표현
this.Button08_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//Filter는 조건에 만족하는 데이터만 보이게 필터링하는 메서드
	//필터링될 조건을 문자열로 설정하며 빈문자열을 ("") 설정시 필터링 조건이 해제된다
	this.Dataset1.filter("GENDER=='M' && MARRIED=='false'");
};


//원본 레코드의 개수와 필터해서 보이는 레코드 갯수 비교
this.Button09_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	//getRowCount는 필터링된 Row를 제외한 Row의 전체개수를 반환하는 메서드
	var nCnt = this.Dataset1.getRowCount();
	
	//getRowCountNF는 필터링된 Row를 포함한 Row 전체 개수를 반환
	var nCntNF = this.Dataset1.getRowCountNF();
	
	var sText = "RowCount : " + nCnt + "\n";
		sText += "RowCountNF : " + nCntNF;
		
	this.TextArea00.set_value(sText);
};


//이름에 O가 포함된 사람만 보이게하기
this.Button10_onclick = function(obj:nexacro.Button,e:nexacro.ClickEventInfo)
{
	var sText = "O";
	
	//toUpperCase는 모든 문자를 대문자로 변환
	//indexOf는 지정된 문자열이 처음으로 일치하는 위치의 인덱스를 반환하는 메서드
	this.Dataset1.filter("FULL_NAME.toUpperCase().indexOf('"+ sText + "') >= 0");
};

댓글