2019年12月17日 星期二

格式化為金額字串且去除結尾多餘小數

$scope.不含結尾多餘小數金額 = function (value, 小數位) {
       var s = $filter('currency')(value, '', 小數位);
        if (s.indexOf('.') > 0 && s.right(1) == '0') s = trim(trim(s, '0'), '.');
        return s;
    }

function trim(s, c) {
    if (c === "]") c = "\\]";
    if (c === "\\") c = "\\\\";
    return s.replace(new RegExp(
        "^[" + c + "]+|[" + c + "]+$", "g"
    ), "");
}

String.prototype.right = function (num) {
    return this.substring(this.length - num, this.length);
}

Entity Framework 建立新物件並儲存後馬上取得關聯資料

使用 CreateProxy 建立物件,不要直接 new var newmodel = _contextXXX.CreateProxy<yyy>(); ... _contextXXX.yyy.Add(newmodel); await _contextXXX.SaveC...