示例#1
0
        /// <summary>
        /// 将当前章节升级
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public bool OutlineToLeft(int couid, int id)
        {
            //当前对象
            Outline current = Gateway.Default.From <Outline>().Where(Outline._.Ol_ID == id).ToFirst <Outline>();
            //当前父对象
            Outline parent = Gateway.Default.From <Outline>().Where(Outline._.Ol_ID == current.Ol_PID).ToFirst <Outline>();

            //顶级列表
            Song.Entities.Outline[] top = Gateway.Default.From <Outline>()
                                          .Where(Outline._.Ol_Tax > parent.Ol_Tax && Outline._.Cou_ID == current.Cou_ID && Outline._.Ol_PID == parent.Ol_PID)
                                          .OrderBy(Outline._.Ol_Tax.Asc).ToArray <Outline>();
            //当前父的同级中,比自己大的子级(即自身后面的)
            Song.Entities.Outline[] child = Gateway.Default.From <Outline>()
                                            .Where(Outline._.Ol_Tax > current.Ol_Tax && Outline._.Cou_ID == current.Cou_ID && Outline._.Ol_PID == current.Ol_PID)
                                            .OrderBy(Outline._.Ol_Tax.Asc).ToArray <Outline>();
            //
            using (DbTrans tran = Gateway.Default.BeginTrans())
            {
                try
                {
                    current.Ol_PID   = 0;
                    current.Ol_Level = 0;
                    current.Ol_Tax   = parent.Ol_Tax + 1;
                    current.Attach();
                    tran.Save <Outline>(current);
                    //处理升级后的顶级排序问题
                    for (int i = 0; i < top.Length; i++)
                    {
                        top[i].Ol_Tax = top[i].Ol_Tax + 1;
                        top[i].Attach();
                        tran.Save <Outline>(top[i]);
                    }
                    //处理升级后,同级的子级的排序号
                    for (int i = 0; i < child.Length; i++)
                    {
                        child[i].Ol_Tax   = i + 1;
                        child[i].Ol_PID   = current.Ol_ID;
                        child[i].Ol_Level = 1;
                        child[i].Attach();
                        tran.Save <Outline>(child[i]);
                    }
                    tran.Commit();
                }
                catch
                {
                    tran.Rollback();
                    throw;
                }
                finally
                {
                    tran.Close();
                }
            }
            this.OnSave(null, EventArgs.Empty);
            return(true);
        }