Example #1
0
        /// <summary>
        /// 生成条件语句
        /// </summary>
        /// <param name="savePar"></param>
        /// <param name="CondiIndex"></param>
        /// <param name="parameters"></param>
        /// <param name="tryCodeStatementCollection"></param>
        /// <param name="paramterQuery"></param>
        /// <param name="sqls"></param>
        /// <param name="sQLsCount"></param>
        /// <param name="stringBuilderBlueprint"></param>
        /// <param name="cONDITION_TYPE"></param>
        /// <param name="customName"></param>
        private void CreateCondition(
            Dictionary <string, string> savePar
            , int CondiIndex
            , Dictionary <int, List <Dictionary <PARAMETER, string> > > parameters
            , CodeStatementCollection tryCodeStatementCollection
            , IParamterQuery paramterQuery
            , List <SqlFormat> sqls
            , int sQLsCount
            , StringBuilderBlueprint stringBuilderBlueprint
            , CONDITION_TYPE cONDITION_TYPE
            , string customName = "")
        {
            if (!savePar.ContainsKey($"{CondiIndex}Par{customName}"))
            {
                StringBuilderBlueprint stringBuilderBlueprintTmp = new StringBuilderBlueprint($"par{CondiIndex}{customName}");

                tryCodeStatementCollection.Add(stringBuilderBlueprintTmp.Create());

                for (int parametersChildCount = 0; parametersChildCount < parameters[CondiIndex].Count; parametersChildCount++)
                {
                    tryCodeStatementCollection.AddRange(paramterQuery.Create(
                                                            stringBuilderBlueprintTmp
                                                            , parameters[CondiIndex][parametersChildCount]
                                                            , cONDITION_TYPE));
                }

                savePar.Add($"{CondiIndex}Par{customName}", stringBuilderBlueprintTmp.Field);
            }

            if (sqls[sQLsCount].CondiIndex != -1)
            {
                tryCodeStatementCollection.Add(stringBuilderBlueprint.AppendField($"par{CondiIndex}{customName}"));
            }
        }
Example #2
0
        private void IndexAdd(
            string otherAdd
            , CONDITION_TYPE cONDITION_TYPE
            , string sQL
            , int maxConditionsCount
            , List <string> spliteCount
            , List <CondiIndex> condiIndices
            , ref bool isNotActiveConditionInsQL)
        {
            for (var sqlCount = 0; sqlCount < maxConditionsCount; sqlCount++)
            {
                int index = 0;
                spliteCount.Add($"{{{sqlCount}{otherAdd}}}");
                while (index != -1)
                {
                    index = sQL.IndexOf($"{{{sqlCount}{otherAdd}}}", index + $"{{{sqlCount}{otherAdd}}}".Length);
                    if (index == -1)
                    {
                        break;
                    }

                    condiIndices.Add(new CondiIndex
                    {
                        Index          = index,
                        CondiCount     = sqlCount,
                        cONDITION_TYPE = cONDITION_TYPE
                    });
                    isNotActiveConditionInsQL = false;
                }
            }
        }
Example #3
0
        public CodeStatementCollection Create(StringBuilderBlueprint sqlStrBlueprint
                                              , Dictionary <PARAMETER, string> paramter
                                              , CONDITION_TYPE cONDITION_TYPE)
        {
            stringBuilderBlueprint = sqlStrBlueprint;

            #region 属性赋值及其格式化处理

            CodeStatementCollection codeStatementCollection = new CodeStatementCollection();
            bool needSplit = false;

            string name;
            if (paramter.ContainsKey(PARAMETER.NAME))
            {
                name = paramter[PARAMETER.NAME];
            }
            else
            {
                throw new Exception("不存在Name属性");
            }
            string fieldName = name.Replace(".", string.Empty);

            string target;
            if (paramter.ContainsKey(PARAMETER.TARGET))
            {
                target = paramter[PARAMETER.TARGET];
            }
            else
            {
                target = name;
            }

            string symbol;
            if (paramter.ContainsKey(PARAMETER.SYMBOL))
            {
                symbol = paramter[PARAMETER.SYMBOL];
                foreach (var c in ConditionSplit)
                {
                    if (symbol.Equals(c, StringComparison.InvariantCultureIgnoreCase))
                    {
                        needSplit = true;
                    }
                }
            }
            else
            {
                symbol = "=";
            }

            string        template  = string.Empty;
            List <string> templates = new List <string>();
            if (paramter.ContainsKey(PARAMETER.TEMPLATE))
            {
                template = paramter[PARAMETER.TEMPLATE];

                if (template.IndexOf("*") == -1)
                {
                    throw new Exception("在模板中,没有作为标记的'*'符号");
                }

                if (needSplit)
                {
                    templates = new List <string>(template.Split('*'));
                }
            }
            else
            {
                if (needSplit)
                {
                    throw new Exception("你使用了in,not in这类多参数的传值没有写模板");
                }
            }

            #endregion

            //FieldName赋值,方便给子类使用
            this.fieldName = fieldName;

            switch (cONDITION_TYPE)
            {
            case CONDITION_TYPE.SET:
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{fieldName} = @{fieldName}ParSET,"));
                    SetTrue(codeStatementCollectionIF);
                    return(codeStatementCollectionIF);
                }));
                break;

            case CONDITION_TYPE.VALUE:
                codeStatementCollection.Add(sqlStrBlueprint.Append($"@{fieldName}VALUE"));
                codeStatementCollection.Add(sqlStrBlueprint.Append(" , "));
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    ValueTrue(codeStatementCollectionIF);
                    return(codeStatementCollectionIF);
                },
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionElse = new CodeStatementCollection();
                    ValueFalse(codeStatementCollectionElse);
                    return(codeStatementCollectionElse);
                }));
                break;

            case CONDITION_TYPE.WHERE:
                codeStatementCollection.Add(ToolManager.Instance.ConditionTool.CreateConditionCode($"!string.IsNullOrWhiteSpace({fieldName})",
                                                                                                   () =>
                {
                    CodeStatementCollection codeStatementCollectionIF = new CodeStatementCollection();
                    codeStatementCollectionIF.Add(stringBuilderBlueprint.Append(" AND "));
                    if (!needSplit)
                    {
                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{target} {symbol} {(string.IsNullOrWhiteSpace(template) ? $"@{fieldName}" : template)}"));
                        ExecuteDataTableNormalBuild(codeStatementCollectionIF);
                    }
                    else
                    {
                        ListBlueprint listBlueprint = new ListBlueprint($"{fieldName}List");
                        codeStatementCollectionIF.Add(listBlueprint.Create <string>($"{fieldName}.Split(',')"));
                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append($"{target} {symbol} {templates[0]}"));

                        codeStatementCollectionIF.Add(ToolManager.Instance.CircleTool.CreateCircle("int i = 0", $"i < {fieldName}List.Count", "i++", () =>
                        {
                            CodeStatementCollection codeStatementCollectionFor = new CodeStatementCollection();
                            ExecuteDataTableCircleBuild(codeStatementCollectionFor);
                            return(codeStatementCollectionFor);
                        }));

                        codeStatementCollectionIF.Add(sqlStrBlueprint.Append(templates[1]));
                    }
                    return(codeStatementCollectionIF);
                }));
                break;
            }

            return(codeStatementCollection);
        }