EasyUI 增删改查完全详细

来源:互联网 发布:练瑜伽的女人啪啪知乎 编辑:程序博客网 时间:2024/06/06 21:45

EasyUI 增删改查完全详细

标签: easyuidatagrid增删改查easyui datagrid
 3287人阅

目录(?)[+]

本实例使用EasyUI创建表格,元素,窗口,以及各种请求。增加,修改,查询及其他知识基本涵盖完全。有用到js创建和html创建.

整体概览:

多条件的分页查询

dialog对话框实现添加功能,加入验证

window弹窗多条件分页查询

修改信息


导入:
[html] view plain copy
  1. <pre name="code" class="html"><%@ page contentType="text/html; charset=utf-8"  import="java.util.*" language="java" %>  
  2. <%@page import="java.text.SimpleDateFormat"%>  
  3. <%@ page language="java" pageEncoding="UTF-8"%>  
  4. <link rel="stylesheet" type="text/css"  href="/portal/css/use.css"  />  
  5. <link rel="stylesheet" type="text/css"  href="/portal/css/style.css">  
  6. <link rel="stylesheet" type="text/css"  href="/portal/js/jquery-easyui/themes/default/easyui.css">  
  7. <link rel="stylesheet" type="text/css"  href="/portal/js/jquery-easyui/themes/icon.css">  
  8. <script type="text/javascript"   src="/portal/js/jquery-easyui/jquery-1.6.min.js"></script>  
  9. <script type="text/javascript"  src="/portal/js/jquery-easyui/jquery.easyui.min.js"></script>  


前端js:

