SSH-BOS Project: Quick Entry of Work Orders

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;
	}
	
	/**
	 * Add work order
	 * @return
	 * @throws IOException
	 */
	public String add() throws IOException{
		String flag = "1";
		try {
			//Call 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;
	}
	
	/**
	 * Paging query work order information
	 * @return
	 */
	public String pageQuery(){
		//调用service#pageQuery(PageBean pageBean);
		workordermanageService.pageQuery(pageBean);
		BOSUtils.writerJson(pageBean, new String[]{"currentPage","pageSize","criteria"});
		
		return NONE;
	}
	
	/**
	 * Delete the specified work order
	 * @return
	 */
	public String delete(){
		//call 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 {

	/**
	 * Add work order
	 * @param model
	 */
	void save(Workordermanage model);

	/**
	 * Paging query work order information
	 * @return
	 */
	void pageQuery(PageBean pageBean);

	/**
	 * Delete the specified work order
	 * @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) {
		//The called dao saves the data
		workordermanageDao.save(model);
	}



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



	@Override
	public void delete(String id) {
		// query object by ID
		Workordermanage _workordermanage = workordermanageDao.findById(id);
		// delete it
		workordermanageDao.delete(_workordermanage);
	}

}

Struts.xml (new action configuration):

		<!-- Work Order Module -->
		<action name="WorkordermanageAction_*" class="workordermanageAction" method="{1}">
			
		</action>

page:

<%@ 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>Work order quick entry</title>
<!-- Import jquery core class library -->
<script type="text/javascript"
	src="${pageContext.request.contextPath }/js/jquery-1.8.3.js"></script>
<!-- Import easyui class library -->
<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("Quickly add electronic order...");
			$("#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('Prompt information','Please select the line to be modified','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('Prompt information','Please select the line to delete','warning');  
		}else{
			
			$.messager.confirm('Prompt message', 'Are you sure you want to delete the work order?', 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;
		}
	}
	
	//toolbar
	var toolbar = [
		id : 'button-add',	
		text : 'Add a new line',
		iconCls : 'icon-edit',
		handler: doAdd
	}, {
		id : 'button-cancel',
		text : 'Cancel editing',
		iconCls : 'icon-cancel',
		handler: doCancel
	}, {
		id : 'button-edit',
		text : 'Modify',
		iconCls : 'icon-edit',
		handler: doEdit
	}, {
		id : 'button-delete',
		text : 'delete',
		iconCls : 'icon-cancel',
		handler: doDelete
	}, {
		id : 'button-save',
		text : 'Save',
		iconCls : 'icon-save',
		handler: doSave
	}];
	// define columns
	var columns = [[{
		field : 'id',
		title : 'Work order number',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
				
			}
		}
	}, {
		field : 'arrivecity',
		title : 'Arrival',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	},{
		field : 'product',
		title : 'Product',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}, {
		field : 'num',
		title:'Number',
		width : 120,
		align : 'center',
		editor :{
			type : 'numberbox',
			options : {
				required: true
			}
		}
	}, {
		field : 'weight',
		title : 'weight',
		width : 120,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}, {
		field : 'floadreqr',
		title : 'Stowage requirements',
		width : 220,
		align : 'center',
		editor :{
			type : 'validatebox',
			options : {
				required: true
			}
		}
	}] ];
	
	$(function(){
		// Hide the body first, then display it, there will be no page refresh effect
		$("body").css({visibility:"visible"});
		
		// Receipt and dispatch standard data table
		$('#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){
					/ / Determine whether the server data is successfully added
					if(data == '0'){//Indicates data entry failed
						$.messager.alert('Prompt message','Data entry failed!','error');
						//delete the failed data entry
						$("#grid").datagrid('deleteRow',rowIndex);
					}
				});
				editIndex = undefined;
			}
		});
	});

	function doDblClickRow(rowIndex, rowData){
		alert("Double click table data...");
		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>



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325920308&siteId=291194637