BPM实例分享——金额规则大写。H3BPM实例分享——金额规则大写。

 金额规则大写

 

 

  在羁押是的时刻,我想起码小白会和本身一样吧,老鸟勿喷,我是菜鸟。下面说自家遇到的情:

当论及金额的流水线中时常会面遇上需要特别写金额多少与微微写金额匹配,如何实现输入数字后活动转换为?

  给小写金额加加onchange事件怎么上加我弗见面了。于是便改变了本的章程:

起码用法

  直接叫多少写控件加onchange=”chineseNumber(this.value)”;

1.每当默认表单基本性javascript
中加进如下金额转换方法

  然后把chineseNumber()中的return去丢改也
$.MvcSheetUI.SetControlValue(“daxiejine”, resAIW);

/** 数字金额大写转换(可以处理整数,小数,负数) */

function chineseNumber(dValue) {

var maxDec = 2;

// 验证输入金额数值或数值字符串:

dValue = dValue.toString().replace(/,/g, "");

dValue = dValue.replace(/^0+/, ""); // 金额数值转字符、移除逗号、移除前导零

if (dValue == "") {

return "零元整";

} // (错误:金额为空!)

else if (isNaN(dValue)) {

return "错误:金额不是合法的数值!";

}

var minus = ""; // 负数的符号“-”的大写:“负”字。可自定义字符,如“(负)”。

var CN_SYMBOL = ""; // 币种名称(如“人民币”,默认空)

if (dValue.length > 1) {

if (dValue.indexOf(‘-‘) == 0) {

dValue = dValue.replace("-", "");

minus = "负";

} // 处理负数符号“-”

if (dValue.indexOf(‘+’) == 0) {

dValue = dValue.replace("+", "");

} // 处理前导正数符号“+”(无实际意义)

}

// 变量定义:

var vInt = "";

var vDec = ""; // 字符串:金额的整数部分、小数部分

var resAIW; // 字符串:要输出的结果

var parts; // 数组(整数部分.小数部分),length=1时则仅为整数。

var digits, radices, bigRadices, decimals; // 数组:数字(0~9——零~玖);基(十进制记数系统中每个数字位的基是10——拾,佰,仟);大基(万,亿,兆,京,垓,杼,穰,沟,涧,正);辅币(元以下,角/分/厘/毫/丝)。

var zeroCount; // 零计数

var i, p, d; // 循环因子;前一位数字;当前位数字。

var quotient, modulus; // 整数部分计算用:商数、模数。

// 金额数值转换为字符,分割整数部分和小数部分:整数、小数分开来搞(小数部分有可能四舍五入后对整数部分有进位)。

var NoneDecLen = (typeof (maxDec) == "undefined" || maxDec == null || Number(maxDec) < 0 || Number(maxDec) > 5); // 是否未指定有效小数位(true/false)

parts = dValue.split(‘.’); // 数组赋值:(整数部分.小数部分),Array的length=1则仅为整数。

if (parts.length > 1) {

vInt = parts[0];

vDec = parts[1]; // 变量赋值:金额的整数部分、小数部分

if (NoneDecLen) {

maxDec = vDec.length > 5 ? 5 : vDec.length;

} // 未指定有效小数位参数值时,自动取实际小数位长但不超5。

var rDec = Number("0." + vDec);

rDec *= Math.pow(10, maxDec);

rDec = Math.round(Math.abs(rDec));

rDec /= Math.pow(10, maxDec); // 小数四舍五入

var aIntDec = rDec.toString().split(‘.’);

if (Number(aIntDec[0]) == 1) {

vInt = (Number(vInt) + 1).toString();

} // 小数部分四舍五入后有可能向整数部分的个位进位(值1)

if (aIntDec.length > 1) {

vDec = aIntDec[1];

} else {

vDec = "";

}

} else {

vInt = dValue;

vDec = "";

if (NoneDecLen) {

maxDec = 0;

}

}

if (vInt.length > 44) {

return "错误:金额值太大了!整数位长【" + vInt.length.toString() + "】超过了上限——44位/千正/10^43(注:1正=1万涧=1亿亿亿亿亿,10^40)!";

}

// 准备各字符数组 Prepare the characters corresponding to the digits:

digits = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); // 零~玖