[javascript] view plain copy
  1. <script type="text/javascript">  
  2.     /* 启动时加载 */  
  3.     $(function(){  
  4.         $('#movement_ode').combobox({      
  5.             url:'/portal/goodsMovingTypeAction.do?type=query',      
  6.             valueField:'movement_types',      
  7.             textField:'summary'     
  8.         });  
  9.         $("#goods_tab").datagrid({  
  10.             title: '货品移动填报',  
  11.             checkOnSelect: false,  
  12.             pagination:true,  
  13.             pageSize:20,  
  14.             pageNumber:1,  
  15.             toolbar: '#tb',  
  16.             url: '/portal/queryGoodsMovementAction.do',  
  17.             loadMsg:'加载中...',  
  18.             fit: true,  
  19.             columns: [[  
  20.                 { field: 'id', checkbox: true},  
  21.                 { field: 'moveid', title: '编号', width:60 },  
  22.                 { field: 'postingdate', title: '过帐日期', width:80},  
  23.                 { field: 'transferreno', title: '移动单号', width:100 },  
  24.                 { field: 'movementcodename', title: '移动类型信息说明', width:150 },  
  25.                 { field: 'fromstoragelocation', title: '来源库位', width:60 },  
  26.                 { field: 'tostoragelocation', title: '接受库位', width:60 },  
  27.                 { field: 'frommaterial', title: '商品编码', width:80 },  
  28.                 { field: 'frombatchnumber', title: '商品批号', width:80 },  
  29.                 { field: 'quantity', title: '数量', width:60 },  
  30.                 { field: 'reasoncodename', title: '原因代码说明', width:120 },  
  31.                 { field: 'documentdatetime', title: '创建时间', width:80 },  
  32.                 { field: 'del_flag', title: '记录状态', width:80,  
  33.                     formatter: function(value,row,index){  
  34.                         if (value=='0'){                              
  35.                             return '<a  href="javascript:void(0);" style="color: #000000;" onclick="updateDelFlag('+value+','+row.moveid+');">有效</a>';  
  36.                         }   
  37.                         if (value=='1'){  
  38.                             return '<a  href="javascript:void(0);" style="color: #ff0000;" onclick="updateDelFlag('+value+','+row.moveid+');">无效</a>';  
  39.                         }  
  40.                     }  
  41.                 },  
  42.                 { field: 'exec_flag', title: '同步状态', width:80,  
  43.                     formatter: function(value,row,index){  
  44.                         if (value=='0'){  
  45.                             return '未同步';  
  46.                         }   
  47.                         if (value=='1'){  
  48.                             return '已同步';  
  49.                         }  
  50.                     }  
  51.                 }  
  52.             ]]            
  53.         });   
  54.           
  55.         /* 选择ERP商品信息 */  
  56.         $("#select_erp_win").window({  
  57.             title:'选择ERP商品信息',  
  58.             width:640,      
  59.             height:400,      
  60.             modal:true     
  61.         }).window("close");    
  62.           
  63.         $("#select_erp_tab").datagrid({  
  64.             url:"/portal/queryerpgoodsAction.do",  
  65.             loadMsg:'加载中...',  
  66.             singleSelect:true,  
  67.             pagination:true,  
  68.             pageSize:10,  
  69.             pageNumber:1,  
  70.             columns:[[  
  71.                 {field:'com_goods_id',title:'com_goods_id',width:100,checkbox:true},      
  72.                 {field:'goods_opcode',title:'ERP商品操作码',width:100},      
  73.                 {field:'goods_name',title:'ERP商品名称',width:100},      
  74.                 {field:'goods_desc',title:'ERP商品规格',width:100},      
  75.                 {field:'product_location',title:'ERP商品厂商',width:100},      
  76.                 {field:'unit_name',title:'ERP商品单位',width:75},                 
  77.                 {field:'package_num',title:'ERP商品包装数',width:75}       
  78.                   
  79.             ]]  
  80.         });  
  81.           
  82.         /* 选择商品批号 */  
  83.         $("#select_batchnumber_win").window({  
  84.             title:'选择ERP商品信息',  
  85.             width:480,      
  86.             height:400,      
  87.             modal:true     
  88.         }).window("close");    
  89.           
  90.         $("#select_batchnumber_tab").datagrid({  
  91.             url:"/portal/queryerpGoodsBatchNumberAction.do",  
  92.             loadMsg:'加载中...',  
  93.             singleSelect:true,  
  94.             pagination:true,  
  95.             pageSize:10,  
  96.             pageNumber:1,  
  97.             columns:[[  
  98.                 {field:'com_lot_id',title:'com_lot_id',width:100,checkbox:true},      
  99.                 {field:'lot_no',title:'商品批号',width:100},      
  100.                 {field:'produce_date',title:'生效日期',width:150},                
  101.                 {field:'expire_date',title:'到期日期',width:150}                  
  102.             ]]  
  103.         });  
  104.         /* 移动类型改变启用原因代码 */  
  105.         $('#tb_movement_code').combobox({             
  106.             onSelect: function(record){  
  107.                 var value = $(this).combobox('getValue');   
  108.                 $('#tb_reasoncode').combobox({      
  109.                     url:'/portal/getAllParameterAction.do?type=reason&movement_types='+value,      
  110.                     valueField:'reason_code',      
  111.                     textField:'reason_name'     
  112.                 });  
  113.                 $("#tb_reasoncode").combobox("enable");  
  114.             }  
  115.         });  
  116.   
  117.           
  118.     });  
  119.       
  120.     /* 查询数据条件 */  
  121.     function checkInputQuery(){  
  122.         var startDate = $('#startDate').datebox('getValue');  
  123.         var endDate = $('#endDate').datebox('getValue');  
  124.         var movingCode = $('#movement_ode').combobox('getValue');   
  125.         $('#goods_tab').datagrid('options').url='/portal/queryGoodsMovementAction.do';  
  126.         $('#goods_tab').datagrid('load',{  
  127.             startDate:startDate,  
  128.             endDate:endDate,  
  129.             movingCode:movingCode,  
  130.         });          
  131.     }  
  132.       
  133.     /* 修改记录状态 */  
  134.     function updateDelFlag(value,row){  
  135.         $.ajax({  
  136.             method : 'post',  
  137.             url : '/portal/updateGoodStatusAction.do',  
  138.             data:{   
  139.                 type : "del",  
  140.                 moveid : row,  
  141.                 del_flag : value  
  142.             },   
  143.             async : false,  
  144.             dataType : 'json',  
  145.             success : function(data) {  
  146.                 if(data){  
  147.                     $('#goods_tab').datagrid('reload');   
  148.                 }else{  
  149.                     $.messager.alert('提示',"更改记录状态失败!");  
  150.                 }  
  151.             },  
  152.             error : function() {  
  153.                 $.messager.alert('异常','更改记录状态异常!');  
  154.             }  
  155.         });  
  156.     }  
  157.       
  158.     /* 修改同步状态,单条或多条 */  
  159.     function updateExecFlag(){  
  160.         var checkedItems = $('#goods_tab').datagrid('getSelections');  
  161.         var moveid = [];  
  162.         $.each(checkedItems, function(index, item){  
  163.             moveid.push(item.moveid);  
  164.         });   
  165.         var str =moveid.toString();  
  166.         if(moveid!=""){  
  167.             $.ajax({  
  168.                 method : 'post',  
  169.                 url : '/portal/updateGoodStatusAction.do',  
  170.                 data:{      
  171.                     type : "exec",  
  172.                     moveids : str  
  173.                 },   
  174.                 async : false,  
  175.                 dataType : 'json',  
  176.                 success : function(data) {  
  177.                     if(data){  
  178.                         $('#goods_tab').datagrid('reload');   
  179.                     }else{  
  180.                         $.messager.alert('提示','更改同步状态失败!');  
  181.                     }  
  182.                 },  
  183.                 error : function() {  
  184.                     $.messager.alert('警告','更改同步状态异常!');  
  185.                 }  
  186.             });  
  187.         }else{  
  188.             $.messager.alert('提示','请至少选择一条数据进行修改!');  
  189.             return false;  
  190.         }  
  191.           
  192.     }  
  193.     /* 下拉框元素填充 */  
  194.     function selectGood(){  
  195.         $('#tb_movement_code').combobox({      
  196.             url:'/portal/goodsMovingTypeAction.do?type=add',      
  197.             valueField:'movement_types',      
  198.             textField:'summary'     
  199.         });  
  200.         $('#tb_fromstoragelocation').combobox({      
  201.             url:'/portal/getAllParameterAction.do?type=fromstor',      
  202.             valueField:'freight_code',      
  203.             textField:'freight_info'     
  204.         });  
  205.         $('#tb_tostoragelocation').combobox({      
  206.             url:'/portal/getAllParameterAction.do?type=tostorage',      
  207.             valueField:'freight_code',      
  208.             textField:'freight_info'     
  209.         });  
  210.         $('#tb_reasoncode').combobox({      
  211.             url:'/portal/getAllParameterAction.do?type=reason',      
  212.             valueField:'reason_code',      
  213.             textField:'reason_name'     
  214.         });   
  215.         $("#frombatchnumberBtn").linkbutton("disable");  
  216.         $("#tb_reasoncode").combobox("disable");  
  217.     }  
  218.     var url;  
  219.     /* 修改商品移动信息 */  
  220.     function updateGood(){  
  221.         selectGood();  
  222.         var checkedItems = $('#goods_tab').datagrid('getSelections');  
  223.         var moveIds = [];  
  224.         var num = 0;  
  225.         $.each(checkedItems, function(index, item){  
  226.             moveIds.push(item.moveid);  
  227.             num++;  
  228.         });   
  229.         if(num != 1){  
  230.             $.messager.alert('提示','请选择一条数据进行修改');  
  231.             return false;  
  232.         }  
  233.         var row = $("#goods_tab").datagrid("getSelected");  
  234.         if (row) {  
  235.             $("#enditTab").dialog("open").dialog('setTitle''编辑货品移动维护');  
  236.             $("#fm").form("load", row);  
  237.             url = "/portal/addGoodMovingAction.do?type=update";  
  238.         }  
  239.         $('#tb_movement_code').combobox("select", row.movementcode);  
  240.         $('#tb_reasoncode').combobox("select", row.reasoncode);  
  241.         //修改商品时把编码和批号传入隐藏文本框(禁用后获取不到值)  
  242.         $('#tb_frommaterial_in').val(row.frommaterial);  
  243.         $('#tb_frombatchnumber_in').val(row.frombatchnumber);  
  244.     }  
  245.       
  246.     /* 添加商品移动信息 */  
  247.     function addGood(){  
  248.         selectGood();  
  249.         $("#enditTab").dialog("open").dialog('setTitle''添加货品移动维护');  
  250.         $("#fm").form("clear");   
  251.         url = "/portal/addGoodMovingAction.do?type=add";  
  252.     }  
  253.       
  254.     /* 数据校验后提交 */  
  255.     function checkInputAdd(){  
  256.         var tb_postingdate = $('#tb_postingdate').datebox('getValue');  
  257.         if(tb_postingdate==''){  
  258.             $.messager.alert('提示','过帐日期不能为空');  
  259.             return false;  
  260.         }  
  261.         var tb_movement_code = $('#tb_movement_code').combobox('getValue');   
  262.         if(tb_movement_code==''){  
  263.             $.messager.alert('提示','移动类型不能为空');  
  264.             return false;  
  265.         }  
  266.         var tb_fromstoragelocation = $('#tb_fromstoragelocation').combobox('getValue');   
  267.         if(tb_fromstoragelocation==''){  
  268.             $.messager.alert('提示','来源库位不能为空');  
  269.             return false;  
  270.         }  
  271.         var tb_tostoragelocation = $('#tb_tostoragelocation').combobox('getValue');   
  272.         if(tb_tostoragelocation==''){  
  273.             $.messager.alert('提示','接收库位不能为空');  
  274.             return false;  
  275.         }  
  276.         var tb_frommaterial = $('#tb_frommaterial').val();   
  277.         if(tb_frommaterial==''){  
  278.             $.messager.alert('提示','商品编码不能为空');  
  279.             return false;  
  280.         }  
  281.         var tb_frombatchnumber = $('#tb_frombatchnumber').val();   
  282.         if(tb_frombatchnumber==''){  
  283.             $.messager.alert('提示','商批号不能为空');  
  284.             return false;  
  285.         }  
  286.         var tb_quantity = $('#tb_quantity').val();   
  287.         if(tb_quantity==''){  
  288.             $.messager.alert('提示','数量不能为空');  
  289.             return false;  
  290.         }  
  291.         /* var tb_reasoncode = $('#tb_reasoncode').combobox('getValue');  
  292.         if(tb_reasoncode==''){ 
  293.             $.messager.alert('提示','原因代码不能为空'); 
  294.             return false; 
  295.         } */  
  296.         $("#fm").form("submit", {  
  297.             url: url,  
  298.             onsubmit: function () {  
  299.                 return $(this).form("validate");  
  300.             },  
  301.             success: function (result) {  
  302.                 if (result == "true") {  
  303.                     $.messager.alert("提示信息""操作成功");  
  304.                     $("#enditTab").dialog("close");  
  305.                     $("#goods_tab").datagrid("load");  
  306.                 }  
  307.                 else {  
  308.                     $.messager.alert("提示信息""保存数据失败");  
  309.                 }  
  310.             }  
  311.         });  
  312.     }  
  313.     /* 选择ERP商品 */  
  314.       
  315.     function selecterpapply(){  
  316.         $("#select_erp_win").window("open");  
  317.         $("#select_erp_tab").datagrid("load");  
  318.     }  
  319.       
  320.     function queryselecterp(){  
  321.         var apply_erp_name = $("#select_erp_name").val();  
  322.         var apply_erp_produce = $("#select_erp_produce").val();  
  323.         $("#select_erp_tab").datagrid("load",{erp_name:apply_erp_name,erp_produce:apply_erp_produce});  
  324.     }  
  325.       
  326.     function saveselecterp(){  
  327.         var select = $('#select_erp_tab').datagrid('getSelections');  
  328.         var goods_opcode = select[0].goods_opcode;  
  329.         var com_goods_id = select[0].com_goods_id;  
  330.         $("#tb_frommaterial").val(goods_opcode);  
  331.         $("#tb_frommaterial_in").val(goods_opcode);  
  332.         $("#com_goods_id").val(com_goods_id);  
  333.         $.messager.progress('close');  
  334.         $('#select_erp_win').window('close');  
  335.         /* 清空原有批号 */  
  336.         $("#tb_frombatchnumber").val("");     
  337.         $("#tb_frombatchnumber_in").val("");  
  338.         $("#frombatchnumberBtn").linkbutton("enable");  
  339.     }  
  340.   
  341.     /* 批号 */  
  342.     function queryFrombatchnumber(num){  
  343.         var com_goods_id = $("#com_goods_id").val();  
  344.         if(num == 1){  
  345.             $("#select_batchnumber_win").window("open");  
  346.             $("#select_batchnumber_tab").datagrid("load",{com_goods_id:com_goods_id});  
  347.         }  
  348.         if(num == 2){  
  349.             var link_goods_id = $("#link_goods_id").val();  
  350.             $("#select_batchnumber_tab").datagrid("load",{com_goods_id:com_goods_id,link_goods_id:link_goods_id});  
  351.         }  
  352.     }  
  353.       
  354.     function saveselectbatchnumber(){  
  355.         var select = $('#select_batchnumber_tab').datagrid('getSelections');  
  356.         var lot_no = select[0].lot_no;  
  357.         $("#tb_frombatchnumber").val(lot_no);  
  358.         $("#tb_frombatchnumber_in").val(lot_no);  
  359.         $.messager.progress('close');  
  360.         $('#select_batchnumber_win').window('close');  
  361.     }     
  362. </script>  


