SSH-BOS项目:工作单快速录入

WorkordermanageAction:

package com.xushuai.bos.web.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.xushuai.bos.entity.Workordermanage;
import com.xushuai.bos.service.WorkordermanageService;
import com.xushuai.bos.utils.BOSUtils;

@Controller("workordermanageAction")
@Scope("prototype")
public class WorkordermanageAction extends BaseAction<Workordermanage> {
	
	@Autowired
	@Qualifier("workordermanageService")
	private WorkordermanageService workordermanageService;
	public void setWorkordermanageService(WorkordermanageService workordermanageService) {
		this.workordermanageService = workordermanageService;
	}
	
	/**
	 * 新增工作单
	 * @return
	 * @throws IOException 
	 */
	public String add() throws IOException{
		String flag = "1";
		try {
			//调用service#save(model)
			workordermanageService.save(model);			
		} catch (Exception e) {
			e.printStackTrace();
			flag = "0";
		}
		HttpServletResponse response = BOSUtils.getResponse();
		response.setContentType("text/html;charset=utf-8");
		response.getWriter().print(flag);
		
		return NONE;
	}
	
	/**
	 * 分页查询工作单信息
	 * @return
	 */
	public String pageQuery(){
		//调用service#pageQuery(PageBean pageBean);
		workordermanageService.pageQuery(pageBean);
		BOSUtils.writerJson(pageBean, new String[]{"currentPage","pageSize","criteria"});
		
		return NONE;
	}
	
	/**
	 * 删除指定工作单
	 * @return
	 */
	public String delete(){
		//调用service#delete(id)
		workordermanageService.delete(model.getId());
		
		return NONE;
	}
}

WorkordermanageService、WorkordermanageServiceImpl:

package com.xushuai.bos.service;

import com.xushuai.bos.entity.Workordermanage;
import com.xushuai.bos.utils.PageBean;

public interface WorkordermanageService {

	/**
	 * 新增工作单
	 * @param model
	 */
	void save(Workordermanage model);

	/**
	 * 分页查询工作单信息
	 * @return
	 */
	void pageQuery(PageBean pageBean);

	/**
	 * 删除指定工作单
	 * @param id
	 */
	void delete(String id);

}
package com.xushuai.bos.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xushuai.bos.dao.WorkordermanageDao;
import com.xushuai.bos.entity.Workordermanage;
import com.xushuai.bos.service.WorkordermanageService;
import com.xushuai.bos.utils.PageBean;

@Service("workordermanageService")
@Transactional
public class WorkordermanageServiceImpl implements WorkordermanageService {
	
	@Autowired
	@Qualifier("workordermanageDao")
	private WorkordermanageDao workordermanageDao;
	public void setWorkordermanageDao(WorkordermanageDao workordermanageDao) {
		this.workordermanageDao = workordermanageDao;
	}



	@Override
	public void save(Workordermanage model) {
		//调用的dao保存数据
		workordermanageDao.save(model);
	}



	@Override
	public void pageQuery(PageBean pageBean) {
		workordermanageDao.findByPage(pageBean);
	}



	@Override
	public void delete(String id) {
		//按照ID查询对象
		Workordermanage _workordermanage = workordermanageDao.findById(id);
		//删除之
		workordermanageDao.delete(_workordermanage);
	}

}

Struts.xml(新增action配置):

		<!-- 工作单模块 -->
		<action name="WorkordermanageAction_*" class="workordermanageAction" method="{1}">
			
		</action>

页面:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>工作单快速录入</title>
<!-- 导入jquery核心类库 -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- 导入easyui类库 -->
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/js/easyui/ext/portal.css">
<link rel="stylesheet" type="text/css"
	href="${pageContext.request.contextPath }/css/default.css">	
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.portal.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/easyui/ext/jquery.cookie.js"></script>
<script
	src="${pageContext.request.contextPath }/js/easyui/locale/easyui-lang-zh_CN.js"
	type="text/javascript"></script>
