2019年6月27日 星期四

解決電腦無故自動喚醒

找出自動喚醒原因: powercfg /waketimers

例如出現以下訊息
原因: Windows 將執行 'NT TASK\Microsoft\Windows\UpdateOrchestrator\Universal Orchestrator Start' 排定要求喚醒電腦的工 作。

則必須進入工作排程器找出 "Universal Orchestrator Start" 並取消勾選 "喚醒電腦以執行此工作"
但預設會沒有權限修改
必須透過 psexec 啟動工作排程器才能修改
psexec下載位置: https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
透過 psexec啟動工作排程器: psexec.exe -i -s %windir%\system32\mmc.exe /s taskschd.msc

可順便檢查還有哪些排程也會自動喚醒電腦,然後一併修改,可參考"下次執行時間"欄位尋找

ui-select 複選架構設定 title 於整個按鈕

無法直接於 ui-select-match 中取得 $item 物件,必須透過下一層來設定,若只在下一層設定 title,滑鼠必須停在文字上才會顯示

<ui-select-match><span ui-select-match-title="{{$item.text}}">...</span></ui-select-match>

.directive('uiSelectMatchTitle', function () {
        return {
            link: function ($scope, $element, attrs) {
                $($element).parent().parent().attr('title', attrs.uiSelectMatchTitle);
            }
        }
    })

2019年6月24日 星期一

ui-select 允許保存自行輸入的資料

透過 onblur 判斷是否有選取既有選項,若未選取則動態設定 ng-model

.directive('selectonblur', function () {
        return {
            require: 'uiSelect',
            link: function ($scope, $element, attrs, $select) {
                var searchInput = $element.querySelectorAll('input.ui-select-search');
                if (searchInput.length !== 1) throw Error("bla");
                searchInput.on('blur', function () {
                    if (!$select.ngModel.$viewValue)
                        $scope.$apply(function () {
                            var user = { name: $select.search };
                            $select.ngModel.$setViewValue(user);
                        });
                });               
            }
        }
    })

2019年6月10日 星期一

應用程式避免執行多個實體

若已執行則不再執行
private void Form1_Load(object sender, EventArgs e) {
if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1) Application.Exit();
}

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

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