前端html:

[html] view plain copy
  1. <body style="padding: 0;margin: 0;">  
  2.       
  3.     <div id="tb" style="width: auto; height: 80px;">  
  4.         <table style="width: auto; height: 75px;" cellspacing="0" border="0">  
  5.             <tr>  
  6.                 <td>开始时间:<input id="startDate" type="text" class="easyui-datebox" required="required" value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"></input></td>  
  7.                 <td>结束时间:<input id="endDate" type="text" class="easyui-datebox" required="required" value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"></input></td>  
  8.                 <td>移动类型:<input  id="movement_ode" name="movement_ode"  value=""  style="width: 350px;"></td>  
  9.                 <td><a id="query" href="#" class="easyui-linkbutton" iconCls="icon-search" onclick="checkInputQuery();">查询</a></td>  
  10.             </tr>  
  11.             <tr>  
  12.                 <td><a href="#" class="easyui-linkbutton" iconCls="" onclick="addGood();">添加</a>  
  13.                 <a href="#" class="easyui-linkbutton" iconCls="" onclick="updateGood();">修改</a>  
  14.                 <a href="#" class="easyui-linkbutton" iconCls="" onclick="updateExecFlag();">重置同步状态</a></td>            
  15.             </tr>  
  16.         </table>  
  17.     </div>  
  18.     <table id="goods_tab" ></table>  
  19.       
  20.       
  21.       
  22.     <div id="enditTab" class="easyui-dialog" style="width: 500px;height: 400px;" closed="true" >    
  23.         <form id="fm" method="post" style="padding:10px 20px 10px 40px;">  
  24.             <table border="0">  
  25.                 <input type="hidden"  id="moveid" name="moveid"  value=""  style="width: 250px;">  
  26.                 <tr style="height: 35px;">  
  27.                     <td>过帐日期:</td>  
  28.                     <td><input id="tb_postingdate" name="postingdate" style="width: 250px;" class="easyui-datebox" required="required"   
  29.                         value="<%=new SimpleDateFormat("yyyy-MM-dd").format(new Date())%>/>  
  30.                     </td>  
  31.                 </tr>  
  32.                 <tr  style="height: 35px;">  
  33.                     <td>移动类型:</td>  
  34.                     <td><input  id="tb_movement_code" name="movement_ode"  value=""  style="width: 250px;"></td>  
  35.                 </tr>  
  36.                 <tr  style="height: 35px;">  
  37.                     <td>来源库位:</td>  
  38.                     <td><input  id="tb_fromstoragelocation" name="fromstoragelocation"  value=""  style="width: 250px;"></td>  
  39.                 </tr>  
  40.                 <tr  style="height: 35px;">  
  41.                     <td>接收库位:</td>  
  42.                     <td><input  id="tb_tostoragelocation" name="tostoragelocation"  value=""  style="width: 250px;"></td>  
  43.                 </tr>  
  44.                 <tr  style="height: 35px;">  
  45.                     <td>商品编码:</td>  
  46.                     <td>  
  47.                         <input  id="tb_frommaterial" name="frommaterial" disabled="disabled" value="" style="width: 250px;">  
  48.                         <input type="hidden" id="tb_frommaterial_in" name="frommaterial_in" value="" />                         
  49.                     </td>  
  50.                     <td>    <a href="#" class="easyui-linkbutton" iconCls="" onclick="selecterpapply();">选择商品</a></td>  
  51.                 </tr>  
  52.                 <tr style="height: 35px;">  
  53.                     <td>商品批号:</td>  
  54.                     <td>  
  55.                         <input type="text" id="tb_frombatchnumber" name="frombatchnumber" disabled="disabled" value=""  style="width: 250px;">  
  56.                         <input type="hidden" id="tb_frombatchnumber_in" name="frombatchnumber_in" value="" />  
  57.                     </td>  
  58.                     <td>    <a href="#" class="easyui-linkbutton" id="frombatchnumberBtn" iconCls="" onclick="queryFrombatchnumber(1);">选择批号</a></td>  
  59.                 </tr>  
  60.                 <tr style="height: 35px;">  
  61.                     <td>数量:</td>  
  62.                     <td><input type="text" class="easyui-numberbox" id="tb_quantity" name="quantity"  value=""  maxlength="6" style="width: 250px;"></td>  
  63.                 </tr>  
  64.                 <tr style="height: 35px;">  
  65.                     <td>原因代码:</td>  
  66.                     <td><input  id="tb_reasoncode" name="reasoncode"  value=""  style="width: 250px;"></td>  
  67.                 </tr>  
  68.                 <tr style="height: 50px;">  
  69.                     <td colspan="3" align="center">  
  70.                         <a href="#" class="easyui-linkbutton" iconCls="" onclick="checkInputAdd();">保存</a>      
  71.                         <a href="#" class="easyui-linkbutton" iconCls="" onclick="javascript:$('#enditTab').dialog('close')">关闭</a>  
  72.                     </td>  
  73.                 </tr>  
  74.             </table>   
  75.         </form>    
  76.     </div>  
  77.     <div id="select_erp_win">  
  78.     品名/操作码:<input type="text" name="select_erp_name"  id="select_erp_name" value="">  
  79.     产地:<input type="text" name="select_erp_produce"  id="select_erp_produce" value="">  
  80.     <input type="hidden" name="select_relation_id" id="select_relation_id" value="">  
  81.     <input type="hidden" name="select_goods_id" id="select_goods_id" value="">  
  82.         <a id="queryselecterp" href="#" class="easyui-linkbutton"  onclick="queryselecterp();">查询</a>  
  83.              
  84.         <a id="saveselecterp" href="#" class="easyui-linkbutton"  onclick="saveselecterp();">保存</a>  
  85.         <table id="select_erp_tab" style="width: auto;height: 325px;"></table>  
  86.     </div>  
  87.     <div id="select_batchnumber_win">  
  88.     批号:<input type="text" name="link_goods_id"  id="link_goods_id" value="">  
  89.         <input type="hidden" id="com_goods_id" name="com_goods_id" value="">  
  90.         <a id="queryselectbatchnumber" href="#" class="easyui-linkbutton"  onclick="queryFrombatchnumber(2);">查询</a>  
  91.              
  92.         <a id="saveselectbatchnumber" href="#" class="easyui-linkbutton"  onclick="saveselectbatchnumber();">保存</a>  
  93.         <table id="select_batchnumber_tab" style="width: auto;height: 325px;"></table>  
  94.     </div>  
  95. </body>  