<script type="text/javascript">
	var editIndex ;
	
	function doAdd(){
		if(editIndex != undefined){
			$("#grid").datagrid('endEdit',editIndex);
		}
		if(editIndex==undefined){
			//alert("快速添加电子单...");
			$("#grid").datagrid('insertRow',{
				index : 0,
				row : {}
			});
			$("#grid").datagrid('beginEdit',0);
			editIndex = 0;
		}
	}
	
	function doSave(){
		$("#grid").datagrid('endEdit',editIndex );
	}
	
	function doEdit(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 0){
			$.messager.alert('提示信息','请选择要修改的行','warning');  
		}else{
			editIndex = $("#grid").datagrid('getRowIndex',rows[0]);
			$("#grid").datagrid('beginEdit',editIndex);
		}
	}
	
	function doDelete(){
		var rows = $("#grid").datagrid('getSelections');
		if(rows.length == 0){
			$.messager.alert('提示信息','请选择要删除的行','warning');  
		}else{
			
			$.messager.confirm('提示信息', '确定要删除该工作单吗?', function(r){
				if (r){
					editIndex = $("#grid").datagrid('getRowIndex',rows[0]);
					$.post('WorkordermanageAction_delete.action',{'id':rows[0].id});
					$("#grid").datagrid('deleteRow',editIndex);
					editIndex = undefined;
				} 
			});
		}
	}
	
	function doCancel(){
		if(editIndex!=undefined){
			$("#grid").datagrid('cancelEdit',editIndex);
			if($('#grid').datagrid('getRows')[editIndex].id == undefined){
				$("#grid").datagrid('deleteRow',editIndex);
			}
			editIndex = undefined;
		}
	}
	
	//工具栏
	var toolbar = [ {
		id : 'button-add',	
		text : '新增一行',
		iconCls : 'icon-edit',
		handler : doAdd
	}, {
		id : 'button-cancel',
		text : '取消编辑',
		iconCls : 'icon-cancel',
		handler : doCancel
	}, {
		id : 'button-edit',
		text : '修改',
		iconCls : 'icon-edit',
		handler : doEdit
	}, {
		id : 'button-delete',
		text : '删除',
		iconCls : 'icon-cancel',
		handler : doDelete
	}, {
		id : 'button-save',
		text : '保存',
		iconCls : 'icon-save',
		handler : doSave
	}];
	// 定义列
	var columns = [ [ {
		field : 'id',
		title : '工作单号',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
				
			}
		}
	}, {
		field : 'arrivecity',
		title : '到达地',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	},{
		field : 'product',
		title : '产品',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}, {
		field : 'num',
		title : '件数',
		width : 120,
		align : 'center',
		editor :{
			type : 'numberbox',
			options : {
				required: true
			}
		}
	}, {
		field : 'weight',
		title : '重量',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}, {
		field : 'floadreqr',
		title : '配载要求',
		width : 220,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}] ];
	
	$(function(){
		// 先将body隐藏,再显示,不会出现页面刷新效果
		$("body").css({visibility:"visible"});
		
		// 收派标准数据表格
		$('#grid').datagrid( {
			iconCls : 'icon-forward',
			fit : true,
			border : true,
			rownumbers : true,
			striped : true,
			singleSelect:true,
			pageList: [15,20,28],
			pageSize:28,
			pagination : true,
			toolbar : toolbar,
			url :  "WorkordermanageAction_pageQuery.action",
			idField : 'id',
			columns : columns,
			onDblClickRow : doDblClickRow,
			onAfterEdit : function(rowIndex, rowData, changes){
				//console.info(rowData);
				$.post('WorkordermanageAction_add.action',rowData,function(data){
					//判断服务器数据是否成功添加
					if(data == '0'){//说明数据录入失败
						$.messager.alert('提示信息','数据录入失败!','error');
						//删除录入失败的数据
						$("#grid").datagrid('deleteRow',rowIndex);
					}
				});
				editIndex = undefined;
			}
		});
	});

	function doDblClickRow(rowIndex, rowData){
		alert("双击表格数据...");
		console.info(rowIndex);
		$('#grid').datagrid('beginEdit',rowIndex);
		editIndex = rowIndex;
	}
</script>
</head>
<body class="easyui-layout" style="visibility:hidden;">
	<div region="center" border="false">
    	<table id="grid"></table>
	</div>
</body>
</html>



阅读更多
博主设置当前文章不允许评论。

没有更多推荐了,返回首页