function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g, '');
if (isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num * 100 + 0.50000000001);
cents = num % 100;
num = Math.floor(num / 100).toString();
if (cents < 10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length - (1 + i)) / 3); i++)
num = num.substring(0, num.length - (4 * i + 3)) + ',' +
num.substring(num.length - (4 * i + 3));
return (((sign) ? '' : '-') + num + '.' + cents);
}
function IsIntText(textControl) {
var str = textControl.value;
var regexp = /^([1-9][0-9]*)$/; //正整數
// ^-?\d+$ 整數含負數
var msg = '';
if (!regexp.test(textControl.value)) {
msg = '數字格式不正確!';
}
if (parseInt(str, 10).toString() == '0') { //表示輸入的是0或0.00啦
msg = '數字格式不可為0!';
}
if( msg != ''){
alert(msg);
textControl.value = "";
}
else{
//檢查都過後重算總金額
//把數字傳給數值欄位計算總金額
//把字串欄位變成貨幣單位(千分位帶逗點)
var fgvD2 = document.getElementById("ctl00_ContentPlaceHolder1_fgvD2");
var totalAMT = 0; //總金額
var AlltotalAMT = 0; //總金額
var ORDERAMT = 0; //單價
var ORDERNUM = 0 ; //數量
if (fgvD2.rows.length > 0) {
for (var i = 1; i < fgvD2.rows.length; i++) {
totalAMT = 0;
//字串去除逗號
//數量字串欄位
ORDERNUM = fgvD2.rows[i].cells[3].getElementsByTagName("input")[0].value;
ORDERNUM = ORDERNUM.replace(new RegExp(",", ''),''); //replaceall
//單價字串欄位
ORDERAMT = fgvD2.rows[i].cells[4].getElementsByTagName("input")[0].value;
ORDERAMT = ORDERAMT.replace(new RegExp(",", ''),''); //replaceall
//單價傳給數值欄位 在.cs pageload給值
//fgvD2.rows[i].cells[4].getElementsByTagName("input")[1].value = ORDERAMT;
//總金額 = 總金額 + 數量 * 單價
totalAMT = (ORDERNUM * ORDERAMT);
AlltotalAMT = AlltotalAMT + (ORDERNUM * ORDERAMT);
//總金額傳給數值欄位 在.cs pageload給值
//fgvD2.rows[i].cells[5].getElementsByTagName("input")[1].value = totalAMT;
//金額字串欄位加上貨幣符號(千分位帶逗點)
fgvD2.rows[i].cells[4].getElementsByTagName("input")[0].value = formatCurrency(ORDERAMT).toString();
fgvD2.rows[i].cells[5].getElementsByTagName("input")[0].value = formatCurrency(totalAMT).toString();
//隱藏td關閉
//document.getElementById('tdORDERAMT').style.display = 'none';
//document.getElementById('tdTOTALAMT').style.display = 'none';
}
document.getElementById("ctl00_ContentPlaceHolder1_lbTOTALAMT").innerText = formatCurrency(AlltotalAMT).toString();
document.getElementById("ctl00_ContentPlaceHolder1_ftbALLTOTALAMT").value = formatCurrency(AlltotalAMT).toString();
}
}
}
function IsfloatText(textControl) {
var str = textControl.value;
var str = textControl.value;
var regexp = /^[0-9]+.[0-9]{1,2}?$/; //帶2位小數正實數 發現10A1這種無法找出 下方修補邏輯
var regexp2 = /^([1-9][0-9]*)$/; //正整數
var msg = '';
if (!regexp.test(textControl.value) && !regexp2.test(textControl.value)) { //整數或小數
msg = '數字格式不正確!';
}
var regexp2 = /[A-Za-z]/
if (regexp2.test(textControl.value)) { //若包含字母
msg = '數字格式不正確!';
}
if (parseFloat(str, 10).toString() == '0') { //表示輸入的是0或0.00啦
msg = '數字格式不可為0!';
}
if (msg != '') {
alert(msg);
textControl.value = "";
}
else {
//檢查都過後重算總金額
//把數字傳給數值欄位計算總金額
//把字串欄位變成貨幣單位(千分位帶逗點)
var fgvD2 = document.getElementById("ctl00_ContentPlaceHolder1_fgvD2");
var totalAMT = 0; //總金額
var AlltotalAMT = 0; //總金額
var ORDERAMT = 0; //單價
var ORDERNUM = 0; //數量
if (fgvD2.rows.length > 0) {
for (var i = 1; i < fgvD2.rows.length; i++) {
totalAMT = 0;
//字串去除逗號
//數量字串欄位
ORDERNUM = fgvD2.rows[i].cells[3].getElementsByTagName("input")[0].value;
ORDERNUM = ORDERNUM.replace(/,/, '');
//單價字串欄位
ORDERAMT = fgvD2.rows[i].cells[4].getElementsByTagName("input")[0].value;
ORDERAMT = ORDERAMT.replace(/,/, '');
//單價傳給數值欄位 在.cs pageload給值
//fgvD2.rows[i].cells[4].getElementsByTagName("input")[1].value = ORDERAMT;
//總金額 = 總金額 + 數量 * 單價
totalAMT = (ORDERNUM * ORDERAMT);
AlltotalAMT = AlltotalAMT + (ORDERNUM * ORDERAMT);
//總金額傳給數值欄位 在.cs pageload給值
//fgvD2.rows[i].cells[5].getElementsByTagName("input")[1].value = totalAMT;
//金額字串欄位加上貨幣符號(千分位帶逗點)
fgvD2.rows[i].cells[4].getElementsByTagName("input")[0].value = formatCurrency(ORDERAMT).toString();
fgvD2.rows[i].cells[5].getElementsByTagName("input")[0].value = formatCurrency(totalAMT).toString();
//隱藏td關閉
//document.getElementById('tdORDERAMT').style.display = 'none';
//document.getElementById('tdTOTALAMT').style.display = 'none';
}
document.getElementById("ctl00_ContentPlaceHolder1_lbTOTALAMT").innerText = formatCurrency(AlltotalAMT).toString();
document.getElementById("ctl00_ContentPlaceHolder1_ftbALLTOTALAMT").value = formatCurrency(AlltotalAMT).toString();
}
}
}