更改日期控件显示和分页标签的显示:
[javascript] view plain copy
  1. <script  language="javascript">  
  2.     if ($.fn.pagination){  
  3.         $.fn.pagination.defaults.beforePageText = '第';  
  4.         $.fn.pagination.defaults.afterPageText = '共{pages}页';  
  5.         $.fn.pagination.defaults.displayMsg = '显示{from}到{to},共{total}记录';  
  6.     }  
  7.     if ($.fn.datagrid){  
  8.         $.fn.datagrid.defaults.loadMsg = '正在处理,请稍待。。。';  
  9.     }  
  10.     if ($.fn.treegrid && $.fn.datagrid){  
  11.         $.fn.treegrid.defaults.loadMsg = $.fn.datagrid.defaults.loadMsg;  
  12.     }  
  13.     if ($.messager){  
  14.         $.messager.defaults.ok = '确定';  
  15.         $.messager.defaults.cancel = '取消';  
  16.     }  
  17.     if ($.fn.calendar){  
  18.         $.fn.calendar.defaults.weeks = ['日','一','二','三','四','五','六'];  
  19.         $.fn.calendar.defaults.months = ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'];  
  20.     }  
  21.     if ($.fn.datebox){  
  22.         $.fn.datebox.defaults.currentText = '今天';  
  23.         $.fn.datebox.defaults.closeText = '关闭';  
  24.         $.fn.datebox.defaults.okText = '确定';  
  25.         $.fn.datebox.defaults.missingMessage = '该输入项为必输项';  
  26.         $.fn.datebox.defaults.formatter = function(date){  
  27.             var y = date.getFullYear();  
  28.             var m = date.getMonth()+1;  
  29.             var d = date.getDate();  
  30.             return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);  
  31.         };  
  32.         $.fn.datebox.defaults.parser = function(s){  
  33.             if (!s) return new Date();  
  34.             var ss = s.split('-');  
  35.             var y = parseInt(ss[0],10);  
  36.             var m = parseInt(ss[1],10);  
  37.             var d = parseInt(ss[2],10);  
  38.             if (!isNaN(y) && !isNaN(m) && !isNaN(d)){  
  39.                 return new Date(y,m-1,d);  
  40.             } else {  
  41.                 return new Date();  
  42.             }  
  43.         };  
  44.     }  
  45.     if ($.fn.datetimebox && $.fn.datebox){  
  46.         $.extend($.fn.datetimebox.defaults,{  
  47.             currentText: $.fn.datebox.defaults.currentText,  
  48.             closeText: $.fn.datebox.defaults.closeText,  
  49.             okText: $.fn.datebox.defaults.okText,  
  50.             missingMessage: $.fn.datebox.defaults.missingMessage  
  51.         });  
  52.     }  
  53. </script>  


