Ejemplo n.º 1
0
        private void LoadItem(List <string> entries)
        {
            int i = 0;

            while (i < entries.Count)
            {
                ListItem item = ListItemViewModels.GetInstance().allItems.FirstOrDefault(j => j.GetId() == entries[i]);
                if (item == null)
                {
                    byte[]      picbytes = Convert.FromBase64String(entries[i + 5]);
                    BitmapImage img      = ByteArrayBitmapExtensions.AsBitmapImage(picbytes);
                    var         dateres  = DateTime.Parse(entries[i + 3]);
                    ListItemViewModels.GetInstance().AddToDoItem(entries[i + 1],
                                                                 entries[i + 2], img, dateres, null, entries[i]);
                    ListItem temp = ListItemViewModels.GetInstance().allItems.FirstOrDefault(j => j.GetId() == entries[i]);
                    temp.completed = (entries[i + 4] == "1" ? true : false);
                    UpdateTile(entries[i + 1], entries[i + 2], DateTime.Parse(entries[i + 3]));
                }
                else
                {
                    item.title        = entries[i + 1];
                    item.description  = entries[i + 2];
                    item.date         = DateTime.Parse(entries[i + 3]);
                    item.Image_Source = ByteArrayBitmapExtensions.AsBitmapImage(Convert.FromBase64String(entries[i + 5]));
                }
                i += 6;
            }
        }
Ejemplo n.º 2
0
        }  //创建item

        private async void CreateDialog(int mode)
        {
            ListItemViewModels myViewModels = ListItemViewModels.GetInstance();
            ImageSource        source       = image.Source;

            if (mode == 0)
            {
                ListItem item = new ListItem(textBox.Text, textBox1.Text, source, datepicker.Date, CurrentPic);
                myViewModels.allItems.Add(item);
                UpdateTile(textBox.Text, textBox1.Text, datepicker.Date);
                byte[] picbyte = await ByteArrayBitmapExtensions.AsByteArray(CurrentPic == null?DefaultPic : CurrentPic);

                string res = Convert.ToBase64String(picbyte);
                DataAccess.AddData(item.GetId(), item.title, item.description, item.date.ToString("d"), (item.completed ? 1 : 0), res);
                CurrentPic = DefaultPic;
            }
            else if (mode == 1)
            {
                myViewModels.UpdateTodoItem(id, textBox.Text, textBox1.Text, source, datepicker.Date, CurrentPic);
                byte[] picbyte = await ByteArrayBitmapExtensions.AsByteArray(CurrentPic == null?DefaultPic : CurrentPic);

                string res = Convert.ToBase64String(picbyte);
                DataAccess.UpdateData(id, textBox.Text, textBox1.Text, datepicker.Date.ToString("d"), 0, res);
                CurrentPic = DefaultPic;
            }
            else
            {
                myViewModels.RemoveTodoItem(id);
                DataAccess.DeleteData(id);
            }
            var dialog = new ContentDialog()
            {
                Title             = "成功",
                PrimaryButtonText = "确定",
                FullSizeDesired   = false,
            };
            await dialog.ShowAsync();

            this.id        = null;
            button.Content = "Create";
            if (mode == 1 || mode == 2)
            {
                button.Click -= Update;
                button.Click += Create;
            }
            textBox.Text          = "";
            textBox1.Text         = "";
            datepicker.Date       = DateTime.Now;
            image.Source          = new BitmapImage(new Uri("ms-appx:///Assets/IMG_0245.JPG"));
            DeleteItem.Visibility = Visibility.Collapsed;
            list.SelectedItem     = null;
            mode = 0;
        }  //管理创建更新删除
Ejemplo n.º 3
0
        private async void CreateDialog(int mode)
        {
            ListItemViewModels myViewModels = ListItemViewModels.GetInstance();
            ImageSource        source       = image.Source;

            if (mode == 0)
            {
                ListItem item = new ListItem(textBox.Text, textBox1.Text, source, datepicker.Date, CurrentPic);
                myViewModels.allItems.Add(item);
                MainPage.UpdateTile(textBox.Text, textBox1.Text, datepicker.Date);
                byte[] picbyte = await ByteArrayBitmapExtensions.AsByteArray(CurrentPic == null?DefaultPic : CurrentPic);

                string res = Convert.ToBase64String(picbyte);
                DataAccess.AddData(item.GetId(), item.title, item.description, item.date.ToString("d"), (item.completed ? 1 : 0), res);
                CurrentPic = null;
            }
            else if (mode == 1)
            {
                byte[] mybytes = await ByteArrayBitmapExtensions.AsByteArray(CurrentPic);

                string res = Convert.ToBase64String(mybytes);
                DataAccess.UpdateData(id, textBox.Text, textBox1.Text, datepicker.Date.ToString("d"), res);
                myViewModels.UpdateTodoItem(id, textBox.Text, textBox1.Text, source, datepicker.Date);
            }
            else
            {
                myViewModels.RemoveTodoItem(id);
            }
            var dialog = new ContentDialog()
            {
                Title             = "成功",
                PrimaryButtonText = "确定",
                FullSizeDesired   = false,
            };
            ContentDialogResult result = await dialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                Frame rootFrame = Window.Current.Content as Frame;
                rootFrame.GoBack();
            }
        }