radices = new Array("", "拾", "佰", "仟"); // 拾,佰,仟

bigRadices = new Array("", "万", "亿", "兆", "京", "垓", "杼", "穰", "沟", "涧", "正"); // 万,亿,兆,京,垓,杼,穰,沟,涧,正

decimals = new Array("角", "分", "厘", "毫", "丝"); // 角/分/厘/毫/丝

resAIW = ""; // 开始处理

// 处理整数部分(如果有)

if (Number(vInt) > 0) {

zeroCount = 0;

for (i = 0; i < vInt.length; i++) {

p = vInt.length – i – 1;

d = vInt.substr(i, 1);

quotient = p / 4;

modulus = p % 4;

if (d == "0") {

zeroCount++;

} else {

if (zeroCount > 0) {

resAIW += digits[0];

}

zeroCount = 0;

resAIW += digits[Number(d)] + radices[modulus];

}

if (modulus == 0 && zeroCount < 4) {

resAIW += bigRadices[quotient];

}

}

resAIW += "元";

}

// 处理小数部分(如果有)

for (i = 0; i < vDec.length; i++) {

d = vDec.substr(i, 1);

if (d != "0") {

resAIW += digits[Number(d)] + decimals[i];

}

}

// 处理结果

if (resAIW == "") {

resAIW = "零" + "元";

} // 零元

if (vDec == "") {

resAIW += "整";

} // …元整

resAIW = CN_SYMBOL + minus + resAIW; // 人民币/负……元角分/整

return resAIW;

}

  注意:在使用高级道的时,修改了js文件,所以只要扫除一下缓存,不然浏览器有缓存,会看不到效果。

 

 

2.每当表单“小写金额”控件增加onchange事件

 

$.MvcSheetUI.MvcRuntime.setDataFieldControlValue($(this),’jinedaxie’,chineseNumber($("input[data-datafield=’jinexiaoxie’]").val()));

官网的章程:

   
金额(小写)数据项编码:jinexiaoxie

Ø  金额规则大写

金额(大写)数据项编码:jinedaxie

于干金额的流水线中常常会遇见需要很写金额数及微写金额匹配,如何促成输入数字后自动转换为?

 

起码用法

高级用法

1.当默认表单基本特性javascript 中长如下金额转换方法

表单文本控件“ComputationRule”属性加大写计算函数。

/** 数字金额大写转换(可以处理整数,小数,负数) */