struts配置:
[html] view plain copy
  1. <action path="/goodsMovingTypeAction" scope="request" type="portal.sysweb.easyui.action.GoodsMovingTypeAction" validate="false">  
  2.           <forward name="" path="" />  
  3.         </action>  
  4.         <action path="/queryGoodsMovementAction" scope="request" type="portal.sysweb.easyui.action.QueryGoodsMovementAction" validate="false">  
  5.           <forward name="" path="" />  
  6.         </action>  
  7.         <action path="/getAllParameterAction" scope="request" type="portal.sysweb.easyui.action.GetAllParameterAction" validate="false">  
  8.           <forward name="" path="" />  
  9.         </action>  
  10.         <action path="/updateGoodStatusAction" scope="request" type="portal.sysweb.easyui.action.UpdateGoodStatusAction" validate="false">  
  11.           <forward name="" path="" />  
  12.         </action>  
  13.         <action path="/addGoodMovingAction" scope="request" type="portal.sysweb.easyui.action.AddGoodMovingAction" validate="false">  
  14.           <forward name="" path="" />  
  15.         </action>  
  16.         <action path="/queryerpgoodsAction" scope="request" type="portal.sysweb.easyui.action.QueryerpgoodsAction" validate="false">  
  17.           <forward name="" path="" />  
  18.         </action>  
  19.         <action path="/queryerpGoodsBatchNumberAction" scope="request" type="portal.sysweb.easyui.action.QueryerpGoodsBatchNumberAction" validate="false">  
  20.           <forward name="" path="" />  
  21.         </action>  

