2019年5月17日 星期五

統一編號驗證

<input uniformvalidate ng-model='uniform'><span style='color:red' ng-show="form1.$error.uniform">*</span>

.directive("uniformvalidate", function () {
return {
            restrict: 'A',
            require: "ngModel",
            link: function (scope, element, attributes, ngModel) {
                ngModel.$validators.uniform = function (modelValue, viewValue) {
                    return 檢查統一編號(modelValue);
                }
            }
        };
    })

function 檢查統一編號(NO) {
    if (!NO) return true;
    var SUM = 0;
    if (NO.length != 8) {
        return false;
    }
    var 統編檢查陣列 = '12121241'.split('');
    var 統編字元陣列 = NO.split("");
    for (i = 0; i <= 7; i++) {
        if (NO.charCodeAt() < 48 || NO.charCodeAt() > 57) {
            return false;
        }
        SUM += 兩位數相加(統編字元陣列[i] * 統編檢查陣列[i]);
    }
    if (SUM % 10 == 0) return true;
    else if (統編字元陣列[6] == 7 && (SUM + 1) % 10 == 0) return true;
    else return false;
}

2019年5月9日 星期四

瀏覽器 console 出現錯誤訊息找不到 glyphicons-halflings-regular.woff2

訊息如下
.../fonts/glyphicons-halflings-regular.woff2 net::ERR_ABORTED 404 (Not Found)
.../fonts/glyphicons-halflings-regular.woff net::ERR_ABORTED 404 (Not Found)

Bootstrap 會使用到,需要把檔案複製到指定路徑,並修改 web.config 加入
<system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="font/woff2" />
    </staticContent>

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

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