我的空間,寫我所寫,禪我所藏

          與我一起遨游吧

           

          在數(shù)據(jù)庫(kù)上進(jìn)行一些配置,動(dòng)態(tài)進(jìn)行配值操作

          package com.augur.wf.shark.common.util;


          import javax.naming.InitialContext;
          import javax.servlet.http.HttpServletRequest;

          import org.apache.commons.dbcp.BasicDataSource;

          import com.augur.wf.shark.common.Exception.*;
          import java.util.List;
          import java.util.ArrayList;
          import  com.augur.wf.shark.common.Db.DbConnectionManager;
          import com.augur.wf.shark.SharkProviderImpl;
          import com.augurit.pysz.login.po.Usertable;
          import com.sun.org.apache.xalan.internal.xsltc.runtime.Hashtable;

          import java.io.RandomAccessFile;
          import java.sql.Statement;
          import java.sql.ResultSet;
          import java.sql.Connection;
          /**
           *
           * @author Administrator
           *
           */
          public class CodeFormula {
              public CodeFormula() {
                  try {
                      jbInit();
                  } catch (Exception ex) {
                      ex.printStackTrace();
                  }
              }

             private static final String poolName = "idb";
             public static final int apply_code = 1;  
             public static final int get_code = 2; 
             public static final int putback_code =3 ;
             public static final int refuse_code =4;
             public static final int abort_code =5;
             private static List getBeforeCode(String procId,String activityId,int codeType)throws WfException{
                 Connection con = DbConnectionManager.getInstance().getConnection(
                                            poolName);
                            Statement st = null;
                            List codes  = new ArrayList();
                            try {
                                    st = con.createStatement();
                                    String iSql = "select code from activitycode a,ASSIGNMENTEVENTAUDITS b where a.FIRETYPE=0 and  a.procdefid=b.PROCESSDEFINITIONID and a.actdefid=ACTIVITYDEFINITIONID and b.PROCESSID='"+procId+"' and b.ACTIVITYID='"+activityId+"' and codetype='"+codeType+"'";
          System.out.println(iSql);
                                    ResultSet rs = st.executeQuery(iSql);
                                    if (rs.next()) {
                                       codes.add(rs.getString(1));
                                    }
                            } catch (Exception e) {
                                throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"獲取節(jié)點(diǎn)代碼失敗!"+activityId,
                                              ErrorInfo.getTrace(e, e.getStackTrace()));
                            } finally {
                                DbConnectionManager.getInstance().freeConnection(poolName, con);
                            }
                            return codes;

             }
             private  static List getAfterCode(String procId,String activityId,int codeType)throws WfException{
                 Connection con = DbConnectionManager.getInstance().getConnection(
                                             poolName);
                             Statement st = null;
                             List codes  = new ArrayList();
                             try {
                                     st = con.createStatement();
                                     String iSql = "select distinct code from activitycode a,ASSIGNMENTEVENTAUDITS b where a.FIRETYPE=1 and a.procdefid=b.PROCESSDEFINITIONID and a.actdefid=ACTIVITYDEFINITIONID and b.PROCESSID='"+procId+"' and b.ACTIVITYID='"+activityId+"' and codetype='"+codeType+"'";
                                     System.out.println(iSql);
                                     ResultSet rs = st.executeQuery(iSql);
                                     if (rs.next()) {
                                        codes.add(rs.getString(1));
                                     }
                             } catch (Exception e) {
                                 throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"獲取節(jié)點(diǎn)代碼失敗!"+activityId,
                                               ErrorInfo.getTrace(e, e.getStackTrace()));
                             } finally {
                                 DbConnectionManager.getInstance().freeConnection(poolName, con);
                             }
                             return codes;

             }

            
             private static void updValue(String formId,String tableName,String fieldName,String value)throws WfException{
                 Connection con = DbConnectionManager.getInstance().getConnection(
                                            poolName);
                            Statement st = null;
                            try {
                                    st = con.createStatement();
                                    String iSql = "update  "+tableName+" set "+fieldName+"='"+value+"' where formid='"+formId+"'";
                                    System.out.println(iSql);
                                    st.execute(iSql);
                            } catch (Exception e) {
                                throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"更新代碼失敗!",
                                              ErrorInfo.getTrace(e, e.getStackTrace()));
                            } finally {
                                DbConnectionManager.getInstance().freeConnection(poolName, con);
                            }
                         

             }

             private static String getValue(String formId,String tableName,String fieldName)throws WfException{
                 Connection con = DbConnectionManager.getInstance().getConnection(
                                            poolName);
                            Statement st = null;
                            String value = null;
                            try {
                                    st = con.createStatement();
                                    String iSql = "select "+fieldName+" from "+tableName+" where applyid='"+formId+"'";
                                    ResultSet rs = st.executeQuery(iSql);
                                    if (rs.next()) {
                                       value = rs.getString(1);
                                    }
                            } catch (Exception e) {
                                throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"獲取值失敗!",
                                              ErrorInfo.getTrace(e, e.getStackTrace()));
                            } finally {
                                DbConnectionManager.getInstance().freeConnection(poolName, con);
                            }
                            return value;

             }


             //private static void get

             private static void parseCode(String procId,String activityId,String code,HttpServletRequest request) throws WfException{
                try{
                    String funName = code.substring(0, 6);
                  
                    ///設(shè)置流程變量代碼解釋   setVal opinion view.opinion or setVal opinion db.table1.opinion
                    if ("setVal".equals(funName)) {
                        String[] strs = code.split(" "); 
                        String valName = strs[1].trim();  //代碼前部分-流程變量名
                        String valValue = strs[2].trim(); //代碼后部分
                        String[] valueDefs = valValue.split("\\."); //解釋代碼后部分
                        String dataDefType =valueDefs[0];   //數(shù)據(jù)來(lái)源類型 view為頁(yè)面,data 為數(shù)據(jù)庫(kù)
                        String defFieldName = null;
                        String value = null;
                        //從頁(yè)面獲取數(shù)據(jù)才設(shè)置變量  格式: setVal
                        if ("view".equals(dataDefType)) {
                            defFieldName = valueDefs[1];
                            value = request.getParameter(
                                    defFieldName);
                        }
                        //從數(shù)據(jù)庫(kù)中獲取數(shù)據(jù)才設(shè)置變量?????
                        else if ("data".equals(dataDefType)) {
                        
                            String tableName = valueDefs[1];
                            defFieldName = valueDefs[2];
                            String formId = ExProcessManager.getExprocessRelaDataId(
                                    procId);
                            value = getValue(formId,tableName,defFieldName);
                        }
                       
                        else if("cons".equals(dataDefType)){
                         value = valueDefs[1];
                        }
                        Usertable user =(Usertable) request.getSession().getAttribute("login_user");
                        SharkProviderImpl.variableSet(SharkProviderImpl.connect(user.getUserid(),user.getPasswd()), activityId, valName,
                                                          value);
                    }
                   
                    if("updFld".equals(funName)){  //updFld tablea.jiaofei data.tableb.jiaofei
                     String[] strs = code.split(" "); 
                        String valName = strs[1].trim();  //代碼前部分-流程變量名
                        String valValue = strs[2].trim(); //代碼后部分
                        String[] fldDef = valName.split("\\.");
                        String[] valueDefs = valValue.split("\\."); //解釋代碼后部分
                        String dataDefType =valueDefs[0];   //數(shù)據(jù)來(lái)源類型 view為頁(yè)面,data 為數(shù)據(jù)庫(kù)
                        String defFieldName = null;
                        String value = null;
                        String formId = ExProcessManager.getExprocessRelaDataId(
                                procId);
                        //從頁(yè)面獲取數(shù)據(jù)才設(shè)置變量  格式: setVal
                        if ("view".equals(dataDefType)) {
                            defFieldName = valueDefs[1];
                            value = request.getParameter(
                                    defFieldName);
                        }
                        //從數(shù)據(jù)庫(kù)中獲取數(shù)據(jù)才設(shè)置變量?????
                        else if ("data".equals(dataDefType)) {
                        
                            String tableName = valueDefs[1];
                            defFieldName = valueDefs[2];
                           
                            value = getValue(formId,tableName,defFieldName);
                        }
                       
                        else if("cons".equals(dataDefType)){
                         value = valueDefs[1];
                        }
                       
                        updValue(formId,fldDef[0],fldDef[1],value);
                    }
                   
                   
                }
                catch(Exception e){
                 e.printStackTrace();
                 throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"解釋代碼失敗!"+code,
                            ErrorInfo.getTrace(e, e.getStackTrace()));
                }
             }


             public static void parseBeforeCode(String procId,String activityId,int codeType,HttpServletRequest request)throws WfException{
                 try{
                    List codes =  getBeforeCode(procId,activityId,codeType);
                    for(int i=0;i<codes.size();i++){
                        parseCode(procId,activityId,codes.get(i).toString(),request);
                    }
                 }
                 catch(WfException e){
                     throw e;
                 }
                 catch(Exception e1){
                     throw new WfException();
                 }
             }
             public static void parseAfterCode(String procId,String activityId,int codeType,HttpServletRequest request)throws WfException{
                 try{
                       List codes = getAfterCode(procId,activityId,codeType);
                       for(int i=0;i<codes.size();i++){
                        parseCode(procId,activityId,codes.get(i).toString(),request);
                    }

                   }
                   catch(WfException e){
                       throw e;
                   }
                   catch(Exception e1){
                       throw new WfException();
                   }

             }
            
            
             public static String limitControls(String procdefId,String activityId,String url)throws WfException{
              Connection con = DbConnectionManager.getInstance().getConnection(
                         poolName);
             Statement st = null;
             String value="";
            try {
                 st = con.createStatement();
                 String iSql = "";
                 ///
                 if(activityId!=null&&!"null".equals(activityId)){
                 iSql = "select distinct a.controltype,a.controlname,a.viewtype,c.formname from activitycontrollimits a,activitycontrol c,ASSIGNMENTEVENTAUDITS b where a.limitno=c.limitno and c.actdefid=b.activitydefinitionid and b.ACTIVITYID='"+activityId+"' and url='"+url+"'" ;
                 
                 }
                 ///進(jìn)去發(fā)起頁(yè)面 activityid is null
                 else
                 iSql = "select distinct a.controltype,a.controlname,a.viewtype,c.formname from activitycontrollimits a,activitycontrol c where a.limitno=c.limitno and procdefid='"+procdefId+"' and actdefid='null' and url='"+url+"'" ;
                 System.out.println(iSql);
                 ResultSet rs = st.executeQuery(iSql);
                
                 while (rs.next()) {
                  int cType = rs.getInt(3);
                  switch(cType){
                  case 0:value = value+"document.all['"+rs.getString(2)+"'].disabled=true;";
                         break;
                  case 1:
                   if(rs.getInt(1)==3)
                    value = value="self.location='commons/noallow.jsp'";
                   else
                   value = value+"document.all['"+rs.getString(2)+"'].style.display='none';";
                         break;
                  //case 2:value=  value+"document.all['"+rs.getString(2)+"'].style.display='block';";
                        // break;
               
                  default:
                     value = value+"document.all['"+rs.getString(2)+"'].disabled=false;";
                     break;
                  }
                 }
                // if(value.trim().length()==0)
                //  value="self.location='/commons/noallow.jsp'";
               } catch (Exception e) {
                e.printStackTrace();
                 throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"生成校驗(yàn)串失敗!",
                           ErrorInfo.getTrace(e, e.getStackTrace()));
                }    finally {
                  DbConnectionManager.getInstance().freeConnection(poolName, con);
              }
                value= "<script language='javascript'>"+value;
                value = value+"</script>";
              return value; 
             }
            
            
            
             public static String parseClientControl(String activityId) throws WfException{
              Connection con = DbConnectionManager.getInstance().getConnection(
                         poolName);
             Statement st = null;
             String value= "";
            try {
                 st = con.createStatement();
                 String iSql = "select distinct a.procdefid,a.actdefid,a.controltype,a.name,a.value,a.label,a.todefid from activitycodecontrol a,ASSIGNMENTEVENTAUDITS b where a.actdefid=b.activitydefinitionid and b.ACTIVITYID='"+activityId+"'" ;
                 System.out.println(iSql);
                 ResultSet rs = st.executeQuery(iSql);
                 while (rs.next()) {
                  int cType = rs.getInt(3);
                  switch(cType){
                  case 0:value = value+"<input type='checkbox'  name='"+rs.getString(4)+"' value='"+rs.getString(5)+"'>"+rs.getString(6);
                         break;
                  case 1:value = value+rs.getString(6)+"<input type='text' name='"+rs.getString(4)+"' value='"+rs.getString(5)+"'>";
                         break;
                  case 2:value=  value+"<input type='radio' onclick=getUsers('"+rs.getString(7)+"') touserid='"+rs.getString(7)+"' name='"+rs.getString(4)+"' value='"+rs.getString(5)+"'>"+rs.getString(6);
                         break;
               
                  default:
                   value = value+"<input type='checkbox' onclick=getUsers('"+rs.getString(7)+"') touserid='"+rs.getString(7)+"' name='"+rs.getString(4)+"' value='"+rs.getString(5)+"'>"+rs.getString(5);
                     break;
                  }
                 }
               } catch (Exception e) {
                e.printStackTrace();
                 throw new WfException(ErrorInfo.EXT_PROC_MANAGER_ERROR,"解釋客戶端變量失敗!",
                           ErrorInfo.getTrace(e, e.getStackTrace()));
                }    finally {
                  DbConnectionManager.getInstance().freeConnection(poolName, con);
              }
              return value;
            }

             public static void main(String[] args){
                 try{
                   //  CodeFormula.parseCode(null,null,"setVal laid data.tablea.filed", null);
                 
                  try{
                   BasicDataSource ds = new BasicDataSource();
                   ds.setDriverClassName("org.gjt.mm.mysql.Driver");
                   ds.setUrl("jdbc:mysql://localhost/sample");
                   ds.setUsername("root");
                   ds.setPassword("dddd");
                   ds.setInitialSize(2);

                   Hashtable env = new Hashtable();
                   env.put("java.naming.factory.initial","org.apache.naming.java.javaURLContextFactory");
                   InitialContext ctx=new InitialContext();

                   ctx.bind("tomcatDS",ds);
                   ds = (BasicDataSource)ctx.lookup("tomcatDS");
                   Connection con = ds.getConnection();
                   Statement stmt = con.createStatement();
                   String strSql = "select * from user";
                   ResultSet rs = stmt.executeQuery(strSql);
                   while(rs.next()){
                   System.out.println("id="+rs.getString(1));
                   }
                   rs.close();
                   stmt.close();
                   con.close();
                  }
                  catch(Exception ex){
                   ex.printStackTrace();
                  }

                


                 }catch(Exception e){
                     e.printStackTrace();
                 }
             }

              private void jbInit() throws Exception {
              }

          }


          解析數(shù)據(jù)庫(kù)表上的Code字段的值樣式:
          updFld exprocess.BUSSSTATE cons.12001

          setVal outopin cont.test

          posted on 2007-06-25 15:29 imcb 閱讀(270) 評(píng)論(0)  編輯  收藏


          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 扶风县| 郸城县| 泗水县| 汝南县| 锦州市| 珠海市| 察隅县| 元江| 扎囊县| 吉隆县| 河南省| 潍坊市| 休宁县| 吉木萨尔县| 信阳市| 通辽市| 吐鲁番市| 天等县| 通化县| 壤塘县| 杭州市| 花垣县| 宝坻区| 闽清县| 古浪县| 朝阳区| 泉州市| 黄梅县| 博白县| 同仁县| 甘德县| 科技| 乐亭县| 馆陶县| 乌拉特中旗| 卫辉市| 临漳县| 台南市| 江安县| 平舆县| 清水河县|