function chineseNumber(dValue) {

var maxDec = 2;

// 验证输入金额数值或数值字符串:

dValue = dValue.toString().replace(/,/g, "");

dValue = dValue.replace(/^0+/, ""); // 金额数值转字符、移除逗号、移除前导零

if (dValue == "") {

return "零元整";

} // (错误:金额为空!)

else if (isNaN(dValue)) {

return "错误:金额不是合法的数值!";

}

var minus = ""; // 负数的符号“-”的大写:“负”字。可自定义字符,如“(负)”。

var CN_SYMBOL = ""; // 币种名称(如“人民币”,默认空)

if (dValue.length > 1) {

if (dValue.indexOf(‘-‘) == 0) {

dValue = dValue.replace("-", "");

minus = "负";

} // 处理负数符号“-”

if (dValue.indexOf(‘+’) == 0) {

dValue = dValue.replace("+", "");

} // 处理前导正数符号“+”(无实际意义)

}

// 变量定义:

var vInt = "";

var vDec = ""; // 字符串:金额的整数部分、小数部分

var resAIW; // 字符串:要输出的结果

var parts; // 数组(整数部分.小数部分),length=1时则仅为整数。

var digits, radices, bigRadices, decimals; // 数组:数字(0~9——零~玖);基(十进制记数系统中每个数字位的基是10——拾,佰,仟);大基(万,亿,兆,京,垓,杼,穰,沟,涧,正);辅币(元以下,角/分/厘/毫/丝)。

var zeroCount; // 零计数

var i, p, d; // 循环因子;前一位数字;当前位数字。

var quotient, modulus; // 整数部分计算用:商数、模数。

// 金额数值转换为字符,分割整数部分和小数部分:整数、小数分开来搞(小数部分有可能四舍五入后对整数部分有进位)。

var NoneDecLen = (typeof (maxDec) == "undefined" || maxDec == null || Number(maxDec) < 0 || Number(maxDec) > 5); // 是否未指定有效小数位(true/false)

parts = dValue.split(‘.’); // 数组赋值:(整数部分.小数部分),Array的length=1则仅为整数。

if (parts.length > 1) {

vInt = parts[0];

vDec = parts[1]; // 变量赋值:金额的整数部分、小数部分

if (NoneDecLen) {

maxDec = vDec.length > 5 ? 5 : vDec.length;

} // 未指定有效小数位参数值时,自动取实际小数位长但不超5。

var rDec = Number("0." + vDec);

rDec *= Math.pow(10, maxDec);

rDec = Math.round(Math.abs(rDec));

rDec /= Math.pow(10, maxDec); // 小数四舍五入

var aIntDec = rDec.toString().split(‘.’);

if (Number(aIntDec[0]) == 1) {

vInt = (Number(vInt) + 1).toString();

} // 小数部分四舍五入后有可能向整数部分的个位进位(值1)

if (aIntDec.length > 1) {

vDec = aIntDec[1];

} else {

vDec = "";

}

} else {

vInt = dValue;

vDec = "";

if (NoneDecLen) {

maxDec = 0;

}

}

if (vInt.length > 44) {

return "错误:金额值太大了!整数位长【" + vInt.length.toString() + "】超过了上限——44位/千正/10^43(注:1正=1万涧=1亿亿亿亿亿,10^40)!";

}

// 准备各字符数组 Prepare the characters corresponding to the digits:

digits = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); // 零~玖

radices = new Array("", "拾", "佰", "仟"); // 拾,佰,仟

bigRadices = new Array("", "万", "亿", "兆", "京", "垓", "杼", "穰", "沟", "涧", "正"); // 万,亿,兆,京,垓,杼,穰,沟,涧,正

decimals = new Array("角", "分", "厘", "毫", "丝"); // 角/分/厘/毫/丝

resAIW = ""; // 开始处理

// 处理整数部分(如果有)

if (Number(vInt) > 0) {

zeroCount = 0;

for (i = 0; i < vInt.length; i++) {

p = vInt.length – i – 1;

d = vInt.substr(i, 1);

quotient = p / 4;

modulus = p % 4;

if (d == "0") {

zeroCount++;

} else {

if (zeroCount > 0) {

resAIW += digits[0];

}

zeroCount = 0;

resAIW += digits[Number(d)] + radices[modulus];

}

if (modulus == 0 && zeroCount < 4) {

resAIW += bigRadices[quotient];

}

}

resAIW += "元";

}

// 处理小数部分(如果有)

for (i = 0; i < vDec.length; i++) {

d = vDec.substr(i, 1);

if (d != "0") {

resAIW += digits[Number(d)] + decimals[i];

}

}

// 处理结果

if (resAIW == "") {

resAIW = "零" + "元";

} // 零元

if (vDec == "") {

resAIW += "整";

} // …元整

resAIW = CN_SYMBOL + minus + resAIW; // 人民币/负……元角分/整

return resAIW;

}

1.在\Portal\WFRes\_Scripts\MVCRuntime\Sheet.Computation.js文件被加上初级中之chineseNumber方法,在盘算函数CompuationFun增加SUMCAPITAL定义。

 

{

        Name: "SUMCAPITAL",

        Accept: function (express) {

            return express.toLocaleLowerCase().indexOf("sumcapital(") == 0;

        },

        Compuator: function (obj, ctl, express, round) {

            var field = this.Field(express);

            express = this.Express(express);

            var val = 0;

            $("input[data-datafield=’" + field + "’],span[data-datafield=’" + field + "’]").each(function (obj, express, round) {

                var thisValue = 0;

                if (express) {

                    thisValue = obj.executeCompute(this.id, round, express);

                }

                else {

                    if (this.tagName.toLocaleLowerCase() == "input" || this.tagName.toLocaleLowerCase() == "select")

                        thisValue = this.value;

                    else

                        thisValue = this.innerText;

                }

                if ($(this).attr("data-formatrule")) thisValue = thisValue.replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (thisValue && !isNaN(thisValue)) {

                    val += parseFloat(thisValue);

                }

            }, [obj, express, round]);

            return chineseNumber(val);

        },

        Field: function (express) {

            var field = express.substring(express.indexOf("{") + 1);

            field = field.substring(0, field.indexOf("}"));

            return field;

        },

        Express: function (express) {

            if (express.indexOf(",") == -1) return "";

            var str = express.substring(express.indexOf(",") + 1);

            return str.substring(0, str.length – 1);

        },

        IsFunc: true

    },