action代码:
[java] view plain copy
  1. public class QueryGoodsMovementAction extends Action {  
  2.     @Override  
  3.     public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)  
  4.             throws Exception {  
  5.         request.setCharacterEncoding("utf-8");  
  6.         String startDate = request.getParameter("startDate");  
  7.         String endDate = request.getParameter("endDate");  
  8.         String movingCode = request.getParameter("movingCode");  
  9.         int page = Integer.parseInt(request.getParameter("page"));  
  10.         int rows = Integer.parseInt(request.getParameter("rows"));  
  11.         QueryEasyuiDao dao = new QueryEasyuiDao();  
  12.         Pagination pagination = dao.queryGoodsMovementList(page,rows,startDate, endDate, movingCode);  
  13.         JSONObject json = new JSONObject();  
  14.         json.put("total", pagination.getMaxElements());  
  15.         json.put("rows", pagination.getPaginationList());  
  16.         json = JSONObject.fromObject(json);  
  17.         response.setCharacterEncoding("GBK");  
  18.         response.getWriter().write(json.toString());  
  19.         response.getWriter().flush();  
  20.         response.getWriter().close();  
  21.         return null;  
  22.     }  
  23. }  

[java] view plain copy
  1. public class GetAllParameterAction extends Action {  
  2.     @Override  
  3.     public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)  
  4.             throws Exception {  
  5.         ActionForm_UserInfo userinfo = (ActionForm_UserInfo) request.getSession().getAttribute("UserInfo");  
  6.         String type = request.getParameter("type");  
  7.         QueryEasyuiDao dao = new QueryEasyuiDao();  
  8.         List<Hashtable> resList = null;  
  9.         Hashtable tab = new Hashtable();  
  10.         if(type.equals("fromstor")){  
  11.             resList = dao.getFromstorType();  
  12.             tab.put("freight_code"0);  
  13.             tab.put("freight_info""----请选择来源库位----");  
  14.         }  
  15.         if(type.equals("tostorage")){  
  16.             resList = dao.getFromstorType();  
  17.             tab.put("freight_code"0);  
  18.             tab.put("freight_info""----请选择接收库位----");  
  19.         }  
  20.         if(type.equals("reason")){  
  21.             String movement_types = request.getParameter("movement_types");  
  22.             //if(movement_types!=null&&!(movement_types.equals(""))){                 
  23.                 resList = dao.getReasonType(movement_types);  
  24.             //}  
  25.             tab.put("reason_code"0);  
  26.             tab.put("reason_name""----请选择原因代码----");  
  27.         }  
  28.         resList.add(0,tab);  
  29.         JSONArray arr = JSONArray.fromObject(resList);  
  30.         response.setCharacterEncoding("GBK");  
  31.         response.getWriter().write(arr.toString());  
  32.         response.getWriter().flush();  
  33.         response.getWriter().close();  
  34.         return null;  
  35.     }  
  36.   
  37. }  

[java] view plain copy
  1. public class GoodsMovingTypeAction extends Action {  
  2.     @Override  
  3.     public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)  
  4.             throws Exception {  
  5.         ActionForm_UserInfo userinfo = (ActionForm_UserInfo) request.getSession().getAttribute("UserInfo");  
  6.         String type = request.getParameter("type");  
  7.         QueryEasyuiDao dao = new QueryEasyuiDao();  
  8.         List<Hashtable> resList = dao.getMovingType();  
  9.         Hashtable tab = new Hashtable();  
  10.         if(type.equals("query")){  
  11.             tab.put("movement_types"0);  
  12.             tab.put("summary""----全部类型----");  
  13.         }  
  14.         if(type.equals("add")){  
  15.             tab.put("movement_types"0);  
  16.             tab.put("summary""----请选择移动类型----");  
  17.         }  
  18.         resList.add(0,tab);  
  19.         JSONArray arr = JSONArray.fromObject(resList);  
  20.         response.setCharacterEncoding("GBK");  
  21.         response.getWriter().write(arr.toString());  
  22.         response.getWriter().flush();  
  23.         response.getWriter().close();  
  24.         return null;  
  25.     }  
  26.   
  27. }  

[java] view plain copy
  1. public class UpdateGoodStatusAction extends Action {  
  2.     @Override  
  3.     public ActionForward execute(ActionMapping mapping, ActionForm form,HttpServletRequest request, HttpServletResponse response)  
  4.             throws Exception {  
  5.         ActionForm_UserInfo userinfo = (ActionForm_UserInfo) request.getSession().getAttribute("UserInfo");  
  6.         String type = request.getParameter("type");  
  7.         String flag = "";  
  8.         QueryEasyuiDao dao = new QueryEasyuiDao();  
  9.         if(type.equals("del")){  
  10.             String moveid = request.getParameter("moveid");  
  11.             String del_flag = request.getParameter("del_flag");  
  12.             flag = dao.updateGoodDelStatusById(moveid, del_flag);  
  13.         }  
  14.         if(type.equals("exec")){  
  15.             String moveids = request.getParameter("moveids");  
  16.             flag = dao.updateGoodExecStatusById(moveids);  
  17.         }  
  18.         response.setCharacterEncoding("GBK");  
  19.         response.getWriter().write(flag);  
  20.         response.getWriter().flush();  
  21.         response.getWriter().close();  
  22.         return null;  
  23.     }  
  24.   
  25. }  

