分享
 
 
 

使用os3grid做一个基于Web和Ajax的工资表录入界面

王朝other·作者佚名  2006-04-20
窄屏简体版  字體: |||超大  

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;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有