Extjs批量审核grid中的数据,并提交到后台

ExtJs 前端代碼:

var piliang_audit=function(){

                  //取得所有選中的行

                  var record=grid.getSelectionModel().getSelections();

                  var sum = 0;//未審核的數據條數

                  var indexs = new Array();//存放所選擇數據行數的下標

                  var str = '[';

                  if(record.length>0){

                      for(var i = 0; i <record.length; i++){

                          if(record[i].get('audit_status').toUpperCase()!='Y'){

                            sum = sum + 1;

                            indexs.push(store.indexOf(record[i]));

                            str += "{detail_id:'"+record[i].get('detail_id');   

                            str += "'}";

                            if(i<record.length-1){

                              str += ",";

                            }

                          }

                      }

                  str += "]";

                  if(sum>0){

                    Ext.Ajax.request({

                       method:'POST',

                       url:'pa_priceAction.do?actionType=piliang_audit',

                       success: function(response){

                                var json=Ext.decode(response.responseText);

                                if(json.success){

                                  Ext.Msg.alert('提示',"批量審核成功!",function(){

                                       for(var i=0;i<indexs.length;i++){

                                          store.getAt(indexs[i]).set("audit_person",json.msg);

                                          store.getAt(indexs[i]).set("audit_status","Y");

                                        }

                                  });

                                }else{

                                  Ext.Msg.alert('提示',json.msg);

                                }

                          },

                          failure:function(response){

                                Ext.Msg.alert('提示','批量審核失敗!');

                          },

                          params:{

                               json:str

                           }

                      });

                  }else{

                      Ext.Msg.alert('提示','沒有需要審核的數據!');

                  }

                }else{

                    Ext.Msg.alert('提示','請選擇要審核的記錄!');

                }

}

Java後臺代碼:

導入Json類,處理數據

public ActionForward piliang_audit(ActionMapping actionMapping,

                                      ActionForm actionForm,

                                      HttpServletRequest httpServletRequest,

                                      HttpServletResponse httpServletResponse) throws

          IOException, ServletException, SQLException {

        HashMap maplist = new HashMap();

        String returnvalue = "";

        boolean success = true;

        String sqlString ="";

        String ip = httpServletRequest.getRemoteHost();

        String user_name = httpServletRequest.getSession().getAttribute("user_name").

         toString();

         String json1 = java.net.URLDecoder.decode(httpServletRequest.getParameter("json"), "utf-8").replace('"', ' ').trim();

         //System.out.println(json1);

        Connection conn = null;

        Statement stmt = null;

        ResultSet rs = null;

        DataSource datasource = null;

        ServletContext context = null;

        context = servlet.getServletContext();

        datasource = (DataSource) context.getAttribute(Globals.DATA_SOURCE_KEY);

        conn = datasource.getConnection();

        stmt = conn.createStatement();

        conn.setAutoCommit(false);

        String temp_str="";

        Date dt = new Date();

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        temp_str=sdf.format(dt);

        try {

          ArrayList list = json.jsonstrToarraylist(json1);

          for (int i = 0; i < list.size(); i++) {

            maplist = (HashMap) list.get(i);

           sqlString = "update a set a.audit_status='Y',a.audit_date='"+temp_str+"',a.audit_person='"+user_name+"' from pa_price a "+

                     "where a.detail_id="+maplist.get("detail_id")+"";

                 stmt.addBatch(sqlString);

          }

          stmt.executeBatch();

            returnvalue =user_name;

conn.commit();

            conn.setAutoCommit(true);

        }

        catch (SQLException e) {

          conn.rollback();

          conn.setAutoCommit(true);

          System.err.println(e.getMessage());

          success = false;

          returnvalue = "批量審核失敗!";

        }

        finally {

          if (rs != null) {

            try {

              rs.close();

            }

            catch (SQLException e) {

              rs = null;

            }

          }

          if (stmt != null) {

            try {

              stmt.close();

            }

            catch (SQLException e) {

              stmt = null;

            }

          }

          if (conn != null) {

            try {

              conn.close();

            }

            catch (SQLException e) {

              conn = null;

            }

          }

        }

        returnvalue = "{success:" + success + ",msg:'" + returnvalue + "'}";

        try {

          httpServletResponse.setContentType("text/json; charset=utf-8");

          httpServletResponse.getWriter().write(returnvalue);

        }

        catch (IOException ex) {

          ex.printStackTrace();

        }

        return actionMapping.findForward("");

  }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值