Exemplo n.º 1
0
        /// <summary>
        /// deleteTreeNode: 删除树节点
        /// </summary>
        /// <param name="_table">表名</param>
        /// <param name="_id">要删除的节点ID</param>
        /// <returns>操作结果</returns>
        public string deleteTreeNode(string _table, int _id)
        {
            MySqlTrans _trans = new MySqlTrans(this);
            string     _val   = String.Empty;

            try
            {
                string _pid = _trans.execScalar("select pid from {0} where id={1};", _table, _id);
                if (!Native.isEmpty(_pid))
                {
                    string _sql = @"update {0} set delFlag=1 where pid={1} or id={1};update {0} set sons=sons-1 where id={2};";
                    _val = _trans.execNonQuery(_sql, _table, _id, _pid).ToString();
                    _trans.commit();
                }
                else
                {
                    _val = Native.getErrorMsg("在表({0})中id={1}的节点不存在", _table, _id);
                }
            }
            catch (Exception e)
            {
                _val = Native.getErrorMsg(e.Message);
                _trans.rollback();
            }
            finally
            {
                _trans.close();
            }
            return(_val);
        }
Exemplo n.º 2
0
        /// <summary>
        /// orderTreeNode: 根据升序或降序尽心修改顺序
        /// </summary>
        /// <param name="_table">表名</param>
        /// <param name="_id">要排序操作的ID值</param>
        /// <param name="_ifAsc">是否按照升序方式排序, true: 升序, false: 降序</param>
        /// <returns></returns>
        public string orderTreeNode(string _table, int _id, bool _ifAsc)
        {
            MySqlTrans _trans = new MySqlTrans(this);
            string     _val = String.Empty, _sign = ">", _fn = "min";

            if (_ifAsc)
            {
                _sign = "<"; _fn = "max";
            }
            try
            {
                Json _node = _trans.execJson(MySqlString.getSelectStr(_table, "pid, treeOrder", "id=" + _id));
                if (_node != null)
                {
                    int  _pid = _node.getInt("pid"), _treeOrder = _node.getInt("treeOrder");
                    Json _target = _trans.execJson("select top 1 id,treeOrder from {0} where pid={1} and treeOrder=(select {2}(treeOrder) from {0} where pid={1} and treeOrder{3}{4});", _table, _pid, _fn, _sign, _treeOrder);
                    if (_target != null)
                    {
                        string _sql = "update {0} set treeOrder={1} where id={2};";
                        _sql  = MySqlString.format(_sql, _table, _target.getValue("treeOrder"), _id);
                        _sql += "update {0} set treeOrder={1} where id={2};";
                        _sql  = MySqlString.format(_sql, _table, _treeOrder, _target.getValue("id"));
                        _trans.execNonQuery(_sql);
                    }
                    else
                    {
                        Native.writeToPage(Native.getErrorMsg("id是{0}的记录指针已经是第一行或最后一行", _id));
                    }
                }
                else
                {
                    Native.writeToPage(Native.getErrorMsg("在表({0})中不存在id是{1}的记录", _table, _id));
                }
                _trans.commit();
            }
            catch (Exception e)
            {
                _val = Native.getErrorMsg(e.Message);
                _trans.rollback();
            }
            finally
            {
                _trans.close();
            }
            return(_val);
        }
Exemplo n.º 3
0
        /// <summary>
        /// moveTreeNode: 移动树节点
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="id"></param>
        public void moveTreeNode(string table, int id)
        {
            MySqlTrans _trans = new MySqlTrans(this);
            string     _val   = String.Empty;

            try
            {
                _val = _trans.execReader("");
                _trans.commit();
            }
            catch (Exception e)
            {
                _val = Native.getErrorMsg(e.Message.ToString());
                _trans.rollback();
            }
            finally
            {
                _trans.close();
            }
        }
Exemplo n.º 4
0
        /*树状表结构的基本操作   --begin*/
        #region updateTreeOrder: 更新树结构的treeOrder
        /// <summary>
        /// updateTreeOrder: 更新树结构的treeOrder
        /// </summary>
        /// <param name="table">表名</param>
        /// <param name="condition">where条件 如: id=12</param>
        /// <param name="treeOrder">更新之后的treeOrder值</param>
        /// <returns></returns>
        public string updateTreeOrder(string table, string condition, int treeOrder)
        {
            MySqlTrans _trans = new MySqlTrans(this);
            string     _val   = String.Empty;

            try
            {
                _val = _trans.execReader("");
                _trans.commit();
            }
            catch (Exception e)
            {
                _val = Native.getErrorMsg(e.Message.ToString());
                _trans.rollback();
            }
            finally
            {
                _trans.close();
            }
            return(_val);
        }
Exemplo n.º 5
0
        /// <summary>
        /// addTreeNode: 添加树节点
        /// </summary>
        /// <param name="_table">表名</param>
        /// <param name="_pid">父节点ID</param>
        /// <param name="_key">字段列表</param>
        /// <param name="_values">值列表</param>
        /// <returns>返回当前树节点ID</returns>
        public string addTreeNode(string _table, int _pid, string jsonStr)
        {
            MySqlTrans _trans = new MySqlTrans(this);
            string     _val   = String.Empty;

            try
            {
                string[] _kv = MConvert.toKV(jsonStr);
                _val = _trans.addTreeNode(_table, _pid, _kv[0], _kv[1]);
                _trans.commit();
            }
            catch (Exception e)
            {
                _trans.rollback();
                _val = Native.getErrorMsg(e.Message);
            }
            finally
            {
                _trans.close();
            }
            return(_val);
        }