コード例 #1
0
        public static object DecodeAny(this object value, ModuleFieldInfo fieldInfo)
        {
            // If value is null or string.Empty return null
            if (value == null || value == DBNull.Value || (value is string && ((string)value) == string.Empty))
            {
                return(null);
            }

            // If type of value same as typeof field return value
            if (value.GetType() == FieldUtils.GetType(fieldInfo.FieldType))
            {
                return(value);
            }

            // If value is string, correct typeof value
            if (value is string && !string.IsNullOrEmpty(fieldInfo.FieldFormat))
            {
                return(Decode((string)value, fieldInfo));
            }

            // Other Convert Value
            switch (fieldInfo.FieldType)
            {
            case CODES.DEFMODFLD.FLDTYPE.INT32:
                return(Convert.ToInt32(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.INT64:
                return(Convert.ToInt64(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.FLOAT:
                return(Convert.ToSingle(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.DOUBLE:
                return(Convert.ToDouble(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.DECIMAL:
                return(Convert.ToDecimal(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.DATE:
            case CODES.DEFMODFLD.FLDTYPE.DATETIME:
                return(Convert.ToDateTime(value, App.Environment.ServerInfo.Culture));

            case CODES.DEFMODFLD.FLDTYPE.STRING:
                return(Convert.ToString(value));

            default:
                return(value);
            }
        }
コード例 #2
0
ファイル: ModuleUtils.cs プロジェクト: TuanCruise/Code
        //End TrungTT

        public static string BuildSearchCondition(ModuleInfo moduleInfo, ref string whereExtension, OracleCommand comm, SearchConditionInstance conditionIntance)
        {
            // Parse And/Or Group Condition
            if (conditionIntance.SQLLogic != null)
            {
                var conditions = new List <string>();
                foreach (var pCondition in conditionIntance.SubCondition)
                {
                    var strCondition = BuildSearchCondition(moduleInfo, ref whereExtension, comm, pCondition);
                    if (!string.IsNullOrEmpty(strCondition))
                    {
                        conditions.Add(strCondition);
                    }
                }

                if (conditions.Count == 0)
                {
                    return(string.Empty);
                }

                switch (conditionIntance.SQLLogic)
                {
                case CODES.SQL_EXPRESSION.SQL_LOGIC.OR:
                    return("(" + string.Join(" OR ", conditions.ToArray()) + ")");

                default:
                    return("(" + string.Join(" AND ", conditions.ToArray()) + ")");
                }
            }

            var condition = FieldUtils.GetModuleFieldByID(moduleInfo.ModuleID, conditionIntance.ConditionID);

            string conditionFormat;

            switch (conditionIntance.Operator)
            {
            case CODES.DEFMODFLD.CONDITION_OPERATOR.LIKE:
                conditionFormat = "{0} LIKE '%' || {1} || '%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTLIKE:
                conditionFormat = "{0} NOT LIKE '%' || {1} || '%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTEQUAL:
                conditionFormat = "{0} <> {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.BEGINWITH:
                conditionFormat = "{0} LIKE {1} || '%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.ENDWITH:
                conditionFormat = "{0} LIKE '%' || {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.LARGER:
                conditionFormat = "{0} > {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.LARGEROREQUAL:
                conditionFormat = "{0} >= {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.SMALLER:
                conditionFormat = "{0} < {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.SMALLEROREQUAL:
                conditionFormat = "{0} <= {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.INARRAY:
                conditionFormat = "{0} IN ({1})";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTINARRAY:
                conditionFormat = "{0} NOT IN ({1})";
                break;

            default:
                conditionFormat = "{0} = {1}";
                break;
            }

            // Build Left Operator
            var leftOperator = condition.ParameterName;

            switch (condition.TextCase)
            {
            case CODES.DEFMODFLD.TEXTCASE.UPPER:
                leftOperator = string.Format("UPPER({0})", condition.ParameterName);
                break;

            case CODES.DEFMODFLD.TEXTCASE.LOWER:
                leftOperator = string.Format("LOWER({0})", condition.ParameterName);
                break;
            }

            string rightOperator;

            if (string.IsNullOrEmpty(conditionIntance.Value))
            {
                var parameterName = ":" + (comm.Parameters.Count + 1);
                comm.Parameters.Add(parameterName, DBNull.Value);

                rightOperator = parameterName;
            }
            else if (
                conditionIntance.Operator == CODES.DEFMODFLD.CONDITION_OPERATOR.INARRAY ||
                conditionIntance.Operator == CODES.DEFMODFLD.CONDITION_OPERATOR.NOTINARRAY)
            {
                var values         = conditionIntance.Value.Split(new[] { "," }, StringSplitOptions.None);
                var parameterNames = new string[values.Length];

                for (var i = 0; i < values.Length; i++)
                {
                    var paramName = ":" + (comm.Parameters.Count + 1);
                    parameterNames[i] = paramName;
                    comm.Parameters.Add(paramName, values[i].Decode(condition));
                }

                rightOperator = string.Join(",", parameterNames);
            }
            else
            {
                var paramName = ":" + (comm.Parameters.Count + 1);

                switch (condition.TextCase)
                {
                case CODES.DEFMODFLD.TEXTCASE.UPPER:
                    comm.Parameters.Add(paramName, conditionIntance.Value.ToUpper());
                    break;

                case CODES.DEFMODFLD.TEXTCASE.LOWER:
                    comm.Parameters.Add(paramName, conditionIntance.Value.ToLower());
                    break;

                default:
                    comm.Parameters.Add(paramName, conditionIntance.Value.Decode(condition));
                    break;
                }

                rightOperator = paramName;
            }

            if (!string.IsNullOrEmpty(condition.WhereExtension))
            {
                whereExtension = whereExtension.Replace("{" + condition.ParameterName + ":RIGHT}", string.Format(conditionFormat, "", rightOperator));
                whereExtension = whereExtension.Replace("{" + condition.ParameterName + ":VALUE}", rightOperator);
            }

            if (!string.IsNullOrEmpty(condition.CustomSearchCondition))
            {
                var customSearchInstance = condition.CustomSearchCondition;
                customSearchInstance = customSearchInstance.Replace("{" + condition.ParameterName + ":RIGHT}", string.Format(conditionFormat, "", rightOperator));
                customSearchInstance = customSearchInstance.Replace("{" + condition.ParameterName + ":VALUE}", rightOperator);
                return(customSearchInstance);
            }

            return(string.Format(conditionFormat, leftOperator, rightOperator));
        }
コード例 #3
0
ファイル: ModuleUtils.cs プロジェクト: TuanCruise/Code
        public static string BuildSearchConditionKey(ModuleInfo moduleInfo, SearchConditionInstance conditionIntance)
        {
            if (conditionIntance.SQLLogic != null)
            {
                var conditions = new List <string>();
                foreach (var pCondition in conditionIntance.SubCondition)
                {
                    var strCondition = BuildSearchConditionKey(moduleInfo, pCondition);
                    if (!string.IsNullOrEmpty(strCondition))
                    {
                        conditions.Add(strCondition);
                    }
                }

                if (conditions.Count == 0)
                {
                    return(string.Empty);
                }

                switch (conditionIntance.SQLLogic)
                {
                case CODES.SQL_EXPRESSION.SQL_LOGIC.OR:
                    return("(" + string.Join(" OR ", conditions.ToArray()) + ")");

                default:
                    return("(" + string.Join(" AND ", conditions.ToArray()) + ")");
                }
            }

            var    condition = FieldUtils.GetModuleFieldByID(moduleInfo.ModuleID, conditionIntance.ConditionID);
            string conditionFormat;

            switch (conditionIntance.Operator)
            {
            case CODES.DEFMODFLD.CONDITION_OPERATOR.LIKE:
                conditionFormat = "{0} LIKE '%{1}%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTLIKE:
                conditionFormat = "{0} NOT LIKE '%{1}%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTEQUAL:
                conditionFormat = "{0} <> {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.BEGINWITH:
                conditionFormat = "{0} LIKE '{1}%'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.ENDWITH:
                conditionFormat = "{0} LIKE '%{1}'";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.LARGER:
                conditionFormat = "{0} > {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.LARGEROREQUAL:
                conditionFormat = "{0} >= {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.SMALLER:
                conditionFormat = "{0} < {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.SMALLEROREQUAL:
                conditionFormat = "{0} <= {1}";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.INARRAY:
                conditionFormat = "{0} IN ({1})";
                break;

            case CODES.DEFMODFLD.CONDITION_OPERATOR.NOTINARRAY:
                conditionFormat = "{0} NOT IN ({1})";
                break;

            default:
                conditionFormat = "{0}={1}";
                break;
            }

            string fieldName;

            //if (App.Environment.EnvironmentType == EnvironmentType.CLIENT_APPLICATION)
            //    fieldName = string.Format("[{0}]",
            //                              LangUtils.Translate(
            //                                  LangType.LABEL_FIELD,
            //                                  moduleInfo.ModuleName,
            //                                  condition.FieldName));
            //else
            fieldName = condition.ParameterName;

            if (conditionIntance.Value == null)
            {
                return(string.Format(conditionFormat, fieldName, null));
            }

            return(string.Format(conditionFormat, fieldName, conditionIntance.Value));
        }