Exemple #1
0
        /// <summary>
        /// 转换成SQL语句
        /// </summary>
        /// <returns>SQL语句</returns>
        public override string ToSQL()
        {
            if (string.IsNullOrEmpty(ConditionString) == false)
            {
                return(ConditionString);
            }

            var relationOper = RelationalOperatorUtis.ConvertToString(RelationalOperator);

            if (ConditionFieldValue.IsNull)
            {
                return(string.Format("{0}.{1} is null ", ConditionField.Table.TableName, ConditionField.FieldName));
            }
            else
            {
                if (relationOper.Value)
                {
                    return(string.Format("{0}.{1} {2} @{3}", ConditionField.Table.TableName, ConditionField.FieldName, relationOper.Key,
                                         ConditionFieldValue.ConditionFieldName));
                }
                else
                {
                    return(string.Format(ConditionField.Table.TableName + "." + ConditionField.FieldName + " " + relationOper.Key,
                                         ConditionFieldValue.ConditionFieldName));
                }
            }
        }
        public static string ParseFilterClause(FilterClause filterClause, DomainObject domainObject, DataObject dataObject)
        {
            var fieldType = filterClause.FilterField.FieldType;
            DataColumn column = null;
            DomainObjectElement element = null;
            switch (fieldType)
            {
                case FieldType.Column:
                    column = dataObject.Columns.FirstOrDefault(i => i.ColumnName == filterClause.FilterField.Field);
                    element = domainObject.Elements.FirstOrDefault(i => i.DataColumnID == column.ID);
                    break;
                case FieldType.Element:
                    element = domainObject.Elements.FirstOrDefault(i => i.Name == filterClause.FilterField.Field || i.ID == filterClause.FilterField.Field);
                    column = dataObject.Columns.FirstOrDefault(i => i.ID == element.DataColumnID);
                    break;
                case FieldType.FunctionExpression:
                    return filterClause.FilterField.Field;
            }

            var relationOper = RelationalOperatorUtis.ConvertToString(filterClause.RelationalOperator);
            if (column.IsNumeric)
            {
                if (filterClause.FilterFieldValue.IsNull)
                {
                    return string.Format("{0} is null ", element.Alias);
                }
                else
                {
                    if (relationOper.Value)
                    {
                        return string.Format("{0} {1} {2}", element.Alias, relationOper.Key,
                            filterClause.FilterFieldValue.FiledValue);
                    }
                    else
                    {
                        return string.Format(element.Alias + " " + relationOper.Key,
                           filterClause.FilterFieldValue.FiledValue);
                    }
                }
            }
            else
            {
                if (filterClause.FilterFieldValue.IsNull)
                {
                    return string.Format("{0} is null ", element.Alias);
                }
                else
                {
                    if (relationOper.Value)
                    {
                        return string.Format("{0} {1}'{2}'", element.Alias, relationOper.Key,
                            filterClause.FilterFieldValue.FiledValue);
                    }
                    else
                    {
                        return string.Format(element.Alias + " " + relationOper.Key,
                           filterClause.FilterFieldValue.FiledValue);
                    }
                }
            }
        }