Ejemplo n.º 1
0
        private async void Create_Update_Click(object sender, RoutedEventArgs e)
        {
            string     alert = "";
            ITextRange range = detail.Document.GetRange(0, TextConstants.MaxUnitCount);

            if (title.Text.Trim() == "")
            {
                alert += "Title can't be empty!\n";
            }
            if (range.Text.Trim() == "")
            {
                alert += "Detail can't be empty!\n";
            }
            if (ddl.Date.Date.CompareTo(DateTime.Today) < 0)
            {
                alert += "The due date has passed!";
            }

            if (alert != "")
            {
                await new MessageDialog(alert).ShowAsync();
            }
            else if (create_update.Content.ToString() == "Create")
            {
                ViewModel.AddItem(ddl.Date.DateTime, Common.selectName, title.Text, range.Text);
                Common.selectName = "";
                await new MessageDialog("Create successfully!").ShowAsync();
                ViewModel.SelectedItem = null;
                Frame.Navigate(typeof(MainPage));
            }
            else
            {
                ViewModel.UpdateItem(ddl.Date.DateTime, Common.selectName, title.Text, range.Text);
                Common.selectName      = "";
                ViewModel.SelectedItem = null;
                await new MessageDialog("Update successfully!").ShowAsync();
                Frame.Navigate(typeof(MainPage));
            }
        }
Ejemplo n.º 2
0
        private async void Create_Update_Click(object sender, RoutedEventArgs e)
        {
            string     alert = "";
            ITextRange range = detail.Document.GetRange(0, TextConstants.MaxUnitCount);

            if (title.Text.Trim() == "")
            {
                alert += "Title can't be empty!\n";
            }
            if (range.Text.Trim() == "")
            {
                alert += "Detail can't be empty!\n";
            }
            if (ddl.Date.Date.CompareTo(DateTime.Today) < 0)
            {
                alert += "The due date has passed!";
            }

            if (alert != "")
            {
                await new MessageDialog(alert).ShowAsync();
            }
            else if (create_update.Content.ToString() == "Create")
            {
                try {
                    string sql = @"INSERT INTO Todo (date, imgname, title, detail, finish) VALUES (?,?,?,?,?)";
                    using (var res = conn.Prepare(sql)) {
                        res.Bind(1, ddl.Date.Date.ToString());
                        res.Bind(2, Common.selectName);
                        res.Bind(3, title.Text.Trim());
                        res.Bind(4, range.Text.Trim());
                        res.Bind(5, "false");
                        res.Step();
                        ViewModel.AddItem(conn.LastInsertRowId(), ddl.Date.DateTime, Common.selectName, title.Text.Trim(), range.Text.Trim(), false);
                        Common.selectName = "";
                        Cancle_Click(null, null);
                        ViewModel.SelectedItem = null;
                        await new MessageDialog("Create successfully!").ShowAsync();
                        Frame.Navigate(typeof(MainPage));
                    }
                } catch (Exception ex) {
                    Debug.WriteLine(ex.Message);
                    throw;
                }
            }
            else
            {
                try {
                    string sql = @"UPDATE Todo SET date = ?, imgname = ?, title = ?, detail = ? WHERE ID = ?";
                    using (var res = conn.Prepare(sql)) {
                        res.Bind(1, ddl.Date.Date.ToString());
                        res.Bind(2, Common.selectName);
                        res.Bind(3, title.Text.Trim());
                        res.Bind(4, range.Text.Trim());
                        res.Bind(5, ViewModel.SelectedItem.ID);
                        res.Step();
                        ViewModel.UpdateItem(ddl.Date.DateTime, Common.selectName, title.Text.Trim(), range.Text.Trim());
                        await new MessageDialog("Update successfully!").ShowAsync();
                        Frame.Navigate(typeof(MainPage));
                    }
                } catch (Exception ex) {
                    Debug.WriteLine(ex.Message);
                    throw;
                }
            }
        }