Beispiel #1
0
        public void SaveStatus()
        {
            var currentData = GetCurrentData();

            using (var db = new DataModel.DataContext()) {
                var tempItem = db.State.FirstOrDefault();
                if (tempItem != null)
                {
                    tempItem.Title     = currentData.Title;
                    tempItem.Des       = currentData.Des;
                    tempItem.DueDate   = currentData.DueDate;
                    tempItem.Icon      = currentData.ImageByte;
                    tempItem.ListIndex = editIndex;
                }
                else
                {
                    db.State.Add(new DataModel.TempState()
                    {
                        Title     = currentData.Title,
                        Des       = currentData.Des,
                        DueDate   = currentData.DueDate,
                        Icon      = currentData.ImageByte,
                        ListIndex = editIndex
                    });
                }
                db.SaveChanges();
            }
        }
Beispiel #2
0
 public void Add(Item newItem)
 {
     Source.Add(newItem);
     Tile.TileManger.AddTile(newItem.Title, newItem.Des, newItem.DueDate, newItem.ImageByte);
     using (var db = new DataModel.DataContext()) {
         db.Add(newItem.ToModel());
         db.SaveChanges();
     }
 }
Beispiel #3
0
        public App()
        {
            this.InitializeComponent();
            this.Suspending += OnSuspending;

            using (var db = new DataModel.DataContext()) {
                db.Database.Migrate();
            }
            Model.ItemsDataSource.GetData().InitFromDB();

            Tile.TileManger.InitTile();
        }
Beispiel #4
0
 public async void InitFromDB()
 {
     using (var db = new DataModel.DataContext()) {
         var items = db.Items.ToList();
         foreach (var item in items)
         {
             Item newItem = await new Item().FromModel(item);
             Source.Add(newItem);
             Tile.TileManger.AddTile(newItem.Title, newItem.Des, newItem.DueDate, item.Icon);
         }
     }
 }
Beispiel #5
0
 // 状态的保存与恢复
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     if (e.NavigationMode == NavigationMode.Back)
     {
         using (var db = new DataModel.DataContext()) {
             var tempItem = db.State.FirstOrDefault();
             if (tempItem != null)
             {
                 NewPage.Current.Restore(tempItem);
             }
         }
     }
 }
Beispiel #6
0
 public bool Remove(int index)
 {
     if (index < 0 || index >= Source.Count)
     {
         return(false);
     }
     using (var db = new DataModel.DataContext()) {
         var item = db.Items.Single(b => b.ListId == Source[index].GetId());
         db.Items.Remove(item);
         db.SaveChanges();
     }
     Source.RemoveAt(index);
     Tile.TileManger.Update(Source);
     return(true);
 }
Beispiel #7
0
        public bool Update(Item newItem, int index)
        {
            if (index < 0 || index >= Source.Count)
            {
                return(false);
            }
            bool state = Source[index].IsCheck;

            Source[index]         = Source[index].GetNewItem(newItem);
            Source[index].IsCheck = state;
            var newDate = Source[index].ToModel();

            using (var db = new DataModel.DataContext()) {
                var item = db.Items.Single(b => b.ListId == newDate.ListId);
                item.Update(newDate);
                db.SaveChanges();
            }
            Tile.TileManger.Update(Source);
            return(true);
        }
Beispiel #8
0
        // 搜索模块
        private void QueryItem(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            var text = args.QueryText;

            searchBox.Text = "";
            using (var db = new DataModel.DataContext()) {
                var items = db.Items.Where(b => b.Title.Contains(text) ||
                                           b.Des.Contains(text) ||
                                           b.DueDate.ToString("D").Contains(text))
                            .ToList();
                string content = "";
                foreach (var item in items)
                {
                    content += $"{item.Title} {item.Des} {item.DueDate.ToString("D")}\n";
                }
                if (content.Equals(""))
                {
                    content = "No Result";
                }
                UtilTool.SendADialog("Search Result", content);
            }
        }