2022年7月22日 星期五

輸入方塊設定唯讀但可接受輸入資料

<b-form-input readonly id="輸入" v-on:keyup="輸入($event)" v-model="單號"></b-form-input>

輸入(event) {
            if (this.單號==null) this.單號 = '';
             if (event.key == 'Backspace') this.單號 = this.單號.left(this.單號.length - 1);
            else if (event.key != 'Enter') this.單號 += event.key;
},

先設定焦點,然後鍵盤輸入時可接收輸入資料,於手機上可避免跳出輸入鍵盤,適用於搭配相機或透過電腦接上掃描器掃條碼的情境

2022年7月20日 星期三

mouseenter 和 mouseover 的差別

mouseover: 當鼠標移入元素或其子元素都會觸發 (會造成重複觸發),對應的移除事件是 mouseout

mouseenter: 當鼠標移入元素本身(不包含子元素)會觸發,對應的移除事件是 mouseleave

2022年7月19日 星期二

取得資料庫表格欄位寬度

public static int? GetMaxLength(this System.Data.Entity.DbContext context, string tableName, string propertyName)
        {
            var oc = ((System.Data.Entity.Infrastructure.IObjectContextAdapter)context).ObjectContext;

            return oc.MetadataWorkspace.GetItems(System.Data.Entity.Core.Metadata.Edm.DataSpace.CSpace).OfType<System.Data.Entity.Core.Metadata.Edm.EntityType>()
                     .Where(et => et.Name == tableName)
                     .SelectMany(et => et.Properties.Where(p => p.Name == propertyName))
                     .Select(p => p.MaxLength)
                     .FirstOrDefault();
        }

2022年7月7日 星期四

c# 例外錯誤訊息顯示為英文

System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
System.Threading.Thread.CurrentThread.CurrentUICulture = new System.Globalization.CultureInfo("en-US");

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

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