예제 #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>
        /// addRow: 添加树节点
        /// </summary>
        /// <param name="_table">表名</param>
        /// <param name="_keys">字段列表</param>
        /// <param name="_values">值列表</param>
        /// <returns></returns>
        public string addRow(string _table, string _keys, string _values)
        {
            if (Native.isEmpty(_keys) || Native.isEmpty(_values))
            {
                return("");
            }
            string _result = String.Empty;
            string sql     = MySqlString.getInsertStr(_table, _keys, _values, true);

            try
            {
                DBUtil.onExecSqlBefore(_CLASS, "addRow", sql);
                cmd.CommandText = @sql;
                state           = ConnectionState.Executing;
                object _rObj = cmd.ExecuteScalar();
                if (_rObj != null)
                {
                    _result = _rObj.ToString();
                }
            }
            catch (Exception e)
            {
                _result = Native.getErrorMsg(e.Message);
                DBUtil.onExecSqlError(_CLASS, "addRow", sql, e.Message);
            }
            return(_result);
        }
예제 #3
0
 /// <summary>
 /// insert: 根据表名(table), 字段(fields), 字段值(value)向数据库插入数据
 /// </summary>
 /// <param name="table">表名(table)</param>
 /// <param name="fields">字段(fields)</param>
 /// <param name="values">字段值(value)</param>
 /// <returns></returns>
 public string insert(string table, string fields, string values)
 {
     return(execQuery(MySqlString.getInsertStr(table, fields, values, true)));
 }