2021年11月17日 星期三

使用 await 等待非同步函數問題

MVC
====
若controller 有全域 DbContext 物件,執行 await 後會造成 物件自動dispose
解決方式為不使用全域DbContext 物件,需要時再透過 using 建立


webforms
====
webmethod 執行 await 後就無法再取得 System.Web.HttpContext.Current,必須先用變數記錄起來,await 之後再填回
var httpcontext = HttpContext.Current;
await xxxAsync().ConfigureAwait(false);
HttpContext.Current = httpcontext;

2021年11月5日 星期五

b-modal 實作範例

顯示表格資料,頂部有欄位名稱,底部有按鈕列,中間有捲軸
<b-modal scrollable size="xl" id="b-modal-列印託運單" no-close-on-backdrop="true" hide-header-close="true">
            <template #modal-header>
                <b-row style="width:100%">
                    <b-col class="col-2">訂單編號</b-col>
                    <b-col class="col-2">客戶名稱</b-col>
                    <b-col class="col-6">品名</b-col>
                    <b-col class="col-2">商品類別</b-col>
                </b-row>
            </template>
            <div class="d-flex align-items-center" v-for="需列印託運單 in 需列印託運單s" style="padding:0.25em;margin-bottom:0.5em">
                <b-row style="width:100%">
                    <b-col class="col-2">{{需列印託運單.訂單號}}</b-col>
                    <b-col class="col-2">{{需列印託運單.客戶名稱}}</b-col>
                    <b-col class="col-6">{{需列印託運單.品名}}</b-col>
                    <b-col class="col-2">
                        <b-form-select v-model="需列印託運單.商品類別" :options="商品類別s" style=" width: 100%; display: inline-block " value-field="value" text-field="text">
                        </b-form-select>
                    </b-col>
                </b-row>
            </div>
            <template #modal-footer>
                <b-button-group>
                    <b-button variant="light" v-on:click="click取消列印託運單()">取消</b-button>
                    <b-button variant="primary" style="width:6em" v-on:click="click開始列印託運單()">列印</b-button>
                </b-button-group>
            </template>
</b-modal> 

區塊陰影效果

 <div style="margin: 0.5em; box-shadow: 0.25em 0.25em 0.5em #cccccc;"></div>

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

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