Пример #1
0
        protected override void OnSaving()
        {
            if (string.IsNullOrEmpty(this.称))
            {
                throw new Exception("名称不能为空。");
            }
            SalaryNode parent = GetSalaryNode(this.级);

            if (parent == null)
            {
                throw new Exception("指定的父节点不存在。");
            }
            else
            {
                //如果还没有分配位置标识
                if (string.IsNullOrEmpty(this.代码))
                {
                    this.代码  = GetNewCode(parent);
                    this.已启用 = false;
                    this.序号  = (parent.子节点.Count + 1).ToString(); //自动分配一个顺序号
                    this.类型  = parent.类型 + 1;
                    SalaryNode foundByCode = GetSalaryNode(this.代码);
                    if (foundByCode != null)
                    {
                        throw new Exception(String.Format("分配代码失败:系统中已存在同代码({0})的单元,请稍后再试。", this.代码));
                    }
                }
                else
                {
                    //如果移动目录
                    SalaryTreeNode cn = new SalaryTreeNode(this.代码);
                    if (cn.ParentNodePosition != parent.代码)
                    {
                        throw new Exception("节点的位置不能改变。");
                    }
                }
            }
            SalaryNode found = GetSalaryNode(this.级, this.称);

            if (found != null && found.标识 != this.标识)
            {
                throw new Exception("在同一个层中不能重复创建同名的节点单元。");
            }
            if (this.类型 == (int)节点类型.薪等)
            {
                if (this.Parent == null || this.Parent.代码 != "")
                {
                    throw new Exception("薪等类型的机构,只能从属于根节点。");
                }
            }
            base.OnSaving();
        }
Пример #2
0
        /// <summary>
        /// 获取一个新的编码
        /// </summary>
        /// <param name="parent">父节点</param>
        /// <returns></returns>
        private string GetNewCode(SalaryNode parent)
        {
            long   nextSeq    = 1;
            string parentcode = ""; //默认为根

            if (parent != null)
            {
                parentcode = parent.代码;
            }
            string last = GetLastChildSalaryNodeCode(parentcode); //父栏目的最后一个子栏目的位置

            if (last == null)                                     //如果父栏目下没有子栏目
            {
                nextSeq = 1;
                SalaryTreeNode cn = new SalaryTreeNode(parentcode, nextSeq);
                return(cn.Position);
            }
            else
            {
                SalaryTreeNode cn = new SalaryTreeNode(last);
                return(cn.NextSibling);
            }
        }