예제 #1
0
        /// <summary>
        /// addTreeNode: 添加树节点
        /// </summary>
        /// <param name="_table">表名</param>
        /// <param name="_pid">父节点ID</param>
        /// <param name="_keys">字段列表</param>
        /// <param name="_values">值列表</param>
        /// <returns>返回当前树节点ID</returns>
        public string addTreeNode(string _table, int _pid, string _keys, string _values)
        {
            string _val = String.Empty;

            if (_pid == 0)
            {
                return(execScalar(MySqlString.getInsertStr(_table, _keys, _values, true)));
            }
            Json _pre = execJson(MySqlString.getSelectStr(_table, "*", "id=" + _pid));

            if (_pre != null)
            {
                string _treeOrder = execScalar("select max(treeOrder)+1 from {0} where delFlag='0' and pid={1};", _table, _pid).ToString();
                if (Native.isNullEmpty(_treeOrder) || _treeOrder.ToLower() == "null")
                {
                    _treeOrder = "1";
                }
                string _k = _keys + ",parentPath,treeOrder,depth";
                string _v = _values + ",'" + _pre.getString("parentPath") + _pid + ",'," + _treeOrder + "," + (_pre.getInt("depth") + 1);
                if (_k.IndexOf("pid") == -1)
                {
                    _k += ",pid"; _v += "," + _pid;
                }
                _val = execScalar(MySqlString.getInsertStr(_table, _k, _v, true));
                execNonQuery(MySqlString.getUpdateStr(_table, "sons=sons+1", "id=" + _pid));
            }
            else
            {
                _val = Native.getErrorMsg("在表({0})中pid={1}的节点不存在", _table, _pid);
            }
            return(_val);
        }
예제 #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);
        }
예제 #3
0
 /// <summary>
 /// updateTreeNode: 更新树节点
 /// </summary>
 /// <param name="_table">表名</param>
 /// <param name="_keyFields">以逗号分隔开的类表</param>
 /// <param name="_jsonCondition">查询条件</param>
 /// <returns>查询结果</returns>
 public string queryTreeNodes(string _table, string _keyFields, string _jsonCondition)
 {
     return(execQuery(MySqlString.getSelectStr(_table, _keyFields, _jsonCondition, "treeOrder", "asc")));
 }
예제 #4
0
 /*单表的增删改查操作   --begin*/
 #region select: 根据表名(table), 查询字段(fields), 查询条件(whereCondiction), 排序字段(orderByColumn), 排序顺序(order)查询结果
 /// <summary>
 /// select: 根据表名(table), 查询字段(fields), 查询条件(whereCondiction)查询结果
 /// </summary>
 /// <param name="table">表名</param>
 /// <param name="fields">查询字段</param>
 /// <param name="whereCondiction">查询条件</param>
 /// <param name="orderByColumn">要排序的字段</param>
 /// <param name="order">排序方式: asc desc</param>
 /// <returns>查询结果</returns>
 public string select(string table, string fields, string whereCondiction, string orderByColumn, string order)
 {
     return(execQuery(MySqlString.getSelectStr(table, fields, whereCondiction, orderByColumn, order)));
 }