| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 517 人关注过本帖
标题:报表中的导入操作
只看楼主 加入收藏
SoftWarezx
Rank: 1
等 级:新手上路
威 望:1
帖 子:47
专家分:9
注 册:2010-7-14
结帖率:100%
收藏
 问题点数:0 回复次数:1 
报表中的导入操作
程序代码:
function exportIn(){
    with(document.getElementById("nameInfo")){
        action = "<%=strContext%>/pretreament/exportAction.do?method=specExportIn";
        method = "post";
        enctype="multipart/form-data";
        submit();
    }
}

<input type="button" value=">>>开始  onclick="exportIn()" />

/** 通过specIn.jsp跳转 通过剂型标准化 Excel导入 (liyc添加) */
    public ActionForward specExportIn(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
    throws Exception {
        System.out.println("+++++++++++++++++++++++++++++++++++++++in_expore_action++++++++");
        try {
            String med_type = (String)request.getSession(true).getAttribute("med_type");
            String taskId = (String) request.getSession(true).getAttribute("taskId");
            String filePath = "" + request.getRealPath("/")
            + "\\jsp\\pretreament\\fileUpload";
            String path = p.uploadFile(form, request, filePath); // 文件的路径
            String result = biz.specExportIn(path, med_type,taskId); // 导入excel
            int num_insert = 0;
            int num_update = 0;
            if(result!=null && !result.trim().equals("")&& !result.trim().equals("0,0")){
                String[] temp = result.split(",");
                num_insert = Integer.parseInt(temp[0]);
                num_update = Integer.parseInt(temp[1]);
            }
            IStandardService sBiz = new StandardServiceImpl();
            ParamUtils pu = new ParamUtils();
            CriterionInfo c = new CriterionInfo();
            String userName = (String) pu.getSessionObject(request, "userNm");
            c.setUserId(userName);
            c.setTitle("PRE_CRITERIONSPEC");
            c.setTaskId(taskId);
            c.setOpeLink("1");
            c.setMedType(med_type);
            c.setTotal(String.valueOf(num_update));
            System.out.println("result===>>>>"+result);
            // 如果插入结果返回值等于0,就不会插入
            if (result!=null && !result.trim().equals("")&& !result.trim().equals("0,0")) {
                sBiz.saveCriterionLog(c); // 添加规则导入日志
                Cronlog cronlog = new Cronlog();
                cronlog.setLogMisId(taskId);
                cronlog.setLogContent("更新规则到剂型全匹配规则库,共添加数据"+num_insert+"条;更新数据"+num_update+"条");
                cronlog.setLogUserId(userName);
                cronlog.setLogModule("2"); // 2:剂型标准化
                cronlog.setLogFlag("1");
                cronlog.setMedType(med_type);
                dLog.createDiary(cronlog);
            }
            /************ 删除服务器上缓存文件 ***********/
            p.deleteFile(filePath, path);
            /***************************/
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new ActionForward(
        "/standardAction.do?method=getCriterionLog&opeLink=1");
    }


// 剂型标准化,导入Excel.【传入参数为:解读的文件路径和药品类型以及任务的ID】
    public String specExprotIn(String filename, String med_type,String taskId) throws Exception {
        Excel ex = new Excel();
        //        String[] list = null;
        String[] array = null;
        boolean result = false;
        int number = 0;
        int num_update = 0;
        PreUtils pu = new PreUtils();
        db = db.getDBTool();
        conn = db.getConn(dbSource);
        // excel总行数
        System.out.println("+++++++++++++++++++++++++++++++++++++++in_spec_daoImpl++++++++");
        int row = 0;
        String sql = "insert into PRE_CRITERIONSPEC(REP_SPEC,MEDNAME,SPEC,CONTENT,CONTENTUNIT,DOSAGE,DOSAGEUNIT,SCALAR,"
            + "PRODUCE_COM,CHARACT,WRAPPER,REST,CREATE_USER,DEPARTMENT,med_type) values("
            + "?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
        /*增加一个更新语句*/
        String sql_update = "UPDATE PRE_CRITERIONSPEC SET SPEC = ? WHERE PRE_CRITERIONSPEC.REP_SPEC= ? and PRE_CRITERIONSPEC.MED_TYPE='"+med_type+"'";

        //增加一个剔除的语句
        String sql_delete = "update pre_standarddata set w_flag='1' where (rep_spec=? or rep_spec is null) and standardtask_id="+taskId+" and (med_type=? or med_type is null)";

        try {
            // 打开excel文件
            result = ex.openExcel(filename);
            if (result) {
                // 读excel文件0号工作薄
                row = ex.getRowCount(0);
                // 如果这个Excel行数 小于1 就返回.
                if (row < 1) {
                    result = false;
                } else {
                    // 执行SQL语句
                    System.out.println(row+"################################################ssss######################"+sql);
                    pst = conn.prepareStatement(sql);
                    //增加一个update预编译
                    pst_update = conn.prepareStatement(sql_update);
                    //增加一个update删除标识预编译
                    pst_delete =conn.prepareStatement(sql_delete);

                    for (int i = 1; i < row; i++) {
                        array = ex.getRowArray(i);
                        int len = array.length;
                        System.out.println(array[1] + "=1 " + array[2]
                                                                    + "=2 " + array[3] + "=3 " + array[4] + "=4 "
                                                                    + array[5] + " =5" + array[6] + "=6 "
                                                                    + array[7] + "=7 " + array[8] + "=8 "
                                                                    + array[9] + "=9 " + array[10] + "=10 "
                                                                    + array[11] + "=11 " + array[12] + " =12"   
                                                                    + array[13]+"=13"+array[14]+"=14"+array[15]+"=15"+array[17]);

                        if (len > 0&&array[14]!=null&&!array[14].trim().equals("")) {  
                            String mSql = "select * from PRE_CRITERIONSPEC where rep_spec='"
                                + array[2] + "' and med_type='"+pu.format5(array[1])+"'";
                            System.out.println(len+"========ddddd=1");
                            int num = pu.getNum(mSql);
                            if (num > 0) {
                                System.out.println("num====="+num);

                                //看有没有删除标识,有的话执行删除规则库操作
                                if(array[15]!=null&&array[15].trim().equals("1")){

                                    pst_delete.setString(1, pu.format4_yuchuli(array[2]));
                                    pst_delete.setString(2, pu.format4_yuchuli(array[1]));
                                    pst_delete.addBatch();
                                    /*看有没有修改标示,有的话执行更新规则库操作*/
                                }else if(array[17]!=null&&array[17].trim().equals("1")){

                                    System.out.println("*&*&*&*&");
                                    pst_update.setString(1, pu.format4(array[4]));
                                    pst_update.setString(2, pu.format4(array[2]));
                                    pst_update.addBatch();
                                    num_update++;

                                }
                                System.out.println(pu.format5(array[1])+"===="+array[2] + ":重复条目");
                            } else if (num == 0) {
                                number++;

                                pst.setString(1, pu.format3(array[2]));
                                pst.setString(2, pu.format4(array[3]));
                                pst.setString(3, pu.format4(array[4]));
                                pst.setString(4, pu.format4(array[5]));
                                pst.setString(5, pu.format4(array[6]));
                                pst.setString(6, pu.format4(array[7]));
                                pst.setString(7, pu.format4(array[8]));
                                pst.setString(8, pu.format4(array[9]));
                                pst.setString(9, pu.format4(array[10]));
                                pst.setString(10, pu.format4(array[11]));
                                pst.setString(11, pu.format4(array[12]));
                                pst.setString(12, pu.format4(array[13]));
                                pst.setString(13, pu.format4(array[14]));
                                pst.setString(14, pu.format4(array[15]));
                                pst.setString(15, pu.format5(array[1]));
                                pst.addBatch();
                            }
                        }
                    }
                    //piliang
                    pst_update.executeBatch();
                    pst.executeBatch();
                    pst_delete.executeBatch();
                }
            }
        } catch (Exception e) {
            number = 0;
            e.printStackTrace();
        } finally {
            this.closeRs();
        }
        return number+","+num_update;
    }




 public final static String PRE_WHOLESALE_TOP[] = {"序号","上报药品名称","上报药品类别","医保序号","上报剂型","上报规格",
        "生产企业名称","最小零售单位","销售数量","销售价格","购进数量","购进价格","批发报送单位","调查年度","地域","标准药品类别","标准医保序号","标准药品名称","标准剂型",
         "标准含量", "标准含量单位", "标准装量","标准装量单位", "包装数量","包装数量单位", "标准生产企业名称", "性状", "包装材料", "其他",
         "标准地域名称","处室","原研定价", "单独定价", "统一定价"};

资源共享,对大家有帮助的就顶下,谢谢了O(∩_∩)O~
搜索更多相关主题的帖子: 报表 function action button method 
2010-10-14 13:53
SoftWarezx
Rank: 1
等 级:新手上路
威 望:1
帖 子:47
专家分:9
注 册:2010-7-14
收藏
得分:0 
需要的包,在下载资源里面有
2010-10-14 14:05
快速回复:报表中的导入操作
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.023090 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved