⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 datacapture.java

📁 gpsLogger是一个基于手机或PDA的个人移动导航(车载导航)系统中记录gps信息的小工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		//does not refresh during until lookup table modification, (see below comment) 
		else if (gpsDataLogger.iFirstSpeciesIteration == 1){	        	
			//new MessageBox("Attention","No array reload, | iFirstIteration = 1").popupModal();  	
		}
		//refreshes ComboBox after modification of lookup table
		else if (gpsDataLogger.iFirstSpeciesIteration == 2){     	
			((ComboBox)cbSpecies).removeAll();
			((ComboBox)cbSpecies).add(gpsDataLogger.szSpeciesLookup);
			cbSpecies.select(0);
			gpsDataLogger.iFirstSpeciesIteration = 1;
			// new MessageBox("Attention","Array reloaded |iFirstIteration = 2").popupModal();	      
		}
	}	
	public void clear(){   	  
		edCumulative.setText("");
		edLastRecord.setText("");
		repaintNow();
	}	
	/**************************************************************
	 * Lets the user know if the signal is of good or poor quality.
	 * Shows "None" if there is no signal.
	 **************************************************************/
	public void LoadPositionFixIndicator(){
		if (gpsDataLogger.szValid.compareTo("V")==0){
			edPositionFix.setBackColor(White);
			szSignal= "Poor";
			edPositionFix.setText(szSignal);}
		else if (gpsDataLogger.szValid.compareTo("A")==0){
			edPositionFix.setBackColor(White);
			szSignal = "Good";
			edPositionFix.setText(szSignal);}
		else if(gpsDataLogger.szValid.compareTo("")==0){
			edPositionFix.setBackColor(Red);
			szSignal = "None";
			edPositionFix.setText(szSignal);}		
	}	
	/***************************************************************
	 * Shows if TrackLog is on or off based in state of flag.
	 ***************************************************************/	
	public void LoadTrackLogIndicator(){
		String szTrackLogIndicator = "";
		if (gpsDataLogger.iTrackLogFlag == 1){
			szTrackLogIndicator = "ON";
			edTrackLogIndicator.setBackColor(White);}			
		else if(gpsDataLogger.iTrackLogFlag == 0){
			szTrackLogIndicator = "OFF";
			edTrackLogIndicator.setBackColor(Red);}
		edTrackLogIndicator.setText(szTrackLogIndicator);
	}
	/*******************************************************************************
	 * ShowSum- This is a function that shows the total counts for the species shown
	 * in the species combobox at the locations shown in the location combobox. 
	 * 
	 * This is done by creating a resultset, (rsSpecies) from the main surveyDB table
	 * listing locations and surveycounts for the species shown in the combobox.
	 * This resultset is then converted into another table, (speciesTemp). The
	 * aggregation function SUM is then used for all surveycounts WHERE the location is 
	 * the one shown in the combobox. 
	 * 
	 * There has got to be an easier way of doing this.
	 *******************************************************************************/
	public void ShowSum(){
		szLocation = cbLocation.getSelectedItem().toString();
		szSpecies = cbSpecies.getSelectedItem().toString();	
		
		String szTempSurveycount;//this is used in the temporary table
		String szTempLocation;//this is used in the temporary table
		ResultSet rsSpecies = driver.executeQuery("select surveycount,location from surveyDB WHERE species like " + "'" + szSpecies + "'");		
		driver.execute("create table speciesTemp(surveycount int, location char(50))");
		
		while (rsSpecies.next()){//do loop moving rs values into the table
			szTempSurveycount = rsSpecies.getString("surveycount");
			szTempLocation = rsSpecies.getString("location");
			driver.executeUpdate("insert into speciesTemp values ('"+szTempSurveycount+"','"+szTempLocation+"')");				
		}
		
		String szSql = "SELECT SUM(surveycount) as sum_species_records FROM speciesTemp WHERE location = " + "'" + szLocation + "'";
		ResultSet rs = driver.executeQuery(szSql);
		
		double dSum = rs.getDouble("sum_species_records");
		rsSpecies.close();
		rs.close();			
		driver.executeUpdate("drop table speciesTemp");
		
		String szSum=Convert.toString(dSum);			
		edCumulative.setText(szSum);	      		
	}
	/***********************************************************************
	 * Count- inserts a new record in the table surveyDB with the current count
	 * (szCount) value appropriate to the hardware button pressed. 
	 ************************************************************************/
	public void Count(){		
		szLocation = cbLocation.getSelectedItem().toString();
		szSpecies = cbSpecies.getSelectedItem().toString();	
		String szTerrain = cbTerrain.getSelectedItem().toString();
		String szLatitude = gpsDataLogger.szLat;
		String szLatns = gpsDataLogger.szLatNs;
		String szLongitude = gpsDataLogger.szLong;
		String szLongew = gpsDataLogger.szLongEw;
		String szSky = edSky.getText();
		String szWater = edWater.getText();
		String szOverall = edOverall.getText();
		String szLive = cbLive.getSelectedItem().toString();		
		if ((szLocation.compareTo("Empty Location Lookup Table")==0)||(szLocation.length() == 0)){
			new MessageBox("Attention","The Location Lookup table is empty. |Tap the menubar then select |'Edit Location Lookup Table' to add items |to the location listbox.").popupModal();	
		}else{				 				 
			String szTime_stamp;		
			long T = new Time().getTimeLong();
			szTime_stamp = Convert.toString(T,1);	   	        	   	        	            
			//szCount = "1";	            
			long lastUpdated = new Time().getTimeLong();	   	        
			int rows = -1;	            	   	        
			rows = driver.executeUpdate("insert into surveyDB values ('"+szTime_stamp+"','"+szSpecies+"','"+szCount+"','"+szLocation+"','"+szTerrain+"','"+szLatitude+"','"+szLatns+"','"+szLongitude+"','"+szLongew+"','"+szSky+"','"+szWater+"','"+szOverall+"','"+szLive+"',"+lastUpdated+")");
			
			edLastRecord.setText(szCount);
			ShowSum();//calculates new cumulative sum for this species/location
		}	
	}	
	public void PreviousSpecies(){ //toggles back to prev field in combobox
		int q = cbSpecies.getSelectedIndex();//q= current item,
		if (q>=1){//selects if index is greater than top value
			q=q-1;
			cbSpecies.select(q);}
		else{//if index is top value, no decrement
			cbSpecies.select(0);}
		ShowSum();}	
	public void NextSpecies(){//toggles to next field in combobox
		int q = cbSpecies.getSelectedIndex();//q= current item,
		q=q+1;
		cbSpecies.select(q);
		ShowSum();}
	public void PreviousLocation(){//toggles back to prev field in combobox
		int q = cbLocation.getSelectedIndex();//q= current item,
		if (q>=1){
			q=q-1;
			cbLocation.select(q);
		}else{
			cbLocation.select(0);}
		ShowSum();}
	public void NextLocation(){
		int q = cbLocation.getSelectedIndex();//q= current item,
		q=q+1;
		cbLocation.select(q);
		ShowSum();}
	public void LiveDeadToggle(){//called by center button in 5-way toggle to actuate live/dead combobox
		int q = cbLive.getSelectedIndex();
		//new MessageBox("Debug","sbLive index value is: "+q).popupModal();			
		if (q == 0){
			cbLive.select(1);
		}else
			cbLive.select(0);}
	/******************************************************************************
	 * Added to allow user to easily delete errant data point on the fly, (no pun).
	 * Deletes last record in the table.
	 ******************************************************************************/
	public void deleteLastRecord(){
		int iRowId;
		String szRowId;
		
		ResultSet rs = driver.executeQuery("select rowid,time_stamp,species,surveycount,location,terrain,latitude,latns,longitude,longew,sky,water,overall,live from surveyDB");
		rs.last();
		szRowId = (rs.getString("rowid"));
		iRowId = Convert.toInt(szRowId);
		if (iRowId != 0){
			driver.executeUpdate("delete surveyDB where rowid="+iRowId);}
	}	
	
	public void onEvent(Event e){		
		switch (e.type){	  
		case ControlEvent.TIMER: 
			//shows % battery remaining on screen
			int iBattery=Vm.getRemainingBattery();			
			String szBattery = Convert.toString(iBattery);
			edBattery.setText(szBattery + "%");
			//shows Greenwich satellite time
			edTime.setText(gpsDataLogger.szTime);
			LoadPositionFixIndicator();			
			break;		
		case ControlEvent.PRESSED:
			if (e.target == cbLocation){ 
				ResultSet rs = null;	                   	
				Object objLocation = cbLocation.getSelectedItem();
				szLocation = objLocation.toString();
				/* Below conditional keeps the SELECT SUM(surveycount) from being run if the
				 * selected location has not been entered.  
				 */
				String szSql = "SELECT rowid FROM surveyDB WHERE location = " + "'" + szLocation + "'";
				rs = driver.executeQuery(szSql);
				int iLocationRowCount = rs.getRowCount();
				rs.close();
				
				if (iLocationRowCount == 0){
					edCumulative.setText("0");
					edLastRecord.setText("");
				}else{            
				}
				ShowSum();
			}else if (e.target == cbSpecies){				
				ResultSet rs = null;	                   	
				Object objSpecies = cbSpecies.getSelectedItem();
				szSpecies = objSpecies.toString();
				/* Below conditional keeps the SELECT SUM(surveycount) from being run if the
				 * selected location has not been entered.  
				 */
				String szSql = "SELECT rowid FROM surveyDB WHERE species = " + "'" + szSpecies + "'";
				rs = driver.executeQuery(szSql);
				int iSpeciesRowCount = rs.getRowCount();
				rs.close();
				
				if (iSpeciesRowCount == 0){
					edCumulative.setText("0");
					edLastRecord.setText("");
				}else{	            
					edLastRecord.setText(""); 
				}
				ShowSum();			
			}else if (e.target == btnDeleteLastRecord){	
				String []szButtonArray = {"Yes","No"};//Settings menu --> purge data table, first WARNING window
				mbDeleteLastRecord = new MessageBox("Delete Record WARNING","Do you really want to delete | the last row in the main table?", szButtonArray);				 					
				mbDeleteLastRecord.setUnpopDelay(3000);
				mbDeleteLastRecord.popupBlockingModal();
				
				int idx = mbDeleteLastRecord.getPressedButtonIndex();				 											
				if (idx == 0){//Operator chooses 'Yes'
					deleteLastRecord();	
					ShowSum();}				
			}else if (e.target == btnCreateZeroCountRecord){	
				String []szButtonArray = {"    YES    ","NO"};				
				mbCreateZeroCountRecord = new MessageBox("Message Box","Enter a count of 'ZERO'?", szButtonArray);				 					
				mbCreateZeroCountRecord.setUnpopDelay(3000);//3 second timeout
				mbCreateZeroCountRecord.popupBlockingModal();
				
				int idx = mbCreateZeroCountRecord.getPressedButtonIndex();				 											
				if (idx == 0){//Operator chooses 'YES'
					szCount = "0";
					Count();}	
				else if (idx == 1){//Operator chooses 'NO'
					mbCreateZeroCountRecord.unpop();}
				//}else if (e.target == btnToggleLocation){
				//ToggleLocation();
			}else if (e.target == btnCountOne){
				szCount = "1";
				Count();
			}else if (e.target == btnCountTen){ 
				szCount = "10";
				Count();
			}else if (e.target == btnCountOneHundred){ 
				szCount = "100";
				Count();
			}else if (e.target == btnCountOneThousand){ 
				szCount = "1000";
				Count();
			}else if (e.target == sbSky){				
				int iValue = ((ScrollBar)e.target).getValue();
				int iNewValue;
				iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed
				sbSky.setValue(iValue);
				edSky.setText(Convert.toString(iNewValue,1));
			}else if (e.target == sbWater){				
				int iValue = ((ScrollBar)e.target).getValue();
				int iNewValue;
				iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed
				sbWater.setValue(iValue);
				edWater.setText(Convert.toString(iNewValue,1));
			}else if (e.target == sbOverall){				
				int iValue = ((ScrollBar)e.target).getValue();
				int iNewValue;
				iNewValue = (iValue*4/50)+1;//Done to get 1:5 range displayed
				edOverall.setText(Convert.toString(iNewValue,1));
			}break;
		}		
	}	
}













⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -