Ejemplo n.º 1
0
        private async void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            TextBox tt           = (TextBox)TitleTextBox;
            TextBox dt           = (TextBox)DetailTextBox;
            string  ErrorMessage = "";

            if (tt.Text == "")
            {
                ErrorMessage += "Title不能为空!\n";
            }
            if (dt.Text == "")
            {
                ErrorMessage += "Detail不能为空!\n";
            }
            DatePicker dp = (DatePicker)Datepicker;

            if (dp.Date < DateTime.Today.Date)
            {
                ErrorMessage += "DueDate不正确!\n";
            }
            if (ErrorMessage != "")
            {
                await new MessageDialog(ErrorMessage).ShowAsync();
            }
            else
            {
                if (this.CreateButton.Content.ToString() == "Create")
                {
                    long newId = 1;
                    for (long i = 1; i < 10; i++)
                    {
                        if (!ViewModel.usingId[i])
                        {
                            ViewModel.usingId[i] = true;
                            newId = i;
                            break;
                        }
                    }
                    InsertItem(newId, TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime.ToString(), false, imgPath);
                    this.ViewModel.AddItemList(newId, TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime, Image.Source, false);
                    await new MessageDialog("Create successfully!").ShowAsync();
                    this.ViewModel.SelectedItem = null;
                    Frame.Navigate(typeof(MainPage), ViewModel);
                }
                else
                {
                    UpdateItem(ViewModel.SelectedItem.id, TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime.ToString(), ViewModel.SelectedItem.ischeck, imgPath);
                    ViewModel.UpdateItemList(ViewModel.SelectedItem.id, TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime, Image.Source, ViewModel.SelectedItem.ischeck);
                    await new MessageDialog("Update successfully!").ShowAsync();
                    ViewModel.SelectedItem = null;
                    Frame.Navigate(typeof(MainPage), ViewModel);
                }
            }
        }
Ejemplo n.º 2
0
        private async void CreateButton_Click(object sender, RoutedEventArgs e)
        {
            TextBox tt           = (TextBox)TitleTextBox;
            TextBox dt           = (TextBox)DetailTextBox;
            string  ErrorMessage = "";

            if (tt.Text == "")
            {
                ErrorMessage += "Title不能为空!\n";
            }
            if (dt.Text == "")
            {
                ErrorMessage += "Detail不能为空!\n";
            }
            DatePicker dp = (DatePicker)Datepicker;

            if (dp.Date < DateTime.Today.Date)
            {
                ErrorMessage += "DueDate不正确!\n";
            }
            if (ErrorMessage != "")
            {
                await new MessageDialog(ErrorMessage).ShowAsync();
            }
            else
            {
                if (this.CreateButton.Content.ToString() == "Create")
                {
                    this.ViewModel.AddItemList(TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime, Image.Source);
                    await new MessageDialog("Create successfully!").ShowAsync();
                    this.ViewModel.SelectedItem = null;
                    Frame.Navigate(typeof(MainPage), ViewModel);
                }
                else
                {
                    ViewModel.UpdateItemList(TitleTextBox.Text, DetailTextBox.Text, Datepicker.Date.DateTime, Image.Source);
                    await new MessageDialog("Update successfully!").ShowAsync();
                    ViewModel.SelectedItem = null;
                    Frame.Navigate(typeof(MainPage), ViewModel);
                }
            }
        }