Beispiel #1
0
        public bool UpdateTreeDataParent(int TreeDataSourceId, string sourcePKValue, string targetPKValue, ref string errorMsg)
        {
            CPTreeDataSource ds = this._CPTreeDataSourceRep.Get(TreeDataSourceId);

            if (string.IsNullOrEmpty(ds.MainTableName))
            {
                errorMsg = "数据源未配置数据表名";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.PKField))
            {
                errorMsg = "数据源未配置表主键字段";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.ParentIdField))
            {
                errorMsg = "数据源未配置存储父级ID的字段名";
                return(false);
            }
            DbHelper _helper = new DbHelper(ds.DbIns, CPAppContext.CurDbType());
            string   strSql2 = "UPDATE   " + ds.MainTableName + " SET " + ds.ParentIdField + "='" + targetPKValue + "'  WHERE " + ds.PKField + " in (" + sourcePKValue + ")";

            _helper.ExecuteNonQuery(strSql2);
            return(true);
        }
Beispiel #2
0
        public bool DeleteTreeData(int TreeDataSourceId, string pkFieldValue, ref string errorMsg)
        {
            CPTreeDataSource ds = this._CPTreeDataSourceRep.Get(TreeDataSourceId);

            if (string.IsNullOrEmpty(ds.MainTableName))
            {
                errorMsg = "数据源未配置数据表名";
                return(false);
            }
            if (string.IsNullOrEmpty(ds.PKField))
            {
                errorMsg = "数据源未配置表主键字段";
                return(false);
            }

            List <string> pkCol = new List <string>();

            pkCol.Add(pkFieldValue);
            DbHelper _helper = new DbHelper(ds.DbIns, CPAppContext.CurDbType());

            if (string.IsNullOrEmpty(ds.ParentIdField) == false)
            {
                //递归删除数据
                string    strSql = "SELECT " + ds.PKField + " FROM " + ds.MainTableName + " WHERE " + ds.ParentIdField;
                DataTable dt     = _helper.ExecuteDataSet(strSql + "='" + pkFieldValue + "'").Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    pkCol.Add(dr[0].ToString());
                    //获取子节点
                    List <string> tCol = this.GetChildPK(strSql, dr[0].ToString(), ds.DbIns);
                    pkCol.AddRange(tCol);
                }
                dt.Dispose();
            }

            string ids = "";

            pkCol.ForEach(t => {
                if (string.IsNullOrEmpty(ids))
                {
                    ids = "'" + t + "'";
                }
                else
                {
                    ids += ",'" + t + "'";
                }
            });
            string strSql2 = "DELETE FROM " + ds.MainTableName + " WHERE " + ds.PKField + " in (" + ids + ")";

            _helper.ExecuteNonQuery(strSql2);
            return(true);
        }