Beispiel #1
0
        public void updateMXField(FBDataModelObjects objectModel, TreeNode tree)
        {
            this.tree = Newtonsoft.Json.JsonConvert.DeserializeObject <JFBTreeStruct>(objectModel.Tree);
            var sql = "update {0} set {1}='0' where {2}='{3}'";

            if (!string.IsNullOrEmpty(this.tree.isdetail))
            {
                var datatypeList = objectModel.ColList.Where(p => p.Code == this.tree.isdetail).ToList();
                if (datatypeList.Count == 1 && datatypeList[0].DataType == "6")
                {
                    //bit类型
                    sql = "update {0} set {1}=@0 where {2}='{3}'";
                    Sql execSql = new Sql(string.Format(sql, objectModel.Code, this.tree.isdetail, objectModel.PKCOLName, tree.dataid), false);
                    db.Execute(execSql);
                }
                else
                {
                    Sql execSql = new Sql(string.Format(sql, objectModel.Code, this.tree.isdetail, objectModel.PKCOLName, tree.dataid));
                    db.Execute(execSql);
                }
            }
            if (!string.IsNullOrEmpty(this.tree.ischild) && this.tree.ischild != this.tree.isdetail)
            {
                // 是否child定义并且 两个字段不一致 才更新 一致的话不更新
                var datatypeList = objectModel.ColList.Where(p => p.Code == this.tree.ischild).ToList();


                if (datatypeList.Count == 1 && datatypeList[0].DataType == "6")
                {
                    //bit类型
                    sql = "update {0} set {1}=@0 where {2}='{3}'";
                    Sql execSql = new Sql(string.Format(sql, objectModel.Code, this.tree.ischild, objectModel.PKCOLName, tree.dataid), false);
                    db.Execute(execSql);
                }
                else
                {
                    Sql execSql = new Sql(string.Format(sql, objectModel.Code, this.tree.ischild, objectModel.PKCOLName, tree.dataid));
                    db.Execute(execSql);
                }
            }
        }
        public static List <Dictionary <string, object> > getDSTreeDataALL(string dsID, string keyWord, string filter, string order, Dictionary <string, object> formstate, Database Db)
        {
            FBDataSource model = getDSModel(dsID, Db);

            Database ywDB = getModelDataSource(model.DsCode);

            var type = model.DsType;
            var sql  = model.SqlInfo;



            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            // 获取树形取数的Sql信息
            StringBuilder sb = new StringBuilder();

            sb.Append(sql);

            string sbInit = sb.ToString();

            //过滤条件
            if (!string.IsNullOrEmpty(filter))
            {
                StringBuilder    sbfilter = new StringBuilder();
                List <Condition> filters  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Condition> >(filter);
                sb.AppendFormat(" {0} ", ConditionParser.Serialize(filters));
            }



            JFBTreeStruct treeInfo = model.treeInfo;

            //排序
            if (!string.IsNullOrEmpty(order))
            {
                List <SortCondition> orders = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SortCondition> >(order);
                if (orders.Count > 0)
                {
                    sb.AppendFormat(" order by {0} ", SortConditionParser.Serialize(orders));
                }
            }
            result = ywDB.Fetch <Dictionary <string, object> >(dealSQL(sb.ToString(), formstate));



            if (!string.IsNullOrEmpty(keyWord))
            {
                string qrySql     = string.Format(" and  {0} like '{1}%'", model.treeInfo.treename, keyWord);
                var    resultList = ywDB.Fetch <Dictionary <string, object> >(dealSQL(sbInit, formstate).Append(new Sql(qrySql)));

                foreach (var item in result)
                {
                    // 获取命中信息
                    var res = resultList.Where(p => p[model.treeInfo.grade].ToString().StartsWith(item[model.treeInfo.grade].ToString()));
                    if (res.ToList().Count > 0)
                    {
                        item["_istarget"] = "1";
                        item["isexpand"]  = true;
                    }
                }
            }


            return(result);
        }
        public static List <Dictionary <string, object> > getDSTreeData(string dsID, string level, string path, string parentID, string keyWord, string filter, string order, Database Db)
        {
            FBDataSource model = getDSModel(dsID, Db);

            Database ywDB = getModelDataSource(model.DsCode);

            var type = model.DsType;
            var sql  = model.SqlInfo;
            List <Dictionary <string, object> > result = new List <Dictionary <string, object> >();

            // 获取树形取数的Sql信息
            StringBuilder sb = new StringBuilder();

            sb.Append(sql);

            //过滤条件
            if (!string.IsNullOrEmpty(filter))
            {
                StringBuilder    sbfilter = new StringBuilder();
                List <Condition> filters  = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Condition> >(filter);
                sb.AppendFormat(" {0} ", ConditionParser.Serialize(filters));
            }

            JFBTreeStruct treeInfo      = model.treeInfo;
            var           isParentModel = true;

            if (string.IsNullOrEmpty(treeInfo.parentid))
            {
                isParentModel = false;
            }

            #region 获取子节点数据
            if (isParentModel)
            {
                if (string.IsNullOrEmpty(parentID) && !string.IsNullOrEmpty(treeInfo.rootvalue))
                {
                    parentID = treeInfo.rootvalue;
                }
                sb.AppendFormat(" and {0}='{1}'", model.treeInfo.parentid, parentID);
            }
            else
            {
                if (string.IsNullOrEmpty(level))
                {
                    level = model.treeInfo.rootlevel;
                }
                else
                {
                    level = (Convert.ToInt32(level) + 1).ToString();
                }
                if (string.IsNullOrEmpty(path))
                {
                    sb.AppendFormat(" and {0}='{1}' ", model.treeInfo.level, level);
                }
                else
                {
                    sb.AppendFormat(" and  {0}='{1}' and {2} like '{3}%'", model.treeInfo.level, level, model.treeInfo.grade, path);
                }
            }
            #endregion



            //排序
            if (!string.IsNullOrEmpty(order))
            {
                List <SortCondition> orders = Newtonsoft.Json.JsonConvert.DeserializeObject <List <SortCondition> >(order);
                if (orders.Count > 0)
                {
                    sb.AppendFormat(" order by {0} ", SortConditionParser.Serialize(orders));
                }
            }
            result = ywDB.Fetch <Dictionary <string, object> >(sb.ToString());



            if (!string.IsNullOrEmpty(keyWord))
            {
                string qrySql     = string.Format(" and {0} like '{1}%'", model.treeInfo.treename, keyWord);
                var    resultList = ywDB.Fetch <Dictionary <string, object> >(new Sql(sql).Append(new Sql(qrySql)));

                foreach (var item in result)
                {
                    // 获取命中信息
                    var res = resultList.Where(p => p[model.treeInfo.grade].ToString().StartsWith(item[model.treeInfo.grade].ToString()));
                    if (res.ToList().Count > 0)
                    {
                        item["_istarget"] = "1";
                    }
                }
            }


            return(result);
        }