示例#1
0
        public static void DoPaste(PasteDataSourceEnum pdstype, PasteAsEnum patype, string targetId, params object[] pasteIds)
        {
            if (!String.IsNullOrEmpty(targetId) && pasteIds.Length > 0)
            {
                IList <SysEnumeration> allnodes = SysEnumeration.FindAllByPrimaryKeys(pasteIds);
                IList <SysEnumeration> nodes    = FilterChildNodes(allnodes);

                // 只提取最高节点或无父子关联的节点进行粘贴
                foreach (SysEnumeration tnode in nodes)
                {
                    switch (pdstype)
                    {
                    case PasteDataSourceEnum.Copy:
                        if (patype == PasteAsEnum.Sibling)
                        {
                            tnode.CopyAsSibling(targetId);
                        }
                        else if (patype == PasteAsEnum.Child)
                        {
                            tnode.CopyAsChild(targetId);
                        }
                        break;

                    case PasteDataSourceEnum.Cut:
                        if (patype == PasteAsEnum.Sibling)
                        {
                            tnode.MoveAsSibling(targetId);
                        }
                        else if (patype == PasteAsEnum.Child)
                        {
                            if (tnode.ParentID == targetId)
                            {
                                tnode.ChangePosition(0);
                            }
                            else
                            {
                                tnode.MoveAsChild(targetId);
                            }
                        }
                        break;
                    }
                }
            }
        }
示例#2
0
        private void DoPaste()
        {
            IList <string> idList  = RequestData.GetList <string>("IdList");
            string         type    = RequestData.Get <string>("type", String.Empty);
            string         tid     = RequestData.Get <string>("tid", String.Empty);     // 目标节点id
            string         pdstype = RequestData.Get <string>("pdstype", String.Empty); // 粘贴数据来源类型

            if (!String.IsNullOrEmpty(tid))
            {
                A_TaskWBS target = A_TaskWBS.Find(tid);

                PasteDataSourceEnum pdsenum = PasteDataSourceEnum.Unknown;
                PasteAsEnum         paenum  = PasteAsEnum.Other;

                if (pdstype == "cut")
                {
                    pdsenum = PasteDataSourceEnum.Cut;
                }
                else if (pdstype == "copy")
                {
                    pdsenum = PasteDataSourceEnum.Copy;
                }

                if (type == "sib")
                {
                    paenum = PasteAsEnum.Sibling;
                }
                else if (type == "sub")
                {
                    paenum = PasteAsEnum.Child;
                }

                if (pdsenum != PasteDataSourceEnum.Unknown && paenum != PasteAsEnum.Other)
                {
                    // 粘贴操作
                    A_TaskWBS.DoPaste(pdsenum, paenum, tid, idList.ToArray());
                }
            }
        }
示例#3
0
        /// <summary>
        /// 获取本节点复制表
        /// </summary>
        /// <returns></returns>
        private DataTable GetCopyTable(T target, PasteAsEnum patype)
        {
            string sql = String.Format("SELECT * FROM {0} WHERE {1} = '{2}' OR [{3}] LIKE '%{2}%'",
                                       TableName, Prop_ID, this.ID,
                                       Prop_Path);

            DataTable dt = DataHelper.QueryDataTable(sql);

            Hashtable noMapping = new Hashtable();    // 新旧id映射
            Hashtable onMapping = new Hashtable();    // 旧新id映射

            object nid, oid;

            foreach (DataRow trow in dt.Rows)
            {
                nid = GenerateNewID();
                oid = trow[Prop_ID];

                noMapping.Add(nid, oid);
                onMapping.Add(oid, nid);
            }

            int    adjustLevel = 0;            // 调整PathLevel级别
            string adjustPath  = String.Empty; // 调整的路径
            string toid;                       // 原id
            string topath = String.Empty;      // 临时原路径
            string tnpath = String.Empty;      // 临时新路径

            if (patype == PasteAsEnum.Sibling)
            {
                adjustLevel = target.PathLevel.GetValueOrDefault() - this.PathLevel.GetValueOrDefault();
                adjustPath  = target.Path;
            }
            else if (patype == PasteAsEnum.Child)
            {
                adjustLevel = target.PathLevel.GetValueOrDefault() - this.PathLevel.GetValueOrDefault() + 1;
                adjustPath  = CombinePath(target.Path, target.ID);
            }

            // 替换ParentID 和 PathLevel
            foreach (DataRow trow in dt.Rows)
            {
                toid = ObjectHelper.ConvertValue <string>(trow[Prop_ID]);

                // 替换ID
                trow[Prop_ID] = onMapping[toid];

                if (toid != this.ID.ToString())
                {
                    // 替换ParentID
                    trow[Prop_ParentID] = onMapping[trow[Prop_ParentID]];

                    // 替换PathLevel
                    trow[Prop_PathLevel] = ObjectHelper.ConvertValue <int>(trow[Prop_PathLevel], 0) + adjustLevel;

                    topath = trow[Prop_Path].ToString();

                    if (!String.IsNullOrEmpty(this.Path))
                    {
                        // 去掉原前导路径
                        topath = topath.Replace(this.Path, String.Empty).TrimStart(PathDivChar);
                    }

                    string[] tpathArr = topath.Split(PathDivChar);

                    for (int i = 0; i < tpathArr.Length; i++)
                    {
                        tpathArr[i] = onMapping[tpathArr[i]].ToString();
                    }

                    // 组合新路径
                    tnpath = StringHelper.Join(tpathArr, PathDivChar);

                    // 替换Path
                    if (!String.IsNullOrEmpty(adjustPath))
                    {
                        tnpath = CombinePath(adjustPath, tnpath);
                    }

                    trow[Prop_Path] = tnpath;
                }
                else
                {
                    if (patype == PasteAsEnum.Sibling)
                    {
                        trow[Prop_ParentID]  = target.ParentID;
                        trow[Prop_PathLevel] = target.PathLevel;
                        trow[Prop_SortIndex] = target.SortIndex + SortInterval;
                    }
                    else if (patype == PasteAsEnum.Child)
                    {
                        trow[Prop_ParentID]  = target.ID;
                        trow[Prop_PathLevel] = target.PathLevel - 1;
                        trow[Prop_SortIndex] = SortStartIndex;
                    }

                    trow[Prop_Path] = adjustPath;
                }
            }

            return(dt);
        }