`
dvtwill
  • 浏览: 9963 次
  • 性别: Icon_minigender_1
  • 来自: 济南
最近访客 更多访客>>
社区版块
存档分类
最新评论

二次 开发!!!!

SQL 
阅读更多

看着别人写的像肥肠一样的代码,我失眠了!!

一个分页查询Action里的代码贴出来,留作纪念。

public class supplierMakeOrder extends Action {

 public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest req, HttpServletResponse resp) throws Exception {
  HttpSession session = req.getSession();
  User loginUser = (User) session.getAttribute("loginUser");
  String username = loginUser.getUserName();
  // System.out.println(username);
  SearchInvoiceActionForm searchinvoiceForm = (SearchInvoiceActionForm) form;

  String forward = "Success";// 下一步的链接

  if (loginUser == null) {
   forward = "outdate";
  } else {

   int newPageNo = searchinvoiceForm.getNewPageNo();
   req.setAttribute("currentPage", new Integer(newPageNo));
   int pageSize = searchinvoiceForm.getPageSize();
   pageSize = 10;
   if (pageSize == 0) {
    PageCt pageCt = new PageCt();// 取得页面大小
    pageSize = pageCt.getInt_num();
   }
   req.setAttribute("pageSize", new Integer(pageSize));

   // System.out.println(forward);
   String orderStates = searchinvoiceForm.getOrderStates();
   String queryBasis = searchinvoiceForm.getQueryBasis();
   String queryCond = searchinvoiceForm.getQueryCond();
   String orderCond = searchinvoiceForm.getOrderCond();
   String cz[] = searchinvoiceForm.getCz();
   if (queryCond == null) {
    queryCond = queryCond;
   } else {
    queryCond = queryCond.trim();
   }
   if (orderCond == null || orderCond.equals(""))
    orderCond = " id DESC ";
   System.out.println(orderCond);

   if ("EBELN".equals(queryBasis)) {
    queryBasis = "SAP_EKPO.EBELN";
   }

   String sql = "";
   String countSql = "";
   // 订单状态为空
   if (queryCond == null || queryCond.trim().length() <= 0)// 没有参数
   {
    StringBuffer sqlQ = new StringBuffer();
    sqlQ
      .append(
        " select  TOP 10  SAP_EKPO.EBELP,SAP_EKPO.EBELN,isNull(jjd,'0') as jjd,ddgz,jdfk,isNull((select sum(qty) from wms_stock where MaterialCode=SAP_EKPO.MATNR and SupplierCode=SAP_EKKO.LIFNR),'0') as kcsl,SAP_EKPO.MATNR,SAP_EKPO.cksl,sap_ekpo.sdsl,dbo.ufun_Suppliernm(LIFNR) AS cjmc,LIFNR,MENGE,EKGRP,CONVERT(VARCHAR(100),BEDAT,23) AS BEDAT,CONVERT(VARCHAR(100),EINDT,23) AS EINDT,CASE KZABS WHEN 'X' THEN '确认' WHEN '1' THEN '发货未完成' when '2' then '发货完成' ELSE '未确认' END AS ZT,case when bsart='ZB04' then TXZ01 else MaterialName end as MaterialName,LGORT,itemcode ")
     
      .append(",case  when RETPO='x' then '退货' " )
      .append(" when RETPO!='x' and bsart = 'ZB04' then '工序' " )
      .append("  when RETPO!='x' and ekgrp in(select ekgrp from sap_showpotype where gb='2')  then '毛坯' " )
      .append(" else '采购' end as cglx  " )        
        
      .append(" from SAP_EKPO ")
      .append(
        " left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN  ")
      .append(
        " left join material on SAP_EKPO.MATNR = material.MaterialCode  ")
      .append(
        " where fbsh='2'  and isNull(sap_ekpo.LOEKZ,'') <> 'L'    and LIFNR=(select cjdh from users where username LIKE '"
          + username         //已送货完成,但仍有部分货物在途
          + "')   and (KZABS ='X' or KZABS ='1'  or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0))  and RETPO<>'X' ");
    sql = sqlQ.toString();
    countSql = "SELECT count(*) AS rsCount FROM SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN where LIFNR=(select cjdh from users where username LIKE '"
      + username
      + "') and fbsh='2'  and (KZABS ='X' or KZABS ='1')  and RETPO<>'X'  and isNull(sap_ekpo.LOEKZ,'') <> 'L'    ";
    if (newPageNo == 0) {

     sql += " and (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) <= (select min(id) from (select top 1 (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) as id from SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN   where fbsh='2' and LIFNR=(select cjdh from users where username LIKE '"
       + username
       + "')  and isNull(sap_ekpo.LOEKZ,'') <> 'L'   and (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0)) and RETPO<>'X' order by (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) desc)as t) ORDER BY (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) DESC";
    } else {
     int a = pageSize * (newPageNo - 1) + 1;
     sql += " and (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) <= (select min(id) from (select top  "
       + a
       + " (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) as id from SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN   where fbsh='2' and LIFNR=(select cjdh from users where username LIKE '"
       + username
       + "')  and isNull(sap_ekpo.LOEKZ,'') <> 'L' and (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0)) and RETPO<>'X' order by (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) desc)as t) ORDER BY (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) DESC";
    }
   }
   // 查询条件不为空
   else {
    StringBuffer sqlQ = new StringBuffer();
    sqlQ
      .append(
        " select  TOP 10  SAP_EKPO.EBELP,SAP_EKPO.EBELN,SAP_EKPO.MATNR,SAP_EKPO.cksl,sap_ekpo.sdsl,dbo.ufun_Suppliernm(LIFNR) AS cjmc,LIFNR,MENGE,EKGRP,CONVERT(VARCHAR(100),BEDAT,23) AS BEDAT,CONVERT(VARCHAR(100),EINDT,23) AS EINDT,CASE KZABS WHEN 'X' THEN '确认' WHEN '1' THEN '发货未完成' when '2' then '发货完成' ELSE '未确认' END AS ZT,case when bsart='ZB04' then TXZ01 else MaterialName end as MaterialName,dbo.ufun_storagenm(LGORT) as LGORT,itemcode ")
      
      .append(",case  when RETPO='x' then '退货' " )
      .append(" when RETPO!='x' and bsart = 'ZB04' then '工序' " )
      .append("  when RETPO!='x' and ekgrp in(select ekgrp from sap_showpotype where gb='2')  then '毛坯' " )
      .append(" else '采购' end as cglx  " )         
      
      .append(" from SAP_EKPO ")
      .append(
        " left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN  ")
      .append(
        " left join material on SAP_EKPO.MATNR = material.MaterialCode  ")
      .append(
        " where fbsh='2'  and LIFNR=(select cjdh from users where username LIKE '"
          + username
          + "')  and  (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0)) and RETPO<>'X'   ")
      .append(
        " and "
          + queryBasis
          + " like '%"
          + queryCond
          + "%'  and isNull(sap_ekpo.LOEKZ,'') <> 'L'     ");
    sql = sqlQ.toString();
    countSql = "SELECT count(*) AS rsCount FROM SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN  left join material on SAP_EKPO.MATNR = material.MaterialCode   where LIFNR=(select cjdh from users where username LIKE '"
      + username
      + "') and fbsh='2' and (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0))  and isNull(sap_ekpo.LOEKZ,'') <> 'L'  and RETPO<>'X' and "
      + queryBasis + " like '%" + queryCond + "%'  ";
    // 处理分页时,只查询当前显示页的数据
    if (newPageNo == 0) {

     sql += " and (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) <= (select min(id) from (select top 1 (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) as id from SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN   where fbsh='2'  and isNull(sap_ekpo.LOEKZ,'') <> 'L'   and LIFNR=(select cjdh from users where username LIKE '"
       + username
       + "')   and (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0)) and RETPO<>'X'  and "
       + queryBasis
       + " like '%"
       + queryCond
       + "%'  order by (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) desc)as t) ORDER BY (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) DESC";
    } else {
     int a = pageSize * (newPageNo - 1) + 1;
     sql += " and (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) <= (select min(id) from (select top  "
       + a
       + " (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) as id from SAP_EKPO  left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN   where fbsh='2'  and isNull(sap_ekpo.LOEKZ,'') <> 'L'   and LIFNR=(select cjdh from users where username LIKE '"
       + username
       + "')   and (KZABS ='X' or KZABS ='1' or (KZABS='2' and (isnull(SAP_EKPO.MENGE,0)-isnull(SAP_EKPO.cksl,0))>0)) and RETPO<>'X'  and "
       + queryBasis
       + " like '%"
       + queryCond
       + "%'  order by (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) desc)as t) ORDER BY (SAP_EKPO.EBELN + convert(varchar(20),SAP_EKPO.EBELP)) DESC";
    }
   }

   int rsCount = 0;

   // 取出本次查询的总记录数,存入request中
   try {
    rsCount = DbPool.executeCountQuery(countSql);
    req.setAttribute("rsCount", new Integer(rsCount));

   } catch (SQLException ex) {
    ex.printStackTrace();
    forward = "error";
   }
   // 处理分页时,只查询当前显示页的数据

   // 本次查询具体内容
   try {
    ArrayList allOrder = DbPool.executeQuery(sql);
    req.setAttribute("allOrder", allOrder);

    String title = "生成送货单信息查询";

    String header = "序号,订单号,图号,物料号,物料描述,订单数量,已送数量,已到数量,订单日期,到货日期,状态";
    String displayColumn = "NUM,EBELN,itemcode,MATNR,MaterialName,MENGE,sdsl,cksl,BEDAT,EINDT,ZT";
    String chExist = "0,0,0,0,1,0,0,0,0,1";
    session.setAttribute("title", title);

    if (queryBasis != null && queryBasis.trim().length() > 0) {

     String con = null;

     if (queryBasis.equals("SAP_EKPO.EBELN")) {
      con = "订单号";
     }
     if (queryBasis.equals("itemcode")) {
      con = "图号";
     }
     if (queryBasis.equals("MATNR")) {
      con = "物料号";
     }
     if (queryBasis.equals("MaterialName")) {
      con = "物料描述";
     }
     if (queryBasis.equals("CONVERT(VARCHAR(100),EINDT,23)")) {
      con = "到货日期";
     }

     session.setAttribute("queryCond", con + "中包含【" + queryCond
       + "】的订单信息");
    } else {
     session.setAttribute("queryCond", "");
    }

    session.setAttribute("header", header);
    session.setAttribute("displayColumn", displayColumn);
    session.setAttribute("chExist", chExist);

    session.setAttribute("resultNow", sql);

    // 订单状态为空
    if (queryCond == null || queryCond.trim().length() <= 0)// 没有参数
    {
     StringBuffer sqlQ = new StringBuffer();
     sqlQ
       .append(
         " select  sap_ekpo.sdsl,SAP_EKPO.EBELP,SAP_EKPO.EBELN,SAP_EKPO.MATNR,SAP_EKPO.cksl,dbo.ufun_Suppliernm(LIFNR) AS cjmc,LIFNR,MENGE,EKGRP,CONVERT(VARCHAR(100),BEDAT,23) AS BEDAT,CONVERT(VARCHAR(100),EINDT,23) AS EINDT,CASE KZABS WHEN 'X' THEN '确认' WHEN '1' THEN '发货未完成' when '2' then '发货完成' ELSE '未确认' END AS ZT,case when bsart='ZB04' then TXZ01 else MaterialName end as MaterialName,dbo.ufun_storagenm(LGORT) as LGORT,itemcode ")
       .append(" from SAP_EKPO ")
       .append(
         " left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN  ")
       .append(
         " left join material on SAP_EKPO.MATNR = material.MaterialCode  ")
       .append(
         " where fbsh='2' and isNull(sap_ekpo.LOEKZ,'') <> 'L' and LIFNR=(select cjdh from users where username LIKE '"
           + username
           + "')   and (KZABS ='X' or KZABS ='1')   ");
     sql = sqlQ.toString();
    }
    // 查询条件不为空
    else {
     StringBuffer sqlQ = new StringBuffer();
     sqlQ
       .append(
         " select  sap_ekpo.sdsl,SAP_EKPO.EBELP,SAP_EKPO.EBELN,SAP_EKPO.MATNR,SAP_EKPO.cksl,dbo.ufun_Suppliernm(LIFNR) AS cjmc,LIFNR,MENGE,EKGRP,CONVERT(VARCHAR(100),BEDAT,23) AS BEDAT,CONVERT(VARCHAR(100),EINDT,23) AS EINDT,CASE KZABS WHEN 'X' THEN '确认' WHEN '1' THEN '发货未完成' when '2' then '发货完成' ELSE '未确认' END AS ZT,case when bsart='ZB04' then TXZ01 else MaterialName end as MaterialName,dbo.ufun_storagenm(LGORT) as LGORT,itemcode ")
       .append(" from SAP_EKPO ")
       .append(
         " left join SAP_EKKO on SAP_EKPO.EBELN=SAP_EKKO.EBELN  ")
       .append(
         " left join material on SAP_EKPO.MATNR = material.MaterialCode  ")
       .append(
         " where fbsh='2' and isNull(sap_ekpo.LOEKZ,'') <> 'L' and LIFNR=(select cjdh from users where username LIKE '"
           + username
           + "')  and  (KZABS ='X' or KZABS ='1')   ")
       .append(
         " and "
           + queryBasis
           + " like '%"
           + queryCond
           + "%' and (KZABS ='X' or KZABS ='1')   ");
     sql = sqlQ.toString();
    }

    // ArrayList printAllOrder = DbPool.executeQuery(sql);

    session.setAttribute("result", sql);
   } catch (SQLException ex) {
    ex.printStackTrace();
    forward = "error";
   }

   searchinvoiceForm.setQueryBasis(queryBasis);
   searchinvoiceForm.setOrderStates(orderStates);
   searchinvoiceForm.setPageSize(pageSize);
   searchinvoiceForm.setQueryCond(queryCond);
   searchinvoiceForm.setNewPageNo(newPageNo);
   searchinvoiceForm.setOrderCond(orderCond);
  }

  return mapping.findForward(forward);
 }

}

分享到:
评论

相关推荐

    100个微信小程序源码.7z—适合新手与二次开发!

    100个微信小程序源码,无需接入第三方,自己开发!适合新手与二次开发!

    UG二次开发教程_准件库的建立等相关教程!

    U_G_二次开发与加工自动化 UG/Grip技术在诱导轮三维设计中的运用 UGOPENC++与xml技术 UG二次开发计算机辅助公差设计 UG二次开发技术的研究 UG二次开发中数据访问方法研究 UG软件CAE_二次开发研究及应用 UG下用户CAD...

    西门子 step7中 FB41 PID 功能块的SCL语言编写,可以转换成C++格式用来二次开发!代码正确,可运行!

    西门子 step7中 FB41 PID 功能块的SCL语言编写,可以转换成C++格式用来二次开发!建议有工控基础和C语言基础的人员下载!转换过程参照: “https://download.csdn.net/download/weixin_37928884/85103667”、...

    义博!Autodesk Revit二次开发基础教程.pdf

    义博!Autodesk revit二次开发基础教程,强烈推荐,强烈推荐,强烈推荐,强烈推荐 !

    CATIA二次开发(关于CATIA的,很珍贵啊!!!)

    CATIA二次开发 摘要:本文介绍了在以Windows XP 为操作系统的微机上应用VC++ 6.0工具,基于Component Application Architecture(CAA) 组件应用架构的CATIA界面二次开发技术。并在此基础上通过建立一个基于CATIA二...

    一个基于C#的ArcGIS二次开发程序!

    本项目是基于C#语言对ArcGIS进行的二次开发,旨在拓展其功能并提供更加定制化的用户体验。 一、C#语言与ArcGIS结合 C#是一种现代化的、类型安全的面向对象编程语言,由微软开发,广泛应用于Windows平台的软件开发。...

    EduSoho二次开发文档

    EduSoho二次开发是针对教育类远程教育平台的个性化定制开发,允许开发者在EduSoho平台的基础上进行功能扩展和界面定制。EduSoho平台采用模块化设计,便于开发者进行二次开发,同时也支持插件化扩展。EduSoho二次开发...

    EZCAD 2.7全套(二次开发函数2.5)

    含32位、64位驱动,支持WIN7系统,打包了二次开发函数库MarkEzd.dll及简易开发文档,可以二次开发!再含接线定义&说明书以及安装说明!!!二次开发有难度,女司机请悠着点!注:本资源仅供研究学习使用!

    creo二次开发helloworld

    本教程将围绕“creo二次开发helloworld”这个主题,详细介绍如何在CREO 2.0环境中利用Visual Studio 2010进行基本的二次开发。 首先,我们需要理解CREO的二次开发主要基于Parametric Technology Corporation(PTC)...

    用友致远A8平台二次开发

    【用友致远A8平台二次开发】是一个针对专业开发人员的手册,旨在提供A8平台的二次开发和第三方应用集成的详细指南。这个手册强调了如何通过接口和增值开发来实现与第三方系统的高效协作,同时降低了开发的技术门槛,...

    可运营级别的第三方支付平台源码多支付渠道+代理功能等支持后台补单,源码全开源,支持二次开发!.txt

    可运营级别的第三方支付平台源码多支付渠道+代理功能等支持后台补单,源码全开源,支持二次开发!.txt

    NIKON相机D5600 二次开发

    VS2019工程C#版本,NIKON相机D5600第二次开发第一版本,亲自开发测试通过,亲们可以拿来接着开发哦~!此版本是NIKON相机D5600与D5500的通用版本可供二次开发!!!版主会陆续更新的

    tpfang 房产源码 可用可学习,是一款不错的房产源码,你可以在上面进行二次开发!!

    这个源码的亮点在于其可学习性和可扩展性,非常适合有志于在房地产信息化领域进行软件开发或二次开发的人员使用。 一、源码核心特性 1. 基于ThinkPHP框架:tpfang源码是基于流行的PHP框架ThinkPHP构建的,该框架以...

    AutoCAD二次开发文档(C++ C# 史上最全版本)

    AutoCAD是一款广泛应用于工程设计领域的计算机辅助设计软件,其二次开发功能允许用户通过编程扩展其功能,以满足特定需求。本资源集合包含了多种语言和技术,包括C++、C#以及.NET,提供了AutoCAD二次开发的全面指导...

    QGIS 示例程序,实现QGIS二次开发

    本示例程序旨在帮助开发者了解并实践QGIS的二次开发,利用vc9(Visual Studio 2008)作为开发环境,结合qgis1.6 SDK(软件开发工具包)和qt4.7库,实现对QGIS基本GIS功能的扩展。 QGIS的二次开发通常涉及以下几个...

    Godex g500条码打印机二次开发

    Godex g500条码打印机的二次开发,使用了官方的例子做出了二次开发,同时也添加了自定义添加标签和条码,但只是开发了5%如有需要可以下载这个文件来练习!不参与任何言论,并且该文件代码是由godex官方提供不参与...

    中控指纹考勤机二次开发包

    中控指纹考勤机二次开发包,源代码!中控指纹考勤机二次开发包,源代码!中控指纹考勤机二次开发包,源代码!

    大华视频web二次开发.zip

    大华视频摄像头对接代码 海康大华WEB二次开发整理 亲测 基于IE webplugin控件由于工作的原因需要开发海康和大华,还有天地伟业的摄像头,而且必须是本地部署开发,每个厂家网页版摄像头接口都不一样,而且在本地...

    C# 调用 bartender 打印的示例(二次开发,含说明)

    在IT行业中,尤其是在软件开发领域,二次开发是指对已有软件进行定制化或功能扩展的过程。在本示例中,我们关注的是如何通过C#语言进行BarTender的二次开发,以便利用BarTender强大的条码和标签设计能力,实现自定义...

Global site tag (gtag.js) - Google Analytics