批量数据录入, 辅助输入数据, 以及相关检测(JScript 客户端)(原创)
作者: 萧月痕
相关链接:批量数据录入, 辅助输入数据, 以及相关检测(ASP 服务器端)(原创)
<script language="JScript">
<!--
function keyDown()
{
if(event.keyCode == 13)
{
if(event.srcElement.className == "fbtclass") return true;
event.keyCode = 9;
return true;
}
}
document.onkeydown = keyDown;
var myform;
var intTotal = <%= intBillTotal%>;
function init(form)
{
myform = form;
formsum();
}
function openWin(intID)
{
var arrValue = window.showModalDialog("<%= GBL__STR_SYS_ROOT_PATH%>WInfo/Product_wList.asp?at=1&1");
if ((arrValue != null) && (arrValue.length == 6))
{
var id = isNaN(parseInt(arrValue[0])) ? 0 : parseInt(arrValue[0]);
if (id == 0) return;
for(var i = 1; i <= intTotal; i++)
{
if ((isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value)) == id)
{
alert("已输入此项产品数据, 若需更改数据, 请在表单中直接修改!");
return;
}
}
try
{
myform["fih_pid_" + intID].value = arrValue[0];
myform["fih_pmodel_" + intID].value = arrValue[1];
myform["fih_pvalue_" + intID].value = arrValue[2];
myform["fih_pspec_" + intID].value = arrValue[3];
myform["fih_punit_" + intID].value = arrValue[4];
myform["fih_pprice_" + intID].value = filternum(arrValue[5], 2);
myform["fih_ptotal_" + intID].value = "0.00";
myform["fih_pcost_" + intID].value = "0.00";
}
catch(e)
{
alert("表单填充出错!");
}
}else
{
clearrow(intID)
}
}
function enterDown()
{
if(event.keyCode == 13) return((event.srcElement.tagName == "TEXTAREA") ? true : false);
}
function formreset(form)
{
var flag = confirm("确实要撤消所有操作并返回初始值吗?");
if (flag){
form.reset();
}
}
function formsubmit(form)
{
if (formsubmitcheck() && confirm("确定提交数据吗?")){
form.submit();
}
}
function formsubmitcheck()
{
var flag = false;
var id = 0;
for(var i = 1; i <= intTotal; i++)
{
id = isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value);
if (id > 0)
{
flag = true;
break;
}
}
if (!flag) alert("空数据不能提交!");
return flag;
}
function formsum()
{
var totalSum = 0;
for(var i = 1; i <= intTotal; i++)
{
if (isNaN(parseInt(myform["fih_pid_" + i].value)) ? 0 : parseInt(myform["fih_pid_" + i].value) == 0) continue;
totalSum += isNaN(parseFloat(myform["fih_pcost_" + i].value)) ? 0 : parseFloat(myform["fih_pcost_" + i].value);
}
myform.fit_totalprice.value = filternum(totalSum, 2);
window.setTimeout( "formsum()", 200);
}
function sumrow(id)
{
var intID = isNaN(parseInt(myform["fih_pid_" + id].value)) ? 0 : parseInt(myform["fih_pid_" + id].value);
if (intID <= 0)
{
clearrow(id)
return;
}
var num = filternum(myform["fih_ptotal_" + id].value, 2);
var price = filternum(myform["fih_pprice_" + id].value, 2);
if (price < 0)
{
alert("单价不能为负数!");
price = Math.abs(price);
myform["fih_pprice_" + id].value = price;
}
var spec = eval(myform["fih_pspec_" + id].value);
var spec = isNaN(parseFloat(spec)) ? 1 : filternum(spec, 2);
var cost = num * price * spec;
myform["fih_ptotal_" + id].value = num;
myform["fih_pprice_" + id].value = price;
myform["fih_pcost_" + id].value = filternum(cost, 2);
}
function clearrow(id)
{
myform["fih_pid_" + id].value = 0;
myform["fih_pmodel_" + id].value = "";
myform["fih_pvalue_" + id].value = "";
myform["fih_pspec_" + id].value = "";
myform["fih_punit_" + id].value = "";
myform["fih_pprice_" + id].value = "";
myform["fih_ptotal_" + id].value = "";
myform["fih_pcost_" + id].value = "";
}
function filternum(num, k)
{
var num = isNaN(parseFloat(num)) ? 0 : parseFloat(num);
try{
return num.toFixed(k);
}
catch(e) {
alert("脚本引擎不支持此操作, 请升级您的浏览为IE5.5以上!");
return 0;
}
}
function isVbDate(str)
{
var miny = 2000;
var maxy = 2005;
var reg = /^(\d{4})(-|\/|\.)(\d{1,2})\2(\d{1,2})$/;
result = str.match(reg);
if(result == null) return false;
var y, m, d;
y = result[1];
m = parseInt(result[3]);
d = parseInt(result[4]);
if ((y > maxy) || (y < miny))
{
alert("年份不能超出( " + miny + " - " + maxy + " )范围!");
return false;
}
if ((m < 1) || (m > 12) || (d < 1) || (d > 31)) return false;
if (((m == 4) || (m == 6) || (m == 9) || (m == 11)) && (d > 30)) return false;
if((y % 4) == 0)
{
if ((m == 2) && (d > 29)) return false;
}else
{
if ((m == 2) && (d > 28)) return false;
}
return true;
}
function checkVbDate(input)
{
if (input.value == "") return;
if (!isVbDate(input.value))
{
alert("日期格式不正确, 请重新输入");
input.focus();
input.select();
}
}
function BrowseCostmer()
{
var arrValue = window.showModalDialog("<%= GBL__STR_SYS_ROOT_PATH%>WInfo/Costmer_wList.asp");
if ((arrValue != null) && (arrValue.length == 2))
{
var id = isNaN(parseInt(arrValue[0])) ? 0 : parseInt(arrValue[0]);
var Costmer = arrValue[1];
myform.fit_CustID.value = id;
myform.fit_CustName.value = Costmer;
}
}
</script>
发表于 @ 2004年09月26日 20:52:00|评论(loading...)|举报|收藏