2018年11月30日 星期五

輸入欄位不要自動跳出建議

此問題因瀏覽器版本跟使用者電腦而異,所以同一個畫面同一個欄位有的人會遇到有的人不會

<input dont-fill type="tel" class="form-control" />

.directive('dontFill', function () {
        return {
            restrict: 'A',
            link: function link(scope, el, attrs) {
                // password fields need one of the same type above it (firefox)
                var type = el.attr('type') || 'text';
                // chrome tries to act smart by guessing on the name.. so replicate a shadow name
                var name = el.attr('name') || '';
                var shadowName = name + '_shadow';
                // trick the browsers to fill this innocent silhouette
                var shadowEl = angular.element('<input type="' + type + '" name="' + shadowName + '" style="display: none">');

                // insert before
                el.parent()[0].insertBefore(shadowEl[0], el[0]);
            }
        };
    })

2018年11月28日 星期三

entity framework transaction 用法

using (var scope = db.Database.BeginTransaction())
{
  ...
  db.SaveChanges();
  scope.Commit();
}

※ 跳出 exception 不須特別呼叫 Rollback()
※ 使用 TransactionScope 對同一個資料庫也會造成 msdtc 相關錯誤,不予採用

2018年11月22日 星期四

使用 LinqToExcel 讀取 csv

不支援 \t 分隔字元(其他未確認)
不支援unicode 編碼

寫法範例
System.IO.File.WriteAllText(FileName, System.IO.File.ReadAllText(FileName).Replace("\t", ","), System.Text.Encoding.Default)
var rows = new ExcelQueryFactory(FileName).WorksheetNoHeader(0)

2018年11月19日 星期一

使用 sessionStorage 針對同一分頁做資料交換

寫入
sessionStorage.setItem("公司id", $scope.companyid);

讀取
$scope.companyid = sessionStorage.getItem("公司id");

2018年11月8日 星期四

ui-select 於 ng-repeat 中綁定變數屬性方式

<div ng-repeat="a in list">
<ui-select append-to-body="true" ng-change="a['收件人id']=a['收件人物件'].value;" ng-model="a['收件人物件']">
                        <ui-select-match allow-clear="true">
                            <span ng-bind="$select.selected.text"></span>
                        </ui-select-match>
                        <ui-select-choices repeat="obj in employees | filter: $select.search track by $index">
                            <span ng-bind="obj.text"></span>
                        </ui-select-choices>
                    </ui-select>

因為ui-select ng-model 對應的是 repeat 中的元素,若該元素是物件,但希望改成對應ng-repeat物件某個屬性(收件人id),則需要另外用屬性物件(收件人物件)來轉換,且若考慮既有資料預設值,陣列元素也需要先設定好該屬性物件,以便正確顯示目前的選項

2018年11月2日 星期五

css 設定注意

1. class 優先權大於 type

.form-control {
width:auto;
}

table.詳細資料 select {
width:150px;
}

最後結果 select width 會是 auto
若要覆蓋.form-contrl 設定,需改成
table.詳細資料 select.form-control {
width:150px;
}

2. 若 select 使用多個class,多個class 優先權大於單一class

table.詳細資料 select.form-control.單位 {
width:100px;
}

最後結果 select width 會是 100px (優先權 :  select.form-control.單位 > select.form-control > .form-control)

3. 下面載入的 css 優先權大於上面載入,因此針對套件內建css 若要客製化,須把客製化css 放下面

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

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