コード例 #1
0
 private void AppBar_Save_Click(object sender, EventArgs e)
 {
     try
     {
         //获取编辑的NoteTable对象
         NoteTable note = (NoteTable)State["note"];
         if (string.IsNullOrEmpty(TxtTitle.Text))
         {
             MessageBox.Show("标题不能为空");
             return;
         }
         if (TxtTitle.Text.Length > 10)
         {
             MessageBox.Show("标题不能超过10个字符");
         }
         else
         {
             note.Title = TxtTitle.Text;
         }
         note.Content = TxtContent.Text;
         //保存数据库的改变
         noteDB.SubmitChanges();
         State["note"] = note;
         //保存完后直接跳到查询页面
         NavigationService.Navigate(new Uri(string.Format("/MainPage.xaml"), UriKind.Relative));
     }
     catch
     {
         MessageBox.Show("编辑出错!");
     }
 }
コード例 #2
0
        private void Delete_Click(object sender, RoutedEventArgs e)
        {
            var SelectedItem = sender as MenuItem;
            var temp         = noteCol.NoteTables.ToList().Find(o => o.ID == (int)SelectedItem.DataContext);

            noteDB.Notes.DeleteOnSubmit(temp);
            noteDB.SubmitChanges();
            //再次绑定
            bindList();
            MessageBox.Show("删除成功");
        }
コード例 #3
0
ファイル: Add.xaml.cs プロジェクト: Audery/Audery-Repository
        private void AppBar_Save_Click(object sender, EventArgs e)
        {
            if (this.TxtTitle.Text == "")
            {
                MessageBox.Show("请填写标题");
                return;
            }
            if (this.TxtTitle.Text.Length > 10)
            {
                MessageBox.Show("标题不能超过10个字符");
                return;
            }
            try
            {
                //连接数据库并初始化DataContext实例
                noteDB = new NoteDataContext(NoteDataContext.DBConnectionString);
                //创建一条表的数据
                NoteTable newNote = new NoteTable {
                    Title = TxtTitle.Text, Time = DateTime.Now.ToLongDateString(), Content = TxtContent.Text.ToString()
                };
                //添加绑定集合的数据
                noteCol.NoteTables.Add(newNote);
                //插入数据库
                noteDB.Notes.InsertOnSubmit(newNote);
                //保存数据库的改变
                noteDB.SubmitChanges();
            }
            catch (Exception)
            {
                MessageBox.Show("保存数据出错!");
            }


            //保存完后直接跳到查询页面
            NavigationService.Navigate(new Uri(string.Format("/MainPage.xaml"), UriKind.Relative));
        }