/// <summary>
        /// 获取PKCount
        /// </summary>
        /// <param name="mongoDbOp"></param>
        /// <param name="tableName"></param>
        /// <param name="maxCount"></param>
        /// <returns></returns>
        public static void UpdateMaxCount(MongoOperation mongoDbOp, string tableName, int maxCount)
        {
            var maxMatCountObj = mongoDbOp.FindOne("TablePKCounter", Query.EQ("tbName", tableName));

            if (maxMatCountObj != null)
            {
                var newObj = new BsonDocument().Add("count", maxCount);
                mongoDbOp.Save("TablePKCounter", Query.EQ("tbName", tableName), newObj);
            }
            else
            {
                var newObj = new BsonDocument().Add("tbName", tableName).Add("count", maxCount);
                mongoDbOp.Save("TablePKCounter", newObj);
            }
        }
        /// <summary>
        /// 获取PKCount
        /// </summary>
        /// <param name="mongoDbOp"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static int GetMaxCount(MongoOperation mongoDbOp, string tableName)
        {
            var maxMatCountObj = mongoDbOp.FindOne("TablePKCounter", Query.EQ("tbName", tableName));

            if (maxMatCountObj != null)
            {
                return(maxMatCountObj.Int("count"));
            }
            else
            {
                var newObj = new BsonDocument().Add("tbName", tableName).Add("count", 1);
                var result = mongoDbOp.Save("TablePKCounter", newObj);
                return(2);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 获取顶级存储语句
        /// </summary>
        /// <param name="varList"></param>
        /// <param name="sourceDic"></param>
        /// <returns></returns>
        public List <StorageData> GetStorageDatas(MongoOperation _dbOp, List <VarRule> varList, Dictionary <string, BsonDocument> sourceDic)
        {
            List <StorageData> resultList = new List <StorageData>();

            #region 处理变量
            List <VarRule> allVarList = new List <VarRule>();

            if (varList != null)
            {
                allVarList.AddRange(varList);
            }

            if (this.Vars != null)
            {
                foreach (var tempVar in this.Vars)
                {
                    if (tempVar.Value.Type == DataObjectType.AValue) //如果是一个值,添加到变量中去
                    {
                        allVarList.Add(tempVar);
                    }
                    else if (tempVar.Value.Type == DataObjectType.ARecord)
                    {
                        BsonDocument tempBson = _dbOp.FindOne(tempVar.Value.TableName, tempVar.Value.GetQuery(allVarList, sourceDic));

                        if (sourceDic == null)
                        {
                            sourceDic = new Dictionary <string, BsonDocument>();
                        }

                        sourceDic.Add(tempVar.Name, tempBson);
                    }
                }
            }
            #endregion

            #region 处理顶级存储语句
            if (this.Storages != null)
            {
                foreach (var tempStorage in this.Storages)
                {
                    StorageData tempData = new StorageData();

                    tempData.Name     = tempStorage.Data.TableName;                                  //操作表名
                    tempData.Query    = tempStorage.Data.GetQuery(allVarList, sourceDic);            //定位记录
                    tempData.Type     = tempStorage.Type;                                            //操作类型
                    tempData.Document = tempStorage.Data.GetDataBsonDocument(allVarList, sourceDic); //操作数据

                    resultList.Add(tempData);
                }
            }
            #endregion

            #region 处理子循环语句
            if (this.Foreachs != null)
            {
                foreach (var tempForeach in this.Foreachs)
                {
                    List <BsonDocument> tempDocList = _dbOp.FindAll(tempForeach.Object.TableName, tempForeach.Object.GetQuery(allVarList, sourceDic)).ToList();

                    foreach (var tempDoc in tempDocList)     //循环处理循环对象
                    {
                        if (sourceDic == null)
                        {
                            sourceDic = new Dictionary <string, BsonDocument>();
                        }

                        if (sourceDic.ContainsKey(tempForeach.Name))
                        {
                            sourceDic[tempForeach.Name] = tempDoc;
                        }
                        else
                        {
                            sourceDic.Add(tempForeach.Name, tempDoc);
                        }

                        List <StorageData> foreachResult = tempForeach.GetStorageDatas(_dbOp, allVarList, sourceDic);  //获取子循环结果

                        resultList.AddRange(foreachResult);
                    }
                }
            }

            #endregion

            #region 处理子判断语句
            if (this.Ifs != null)
            {
                foreach (var tempIf in this.Ifs)
                {
                    if (tempIf.Condition.GetResult(allVarList, sourceDic))
                    {
                        List <StorageData> ifResult = tempIf.GetStorageDatas(_dbOp, allVarList, sourceDic);  //获取子判断结果

                        resultList.AddRange(ifResult);
                    }
                }
            }
            #endregion

            return(resultList);
        }