2.在表单“小写金额”控件增加onchange事件

2.
履行计算主方法判断中文计算,修改后要下

$.MvcSheetUI.MvcRuntime.setDataFieldControlValue($(this),’jinedaxie’,chineseNumber($("input[data-datafield=’jinexiaoxie’]").val()));

computator: function (id, round, express) {

        var v = this.executeCompute(id, round, express);

        try {

            eval(v); //判断是否中文数字

            // 结果四舍五入取小数位

            if (isFinite(v)) {

                v = Math.round(v * Math.pow(10, round)) / Math.pow(10, round);

                var target = $("#" + id);

                if (target.is("input,textarea")) {

                    var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.val(v);

                        target.trigger("change"); // target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

                else if (target.is("div,span")) {

                    var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.html(v);

                        target.trigger("change"); //target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

            } // end if(isFinite(v))

        }

        catch (e) {

            var target = $("#" + id);

            if (target.is("input,textarea")) {

                var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.val(v);

                    target.trigger("change"); // target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

            else if (target.is("div,span")) {

                var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.html(v);

                    target.trigger("change"); //target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

        }

    }

    金额(小写)数据项编码:jinexiaoxie

3.\Portal\WFRes\_Scripts\MVCRuntime\Sheet.js
文件计算结果值getResultValue定义修改如下

金额(大写)数据项编码:jinedaxie

getResultValue: function (express) {

        if (express.indexOf("return") == -1) {

            try {

                return eval(express);}

            catch (e) {

            return express;}

        }

        else {

            return new Function(express).call(this);

        }

    },

 

 

高级用法

4.
\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中长金额大写的按钮

表单文本控件“ComputationRule”属性加大写计算函数。

<div style="margin-top: 10px;">

                <input type="button" id="btnSum" value="SUM"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnSumCapital" value="SUMCAPITAL"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnAvg" value="AVG"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMax" value="MAX"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMin" value="MIN"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnCount" value="COUNT"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

            </div>

1.在\Portal\WFRes\_Scripts\MVCRuntime\Sheet.Computation.js文件被长初级中的chineseNumber方法,在测算函数CompuationFun增加SUMCAPITAL定义。

5.
\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中增金额大写的按钮事件

{

        Name: "SUMCAPITAL",

        Accept: function (express) {

            return express.toLocaleLowerCase().indexOf("sumcapital(") == 0;

        },

        Compuator: function (obj, ctl, express, round) {

            var field = this.Field(express);

            express = this.Express(express);

            var val = 0;

            $("input[data-datafield=’" + field + "’],span[data-datafield=’" + field + "’]").each(function (obj, express, round) {

                var thisValue = 0;

                if (express) {

                    thisValue = obj.executeCompute(this.id, round, express);

                }

                else {

                    if (this.tagName.toLocaleLowerCase() == "input" || this.tagName.toLocaleLowerCase() == "select")

                        thisValue = this.value;

                    else

                        thisValue = this.innerText;

                }

                if ($(this).attr("data-formatrule")) thisValue = thisValue.replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (thisValue && !isNaN(thisValue)) {

                    val += parseFloat(thisValue);

                }

            }, [obj, express, round]);

            return chineseNumber(val);

        },

        Field: function (express) {

            var field = express.substring(express.indexOf("{") + 1);

            field = field.substring(0, field.indexOf("}"));

            return field;

        },

        Express: function (express) {

            if (express.indexOf(",") == -1) return "";

            var str = express.substring(express.indexOf(",") + 1);

            return str.substring(0, str.length – 1);

        },

        IsFunc: true

    },

$("#btnSum,#btnSumCapital,#btnAvg,#btnCount,#btnMax,#btnMin").click(function () {

                var input = $("#txtComputationRule")[0];

                var text = $(this).val() + "()";

                var pos = getCaretPos(input);

                insertAtCaret(input, text);

                setCaretToPos(input, pos + text.length – 1);

2.履计算主方法判断中文计算,修改后如果下

 

computator: function (id, round, express) {

        var v = this.executeCompute(id, round, express);

        try {

            eval(v); //判断是否中文数字

            // 结果四舍五入取小数位

            if (isFinite(v)) {

                v = Math.round(v * Math.pow(10, round)) / Math.pow(10, round);

                var target = $("#" + id);

                if (target.is("input,textarea")) {

                    var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.val(v);

                        target.trigger("change"); // target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

                else if (target.is("div,span")) {

                    var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.html(v);

                        target.trigger("change"); //target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

            } // end if(isFinite(v))

        }

        catch (e) {

            var target = $("#" + id);

            if (target.is("input,textarea")) {

                var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.val(v);

                    target.trigger("change"); // target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

            else if (target.is("div,span")) {

                var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.html(v);

                    target.trigger("change"); //target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

        }

    }

   
接下去控件的ComputationRule属性就可行使大写计算公式了,是不是殊要命,赶紧试一试试吧。

3.\Portal\WFRes\_Scripts\MVCRuntime\Sheet.js
文件计算结果值getResultValue定义修改如下

 

getResultValue: function (express) {

        if (express.indexOf("return") == -1) {

            try {

                return eval(express);}

            catch (e) {

            return express;}

        }

        else {

            return new Function(express).call(this);

        }

    },

 

4.\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中益金额大写的按钮

<div style="margin-top: 10px;">

                <input type="button" id="btnSum" value="SUM"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnSumCapital" value="SUMCAPITAL"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnAvg" value="AVG"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMax" value="MAX"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMin" value="MIN"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnCount" value="COUNT"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

            </div>

5.\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中追加金额大写的按钮事件

$("#btnSum,#btnSumCapital,#btnAvg,#btnCount,#btnMax,#btnMin").click(function () {

                var input = $("#txtComputationRule")[0];

                var text = $(this).val() + "()";

                var pos = getCaretPos(input);

                insertAtCaret(input, text);

                setCaretToPos(input, pos + text.length – 1);

 

    接下控件的ComputationRule属性就好利用大写计算公式了,是无是异常特别,赶紧试一尝试吧。

 

 

 

Ø  金额规则大写

当关乎金额的流程中常会遇到需要充分写金额数和微微写金额匹配,如何兑现输入数字后自行转换为?

初级用法

1.以默认表单基本属性javascript 中追加如下金额转换方法

/** 数字金额大写转换(可以处理整数,小数,负数) */

function chineseNumber(dValue) {

var maxDec = 2;

// 验证输入金额数值或数值字符串:

dValue = dValue.toString().replace(/,/g, "");

dValue = dValue.replace(/^0+/, ""); // 金额数值转字符、移除逗号、移除前导零

if (dValue == "") {

return "零元整";

} // (错误:金额为空!)

else if (isNaN(dValue)) {

return "错误:金额不是合法的数值!";

}

var minus = ""; // 负数的符号“-”的大写:“负”字。可自定义字符,如“(负)”。

var CN_SYMBOL = ""; // 币种名称(如“人民币”,默认空)

if (dValue.length > 1) {

if (dValue.indexOf(‘-‘) == 0) {

dValue = dValue.replace("-", "");

minus = "负";

} // 处理负数符号“-”

if (dValue.indexOf(‘+’) == 0) {

dValue = dValue.replace("+", "");

} // 处理前导正数符号“+”(无实际意义)

}

// 变量定义:

var vInt = "";

var vDec = ""; // 字符串:金额的整数部分、小数部分

var resAIW; // 字符串:要输出的结果

var parts; // 数组(整数部分.小数部分),length=1时则仅为整数。

var digits, radices, bigRadices, decimals; // 数组:数字(0~9——零~玖);基(十进制记数系统中每个数字位的基是10——拾,佰,仟);大基(万,亿,兆,京,垓,杼,穰,沟,涧,正);辅币(元以下,角/分/厘/毫/丝)。

var zeroCount; // 零计数

var i, p, d; // 循环因子;前一位数字;当前位数字。

var quotient, modulus; // 整数部分计算用:商数、模数。

// 金额数值转换为字符,分割整数部分和小数部分:整数、小数分开来搞(小数部分有可能四舍五入后对整数部分有进位)。

var NoneDecLen = (typeof (maxDec) == "undefined" || maxDec == null || Number(maxDec) < 0 || Number(maxDec) > 5); // 是否未指定有效小数位(true/false)

parts = dValue.split(‘.’); // 数组赋值:(整数部分.小数部分),Array的length=1则仅为整数。

if (parts.length > 1) {

vInt = parts[0];

vDec = parts[1]; // 变量赋值:金额的整数部分、小数部分

if (NoneDecLen) {

maxDec = vDec.length > 5 ? 5 : vDec.length;

} // 未指定有效小数位参数值时,自动取实际小数位长但不超5。

var rDec = Number("0." + vDec);

rDec *= Math.pow(10, maxDec);

rDec = Math.round(Math.abs(rDec));

rDec /= Math.pow(10, maxDec); // 小数四舍五入

var aIntDec = rDec.toString().split(‘.’);

if (Number(aIntDec[0]) == 1) {

vInt = (Number(vInt) + 1).toString();

} // 小数部分四舍五入后有可能向整数部分的个位进位(值1)

if (aIntDec.length > 1) {

vDec = aIntDec[1];

} else {

vDec = "";

}

} else {

vInt = dValue;

vDec = "";

if (NoneDecLen) {

maxDec = 0;

}

}

if (vInt.length > 44) {

return "错误:金额值太大了!整数位长【" + vInt.length.toString() + "】超过了上限——44位/千正/10^43(注:1正=1万涧=1亿亿亿亿亿,10^40)!";

}

// 准备各字符数组 Prepare the characters corresponding to the digits:

digits = new Array("零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"); // 零~玖

radices = new Array("", "拾", "佰", "仟"); // 拾,佰,仟

bigRadices = new Array("", "万", "亿", "兆", "京", "垓", "杼", "穰", "沟", "涧", "正"); // 万,亿,兆,京,垓,杼,穰,沟,涧,正

decimals = new Array("角", "分", "厘", "毫", "丝"); // 角/分/厘/毫/丝

resAIW = ""; // 开始处理

// 处理整数部分(如果有)

if (Number(vInt) > 0) {

zeroCount = 0;

for (i = 0; i < vInt.length; i++) {

p = vInt.length – i – 1;

d = vInt.substr(i, 1);

quotient = p / 4;

modulus = p % 4;

if (d == "0") {

zeroCount++;

} else {

if (zeroCount > 0) {

resAIW += digits[0];

}

zeroCount = 0;

resAIW += digits[Number(d)] + radices[modulus];

}

if (modulus == 0 && zeroCount < 4) {

resAIW += bigRadices[quotient];

}

}

resAIW += "元";

}

// 处理小数部分(如果有)

for (i = 0; i < vDec.length; i++) {

d = vDec.substr(i, 1);

if (d != "0") {

resAIW += digits[Number(d)] + decimals[i];

}

}

// 处理结果

if (resAIW == "") {

resAIW = "零" + "元";

} // 零元

if (vDec == "") {

resAIW += "整";

} // …元整

resAIW = CN_SYMBOL + minus + resAIW; // 人民币/负……元角分/整

return resAIW;

}

 

2.于表单“小写金额”控件增加onchange事件

$.MvcSheetUI.MvcRuntime.setDataFieldControlValue($(this),’jinedaxie’,chineseNumber($("input[data-datafield=’jinexiaoxie’]").val()));

    金额(小写)数据项编码:jinexiaoxie

金额(大写)数据项编码:jinedaxie

 

高档用法

表单文本控件“ComputationRule”属性加大写计算函数。

1.在\Portal\WFRes\_Scripts\MVCRuntime\Sheet.Computation.js文件中加上初级中的chineseNumber方法,在算函数CompuationFun增加SUMCAPITAL定义。

{

        Name: "SUMCAPITAL",

        Accept: function (express) {

            return express.toLocaleLowerCase().indexOf("sumcapital(") == 0;

        },

        Compuator: function (obj, ctl, express, round) {

            var field = this.Field(express);

            express = this.Express(express);

            var val = 0;

            $("input[data-datafield=’" + field + "’],span[data-datafield=’" + field + "’]").each(function (obj, express, round) {

                var thisValue = 0;

                if (express) {

                    thisValue = obj.executeCompute(this.id, round, express);

                }

                else {

                    if (this.tagName.toLocaleLowerCase() == "input" || this.tagName.toLocaleLowerCase() == "select")

                        thisValue = this.value;

                    else

                        thisValue = this.innerText;

                }

                if ($(this).attr("data-formatrule")) thisValue = thisValue.replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (thisValue && !isNaN(thisValue)) {

                    val += parseFloat(thisValue);

                }

            }, [obj, express, round]);

            return chineseNumber(val);

        },

        Field: function (express) {

            var field = express.substring(express.indexOf("{") + 1);

            field = field.substring(0, field.indexOf("}"));

            return field;

        },

        Express: function (express) {

            if (express.indexOf(",") == -1) return "";

            var str = express.substring(express.indexOf(",") + 1);

            return str.substring(0, str.length – 1);

        },

        IsFunc: true

    },

2.实行计算主方法判断中文计算,修改后一旦下

computator: function (id, round, express) {

        var v = this.executeCompute(id, round, express);

        try {

            eval(v); //判断是否中文数字

            // 结果四舍五入取小数位

            if (isFinite(v)) {

                v = Math.round(v * Math.pow(10, round)) / Math.pow(10, round);

                var target = $("#" + id);

                if (target.is("input,textarea")) {

                    var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.val(v);

                        target.trigger("change"); // target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

                else if (target.is("div,span")) {

                    var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                    if (oldV != v) {

                        target.html(v);

                        target.trigger("change"); //target.trigger("change.MobileMaskText");

                        target.blur();

                    }

                }

            } // end if(isFinite(v))

        }

        catch (e) {

            var target = $("#" + id);

            if (target.is("input,textarea")) {

                var oldV = target.val().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.val(v);

                    target.trigger("change"); // target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

            else if (target.is("div,span")) {

                var oldV = target.html().replace(/,/g, "").replace(/$/g, "").replace(/¥/g, "");

                if (oldV != v) {

                    target.html(v);

                    target.trigger("change"); //target.trigger("change.MobileMaskText");

                    target.blur();

                }

            }

        }

    }

3.\Portal\WFRes\_Scripts\MVCRuntime\Sheet.js
文件计算结果值getResultValue定义修改如下

getResultValue: function (express) {

        if (express.indexOf("return") == -1) {

            try {

                return eval(express);}

            catch (e) {

            return express;}

        }

        else {

            return new Function(express).call(this);

        }

    },

 

4.\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中追加金额大写的按钮

<div style="margin-top: 10px;">

                <input type="button" id="btnSum" value="SUM"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnSumCapital" value="SUMCAPITAL"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnAvg" value="AVG"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMax" value="MAX"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnMin" value="MIN"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

                <input type="button" id="btnCount" value="COUNT"

                    style="height: 28px; padding-left: 8px; padding-right: 8px;" />

            </div>

5.\Portal\Admin\MvcDesigner\MvcDesigner.aspx表单中增加金额大写的按钮事件

$("#btnSum,#btnSumCapital,#btnAvg,#btnCount,#btnMax,#btnMin").click(function () {

                var input = $("#txtComputationRule")[0];

                var text = $(this).val() + "()";

                var pos = getCaretPos(input);

                insertAtCaret(input, text);

                setCaretToPos(input, pos + text.length – 1)});

 

    接下控件的ComputationRule属性就好以大写计算公式了,是勿是充分怪,赶紧试一试跳吧。

图片 1

 

 

 

 

admin

网站地图xml地图