最近做了个jqGrid的例子,Tony的例子都是基于php的,就试着做了个基于java的。
首先贴出页面的jsp代码, jqGrid表格显示代码沿用的是Tony的代码,基本未改。
filename=index.jsp
----------------------
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<% String path = request.getContextPath();%>
<html>
<head>
<title>jqgrid demo in Struts2</title>
<link rel="stylesheet" type="text/css" media="screen" href="themes/redmond/jquery-ui-1.7.1.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="themes/jquery.searchFilter.css" />
<style>
html, body {
margin: 0; /* Remove body margin/padding */
padding: 0;
overflow: hidden; /* Remove scroll bars on browser window */
font-size: 75%;
}
.ui-tabs-nav li {position: relative;}
.ui-tabs-selected a span {padding-right: 10px;}
.ui-tabs-close {display: none;position: absolute;top: 3px;right: 0px;z-index: 800;width: 16px;height: 14px;font-size: 10px; font-style: normal;cursor: pointer;}
.ui-tabs-selected .ui-tabs-close {display: block;}
.ui-layout-west .ui-jqgrid tr.jqgrow td { border-bottom: 0px none;}
.ui-datepicker {z-index:1200;}
</style>
<script src="js/jquery.js" type="text/javascript"></script>
<script src="js/jquery-ui-1.7.2.custom.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
jQuery("#jsonmap").jqGrid({
url:'json.action' ,
datatype: "json",
colNames:['Inv No','Date', '客户', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:90},
{name:'Date',index:'invdate', width:110, jsonmap:"invdate"},
{name:'name',index:'name asc, invdate', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
rowList:[10,20,30],
imgpath: 'themes/sand/images',
pager: jQuery('#pjmap'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
jsonReader: {
repeatitems : false,
id: "0"
},
caption: "JSON Mapping----download from -> http://download.youkuaiyun.com/user/hanit ", height: '220'
}).navGrid('#pjmap',{edit:false,add:false,del:false});
});
</script>
<script type="text/javascript">
function jSearchCounselor(){
$.getJSON("<%=path%>/json.action",null,function call(data){
wirteHtml(data);
});}
function wirteHtml(data){
var lineitem = data.rows;
var ocsTable = $("#csTable")
ocsTable.empty()
$("<tr><td><b>ID</b></td><td><b>Date</b></td><td><b>Amount</b></td></tr>").appendTo(ocsTable);
for(var i=0;i<lineitem.length;i++){
$("<tr><td>"
+ lineitem[i].id + "</td><td>"
+ lineitem[i].invdate + "</td><td>"
+ lineitem[i].total + "</td>"
+"</tr>").appendTo(ocsTable)
}
}
</script>
</head>
<body>
<h3>JQuery, jqGrid, Json, Struts2, Hibernate simple Demo</h3>
<table id="jsonmap" class="scroll" cellpadding="0" cellspacing="0"></table>
<div id="pjmap" class="scroll" style="text-align:center;"></div>
<s:form action="json" method="post">
<s:textfield name="message" label="Message" value="Hello World!" size="50" />
<s:submit value="Show Json Data" align="center"></s:submit><br>
<input type="button" value="Get Data" onClick="jSearchCounselor();">
</s:form>
<table id="csTable" width="400" border="1">
<tr>
<td scope="col"><b>ID</b></td>
<td scope="col"><b>Date</b></td>
<td scope="col"><b>amount</b></td>
</tr>
</table>
<br/><br>
<p>
<b>This demostration is based on jqGrid 3.5 beta, thanks a lot to Tony for publishing this new release.</b>
</p>
<table width="777"><tr bgcolor="#BBECF7"><td><div bgcolor="blue" align="center">Free software by Hanit, 2009. Any feedback please mail to hanit@live.com</div >
</td></tr></table>
</body>
</html>
接下来是struts.xml
只有一个action,所以很短。
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd " >
<struts>
<include file="struts-default.xml"></include>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<package name="JsonDemo" extends="struts-default">
<action name="json" class="com.hanwill.grid.action.JsonDataAction" method="getJsonData">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
<interceptor-ref name="defaultStack"></interceptor-ref>
</action>
</package>
</struts>
下面是web.xml,里面有struts2的引用
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee "
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd ">
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
下面是比较关键的代码struts2的Action Class
package com.hanwill.grid.action;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.hanwill.grid.pojos.Invheader;
import com.hanwill.grid.persistence.service.InvheaderService;
import com.hanwill.grid.persistence.service.InvheaderDaoService;
import net.sf.json.JSONObject;
import net.sf.json.JSONArray;
public class JsonDataAction extends ActionSupport {
private String page;
private String rows;
private String sidx;
private String sord;
private String message;
private InvheaderService isvc;
public JsonDataAction() {
System.out.println("Enter Constructor. ");
}
public String getMessage() {
return message;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
public String getRows() {
return rows;
}
public void setRows(String rows) {
this.rows = rows;
}
public String getSidx() {
return sidx;
}
public void setSidx(String sidx) {
this.sidx = sidx;
}
public String getSord() {
return sord;
}
public void setSord(String sord) {
this.sord = sord;
}
public void setMessage(String message) {
this.message = message;
}
public String getJsonData() throws Exception {
System.out.println("***************************************************");
System.out.println("*********** Json and jqGrid by Hanwill *********");
System.out.println("***************************************************");
if(page==null) page ="1";
if(sidx==null) sidx ="id";
if(rows==null) rows ="10";
if(sord==null) sord ="asc";
int rowsInt=Integer.parseInt(rows);
int totalRows =isvc.getTotalRows();
int totalPages =(int)Math.floor( (double)totalRows/(double)rowsInt+1);
//--分页
List list =isvc.getRowsByPage(Integer.parseInt(page),Integer.parseInt(rows), sidx, sord);
HttpServletResponse response = ServletActionContext.getResponse();
PrintWriter out = response.getWriter();
//--生成JSON格式数据
try {
JSONObject obj = new JSONObject();
obj.put("page", ""+page);
obj.put("total",totalPages);
obj.put("records",""+totalRows);
JSONArray lineitemArray = new JSONArray();
Invheader invheader = new Invheader();
Iterator it = list.iterator();
int no=0;
while (it.hasNext()) {
no++;
invheader = (Invheader) it.next();
JSONObject objlineitem = new JSONObject();
objlineitem.put("id",""+ invheader.getId());
objlineitem.put("invdate", ""+invheader.getInvdate().toString());
objlineitem.put("name", "Client "+no); //fake data, so sorting won't work on this column
objlineitem.put("amount", ""+invheader.getAmount());
objlineitem.put("tax", ""+invheader.getTax());
objlineitem.put("total", ""+invheader.getTotal());
objlineitem.put("note", invheader.getNote());
lineitemArray.add(objlineitem);
}
obj.put("rows", lineitemArray);
out.print(obj.toString());
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Action 类一定得要下面的这个hibernate著名的DAO Class来配合
package com.hanwill.grid.persistence;
import com.hanwill.grid.pojos.Invheader;
import java.util.Date;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import static org.hibernate.criterion.Example.create;
public class InvheaderDAO extends BaseHibernateDAO {
private static final Log log = LogFactory.getLog(InvheaderDAO.class);
// property constants
public static final String CLIENT_ID = "clientId";
public static final String AMOUNT = "amount";
public static final String TAX = "tax";
public static final String TOTAL = "total";
public static final String NOTE = "note";
public static final String CLOSED = "closed";
public static final String SHIP_VIA = "shipVia";
public void save(Invheader transientInstance) {
log.debug("saving Invheader instance");
try {
getSession().save(transientInstance);
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
public void delete(Invheader persistentInstance) {
log.debug("deleting Invheader instance");
try {
getSession().delete(persistentInstance);
log.debug("delete successful");
} catch (RuntimeException re) {
log.error("delete failed", re);
throw re;
}
}
public Invheader findById(java.lang.Integer id) {
log.debug("getting Invheader instance with id: " + id);
try {
Invheader instance = (Invheader) getSession().get(
"com.hanwill.grid.pojos.Invheader", id);
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
public List<Invheader> findByExample(Invheader instance) {
log.debug("finding Invheader instance by example");
try {
List<Invheader> results = (List<Invheader>) getSession()
.createCriteria("com.hanwill.grid.pojos.Invheader").add(
create(instance)).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
public List findByProperty(String propertyName, Object value) {
log.debug("finding Invheader instance with property: " + propertyName
+ ", value: " + value);
try {
String queryString = "from Invheader as model where model."
+ propertyName + "= ?";
Query queryObject = getSession().createQuery(queryString);
queryObject.setParameter(0, value);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
public List<Invheader> findByClientId(Object clientId) {
return findByProperty(CLIENT_ID, clientId);
}
public List<Invheader> findByAmount(Object amount) {
return findByProperty(AMOUNT, amount);
}
public List<Invheader> findByTax(Object tax) {
return findByProperty(TAX, tax);
}
public List<Invheader> findByTotal(Object total) {
return findByProperty(TOTAL, total);
}
public List<Invheader> findByNote(Object note) {
return findByProperty(NOTE, note);
}
public List<Invheader> findByClosed(Object closed) {
return findByProperty(CLOSED, closed);
}
public List<Invheader> findByShipVia(Object shipVia) {
return findByProperty(SHIP_VIA, shipVia);
}
public Invheader merge(Invheader detachedInstance) {
log.debug("merging Invheader instance");
try {
Invheader result = (Invheader) getSession().merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public void attachDirty(Invheader instance) {
log.debug("attaching dirty Invheader instance");
try {
getSession().saveOrUpdate(instance);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public void attachClean(Invheader instance) {
log.debug("attaching clean Invheader instance");
try {
getSession().lock(instance, LockMode.NONE);
log.debug("attach successful");
} catch (RuntimeException re) {
log.error("attach failed", re);
throw re;
}
}
public List findAll() {
log.debug("finding all Student instances");
try {
String queryString = "from Invheader";
Query queryObject = getSession().createQuery(queryString);
return queryObject.list();
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
//--关键Dao方法
public Long getAllRowCount() {
Session session = this.getSession();
try {
String queryString = "select count(*) from Invheader";
Query queryObject = session.createQuery(queryString);
Long rows = (Long)queryObject.list().get(0);
return (Long)queryObject.list().get(0);
} catch (RuntimeException re) {
throw re;
} finally {
session.close();
}
}
public List findByPage(int page, int pagesize, String sortColumn, String sortDirection) {
Session session = this.getSession();
try {
String queryString = "select * from invheader ORDER BY " + sortColumn + " " + sortDirection;
System.out.println("findByPage queryString:::::::::::::=" + queryString);
int start = pagesize * (page - 1);
//String queryString = "from Invheader ORDER BY " + sortColumn + " " + sortDirection;
//Query queryObject = session.createQuery(queryString);
Query queryObject = session.createSQLQuery(queryString).addEntity(Invheader.class);
queryObject.setFirstResult(start);
queryObject.setMaxResults(pagesize);//limit;
List result = queryObject.list();
System.out.println("result:== " + result.size());
return result;
} catch (RuntimeException re) {
log.error("findByPage failed", re);
throw re;
} finally {
session.close();
}
}
}
好了,关键的代码都贴好了,我相信,有了这些,你就可以在Struts2中使用jqGrid了。
现在贴出数据库脚本,数据库的结构和数据都来自Tony的jqGrid示例。
数据库用的是MySQL 5.0
/*
SQLyog Enterprise - MySQL GUI v8.05
MySQL - 5.0.22-community-nt : Database - griddemo
*********************************************************************
*/
/*!40101 SET NAMES utf8 */;
/*!40101 SET SQL_MODE=''*/;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`griddemo` /*!40100 DEFAULT CHARACTER SET latin1 */;
USE `griddemo`;
/*Table structure for table `clients` */
DROP TABLE IF EXISTS `clients`;
CREATE TABLE `clients` (
`client_id` int(11) NOT NULL auto_increment,
`name` char(120) default NULL,
PRIMARY KEY (`client_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*Data for the table `clients` */
insert into `clients`(`client_id`,`name`) values (1,'Client 1');
insert into `clients`(`client_id`,`name`) values (2,'Client 2');
insert into `clients`(`client_id`,`name`) values (3,'Client 3');
/*Table structure for table `invheader` */
DROP TABLE IF EXISTS `invheader`;
CREATE TABLE `invheader` (
`id` int(11) NOT NULL auto_increment,
`invdate` date NOT NULL,
`client_id` int(11) NOT NULL,
`amount` decimal(10,2) NOT NULL default '0.00',
`tax` decimal(10,2) NOT NULL default '0.00',
`total` decimal(10,2) NOT NULL default '0.00',
`note` char(100) default NULL,
`closed` char(3) default 'No',
`ship_via` char(3) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*Data for the table `invheader` */
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (1,'2007-10-01',1,'100.00','20.00','120.00','note 1','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (2,'2007-10-03',1,'200.00','40.00','240.00','note 2','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (3,'2007-10-02',2,'300.00','60.00','360.00','note for invoice 3','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (4,'2007-10-04',3,'150.00','0.00','150.00','no tax','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (5,'2007-10-05',3,'100.00','0.00','100.00','no tax','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (6,'2007-10-05',1,'50.00','10.00','60.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (7,'2007-10-05',2,'120.00','12.00','134.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (8,'2007-10-06',3,'200.00','0.00','200.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (9,'2007-10-06',1,'200.00','40.00','240.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (10,'2007-10-06',2,'100.00','20.00','120.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (11,'2007-10-06',1,'600.00','120.00','720.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (12,'2007-10-06',2,'700.00','140.00','840.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (13,'2007-10-06',3,'1000.00','0.00','1000.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (14,'2009-07-01',1,'100.00','20.00','120.00','note 1','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (15,'2009-07-03',1,'200.00','40.00','240.00','note 2','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (16,'2009-07-02',2,'300.00','60.00','360.00','note for invoice 3','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (17,'2009-07-04',3,'150.00','0.00','150.00','no tax','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (18,'2009-07-05',3,'100.00','0.00','100.00','no tax','No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (19,'2009-07-05',1,'50.00','10.00','60.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (20,'2009-07-05',2,'120.00','12.00','134.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (21,'2009-07-06',3,'200.00','0.00','200.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (22,'2009-07-06',1,'200.00','40.00','240.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (23,'2009-07-06',2,'100.00','20.00','120.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (24,'2009-07-06',1,'600.00','120.00','720.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (25,'2009-07-06',2,'700.00','140.00','840.00',NULL,'No',NULL);
insert into `invheader`(`id`,`invdate`,`client_id`,`amount`,`tax`,`total`,`note`,`closed`,`ship_via`) values (26,'2009-07-06',3,'1000.00','0.00','1000.00',NULL,'No',NULL);
/*Table structure for table `invlines` */
DROP TABLE IF EXISTS `invlines`;
CREATE TABLE `invlines` (
`id` int(11) NOT NULL,
`num` int(11) NOT NULL auto_increment,
`item` char(20) default NULL,
`qty` decimal(8,2) NOT NULL default '0.00',
`unit` decimal(10,2) NOT NULL,
PRIMARY KEY (`id`,`num`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
/*Data for the table `invlines` */
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (1,1,'item 1','1.00','20.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (1,2,'item 2','2.00','40.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (2,1,'item 1','2.00','20.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (2,2,'item 2','4.00','40.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (3,1,'item 3','1.00','100.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (3,2,'item 4','1.00','200.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (4,1,'item 1','1.00','100.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (4,2,'item 2','1.00','50.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (5,1,'item 3','1.00','100.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (6,1,'item 4','1.00','50.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (7,1,'item 5','2.00','10.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (7,2,'item 1','1.00','100.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (8,1,'item 3','1.00','50.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (8,2,'item 2','1.00','120.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (8,3,'item 3','1.00','30.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (9,1,'item 6','1.00','140.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (9,2,'item 3','1.00','60.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (10,1,'item 5','3.00','10.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (10,2,'item 4','1.00','70.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (11,1,'item 1','2.00','100.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (11,2,'item 2','3.00','50.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (11,3,'item 3','1.00','50.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (11,4,'item 4','1.00','200.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (12,1,'item 4','1.00','300.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (12,2,'item 2','1.00','400.00');
insert into `invlines`(`id`,`num`,`item`,`qty`,`unit`) values (13,1,'item 13','1.00','1000.00');
/*Table structure for table `items` */
DROP TABLE IF EXISTS `items`;
CREATE TABLE `items` (
`item_id` int(10) unsigned NOT NULL auto_increment,
`item` varchar(200) default NULL,
`item_cd` varchar(15) default NULL,
PRIMARY KEY (`item_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*Data for the table `items` */
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
暂时先贴到这里,稍后再加些说明。
完整项目已上传到我的下载中