1 首先對os3grid做一些小的修改:加入下面代碼
function strlen(str)
{
var len;
var i;
len = 0;
for (i=0;i<str.length;i++)
{
if (str.charCodeAt(i)>255) len+=2; else len++;
}
return len;
}
然後在function grid_cell_txt_edit ( cell )裡面修改以下一行,主要是應付中文
s += ' size="'+ strlen(val) + '" ';
另外,修改一些顏色
this.cols = { "hover" : "#d5f1ff",
2 工資表結構
考慮到每一個單位都有不同的帳套,所以按一對多建立帳套表
CREATE TABLE pq_unitgzxm (
unit_id char(8) NOT NULL DEFAULT '',
xmbh int NOT NULL DEFAULT 0,
xmbm varchar(3) NOT NULL PRIMARY KEY,
xmmc varchar(200) NOT NULL DEFAULT '',
lx varchar(200) NOT NULL DEFAULT '',
JSgs varchar(200) NOT NULL DEFAULT ''
)
INSERT INTO pq_unitgzxm values ('00000001',1,'F01','員工號','系統值','');
INSERT INTO pq_unitgzxm values ('00000001',2,'F02','姓名','系統值','');
INSERT INTO pq_unitgzxm values ('00000001',3,'F03','單位','系統值','');
INSERT INTO pq_unitgzxm values ('00000001',4,'F04','基本工資','錄入值','');
INSERT INTO pq_unitgzxm values ('00000001',5,'F05','獎金','錄入值','');
INSERT INTO pq_unitgzxm values ('00000001',6,'F06','應發工資','計算值','');
INSERT INTO pq_unitgzxm values ('00000001',7,'F07','個人所得稅','計算值','');
INSERT INTO pq_unitgzxm values ('00000001',8,'F08','應扣工資','計算值','');
INSERT INTO pq_unitgzxm values ('00000001',9,'F09','實發工資','計算值','');
實際工資錄入采用空間冗余的辦法
CREATE TABLE pq_gzxm (
gzb_id char(8) NOT NULL DEFAULT '',
employee_id char(8) NOT NULL DEFAULT '',
xm varchar(400) NOT NULL DEFAULT '',
employeecontract_id char(8) NOT NULL DEFAULT '',
gzdata1 decimal NOT NULL DEFAULT '0',
gzdata2 decimal NOT NULL DEFAULT '0',
gzdata3 decimal NOT NULL DEFAULT '0',
gzdata4 decimal NOT NULL DEFAULT '0',
gzdata5 decimal NOT NULL DEFAULT '0',
gzdata6 decimal NOT NULL DEFAULT '0',
gzdata7 decimal NOT NULL DEFAULT '0',
gzdata8 decimal NOT NULL DEFAULT '0',
gzdata9 decimal NOT NULL DEFAULT '0',
gzdata10 decimal NOT NULL DEFAULT '0',
gzdata11 decimal NOT NULL DEFAULT '0',
gzdata12 decimal NOT NULL DEFAULT '0',
gzdata13 decimal NOT NULL DEFAULT '0',
gzdata14 decimal NOT NULL DEFAULT '0',
gzdata15 decimal NOT NULL DEFAULT '0',
gzdata16 decimal NOT NULL DEFAULT '0',
gzdata17 decimal NOT NULL DEFAULT '0',
gzdata18 decimal NOT NULL DEFAULT '0',
gzdata19 decimal NOT NULL DEFAULT '0',
gzdata20 decimal NOT NULL DEFAULT '0'
)
INSERT INTO pq_gzxm (gzb_id,employee_id,xm,employeecontract_id,gzdata1) values ('00000001','00000001','張三','00000001',0);
INSERT INTO pq_gzxm (gzb_id,employee_id,xm,employeecontract_id,gzdata1) values ('00000001','00000002','李四','00000002',0);
3 生成表單
function show_form($unit_id = '', $gzyear ='', $gzmonth='',$error = '') {
global $db, $me, $t,$_POST;
extract($_POST);
if ($unit_id && !$error) {
$rs = $db->Execute("select * from ".TBL_UNITGZXM." where unit_id = '$unit_id'");
$items = $rs->GetArray();
$t->assign('items', $items);
//$rs = $db->Execute("select e.employee_id,e.xm,ec.dwmc from ".TBL_EMPLOYEE." e,".TBL_EMPLOYEECONTRACT." ec,".TBL_UNITCONTRACT." uc where e.employee_id=
ec.employee_id and ec.unitcontract_id = uc.unitcontract_id and uc.unit_id ='$unit_id'");
//$t->assign('employees', $rs->GetArray());
$gzb_id = '';
$dwmc = '';
$gzb = $db->GetRow("select gzb_id,dwmc from ".TBL_GZB." where unit_id = '$unit_id'
and gzyear='2006' and gzmonth='04'");
$gzb_id = $gzb['gzb_id'];
$dwmc = $gzb['dwmc'];
$gz_array = array();
$rs = $db->Execute("select * from ".TBL_GZXM." where gzb_id = '$gzb_id'");
while (!$rs->EOF) {
$gzdata_array = array();
//gzdata1 從1開始
for ($i = 1, $count = count($items)-3; $i <= $count; $i++) {
array_push($gzdata_array, $rs->fIElds['gzdata'.$i]);
}
$gzline = array($rs->fields['employee_id'],$rs->fIElds['xm'],$dwmc,$gzdata_array);
array_push($gz_array, $gzline);
$rs->MoveNext();
}
} else {
$t->assign($_POST);
}
//print_r($gz_array);
$t->assign('error', $error);
$t->assign('gz_array', $gz_array);
$t->render('salary.html', PAGE_TITLE,'wrap.Html',False);
}
表單模板
<script>
var request_id = 0;
// 這裡將錄入的數據生成一個XML文件,並使用AJax方法返回給服務器端。
function get_data ( g)
{
var objDom = new ActiveXObject("MSXML.DOMDocument"); //define a DOM object
objDom.async=false;
var objRoot = objDom.createElement("SALARY"); //create the root
objDom.appendChild(objRoot);
var l = g.length ();
var t;
var data, attrs;
var s = "";
var i, v;
for ( t = 0; t < l; t ++ )
{
var objFIEld = objDom.createElement("Item");
objDom.documentElement.appendChild(objFIEld);
curnode=objDom.documentElement.lastChild;
data = g.get_row ( t );
//alert(data[0]+data[1]+data[2]);
//attrs = g.get_row_attrs ( t );
for ( i = 3; i < data.length; i ++ ) {
var gzdata = objDom.createElement("gzdata"+(i-2));
gzdata.text=data [ i ];
curnode.appendChild(gzdata);
}
}
//alert(objDom.XML);
post_data = "op=savesalary&salarydata=" + escape(objDom.XML);
var returnstuff = http_fetch_sync('salary.PHP',post_data);
//alert(returnstuff['responseText']);
if(returnstuff['responseText'].indexOf("ok")!=-1)
{
alert("保存成功!");
}
}
function row_modifIEd ( grid, cell_pos, row_num, new_val )
{
var attrs = grid.get_row_attrs ( row_num );
attrs [ 'changed' ] = 'YES';
}
// Create an OS3Grid instance
var g = new OS3Grid ();
// Set the callback for modifications
g.onchange = row_modifIEd;
g.set_size ( "100%", "250px" );
// Grid Headers are the grid column names
g.set_headers ( <?PHP
for ($i = 0, $count = count($items); $i < $count; $i++) {
echo "'".$items[$i]['xmmc']."'";
if($i!=$count-1) echo ",";
}
?> );
// If contents is bigger than container, Grid will automatically show scrollbars
g.set_scrollbars ( true );
// The grid will have a solid border (these are CSS attributes)
g.set_border ( 1, "solid", "#cccccc" );
// Now, we add some rows
//g.add_row ( "fsoft", "純月", "fsoft (@) sourceforge (dot) net" );
//g.set_row_attr ( -1, 'magic', 'magic-fsoft' );
//g.set_row_attr ( -1, 'changed', 'NO' );
<?PHP
for ($i = 0, $count = count($gz_array); $i < $count; $i++) {
$str = "";
$str .= "g.add_row('".$gz_array[$i][0]."','".$gz_array[$i][1]."','".$gz_array[$i][2]."',";
$gzdata_array = $gz_array[$i][3];
for ($j = 0, $count2 = count($gzdata_array); $j < $count2; $j++) {
$str .= "'";
$str .= $gzdata_array[$j][0];
$str .= "'";
if($j!=$count2-1) $str .= ",";
}
$str = $str.");";
echo $str;
// mygrid.addRow("2","00000002,text1,text2,1,1,1,1,1,1");
} ?>
// Enable sortable rows
//g.set_sortable ( true );
// Enable highlight of rows with the mouse
g.set_highlight ( true );
//g.set_col_editable ( 1, "txt" );
//g.set_col_editable ( 2, "txt" );
<?PHP
for ($i = 3, $count = count($items); $i <= $count; $i++) {
echo "g.set_col_editable ( ".$i.", \"txt\" );";
}
?>
g.sort_on_edit = true;
// Show the grid replacing the original Html object with the "grid" ID.
g.render ( 'grid' );
</script>
4 http_fetch_sync 函數如下
var global_xmlhttp = getXMLHTTPinstance();
function http_fetch_sync(url,post_data)
{
global_xmlhttp = getXMLHTTPinstance();
var method = 'GET';
if ( typeof(post_data) != 'undefined' )
{
method = 'POST';
}
try
{
//global_XMLhttp.open(method, url,true);
global_XMLhttp.open(method, url,false);
}
catch(e)
{
alert('message:'+e.message+":url:"+url);
}
if ( method == 'POST')
{
global_XMLhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
}
global_XMLhttp.send(post_data);
var args = {"responseText":global_xmlhttp.responseText,"responseXML":global_xmlhttp.responseXML,
"request_id":request_id};
return args;
}