public bool Delete(Relation relation) { bool IsSuccess = false; using (ISession session = sessionFactory.OpenSession()) { ITransaction trans = session.BeginTransaction(); session.Delete(relation); trans.Commit(); if (trans.WasCommitted) { IsSuccess = true; } } return IsSuccess; }
public bool Save(Relation relation) { bool IsSuccess = false; using (ISession session=sessionFactory.OpenSession()) { ITransaction trans = session.BeginTransaction(); Guid id=(Guid)session.Save(relation); trans.Commit(); if (id != Guid.Empty) { IsSuccess = true; } } return IsSuccess; }
private void RemoveRelation(Relation removeRelation,Guid guidFlag) { bool IsRemoved = RelationsDAO.CreateRelationsDAO().Delete(removeRelation); if (!IsRemoved) { MessageBoxEx.Show(Constant.KM_REMOVE_REFERENCE_WRONG, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); } else { //rectlblContainer.Controls.RemoveAt(0); RectangleLabel removeLabel = null; foreach (RectangleLabel rlbl in rectlblContainer.Controls) { if (rlbl.Tag.ToString() == guidFlag.ToString()) { removeLabel = rlbl; } } if (removeLabel != null) { rectlblContainer.Controls.Remove(removeLabel); } } }
/// <summary> /// 选择标签,用于“选中标签”并同步到数据库 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Label_LabelCheckedEvent(object sender, LabelWithCheckEventArgs e) { if (CallBack) { return; } CheckBox lc = (CheckBox)sender; CheckState cs = lc.CheckState; curNode = tv_Folder.SelectedNode; if (curNode == null) { MessageBoxEx.Show(Constant.KM_WN_NODE_NOT_SELECTED, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); return; } if (cs.ToString() == "Checked") { //removeRelation = null; //labels = e.LabelText; labelsId = e.Id;//tagId guidFlag = Guid.NewGuid(); bool exist = CheckExistTag(curNode.Name.ToGuid(), e.Id); if (exist) { MessageBoxEx.Show(Constant.KM_WN_ADD_EXIST_LABEL_NOT_ALLOWED, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); CallBack = true; lc.CheckState = CheckState.Unchecked; CallBack = false; return; } if (labelDic.ContainsValue(labelsId)) { MessageBoxEx.Show(Constant.KM_WN_ADD_EXIST_LABEL_NOT_ALLOWED, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); return; } labelDic.Add(labelsId, guidFlag); //将关联存入数据库 if (curNode == null) { MessageBoxEx.Show(Constant.KM_WN_NODE_NOT_SELECTED, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); return; } if (curNode.Tag.ToString() == Enums.LEAVES.ToString()) { //int i = SQLHelper.AddRelations(curNode.Name.ToInt(), e.Id); removeRelation=AddRelation(curNode.Name.ToGuid(), e.Id, guidFlag,removeRelation); } } else if (cs.ToString() == "Unchecked") { //guidFlag = Guid.Empty; //将关联移出数据库 curNode = tv_Folder.SelectedNode; if (curNode == null) { MessageBoxEx.Show(Constant.KM_WN_NOTE_NOT_SELECTED, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); return; } if (curNode.Tag.ToString() == Enums.LEAVES.ToString()) { bool Nothing; Relation i = RelationsDAO.CreateRelationsDAO().IsExistTag(curNode.Name.ToGuid(),e.Id,out Nothing); if (removeRelation != null) { removeRelation = i; RemoveRelation(removeRelation, labelDic[e.Id]); labelDic.Remove(e.Id); } } } //txt_SelectedLabel.ControlText = ShowLabel(labelDic); //变更为 向Panel中添加Rectanglelabel 重点 }
/// <summary> /// 保存文章 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn_Save_Click(object sender, EventArgs e) { TreeNode node = tv_Folder.SelectedNode; if (node == null) { return; } if (node.Tag.ToString() == Enums.LEAVES.ToString()) { bool IsSuccess = false; //同时更新标题和内容(原方案) //int i = SQLHelper.UpdateContent(node.Name.ToInt(), txt_Title.Text, txt_Content.Text); //同时更新标题和内容(新方案) Model.PostContents.PostContent post = PostContentsDAO.CreatePostContentsDAO().GetEntityById(node.Name.ToGuid()); post.Enable = true; post.Type = true; post.Title = txt_Title.ControlText; post.Content = txt_Content.ControlText; post.ModifyDate = DateTime.Now; IsSuccess= PostContentsDAO.CreatePostContentsDAO().Update(post); //重要!同时更新文章标签,此处需要设计一个额外的控件,圆角矩形来存储Relation对象 if (rectlblContainer.Controls.Count > 0) { //循环添加Tag和Post的关系Relation foreach (Control rectLbl in rectlblContainer.Controls) { Model.PostContents.PostContent currentPost = PostContentsDAO.CreatePostContentsDAO().GetEntityById(node.Name.ToGuid());//Guid.NewGuid 临时替代真正的ID Model.Tags.Tag currentag = TagsDAO.CreateTagsDAO().GetTagById(rectLbl.Tag.ToGuid());//Guid.NewGuid 临时替代真正的ID Model.Relations.Relation relation = new Model.Relations.Relation(); relation.RelationId = Guid.NewGuid(); relation.Post = currentPost; relation.TagId = currentag.TagId; bool IsSaved = RelationsDAO.CreateRelationsDAO().Save(relation); } } //同时重新加载Treeview。已注掉,暂时没有必要Reload //BuildTree(this.tv_Folder, GetFolderSet()); if (IsSuccess) { SetReadOnly(true); MessageBoxEx.Show(Constant.KM_INFO_SAVE_OK,Constant.KM_TYPE_INFO , MessageBoxButtons.OK); tv_Folder.SelectedNode = node; } } else { MessageBoxEx.Show("请选择要保存的文章",Constant.KM_TYPE_WARN, MessageBoxButtons.OK); } }
private Relation AddRelation(Guid postId,Guid tagId, Guid guidFlag,Relation removeRelation) { //加非空校验; removeRelation.RelationId = Guid.NewGuid(); removeRelation.PostId = postId; removeRelation.TagId = tagId; bool IsSucess = RelationsDAO.CreateRelationsDAO().Save(removeRelation); Model.Tags.Tag tag = TagsDAO.CreateTagsDAO().GetTagById(tagId); //removeRelation = relation; if (IsSucess) { RectangleLabel label = new RectangleLabel(); label.ControlText = tag.TagContent; label.BorderColor = Color.Purple; label.BorderWidth = 1; label.InnerColor = Color.Transparent; //label.Tag = guidFlag; label.Tag = tagId; //计算位置 AddLabelToLocation(rectlblContainer, 2, label); //rectlblContainer.Controls.Add(label);//添加一个事件,E区显示已添加标签 } if (!IsSucess) { MessageBoxEx.Show(Constant.KM_ER_REFERENCE_ID_WRONG, Constant.KM_TYPE_WARN, MessageBoxButtons.OK); } return removeRelation; }