📄 placecode.java
字号:
/**
* 全国省市县区信息
*/
package com.NCL;
import java.util.*;
import com.sinosoft.common.*;
import java.io.File;
import java.io.IOException;
import jxl.*;
import jxl.read.biff.*;
public class PlaceCode {
/**
* @param args
* @author vincent 地方关联数据
* @date 2007-8-9
*/
protected IndexMap propList;
protected HashSet Property;
private boolean EOF = false;
private int COUNT;
/**
* 构造函数
*
*/
public PlaceCode(){
propList=new IndexMap();
Property=new HashSet();
Property.add("PlaceType"); //地区类型
Property.add("PlaceCode"); //地区代码
Property.add("PlaceName"); //地区名字
Property.add("UpPlaceCode"); //上一级代码
}
/**
* 初始化
* @param PlaceCode 地区代码
*/
public void init(String PlaceCode){
DBAccess d = new DBAccess();
String sql = "SELECT * from PlaceCode where PlaceCode=?";
this.propList = d.init(sql,PlaceCode,this.Property);
}
/**
* 根据条件获取地区的html代码
* @param PlaceType 地区类型
* @param tmpUpPlaceCode 上一级代码
* @param OptionCode 已选定项
* @return String
*/
public String getOption(String PlaceType,String tmpUpPlaceCode,String OptionCode){
String result="";
String PlaceID="";
PlaceCode pc = new PlaceCode();
if("01".equals(PlaceType)){//省级
PlaceID=pc.findProvince(pc);
if("".equals(PlaceID))
return "";
String[] PlaceIDArray = PlaceID.split(",");
for(int i=0;i<PlaceIDArray.length;i++){
pc.init(PlaceIDArray[i]);
if(pc.get("PlaceCode").equals(OptionCode))
result = result + "<option selected value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option> ";
else
result = result + "<option value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option>";
pc.clear();
}
}else if("02".equals(PlaceType)){//市
if("".equals(tmpUpPlaceCode))
return "";
else
pc.set("UpPlaceCode", tmpUpPlaceCode);
//System.out.println("UpplaceCode"+pc.get("UpPlaceCode"));
PlaceID=pc.findCity(pc);
if("".equals(PlaceID))
return "";
String[] PlaceIDArray = PlaceID.split(",");
for(int i=0;i<PlaceIDArray.length;i++){
pc.init(PlaceIDArray[i]);
if(pc.get("PlaceCode").equals(OptionCode))
result = result + "<option selected value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option>";
else
result = result + "<option value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option>";
pc.clear();
}
}else if("03".equals(PlaceType)){//县
if("".equals(tmpUpPlaceCode))
return "";
else
pc.set("UpPlaceCode", tmpUpPlaceCode);
PlaceID=pc.findCounty(pc);
if("".equals(PlaceID))
return "";
String[] PlaceIDArray = PlaceID.split(",");
for(int i=0;i<PlaceIDArray.length;i++){
pc.init(PlaceIDArray[i]);
if(pc.get("PlaceCode").equals(OptionCode))
result = result + "<option selected value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option>";
else
result = result + "<option value='"+ pc.get("PlaceCode") +"'>"+ pc.get("PlaceName") +"</option>";
pc.clear();
}
}
return result;
}
/**
* 获取省代码
* @param pc 对象
* @return String
*/
public String findProvince(PlaceCode pc){
String result="";
StringBuffer Condition = new StringBuffer("select PLACECODE from PLACECODE where PLACETYPE='01' order by PLACECODE");
DBAccess q = new DBAccess();
result = q.executeQuery(Condition.toString(),pc.propList,0,1);
setCOUNT(q.COUNT);
setEOF(q.EOF);
return result;
}
/**
* 获取市代码
* @param pc 对象
* @return String
*/
public String findCity(PlaceCode pc){
String result="";
StringBuffer Condition = new StringBuffer("select PLACECODE from PLACECODE where PLACETYPE='02'");
if(Data.hasValue(pc.get("UpPlaceCode")))
Condition.append(" and UPPLACECODE =?");
Condition.append(" order by PLACECODE");
DBAccess q = new DBAccess();
result = q.executeQuery(Condition.toString(),pc.propList,0,1);
setCOUNT(q.COUNT);
setEOF(q.EOF);
return result;
}
/**
* 获取县代码
* @param pc 对象
* @return String
*/
public String findCounty(PlaceCode pc){
String result="";
StringBuffer Condition = new StringBuffer("select PLACECODE from PLACECODE where PLACETYPE='03'");
if(Data.hasValue(pc.get("UpPlaceCode")))
Condition.append(" and UPPLACECODE =?");
Condition.append(" order by PLACECODE");
System.out.println(Condition.toString());
DBAccess q = new DBAccess();
result = q.executeQuery(Condition.toString(),pc.propList,0,1);
setCOUNT(q.COUNT);
setEOF(q.EOF);
return result;
}
/**
* 删除
* @return boolean
*/
public boolean delete(){
StringBuffer SQL = new StringBuffer("delete PLACECODE");
DBAccess DBA = new DBAccess();
return DBA.execute(SQL.toString());
}
/**
* 分析Excel文件并入库
*/
public boolean FromExcelToOracle(String excelUrl){
try{
Workbook workbook = Workbook.getWorkbook(new File(excelUrl));
Sheet sheet = workbook.getSheet(0);
int rows=sheet.getRows();//得到总行数
//删除PlaceCode表
if(!delete())
return false;
String sql = "insert into PLACECODE values (?,?,?,?)";
List l = new ArrayList();
for(int i=2;i<rows;i++){
String[] colValue = new String[4];
colValue[0] = sheet.getCell(0,i).getContents().trim();
colValue[1] = sheet.getCell(1,i).getContents().trim();
colValue[2] = sheet.getCell(2,i).getContents().trim();
colValue[3] = sheet.getCell(3,i).getContents().trim();
l.add(colValue);
}
DBAccess d = new DBAccess();
return d.mulExecute(sql,l);
}catch (BiffException ex){
ex.printStackTrace();
return false;
}catch (IOException ex){
ex.printStackTrace();
return false;
}
}
/**
* 在此映射中关联指定值与指定键
* @param name 指定键
* @param value 指定值
*/
public boolean set(String name, Object value){
if(Property.contains(name)){
propList.put(name,value);
return true;
}else
return false;
}
/**
* 返回指定键在此映射中所映射的值
* @param name 指定键
* @return
*/
public String get(String name){
if (Property.contains(name)){
String value = (String)propList.get(name);
if(value != null && !value.equals(""))
return value;
else
return "";
}else
return "";
}
/**
* 返回COUNT
* @return int
*/
public int getCOUNT() {
return COUNT;
}
/**
* 设置COUNT
* @param count
*/
public void setCOUNT(int count) {
COUNT = count;
}
/**
* 返回EOF
* @return boolean
*/
public boolean isEOF() {
return EOF;
}
/**
* 设置EOF
* @param eof
*/
public void setEOF(boolean eof) {
EOF = eof;
}
/**
* 清空propList
*
*/
public void clear(){
propList.clear();
}
/**
* 获取省一级的html代码
* @return String
*/
public String getProOption(){
String str = "";
String sql = "select placecode,placename from placecode where placetype='01' order by placecode";
DBAccess d = new DBAccess();
List result = d.parseSQL(sql, new ArrayList());
if(result==null)return str;
for(int i=0;i<result.size();i+=2){
str += "<option value='"+result.get(i).toString().trim()+"'>"+result.get(i+1).toString().trim()+"</option>";
}
return str;
}
/**
* 获取市代码、市名称
* @param ProvinceCode 省代码
* @return List
*/
public List getCityOption(String ProvinceCode){
if(!Data.hasValue(ProvinceCode))return null;
String sql = "select placecode,placename from placecode where placetype=? and upplacecode=? order by placecode";
DBAccess d = new DBAccess();
List l = new ArrayList();
l.add("02");
l.add(ProvinceCode);
return d.parseSQL(sql, l);
}
/**
* 根据代码得到相应的名称
* @param code 地区代码
* @return String
*/
public String getName(String code){
if(!Data.hasValue(code))return "";
String sql = "select placename from placecode where placecode=? order by placecode";
DBAccess d = new DBAccess();
List l = new ArrayList();
l.add(code);
List result = d.parseSQL(sql, l);
if(result!=null && result.size()!=0){
sql = (String)result.get(0);
if(sql!=null)return sql.trim();
else return "";
}else return "";
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -