internal bool Save(FlowDocument fd, string diaryTime) { bool isok = false; DateTime datetime = Convert.ToDateTime(diaryTime); TextRange textRange = new TextRange(fd.ContentStart, fd.ContentEnd); DiaryModel diaOld = getTodayDiary(datetime); DiaryDAL diaryDal = new DiaryDAL(); TreeBLL treeBll = new TreeBLL(); //如果内容清空表示删除日记 if (textRange.Text.Length <= 0) { if (diaOld != null) { diaryDal.DeleteById(diaOld.ID); treeBll.Delete(diaOld.ID); } return true; } //保存日记内容 DiaryModel diaNew = new DiaryModel(); string contents = XamlHelper.ToXaml(fd); int pubTime = TimesTampHelper.ConvertDateTimeInt(datetime); string title = datetime.ToString("yyyy-MM-dd") + " " + datetime.DayOfWeek; diaNew.Title = title; diaNew.PubTime = pubTime; diaNew.Contents = contents; //查找是否有当天内容 if (diaOld != null) { diaNew.ID = diaOld.ID; diaNew.PubTime = diaOld.PubTime; return diaryDal.Update(diaNew); } int lastID = diaryDal.Insert(diaNew); isok = treeBll.Save(lastID, datetime); return isok; }
internal DateTime SelectTimeById(int? id) { int diaID = Convert.ToInt32(id); DiaryModel model = new DiaryDAL().GetById(diaID); return TimesTampHelper.GetTime(model.PubTime); }
private void tbSearch_KeyDown(object sender, KeyEventArgs e) { if (tbSearch.Text.Trim().Length <= 0) { e.Handled = true; return; } if (e.Key == Key.Enter) { BindTree(); TextRange textRange = new TextRange(rtbEdit.Document.ContentStart, rtbEdit.Document.ContentEnd); textRange.ApplyPropertyValue(TextElement.BackgroundProperty, rtbEdit.Background); Helper.SearchHelper.ReplaceKeywordColor(rtbEdit.Document, tbSearch.Text.Trim()); //搜索其他时间带有关键字的日记 DAL.DiaryDAL dal = new DAL.DiaryDAL(); List<Model.DiaryModel> listModel = dal.ListAll().ToList(); List<Model.TreeModel> listTreeView = tvSideBar.ItemsSource as List<Model.TreeModel>; List<Model.TreeModel> listTreeSrc = new DAL.TreeDAL().ListAll().ToList(); foreach (Model.DiaryModel model in listModel) { FlowDocument fd = Helper.XamlHelper.FromXaml(model.Contents); bool isFind = Helper.SearchHelper.isFindMatchedTextRanges(fd, tbSearch.Text.Trim()); if (isFind) { Model.TreeModel nodeSrc = listTreeSrc.Find(delegate(Model.TreeModel t) { return t.DiaID == model.ID; }); Model.TreeModel tvModel = listTreeView.Find(delegate(Model.TreeModel t) { return t.ID == nodeSrc.PID; }); Model.TreeModel tvNodeModel = tvModel.Nodes.Find(delegate(Model.TreeModel t) { return t.DiaID == nodeSrc.DiaID; }); TreeViewItem currentContainer = tvSideBar.ItemContainerGenerator.ContainerFromItem(tvModel) as TreeViewItem; currentContainer.SetValue(TreeViewItem.IsExpandedProperty, true); currentContainer.UpdateLayout(); TreeViewItem tvitem = currentContainer.ItemContainerGenerator.ContainerFromItem(tvNodeModel) as TreeViewItem; tvitem.Background = System.Windows.Media.Brushes.IndianRed; } } } }