Exemplo n.º 1
0
        internal static string ColumnFKMatchesParentProperty(CslaObjectInfo parent, CslaObjectInfo info,
                                                             IColumnInfo validatingColumn)
        {
            foreach (var prop in info.ParentProperties)
            {
                var parentPropertyFound = parent.GetAllValueProperties().Find(prop.Name);
                if (parentPropertyFound != null)
                {
                    var parentSchema = parentPropertyFound.DbBindColumn.SchemaName;
                    var parentTable  = parentPropertyFound.DbBindColumn.ObjectName;
                    var parentColumn = parentPropertyFound.DbBindColumn.Column;
                    if (parentColumn != null)
                    {
                        if (validatingColumn.FKConstraint != null)
                        {
                            if (parentSchema == validatingColumn.FKConstraint.PKTable.ObjectSchema ||
                                parentTable == validatingColumn.FKConstraint.PKTable.ObjectName)
                            {
                                foreach (var pkColumn in validatingColumn.FKConstraint.Columns)
                                {
                                    if (pkColumn.PKColumn == parentColumn)
                                    {
                                        return(validatingColumn.FKConstraint.ConstraintTable.ObjectName + "." +
                                               validatingColumn.ColumnName);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(string.Empty);
        }
Exemplo n.º 2
0
        public List <IResultObject> GetTables(Criteria crit, CslaObjectInfo info, bool includeParentObjects)
        {
            List <IResultObject> tablesCol = new List <IResultObject>();

            if (includeParentObjects)
            {
                CslaObjectInfo parent = FindParent(info);
                if (parent != null)
                {
                    tablesCol.AddRange(GetTables(crit, parent, true));
                }
            }

            foreach (ValueProperty prop in info.GetAllValueProperties())
            {
                if (prop.DbBindColumn.ColumnOriginType == ColumnOriginType.Table ||
                    prop.DbBindColumn.ColumnOriginType == ColumnOriginType.View)
                {
                    IResultObject table = (IResultObject)prop.DbBindColumn.DatabaseObject;
                    if (!tablesCol.Contains(table))
                    {
                        tablesCol.Add(table);
                    }
                }
            }
            foreach (IResultObject table in GetTables(crit))
            {
                if (!tablesCol.Contains(table))
                {
                    tablesCol.Add(table);
                }
            }
            return(tablesCol);
        }
Exemplo n.º 3
0
        public void StoreCorrelationNames(CslaObjectInfo info)
        {
            correlationNames.Clear();
            DuplicateTables         readCorr;
            DuplicateTables         writeCorr = new DuplicateTables();
            ValuePropertyCollection vpc       = new ValuePropertyCollection();

            vpc.AddRange(info.GetAllValueProperties());
            for (int vp = 0; vp < vpc.Count; vp++)
            {
                int count = 1;
                for (int prop = 0; prop < vp; prop++)
                {
                    readCorr = correlationNames[prop];
                    if (readCorr.PropertyName != vpc[vp].Name)
                    {
                        if (readCorr.TableName == vpc[vp].DbBindColumn.ObjectName &&
                            readCorr.ColumnName == vpc[vp].DbBindColumn.ColumnName)
                        {
                            if (readCorr.Order >= count)
                            {
                                count = readCorr.Order + 1;
                            }
                        }
                    }
                }
                writeCorr.PropertyName = vpc[vp].Name;
                writeCorr.TableName    = vpc[vp].DbBindColumn.ObjectName;
                writeCorr.ColumnName   = vpc[vp].DbBindColumn.ColumnName;
                writeCorr.Order        = count;
                correlationNames.Add(writeCorr);
            }
        }
Exemplo n.º 4
0
        public string GetFromClause(Criteria crit, CslaObjectInfo info, bool includeParentObjects)
        {
            // check object uses FKConstraint field
            bool FKField = false;
            ValuePropertyCollection valPropColl = new ValuePropertyCollection();

            valPropColl.AddRange(info.GetAllValueProperties());
            foreach (ValueProperty valProp in valPropColl)
            {
                if (valProp.FKConstraint != string.Empty)
                {
                    FKField = true;
                    break;
                }
            }

            if (FKField)
            {
                return(GetFromClauseFK(crit, info, includeParentObjects));
            }
            else
            {
                return(GetFromClauseClassic(crit, info, includeParentObjects));
            }
        }
Exemplo n.º 5
0
 public static bool IsChangedUserColumnPresent(this CslaObjectInfo info)
 {
     foreach (var valueProperty in info.GetAllValueProperties())
     {
         if (valueProperty.Name == info.Parent.Params.ChangedUserColumn)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 6
0
 public bool IgnoreFilter(CslaObjectInfo originalInfo)
 {
     if (Info.Parent.Params.SpIgnoreFilterWhenSoftDeleteIsParam)
     {
         foreach (var prop in originalInfo.GetAllValueProperties())
         {
             if (prop.Name == Info.Parent.Params.SpBoolSoftDeleteColumn)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        public List <IResultObject> GetTablesDelete(CslaObjectInfo info)
        {
            List <IResultObject> tablesCol = new List <IResultObject>();

            foreach (ValueProperty prop in info.GetAllValueProperties())
            {
                if (prop.DataAccess != ValueProperty.DataAccessBehaviour.ReadOnly && prop.DbBindColumn.ColumnOriginType == ColumnOriginType.Table)
                {
                    IResultObject table = (IResultObject)prop.DbBindColumn.DatabaseObject;
                    if (!tablesCol.Contains(table))
                    {
                        tablesCol.Add(table);
                    }
                }
            }
            return(tablesCol);
        }
Exemplo n.º 8
0
        public string GetSelectFields(CslaObjectInfo info)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(Indent(2) + "SELECT" + Environment.NewLine);
            bool first = true;
            ValuePropertyCollection vpc = new ValuePropertyCollection();

            if (IncludeParentProperties)
            {
                vpc.AddRange(info.GetParentValueProperties());
            }
            vpc.AddRange(info.GetAllValueProperties());
            foreach (ValueProperty prop in vpc)
            {
                if (prop.DataAccess != ValueProperty.DataAccessBehaviour.WriteOnly)
                {
                    if (!first)
                    {
                        sb.Append("," + Environment.NewLine);
                    }
                    else
                    {
                        first = false;
                    }
                    sb.Append(Indent(3) + " ");
                    if (prop.DbBindColumn.DataType.ToString() == "StringFixedLength")
                    {
                        sb.Append("RTRIM(");
                        sb.Append("[" + GetCorrelationName(prop) + "].[" + prop.DbBindColumn.ColumnName + "]" + ")");
                        sb.Append(String.Format(" AS [{0}]", prop.ParameterName));
                    }
                    else
                    {
                        sb.Append("[" + GetCorrelationName(prop) + "].[" + prop.DbBindColumn.ColumnName + "]");
                        if (prop.DbBindColumn.ColumnName != prop.ParameterName)
                        {
                            sb.Append(String.Format(" AS [{0}]", prop.ParameterName));
                        }
                    }
                }
            }
            sb.Append(Environment.NewLine);
            return(sb.ToString());
        }
        private static PropertyCollection BuildParentProperties(CslaObjectInfo info)
        {
            var propertyCollection = new PropertyCollection();

            CslaObjectInfo parent = info.FindMyParent(info);

            if (parent != null)
            {
                foreach (Property pvp in parent.ValueProperties)
                {
                    ValueProperty prop = parent.GetAllValueProperties().Find(pvp.Name);
                    if (prop != null && prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                    {
                        propertyCollection.Add(prop);
                    }
                }
            }

            return(propertyCollection);
        }
Exemplo n.º 10
0
 public static bool UseSimpleAuditTrail(this CslaObjectInfo info)
 {
     if (!string.IsNullOrEmpty(info.Parent.Params.CreationDateColumn) ||
         !string.IsNullOrEmpty(info.Parent.Params.CreationUserColumn) ||
         !string.IsNullOrEmpty(info.Parent.Params.ChangedDateColumn) ||
         !string.IsNullOrEmpty(info.Parent.Params.ChangedUserColumn))
     {
         foreach (var valueProperty in info.GetAllValueProperties())
         {
             if (valueProperty.Name == info.Parent.Params.CreationDateColumn ||
                 valueProperty.Name == info.Parent.Params.CreationUserColumn ||
                 valueProperty.Name == info.Parent.Params.ChangedDateColumn ||
                 valueProperty.Name == info.Parent.Params.ChangedUserColumn)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 11
0
        internal static bool MultipleColumnFKMatchesParent(CslaObjectInfo parent, CslaObjectInfo info,
                                                           IColumnInfo validatingColumn)
        {
            foreach (var prop in info.ParentProperties)
            {
                var parentPropertyFound = parent.GetAllValueProperties().Find(prop.Name);
                if (parentPropertyFound != null)
                {
                    var parentSchema = parentPropertyFound.DbBindColumn.SchemaName;
                    var parentTable  = parentPropertyFound.DbBindColumn.ObjectName;
                    var parentColumn = parentPropertyFound.DbBindColumn.Column;
                    if (parentColumn != null)
                    {
                        if (validatingColumn.FKConstraint != null)
                        {
                            if (parentSchema == validatingColumn.FKConstraint.PKTable.ObjectSchema ||
                                parentTable == validatingColumn.FKConstraint.PKTable.ObjectName)
                            {
                                foreach (var pkColumn in validatingColumn.FKConstraint.Columns)
                                {
                                    if (pkColumn.PKColumn == parentColumn)
                                    {
                                        var matchCounter =
                                            CountMatchingInfoColumns(validatingColumn.FKConstraint.ConstraintTable,
                                                                     parentSchema, parentTable, parentColumn);
                                        return(matchCounter > 1);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            _editorService = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
            if (_editorService != null)
            {
                if (context.Instance != null)
                {
                    // CR modifying to accomodate PropertyBag
                    Type   instanceType = null;
                    object objinfo      = null;
                    var    propColl     = new PropertyCollection();
                    var    obj          = new CslaObjectInfo();

                    TypeHelper.GetContextInstanceObject(context, ref objinfo, ref instanceType);
                    if (instanceType == typeof(CslaObjectInfo))
                    {
                        PropertyInfo propInfo;
                        if (context.PropertyDescriptor.DisplayName == "Hashcode Property")
                        {
                            propInfo = instanceType.GetProperty("HashcodeProperty");
                        }
                        else if (context.PropertyDescriptor.DisplayName == "Equals Property")
                        {
                            propInfo = instanceType.GetProperty("EqualsProperty");
                        }
                        else
                        {
                            propInfo = instanceType.GetProperty("ToStringProperty");
                        }

                        propColl = (PropertyCollection)propInfo.GetValue(objinfo, null);
                        obj      = (CslaObjectInfo)objinfo;
                    }
                    else
                    {
                        instanceType = null;
                        objinfo      = null;
                        TypeHelper.GetChildPropertyContextInstanceObject(context, ref objinfo, ref instanceType);
                        var parentPropertiesPropInfo = instanceType.GetProperty("ParentLoadProperties");
                        propColl = (PropertyCollection)parentPropertiesPropInfo.GetValue(objinfo, null);

                        obj = (CslaObjectInfo)GeneratorController.Current.MainForm.ProjectPanel.ListObjects.SelectedItem;
                    }

                    var valueProps = obj.GetAllValueProperties();
                    if (valueProps.Count > 0)
                    {
                        _lstProperties.Items.Clear();
                        _lstProperties.Items.Add(new DictionaryEntry("(None)", new ValueProperty()));
                        for (int i = 0; i < valueProps.Count; i++)
                        {
                            _lstProperties.Items.Add(new DictionaryEntry(valueProps[i].Name, valueProps[i]));
                        }

                        foreach (var parentProp in propColl)
                        {
                            _lstProperties.SelectedItems.Add(new DictionaryEntry(parentProp.Name, parentProp));
                        }

                        _lstProperties.SelectedIndexChanged += LstPropertiesSelectedIndexChanged;
                        _editorService.DropDownControl(_lstProperties);
                        _lstProperties.SelectedIndexChanged -= LstPropertiesSelectedIndexChanged;

                        if (_lstProperties.SelectedItems.Count > 0)
                        {
                            var prop = new PropertyCollection();
                            foreach (var item in _lstProperties.SelectedItems)
                            {
                                prop.Add((Property)((DictionaryEntry)item).Value);
                            }
                            return(prop);
                        }

                        return(new PropertyCollection());
                    }
                }
            }

            return(value);
        }
Exemplo n.º 13
0
        public string GetFromClauseFK(Criteria crit, CslaObjectInfo info, bool includeParentObjects)
        {
            List <IResultObject> tables = GetTables(crit, info, includeParentObjects);

            SortTables(tables);
            CheckTableJoins(tables);
            IResultObject curTable = tables[0];

            StringBuilder sb = new StringBuilder();

            sb.Append(Indent(2) + "FROM ");
            if (tables.Count == 1)
            {
                sb.AppendFormat("[{0}].[{1}]", tables[0].ObjectSchema, curTable.ObjectName);
                sb.Append(Environment.NewLine);
                return(sb.ToString());
            }
            else if (tables.Count > 1)
            {
                sb.AppendFormat("[{0}].[{1}]", curTable.ObjectSchema, curTable.ObjectName);
                ValuePropertyCollection vpc = new ValuePropertyCollection();
                vpc.AddRange(info.GetAllValueProperties());
                foreach (ValueProperty vp in vpc)
                {
                    if (vp.DbBindColumn.ObjectName != curTable.ObjectName)
                    {
                        List <IForeignKeyConstraint> fKeys = Catalog.ForeignKeyConstraints.GetConstraintsFor(curTable);
                        foreach (IForeignKeyConstraint fKey in fKeys)
                        {
                            if (fKey.ConstraintName == vp.FKConstraint)
                            {
                                sb.Append(Environment.NewLine + Indent(3));
                                sb.Append(" INNER JOIN ");
                                sb.AppendFormat("[{0}].[{1}]", curTable.ObjectSchema, fKey.PKTable.ObjectName);
                                string corrName = GetCorrelationName(vp);
                                if (corrName != vp.DbBindColumn.ObjectName)
                                {
                                    sb.AppendFormat(" AS [{0}]", corrName);
                                }
                                sb.Append(" ON ");
                                bool firstCol = true;
                                for (int i = 0; i < fKey.Columns.Count; i++)
                                {
                                    if (!firstCol)
                                    {
                                        sb.Append(" AND ");
                                    }
                                    else
                                    {
                                        firstCol = false;
                                    }
                                    sb.AppendFormat("[{0}].[{1}]", corrName, fKey.Columns[i].PKColumn.ColumnName);
                                    sb.Append(" = ");
                                    sb.Append(GetAliasedFieldString(fKey.ConstraintTable, fKey.Columns[i].FKColumn));
                                }
                                break;
                            }
                        }
                    }
                }
                sb.Append(Environment.NewLine);
                return(sb.ToString());
            }
            else
            {
                return(String.Empty);
            }
        }