//提交表单时的处理 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"; }