public void ReadData() { using (var statement = conn.Prepare("SELECT Id,Title,Description,Date,Image, Completed FROM ListItem")) { while (SQLiteResult.ROW == statement.Step()) { TodoItemViewModels ViewModels = ((App)App.Current).ViewModels; bool completed = false; if (statement[5] != null && (string)statement[5] == "True") { completed = true; } TodoItem item = new TodoItem((string)statement[0], (string)statement[1], (string)statement[2], StringToDateTime((string)statement[3]), new Uri((string)statement[4]), completed); ViewModels.AddTodoItem(item); } } }
//提交表单时的处理 private void submit_Click(object sender, RoutedEventArgs e) { BitmapImage icon = (BitmapImage)image.Source; string warning = ""; if (title.Text.Equals("")) { warning += "The title should not be blank!\n"; } if (description.Text.Equals("")) { warning += "The description should not be blank!\n"; } if (datePicker.Date.Year < DateTime.Now.Year || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month < DateTime.Now.Month || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month.Equals(DateTime.Now.Month) && datePicker.Date.Day < DateTime.Now.Day) { warning += "The date should not be earlier than today!\n"; } if (!warning.Equals("")) { showMessageDialog(warning); return; } if (submit.Content.Equals("Create")) { String id = ViewModels.AddTodoItem(title.Text, description.Text, datePicker.Date, (BitmapImage)image.Source, imageType, imageType == "default" ? false : true); DataAccess.Instance.AddData(id, title.Text, description.Text, datePicker.Date, imageType); showMessageDialog("Create successfully!"); } else if (submit.Content.Equals("Update")) { ViewModels.UpdateTodoItem(id.Text, title.Text, description.Text, datePicker.Date, (BitmapImage)image.Source, imageType, imageType == "default" ? false : true); DataAccess.Instance.UpdateData(id.Text, title.Text, description.Text, datePicker.Date, imageType); showMessageDialog("Update successfully!"); } clearForm(); MainPage.latestInstance.showItemList(); MainPage.latestInstance.UpdatePrimaryTile(); }
private void submit_Click(object sender, RoutedEventArgs e) { string warning = ""; if (title.Text.Equals("")) { warning += "The title should not be blank!\n"; } if (description.Text.Equals("")) { warning += "The description should not be blank!\n"; } if (datePicker.Date.Year < DateTime.Now.Year || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month < DateTime.Now.Month || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month.Equals(DateTime.Now.Month) && datePicker.Date.Day < DateTime.Now.Day) { warning += "The date should not be earlier than today!\n"; } if (!warning.Equals("")) { showMessageDialog(warning, false); return; } var img = (ImageSource)imagePicker.Background.GetValue(ImageBrush.ImageSourceProperty); BitmapImage icon = (BitmapImage)img; if (ViewModels == null) { return; } if (submit.Content.Equals("Create")) { ViewModels.AddTodoItem(title.Text, description.Text, datePicker.Date, icon); showMessageDialog("Create successfully!", true); } else if (submit.Content.Equals("Update")) { ViewModels.UpdateTodoItem(id.Text, title.Text, description.Text, datePicker.Date, icon); showMessageDialog("Update successfully!", true); } }
private void submit_Click(object sender, RoutedEventArgs e) { BitmapImage icon = (BitmapImage)image.Source; string warning = ""; if (title.Text.Equals("")) { warning += "The title should not be blank!\n"; } if (description.Text.Equals("")) { warning += "The description should not be blank!\n"; } if (datePicker.Date.Year < DateTime.Now.Year || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month < DateTime.Now.Month || datePicker.Date.Year.Equals(DateTime.Now.Year) && datePicker.Date.Month.Equals(DateTime.Now.Month) && datePicker.Date.Day < DateTime.Now.Day) { warning += "The date should not be earlier than today!\n"; } if (!warning.Equals("")) { showMessageDialog(warning); return; } if (submit.Content.Equals("Create")) { ViewModels.AddTodoItem(title.Text, description.Text, datePicker.Date, icon); showMessageDialog("Create successfully!"); } else if (submit.Content.Equals("Update")) { ViewModels.UpdateTodoItem(id.Text, title.Text, description.Text, datePicker.Date, icon); showMessageDialog("Update successfully!"); } id.Text = ""; title.Text = ""; description.Text = ""; datePicker.Date = DateTime.Now; submit.Content = "Create"; }
private async void CreateClick(object sender, RoutedEventArgs e) { string message = string.Empty; if (ViewModels.EditingTitle.Length == 0) { message += "Title is empty! \n"; } if (ViewModels.EditingDetail.Length == 0) { message += "Detail is empty! \n"; } if (ViewModels.EditingDueDate < DateTime.Today) { message += "Due Date is before today! \n"; } if (message.Length == 0) { //message = "Correct!"; if (ViewModels.SelectedItem == null) { ViewModels.AddTodoItem(ViewModels.EditingTitle, ViewModels.EditingDetail, ViewModels.EditingDueDate, ViewModels.EditingImgSrc); ViewModels.ClearEdits(); } else { ViewModels.UpdateSelectedItem(ViewModels.EditingTitle, ViewModels.EditingDetail, ViewModels.EditingDueDate, ViewModels.EditingImgSrc); } //CirculationUpdate(); /* Frame frame = (Frame)Window.Current.Content; * if (frame.CanGoBack) frame.GoBack();*/ } else { var messageDialog = new MessageDialog(message); await messageDialog.ShowAsync(); } }
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; int count = (int)composite["count"]; int selected = (int)composite["selected"]; for (int i = 0; i < count; i++) { String id = (String)composite["id" + i]; String title = (String)composite["title" + i]; String description = (String)composite["description" + i]; bool completed = (bool)composite["completed" + i]; DateTimeOffset date = (DateTimeOffset)composite["date" + i]; String imageType = (String)composite["imageType" + i]; ViewModels.AddTodoItem(title, description, date, null, imageType, false, completed, id); } if (selected != -1) { ViewModels.SelectedItem = ViewModels.AllItems[selected]; } String oldState = (String)composite["state"]; if (oldState == stateList) { showItemList(); } else if (oldState == stateEdit) { showItemDetail(); } EditItem.latestInstance.Id = (String)composite["editId"]; EditItem.latestInstance.Title = (String)composite["editTitle"]; EditItem.latestInstance.Description = (String)composite["editDescription"]; EditItem.latestInstance.Date = (DateTimeOffset)composite["editDate"]; //读取imagePicker应有的图片 if (ApplicationData.Current.LocalSettings.Values["imagepicker"] != null) { StorageFile file; file = await StorageApplicationPermissions.FutureAccessList.GetFileAsync((String)ApplicationData.Current.LocalSettings.Values["imagepicker"]); IRandomAccessStream ir = await file.OpenAsync(FileAccessMode.Read); BitmapImage bmp = new BitmapImage(); await bmp.SetSourceAsync(ir); EditItem.latestInstance.setImage(bmp); ApplicationData.Current.LocalSettings.Values["imagepicker"] = null; } ApplicationData.Current.LocalSettings.Values.Remove("newpage"); } } }