1、今日完成任务:
(1)完成业务管理-派车单登记模块的代码书写及测试工作
2、核心源码:
package com.dw.controller;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.dw.entity.Dispatch;
import com.dw.service.DispatchService;
@Controller
public class DispatchController {
@Autowired
private DispatchService ds;
@RequestMapping("/queryAllDispatch")
@ResponseBody
public List<Dispatch> queryAllDispatch(Integer status,Integer carid,String year,String month,Integer companyid,Integer driverid,Integer clerkid,String startdate,String enddate){
try {
List<Dispatch> list = ds.queryAll(status,carid,year,month,companyid,driverid,clerkid,startdate,enddate);
return list;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
@RequestMapping("/saveDispatch")
@ResponseBody
public void saveDispatch(Dispatch dispatch){
try {
ds.save(dispatch);
} catch (Exception e) {
e.printStackTrace();
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>派车单登记</title>
<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/default/easyui.css"/>
<link rel="stylesheet" type="text/css" href="../../js/easyui/themes/icon.css"/>
<link rel="stylesheet" type="text/css" href="../../js/easyui/ext/portal.css"/>
<link rel="stylesheet" type="text/css" href="../../css/default.css"/>
<script src="../../js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/ext/jquery.portal.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/easyui/locale/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(function(){
$('#dg').datagrid({
toolbar: [{
id: 'add',
text:'登记',
iconCls: 'icon-add',
handler: function(){
$("#win").window('open');
$("#ff").form('reset');
}
}]
});
$("#save").click(function(){
if($("#ff").form('validate')){
$("#ff").form('submit',{
success:function(data){
$("#win").window('close');
$("#dg").datagrid('reload');
}
});
}else{
$.messager.alert('警告','表单中包含非法数据!','warning');
}
});
$("#cc").combobox({
onSelect: function(rec){
$("#name").val(rec.name);
$("#phone").val(rec.phone);
}
});
})
</script>
</head>
<body>
<table id="dg" class="easyui-datagrid"
data-options="url:'../../queryAllDispatch',fitColumns:true,rownumbers:true">
<thead>
<tr>
<th data-options="field:'id',width:70,align:'center'">派车单号</th>
<th data-options="field:'registdate',width:100,align:'center'">登记日期</th>
<th data-options="field:'car.carnumber',width:80,align:'center',formatter: function(value,row,index){return row.car.carnumber;}">车牌号码</th>
<th data-options="field:'senddate',width:100,align:'center'">出车日期</th>
<th data-options="field:'sendtime',width:70,align:'center'">出车时间</th>
<th data-options="field:'category',width:70,align:'center'">所属类别</th>
<th data-options="field:'start',width:120,align:'center'">起始地点</th>
<th data-options="field:'customer.company',width:100,align:'center',formatter: function(value,row,index){return row.customer.company;}">用车单位</th>
<th data-options="field:'customer.name',width:70,align:'center',formatter: function(value,row,index){return row.customer.name;}">联系人</th>
<th data-options="field:'customer.phone',width:100,align:'center',formatter: function(value,row,index){return row.customer.phone;}">联系电话</th>
<th data-options="field:'clerk.name',width:70,align:'center',formatter: function(value,row,index){return row.clerk.name;}">业务员</th>
<th data-options="field:'driver.name',width:70,align:'center',formatter: function(value,row,index){return row.driver.name;}">驾驶员</th>
<th data-options="field:'rentmoney',width:70,align:'center'">租车费</th>
<th data-options="field:'discount',width:70,align:'center'">折扣金额</th>
<th data-options="field:'realmoney',width:70,align:'center'">实际金额</th>
<th data-options="field:'paytype',width:70,align:'center'">支付方式</th>
<th data-options="field:'remark',width:70,align:'center'">备注</th>
<th data-options="field:'status',width:90,align:'center',formatter: function(value,row,index){if(value==-1){return '未审核未收款';}else if(value==0){return '已审核未收款';}else{return '已审核已收款';}}">状态</th>
</tr>
</thead>
</table>
<div id="win" class="easyui-window" title="派车单登记" style="width:750px;height:450px;"
data-options="modal:true,minimizable:false,maximizable:false,closed:true">
<div class="datagrid-toolbar">
<a id="save" href="#" class="easyui-linkbutton" icon="icon-save">保存</a>
</div>
<form id="ff" method="post" action="../../saveDispatch">
<table class="table-edit" align="center" width="80%">
<tr class="title">
<td colspan="4">派车单登记</td>
</tr>
<tr>
<td>派车单号:</td>
<td><input class="easyui-validatebox" type="text" name="id" data-options="required:true" /></td>
<td>登记日期:</td>
<td><input class="easyui-datebox" type="text" name="registdate" data-options="required:true" /></td>
</tr>
<tr>
<td>业务员:</td>
<td>
<input class="easyui-combobox" name="clerk.id" style="width:174px;" data-options="required:true,valueField:'id',textField:'name',url:'../../queryAllClerk'" />
</td>
<td>用车单位:</td>
<td><input id="cc" class="easyui-combobox" name="customer.id" style="width:174px;" data-options="required:true,valueField:'id',textField:'company',url:'../../queryAllCustomer'" /></td>
</tr>
<tr>
<td>联系人:</td>
<td><input id="name" class="easyui-textbox" type="text" readonly="readonly" /></td>
<td>联系电话:</td>
<td><input id="phone" class="easyui-textbox" type="text" readonly="readonly" /></td>
</tr>
<tr>
<td>出车日期:</td>
<td><input class="easyui-datebox" type="text" name="senddate" data-options="required:true" /></td>
<td>出车时间:</td>
<td><input class="easyui-timespinner" type="text" style="width:174px;" name="sendtime" data-options="required:true" /></td>
</tr>
<tr>
<td>支付方式:</td>
<td>
<select class="easyui-combobox" name="paytype" style="width:174px;" data-options="required:true">
<option value="现金">现金</option>
<option value="刷卡">刷卡</option>
<option value="微信">微信</option>
<option value="支付宝">支付宝</option>
</select>
</td>
<td>所属类别:</td>
<td>
<select class="easyui-combobox" name="category" style="width:174px;" data-options="required:true">
<option value="包车">包车</option>
<option value="商用">商用</option>
<option value="旅游">旅游</option>
<option value="自驾">自驾</option>
</select>
</td>
</tr>
<tr>
<td>起始地点:</td>
<td><input class="easyui-validatebox" type="text" name="start" data-options="required:true" /></td>
<td>车牌号码:</td>
<td><input class="easyui-combobox" name="car.id" style="width:174px;" data-options="required:true,valueField:'id',textField:'carnumber',url:'../../queryAllCar'" /></td>
</tr>
<tr>
<td>驾驶员:</td>
<td><input class="easyui-combobox" name="driver.id" style="width:174px;" data-options="required:true,valueField:'id',textField:'name',url:'../../queryAllDriver'" /></td>
<td>租车费:</td>
<td><input class="easyui-validatebox" type="text" name="rentmoney" data-options="required:true" /></td>
</tr>
<tr>
<td>折扣金额:</td>
<td><input class="easyui-validatebox" type="text" name="discount" data-options="required:true" /></td>
<td>实际金额:</td>
<td><input class="easyui-validatebox" type="text" name="realmoney" data-options="required:true" /></td>
</tr>
<tr>
<td>备注:</td>
<td><input class="easyui-validatebox" type="text" name="remark" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
3、遇到的问题:
(1)使用easyui的datagrid显示对象的属性时出错
4、解决的方法:
(1)使用datagrid表格列属性的formatter方法进行格式化
<th data-options="field:'customer.company',width:100,align:'center',formatter: function(value,row,index){return row.customer.company;}">用车单位</th>
<th data-options="field:'customer.name',width:70,align:'center',formatter: function(value,row,index){return row.customer.name;}">联系人</th>
<th data-options="field:'customer.phone',width:100,align:'center',formatter: function(value,row,index){return row.customer.phone;}">联系电话</th>
<th data-options="field:'clerk.name',width:70,align:'center',formatter: function(value,row,index){return row.clerk.name;}">业务员</th>
<th data-options="field:'driver.name',width:70,align:'center',formatter: function(value,row,index){return row.driver.name;}">驾驶员</th>
5、项目燃尽图更新: