Chinaunix首页 | 论坛 | 博客
  • 博客访问: 14208
  • 博文数量: 12
  • 博客积分: 1410
  • 博客等级: 上尉
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2009-08-19 15:05
文章分类

全部博文(12)

文章存档

2011年(1)

2009年(11)

我的朋友
最近访客

分类: Java

2009-08-20 12:02:18

package com.wm.affnet.util;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import com.wm.affnet.dao.impl.AffDeptCatMapDao;
import com.wm.affnet.dataobj.AffDeptCatMap;
@SuppressWarnings("unchecked")
public class DeptCatMap {
 public static Vector deptNames;
 public static HashMap> deptCatMap;
 public static HashMap deptNameIdMap;
 public static HashMap catNameIdMap;
 public static HashMap> deptCatNameMap;
 public static Hashtable hashDeptCat;
 static {
  deptNames = new Vector();
  deptCatMap = new HashMap>();
  deptNameIdMap = new HashMap();
  catNameIdMap = new HashMap();
  deptCatNameMap = new HashMap>();
  hashDeptCat = new Hashtable();
  String deptName = "";
  Long deptId = 0L;
  try {
   AffDeptCatMapDao affDeptCatMapDao = AffDeptCatMapDao.getInstance();
   List list = affDeptCatMapDao.findByStatus(Constants.DEPT_CAT_MAP_STATUS_ACTIVE);
   Vector[] deptCats = new Vector[list.size()];
   Vector[] deptCatNames = new Vector[list.size()];
   int i = 0;
   deptCats[0] = new Vector();
   deptCatNames[0] = new Vector();
   if (list != null && list.size() != 0) {
    for (AffDeptCatMap affDeptCatMap : list) {
     if (!deptName.equals("")) {
      if (!deptName.equals(affDeptCatMap.getDeptName())) {
       deptNames.add(deptName);
       deptCatMap.put(deptName, deptCats[i]);
       deptNameIdMap.put(deptName, deptId);
       ++i;
       deptCats[i] = new Vector();
       deptCatNames[i] = new Vector();
      }
     }
     deptName = affDeptCatMap.getDeptName();
     deptId = affDeptCatMap.getDeptId();
     String catName = affDeptCatMap.getCatName();
     Long catId = affDeptCatMap.getCatId();
     deptCats[i].add(catId);
     deptCatNames[i].add(catName);
     catNameIdMap.put(catId, catName);
     hashDeptCat.put(String.valueOf(deptId), deptName);
     hashDeptCat.put(String.valueOf(catId), catName);
    }
    deptNames.add(deptName);
    deptCatMap.put(deptName, deptCats[i]);
    deptNameIdMap.put(deptName, deptId);
    deptCatNameMap.put(deptName, deptCatNames[i]);
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
 public static String getScript(HashMap> deptCatMap, String strFormName,
           String strDeptName, String strCatName) {
  String javaScriptOut = "";
  Iterator iterator = deptCatMap.keySet().iterator();
  int outerCount = 0;
  while (iterator.hasNext()) {
   String mapKey = iterator.next();
   Vector mapValue = deptCatMap.get(mapKey);
   int mapValueSize = mapValue.size();
   outerCount++;
   if (outerCount == 1) {
    javaScriptOut = "if(document." + strFormName + "." + strDeptName + ".value == '"
      + deptNameIdMap.get(mapKey) + "') {\n";
   } else {
    javaScriptOut = javaScriptOut + "else if(document." + strFormName + "." + strDeptName + ".value == '"
      + deptNameIdMap.get(mapKey) + "') {\n";
   }
   for (int j = 0; j < mapValueSize; j++) {
    javaScriptOut = javaScriptOut + "addOption(document." + strFormName + "." + strCatName + ", \""
      + catNameIdMap.get(mapValue.elementAt(j)) + "\", \"" + mapValue.elementAt(j) + "\");\n";
   }
   javaScriptOut = javaScriptOut + "}\n";
  }
  System.out.println(javaScriptOut+"in DeptCatMap");
  return javaScriptOut;
 }
 public static Hashtable getDeptCat() {
  return hashDeptCat;
 }
}
阅读(326) | 评论(0) | 转发(0) |
0

上一篇:send email

下一篇:exception handler

给主人留下些什么吧!~~