Dao:
[java] view plain copy
  1. public List<Hashtable> getMovingType(){  
  2.         List<Hashtable> resList = new ArrayList<Hashtable>();  
  3.         String  sql = "select mt.movement_types,(mt.movement_types||to_char('  ')||mt.summary||to_char('  ')||mt.description) as summary from gsk_v2_goodsmoving_types mt";  
  4.         DataManage db;  
  5.         try {  
  6.             db = new DataManage();  
  7.             resList = db.executeQuerys(sql);  
  8.         } catch (SystemException e) {  
  9.             e.printStackTrace();  
  10.         } catch (NamingException e) {  
  11.             e.printStackTrace();  
  12.         } catch (SQLException e) {  
  13.             e.printStackTrace();  
  14.         }         
  15.         return resList;  
  16.     }  
  17.       
  18.     public List<Hashtable> getFromstorType(){  
  19.         List<Hashtable> resList = new ArrayList<Hashtable>();  
  20.         String  sql = "select fp.freight_code,fp.freight_code||to_char('  ')||fp.freight_name||to_char('  ')||fp.freight_description freight_info from gsk_v2_freight_position fp";  
  21.         DataManage db;  
  22.         try {  
  23.             db = new DataManage();  
  24.             resList = db.executeQuerys(sql);  
  25.         } catch (SystemException e) {  
  26.             e.printStackTrace();  
  27.         } catch (NamingException e) {  
  28.             e.printStackTrace();  
  29.         } catch (SQLException e) {  
  30.             e.printStackTrace();  
  31.         }         
  32.         return resList;  
  33.     }  
  34.       
  35.     public List<Hashtable> getReasonType(String movement_types){  
  36.         List<Hashtable> resList = new ArrayList<Hashtable>();  
  37.         String  sql = "select gr.reason_code reason_code,(gr.reason_code||to_char('  ')||gr.reason_name) reason_name "  
  38.                 + "from gsk_v2_goodsmoving_reasoncode gr where gr.reason_code in("  
  39.                 + "select gref.reason_code from gsk_v2_gv_types_rc_ref gref "  
  40.                 + "where gref.movement_types='"+movement_types+"')";  
  41.         //System.out.println("getReasonTypeSQL:"+sql);  
  42.         DataManage db;  
  43.         try {  
  44.             db = new DataManage();  
  45.             resList = db.executeQuerys(sql);  
  46.         } catch (SystemException e) {  
  47.             e.printStackTrace();  
  48.         } catch (NamingException e) {  
  49.             e.printStackTrace();  
  50.         } catch (SQLException e) {  
  51.             e.printStackTrace();  
  52.         }         
  53.         return resList;  
  54.     }  
  55.       
  56.     public String updateGoodDelStatusById(String moveid ,String del_flag){  
  57.         String value = del_flag.equals("0")?"1":"0";  
  58.         String sql = "update gsk_v2_goodsmoving gm";  
  59.         sql += " set gm.del_flag="+value;  
  60.         sql += " where gm.moveid="+moveid;  
  61.         try {  
  62.             DataManage db = new DataManage();  
  63.             //System.out.println("updateGoodStatusById:"+sql);  
  64.             db.exeUpdate(sql);  
  65.             return "true";  
  66.         } catch (Exception ex) {  
  67.             ex.printStackTrace();  
  68.         }  
  69.         return "false";  
  70.     }  
  71.       
  72.     public String updateGoodExecStatusById(String moveids){  
  73.         String sql = "update gsk_v2_goodsmoving gm set gm.exec_flag=0";  
  74.         sql += " where gm.moveid in("+moveids+")";  
  75.         try {  
  76.             DataManage db = new DataManage();  
  77.             //System.out.println("updateGoodExecStatusById:"+sql);  
  78.             db.exeUpdate(sql);  
  79.             return "true";  
  80.         } catch (Exception ex) {  
  81.             ex.printStackTrace();  
  82.         }  
  83.         return "false";  
  84.     }  
  85.       
  86.     public String updateGoodMovingById(String moveid,String postingdate,String movementcode,String fromstoragelocatione,String tostoragelocatione,  
  87.             String frommaterial,String frombatchnumbere,String quantity,String reasoncode){  
  88.         String sql = "update gsk_v2_goodsmoving gm set gm.postingdate='"+postingdate  
  89.                 + "',gm.movementcode='"+movementcode  
  90.                 + "',gm.fromstoragelocation='"+fromstoragelocatione  
  91.                 + "',gm.tostoragelocation='"+tostoragelocatione  
  92.                 + "',gm.frommaterial='"+frommaterial  
  93.                 + "',gm.frombatchnumber='"+frombatchnumbere  
  94.                 + "',gm.tomaterial='"+frommaterial  
  95.                 + "',gm.tobatchnumber='"+frombatchnumbere  
  96.                 + "',gm.quantity="+quantity  
  97.                 + ",gm.reasoncode="+reasoncode;  
  98.         sql += " where gm.moveid="+moveid;  
  99.         try {  
  100.             DataManage db = new DataManage();  
  101.             System.out.println("updateGoodMovingById:"+sql);  
  102.             int n = db.exeUpdate(sql);  
  103.             return n>=1?"true":"false";  
  104.         } catch (Exception ex) {  
  105.             ex.printStackTrace();  
  106.         }  
  107.         return "false";  
  108.     }  
  109.       
  110.     public String addGoods(String postingdate,String movementcode,String fromstoragelocatione,String tostoragelocatione,  
  111.             String frommaterial,String frombatchnumbere,String quantity,String reasoncode){  
  112.         String sql = "insert into gsk_v2_goodsmoving"  
  113.                 + "(moveid,postingdate,transferreno,frommaterial,fromstoragelocation,frombatchnumber,"  
  114.                 + "movementcode,quantity,tomaterial,tostoragelocation,tobatchnumber,reasoncode,documentdatetime) "  
  115.                 + "values(seq_gsk_goodsmoving.nextval,'"+postingdate+"',to_char(sysdate,'yyyymmdd')||to_char(seq_gsk_goodsmoving_num.nextval),"  
  116.                 + "'"+frommaterial+"','"+fromstoragelocatione+"','"+frombatchnumbere+"','"+movementcode+"',"  
  117.                 + "'"+quantity+"','"+frommaterial+"','"+tostoragelocatione+"','"+frombatchnumbere+"','"+reasoncode+"',to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'))";  
  118.         try {  
  119.             DataManage db = new DataManage();  
  120.             //System.out.println("addGoods:"+sql);  
  121.             int n = db.exeUpdate(sql);  
  122.             return n>=1?"true":"false";  
  123.         } catch (Exception ex) {  
  124.             ex.printStackTrace();  
  125.         }  
  126.         return "false";  
  127.     }  
  128.       
  129.     public Pagination queryGoodsMovementList( int pageNumber,int pageSize,String startDate,String endDate, String movingCode){        
  130.         //List<Hashtable<String, String>> resList = new ArrayList<Hashtable<String,String>>();  
  131.          String sql = "select gm.moveid,gm.postingdate,gm.transferreno,gm.movementcode,"  
  132.                 + "(gm.movementcode||to_char('/')||gmt.summary||to_char('/')||gmt.description) as movementcodename ,"  
  133.                 + "gm.fromstoragelocation,gm.tostoragelocation,gm.frommaterial, gm.frombatchnumber,"  
  134.                 + "gm.quantity,gm.reasoncode,(gm.reasoncode||to_char('/')||gmr.reason_name) as reasoncodename,gm.documentdatetime,"  
  135.                 + "gm.exec_flag,gm.del_flag from gsk_v2_goodsmoving gm left join gsk_v2_goodsmoving_types gmt "  
  136.                 + "on gm.movementcode = gmt.movement_types left join gsk_v2_goodsmoving_reasoncode gmr "  
  137.                 + "on gm.reasoncode = gmr.reason_code where 1=1";  
  138.          if(startDate!=null&&!(startDate.equals(""))){  
  139.              sql += " and gm.indate >= to_date('"+startDate+" 00:00:00','yyyy-mm-dd hh24:mi:ss')";  
  140.          }  
  141.          if(endDate!=null&&!(endDate.equals(""))){  
  142.              sql += " and gm.indate <= to_date('"+endDate+" 23:59:29','yyyy-mm-dd hh24:mi:ss')";  
  143.          }  
  144.          if(movingCode!=null&&!(movingCode.equals(""))){  
  145.              sql += " and gm.movementcode = '" + movingCode + "' ";            
  146.          }  
  147.          sql += " order by gm.moveid desc";  
  148.          /*sql += " and a.create_date between " + 
  149.             "  to_date('" + startDate + 
  150.             " 00:00:00', 'yyyy-mm-dd hh24:mi:ss') and " + 
  151.             "  to_date('" + endDate + 
  152.             " 23:59:59', 'yyyy-mm-dd hh24:mi:ss')";*/  
  153.          //System.out.println("queryGoodsMovementList---"+sql);  
  154.          Pagination page = new OraclePagination(sql,pageSize,pageNumber);  
  155.          return page;  
  156.          /*try { 
  157.             DataManage db = new DataManage(); 
  158.             resList = db.executeQuerys(sql); 
  159.         } catch (SystemException e) { 
  160.             e.printStackTrace(); 
  161.         } catch (NamingException e) { 
  162.             e.printStackTrace(); 
  163.         } catch (SQLException e) { 
  164.             e.printStackTrace(); 
  165.         } 
  166.         return resList;*/  
  167.     }  
  168.       
  169.     /** 
  170.      * 查询ERP商品信息 
  171.      */  
  172.     public Pagination queryErpGoods(int pagemun,int pagesize,String erp_name,String erp_produce,String companyId){  
  173.         //String dbl = basicDao.getApplyDBlink(companyId);  
  174.         String sql = " select com_goods_id,goods_name,goods_desc,product_location,unit_name,goods_opcode,  ";  
  175.         sql += " package_num from temp_com_goods where 1=1 ";         
  176.         if(erp_name!=null&&!(erp_name.equals(""))){  
  177.             sql += " and  (goods_name like '%"+erp_name+"%' or goods_opcode like  ";  
  178.             sql += " '%"+erp_name+"%' or upper(goods_spell) like '%"+erp_name.toUpperCase()+"%' ) ";  
  179.         }  
  180.         if(erp_produce!=null&&!(erp_produce.equals(""))){  
  181.             sql += " and product_location like '%"+erp_produce+"%' ";  
  182.         }  
  183.         //System.out.println("queryErpGoodsSQL:"+sql);  
  184.         Pagination page = new OraclePagination(sql,pagesize,pagemun);  
  185.         return page;  
  186.     }  


其它:
分页接口:
[java] view plain copy
  1. public interface Pagination {  
  2.     public boolean isFirst();  
  3.     public boolean isLast();  
  4.     public boolean hasNext();  
  5.     public boolean hasPrevious();  
  6.     public int getMaxElements();  
  7.     public int getMaxPages();  
  8.     public int getNext();  
  9.     public int getPrevious();  
  10.     public int getPageSize();  
  11.     public int getPageNumber();  
  12.     public List getPaginationList();  
  13.     public String getToolBar(String url);  
  14.     public String getToolBar(String url,String formName);  
  15.     public String getToolBar(String url,String formName,boolean isIE);  
  16.     public void setPageSize(int pageSize);  
  17.     public void setPageNumber(int pageNumber);  
  18.   
  19. }  



0 0
原创粉丝点击