コード例 #1
0
 public void ClearHistory()
 {
     historyWords.Clear();
     using (BiliMusicContext db = new BiliMusicContext())
     {
         db.SearchHistorys.RemoveRange(db.SearchHistorys);
         db.SaveChangesAsync();
     }
 }
コード例 #2
0
 /// <summary>
 /// 初始化单一实例应用程序对象。这是执行的创作代码的第一行,
 /// 已执行,逻辑上等同于 main() 或 WinMain()。
 /// </summary>
 public App()
 {
     this.InitializeComponent();
     this.Suspending += OnSuspending;
     using (var db = new BiliMusicContext())
     {
         db.Database.Migrate();
     }
 }
コード例 #3
0
 public void LoadHistory()
 {
     historyWords.Clear();
     using (BiliMusicContext db = new BiliMusicContext())
     {
         foreach (var item in db.SearchHistorys.OrderByDescending(x => x.datetime))
         {
             historyWords.Add(item.content);
         }
     }
 }
コード例 #4
0
 private void SaveHistory(string keyword)
 {
     using (BiliMusicContext db = new BiliMusicContext())
     {
         var search = db.SearchHistorys.FirstOrDefault(x => x.content.Equals(keyword));
         if (search != null)
         {
             search.datetime = DateTime.Now;
         }
         else
         {
             db.SearchHistorys.Add(new SearchHistory()
             {
                 content  = keyword,
                 datetime = DateTime.Now
             });
         }
         db.SaveChangesAsync();
     }
 }