Ejemplo n.º 4
0
        } //挂起操作

        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                ApplicationData.Current.LocalSettings.Values.Remove("newpage");
            }
            else
            {
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("newpage"))
                {
                    var composite = ApplicationData.Current.LocalSettings.Values["newpage"] as ApplicationDataCompositeValue;
                    for (int i = 0; i < ListItemViewModels.GetInstance().allItems.Count(); i++)
                    {
                        ListItemViewModels.GetInstance().allItems[i].completed = (bool)composite["ischecked" + i];
                    }
                    if ((int)composite["mode"] == 1)
                    {
                        button.Content        = "Update";
                        button.Click         -= Create;
                        button.Click         += Update;
                        DeleteItem.Visibility = Visibility.Visible;
                    }
                    textBox.Text    = (string)composite["title"];
                    textBox1.Text   = (string)composite["des"];
                    id              = (string)composite["id"];
                    datepicker.Date = (DateTimeOffset)composite["date"];
                    StorageFile pic = await ApplicationData.Current.LocalFolder.GetFileAsync("hangpic");

                    BitmapImage img = await ByteArrayBitmapExtensions.AsBitmapImage(pic);

                    image.Source = img;
                    ApplicationData.Current.LocalSettings.Values.Remove("newpage");
                    list.SelectedItem = ListItemViewModels.GetInstance().allItems.FirstOrDefault(j => j.GetId() == id);
                }
            }
        }
Ejemplo n.º 5
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.New)
            {
                if (e.Parameter != null)
                {
                    mode = 1;
                    var item = ListItemViewModels.GetInstance().allItems.FirstOrDefault(j => j.GetId() == e.Parameter as String);
                    id = e.Parameter as String;
                    List <string> data    = DataAccess.GetData();
                    byte[]        thispic = null;
                    int           i       = 0;
                    while (i < data.Count)
                    {
                        if (data[i] == id)
                        {
                            thispic = Convert.FromBase64String(data[i + 5]);
                            break;
                        }
                        i += 6;
                    }
                    StorageFile picfile = await ApplicationData.Current.LocalFolder.CreateFileAsync("tempic", CreationCollisionOption.ReplaceExisting);

                    await FileIO.WriteBytesAsync(picfile, thispic);

                    CurrentPic            = picfile;
                    button.Content        = "Update";
                    button.Click         -= Create;
                    button.Click         += Update;
                    textBox.Text          = item.title;
                    textBox1.Text         = item.description;
                    datepicker.Date       = item.date;
                    image.Source          = item.Image_Source;
                    DeleteItem.Visibility = Visibility.Visible;
                }
                else
                {
                    DeleteItem.Visibility = Visibility.Collapsed;
                    mode = 0;
                }
                base.OnNavigatedTo(e);
                ApplicationData.Current.LocalSettings.Values.Remove("newpage");
            }
            else
            {
                if (ApplicationData.Current.LocalSettings.Values.ContainsKey("newpage"))
                {
                    var composite = ApplicationData.Current.LocalSettings.Values["newpage"] as ApplicationDataCompositeValue;
                    if ((int)composite["mode"] == 1)
                    {
                        mode                  = 1;
                        button.Content        = "Update";
                        button.Click         -= Create;
                        button.Click         += Update;
                        DeleteItem.Visibility = Visibility.Visible;
                    }
                    else
                    {
                        mode = 0;
                    }
                    textBox.Text    = (string)composite["title"];
                    textBox1.Text   = (string)composite["des"];
                    datepicker.Date = (DateTimeOffset)composite["date"];
                    id = (string)composite["id"];
                    StorageFile pic = await ApplicationData.Current.LocalFolder.GetFileAsync("hangpic");

                    CurrentPic = pic;
                    BitmapImage img = await ByteArrayBitmapExtensions.AsBitmapImage(pic);

                    image.Source = img;
                    ApplicationData.Current.LocalSettings.Values.Remove("newpage");
                }
            }
        }