Beispiel #1
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);
        }
Beispiel #2
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);
            }
        }
Beispiel #3
0
        public string GetChildSelects(CslaObjectInfo info, Criteria crit, bool searchWhereClause)
        {
            bool collType = IsCollectionType(info.ObjectType);

            if (collType)
            {
                info = FindChildInfo(info, info.ItemType);
            }

            StringBuilder sb    = new StringBuilder();
            var           first = true;

            foreach (ChildProperty childProp in info.GetAllChildProperties())
            {
                CslaObjectInfo childInfo = FindChildInfo(info, childProp.TypeName);
                if (!collType && childInfo != null && childProp.LoadingScheme != LoadingScheme.SelfLoad)
                {
                    if (!first)
                    {
                        sb.Append(Environment.NewLine);
                    }
                    else
                    {
                        first = false;
                    }

                    sb.Append(GetSelect(childInfo, crit, true, searchWhereClause));
                    sb.Append(GetChildSelects(childInfo, crit, searchWhereClause));
                }
            }

            return(NormalizeNewLineAtEndOfFile(sb.ToString()));
        }
Beispiel #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));
            }
        }
        private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var isCSharp = GeneratorController.Current.CurrentUnit.GenerationParams.OutputLanguage == CodeLanguage.CSharp;
            var result   = new CriteriaPropertyCollection();
            var index    = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            if (isCSharp)
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                            else
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperVB.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
Beispiel #6
0
        public string GetSelect(CslaObjectInfo info, Criteria crit, bool childSelect, bool searchWhereClause)
        {
            bool collType = IsCollectionType(info.ObjectType);

            if (collType)
            {
                info = FindChildInfo(info, info.ItemType);
            }
            StoreCorrelationNames(info);
            StringBuilder sb = new StringBuilder();

            sb.Append(Environment.NewLine);
            sb.Append(Indent(2) + "/* Get " + info.ObjectName + " from table */" + Environment.NewLine);
            sb.Append(GetSelectFields(info));

            sb.Append(searchWhereClause
                          ? GetFromClause(crit, info, true)
                          : GetFromClause(crit, info, childSelect));

            sb.Append(searchWhereClause
                          ? GetSearchWhereClause(_topLevelObject, info, crit)
                          : GetWhereClause(info, crit, childSelect));

            return(NormalizeNewLineAtEndOfFile(sb.ToString()));
        }
Beispiel #7
0
        public static CslaObjectInfo FindAncestor(this CslaObjectInfo info)
        {
            while (true)
            {
                if (info.ParentType == string.Empty) // no parent specified; this is the last ancestor
                {
                    return(info);
                }

                var parentInfo = info.Parent.CslaObjects.Find(info.ParentType);
                if (parentInfo == null) // the parent wasn't found; for practical purposes, this is the last ancestor
                {
                    return(info);
                }

                var notFound = true;
                foreach (var child in parentInfo.AllChildProperties)
                {
                    if (child.TypeName == info.ParentType)
                    {
                        notFound = false;
                        break;
                    }
                }

                if (notFound) // the parent doesn't know the child; for practical purposes, this is the last ancestor
                {
                    return(info);
                }

                info = parentInfo;
            }
        }
Beispiel #8
0
        private string GetBaseFileName(CslaObjectInfo info, bool separateBaseClasses, bool separateNamespaces, bool useDotDesigner, CodeLanguage OutputLanguage)
        {
            string fileNoExtension = GetFileNameWithoutExtension(info.FileName);

            //if (info.ObjectType != CslaObjectType.NameValueList) { fileNoExtension += "Base"; }
            if (useDotDesigner)
            {
                fileNoExtension += ".Designer";
            }
            else
            {
                fileNoExtension += "Base";
            }
            string fileExtension = GetFileExtension(info.FileName);

            if (fileExtension == String.Empty)
            {
                if (OutputLanguage == CodeLanguage.CSharp)
                {
                    fileNoExtension += ".cs";
                }
                if (OutputLanguage == CodeLanguage.VB)
                {
                    fileNoExtension += ".vb";
                }
            }
            else
            {
                fileNoExtension += fileExtension;
            }

            return(GetNamespaceDirectory(_targetDirectory, info, separateBaseClasses, separateNamespaces) + fileNoExtension);
        }
Beispiel #9
0
 private string GenerateProcedure(CslaObjectInfo objInfo, Criteria crit, string templateName, string sprocName)
 {
     if (objInfo != null)
     {
         try
         {
             if (templateName != String.Empty)
             {
                 string       path     = _templatesDirectory + @"sprocs\" + templateName;
                 CodeTemplate template = GetTemplate(objInfo, path);
                 if (crit != null)
                 {
                     template.SetProperty("Criteria", crit);
                 }
                 template.SetProperty("IncludeParentProperties", objInfo.DataSetLoadingScheme);
                 if (template != null)
                 {
                     using (StringWriter sw = new StringWriter())
                     {
                         template.Render(sw);
                         sprocSuccess++;
                         return(sw.ToString());
                     }
                 }
             }
         }
         catch (Exception e)
         {
             sprocFailed++;
             throw (new Exception("Error generating " + GetFileNameWithoutExtension(templateName) + ": " + sprocName, e));
         }
     }
     return(String.Empty);
 }
Beispiel #10
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);
        }
Beispiel #11
0
 private void GenerateAccessoryFile(string fileName, string templateFile, CslaObjectInfo objInfo, bool activeObjects, CslaGeneratorUnit unit)
 {
     // Create Inheritance file if it does not exist
     if (!File.Exists(fileName)) //&& objInfo.ObjectType != CslaObjectType.NameValueList)
     {
         // string tPath = this._fullTemplatesPath + objInfo.OutputLanguage.ToString() + "\\InheritFromBase.cst";
         string       tPath    = _fullTemplatesPath + objInfo.OutputLanguage + templateFile;
         CodeTemplate template = GetTemplate(objInfo, tPath);
         if (template != null)
         {
             template.SetProperty("ActiveObjects", activeObjects);
             template.SetProperty("CurrentUnit", unit);
             FileStream fs = File.Open(fileName, FileMode.Create);
             OnGenerationFileName(fileName);
             StreamWriter sw = new StreamWriter(fs);
             try
             {
                 template.Render(sw);
             }
             catch (Exception e)
             {
                 ShowExceptionInformation(e);
             }
             finally
             {
                 sw.Close();
             }
         }
     }
 }
        private ValueProperty GetRelatedValueProperty(ValueProperty prop)
        {
            foreach (var constraint in _associativeTable.Catalog.ForeignKeyConstraints)
            {
                if (constraint.ConstraintTable.ObjectName == _associativeTable.ObjectName)
                {
                    if (constraint.PKTable.ObjectName == prop.DbBindColumn.DatabaseObject.ObjectName)
                    {
                        if (constraint.Columns[0].PKColumn.ColumnName == prop.DbBindColumn.ColumnName)
                        {
                            IColumnInfo col     = constraint.Columns[0].PKColumn;
                            var         info    = new CslaObjectInfo();
                            var         newProp = new ValueProperty();
                            newProp.Name         = prop.Name;
                            newProp.PropertyType = col.ManagedType.GetTypeCodeEx();
                            var currentFactory = new ObjectFactory(_currentUnit, info);
                            currentFactory.SetValuePropertyInfo(_dbObject, _resultSet, col, newProp);
                            return(newProp);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #13
0
        private string GetTemplateName(CslaObjectInfo info)
        {
            switch (info.ObjectType)
            {
            case CslaObjectType.EditableRoot:
                return(ConfigurationManager.AppSettings["EditableRootTemplate"]);

            case CslaObjectType.EditableChild:
                return(ConfigurationManager.AppSettings["EditableChildTemplate"]);

            case CslaObjectType.EditableRootCollection:
                return(ConfigurationManager.AppSettings["EditableRootCollectionTemplate"]);

            case CslaObjectType.EditableChildCollection:
                return(ConfigurationManager.AppSettings["EditableChildCollectionTemplate"]);

            case CslaObjectType.EditableSwitchable:
                return(ConfigurationManager.AppSettings["EditableSwitchableTemplate"]);

            case CslaObjectType.DynamicEditableRoot:
                return(ConfigurationManager.AppSettings["DynamicEditableRootTemplate"]);

            case CslaObjectType.DynamicEditableRootCollection:
                return(ConfigurationManager.AppSettings["DynamicEditableRootCollectionTemplate"]);

            case CslaObjectType.ReadOnlyObject:
                return(ConfigurationManager.AppSettings["ReadOnlyObjectTemplate"]);

            case CslaObjectType.ReadOnlyCollection:
                return(ConfigurationManager.AppSettings["ReadOnlyCollectionTemplate"]);

            default:
                return(String.Empty);
            }
        }
Beispiel #14
0
 void GenerateInheritanceFile(string fileName, CslaObjectInfo objInfo, bool activeObjects, CslaGeneratorUnit unit)
 {
     // Create Inheritance file if it does not exist
     if (!File.Exists(fileName)) //&& objInfo.ObjectType != CslaObjectType.NameValueList)
     {
         string       tPath    = this._fullTemplatesPath + unit.GenerationParams.OutputLanguage.ToString() + "\\InheritFromBase.cst";
         CodeTemplate template = GetTemplate(objInfo, tPath);
         if (template != null)
         {
             template.SetProperty("ActiveObjects", activeObjects);
             template.SetProperty("CurrentUnit", unit);
             FileInfo fi = new FileInfo(fileName);
             using (FileStream fs = fi.Open(FileMode.Create))
             {
                 OnGenerationFileName(fi.FullName);
                 using (StreamWriter sw = new StreamWriter(fs))
                 {
                     try
                     {
                         template.Render(sw);
                     }
                     catch (Exception e)
                     {
                         ShowExceptionInformation(e);
                     }
                 }
             }
         }
     }
 }
        private bool CheckCollectionItemCriteriaDelete(Criteria crit, CslaObjectInfo info, CslaObjectInfo myRootInfo, string critName)
        {
            if (crit.Name != critName)
            {
                var accept = false;
                if (crit.DeleteOptions.Factory)
                {
                    if (crit.DeleteOptions.Procedure || crit.DeleteOptions.DataPortal)
                    {
                        accept = crit.DeleteOptions.ProcedureName != string.Empty;
                    }
                    else
                    {
                        accept = true;
                    }
                }
                if (!crit.DeleteOptions.Factory)
                {
                    accept = false;
                }

                return(accept);
            }

            SetCollectionItemCriteriaDelete(crit, info, myRootInfo == MainObjectInfo, critName);
            return(true);
        }
        private void SetCollectionCriteriaGet(Criteria crit, CslaObjectInfo info, string critName)
        {
            if (crit.Name != critName)
            {
                crit.GetOptions.Factory = true;
            }
            else
            {
                crit.CreateOptions.Factory       = false;
                crit.CreateOptions.AddRemove     = false;
                crit.CreateOptions.DataPortal    = false;
                crit.CreateOptions.RunLocal      = false;
                crit.CreateOptions.Procedure     = false;
                crit.CreateOptions.ProcedureName = string.Empty;

                crit.GetOptions.Factory       = true;
                crit.GetOptions.AddRemove     = false;
                crit.GetOptions.DataPortal    = true;
                crit.GetOptions.RunLocal      = false;
                crit.GetOptions.Procedure     = true;
                crit.GetOptions.ProcedureName = _entity.Parent.Params.GetGetProcName(info.ObjectName);

                crit.DeleteOptions.Factory       = false;
                crit.DeleteOptions.AddRemove     = false;
                crit.DeleteOptions.DataPortal    = false;
                crit.DeleteOptions.RunLocal      = false;
                crit.DeleteOptions.Procedure     = false;
                crit.DeleteOptions.ProcedureName = string.Empty;
            }
        }
        private static void RemoveDefaultItemCriteria(CslaObjectInfo info, string critName)
        {
            StringBuilder sb;

            var itemCriteria = info.CriteriaObjects;

            foreach (var crit in itemCriteria)
            {
                if (crit.Name != critName)
                {
                    if (crit.Properties.Count > 0)
                    {
                        // clear CriteriaGet properties
                        crit.Properties.Clear();

                        // display message to the user
                        sb = new StringBuilder();
                        sb.AppendFormat("ReadOnly object - successfully removed all criteria properties of {0} on {1} item object.", critName, info.ObjectName);
                        OutputWindow.Current.AddOutputInfo(sb.ToString());
                    }
                }
                itemCriteria.Remove(crit);
                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("ReadOnly object - successfully removed criteria {0} to {1} item object.", critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
                break;
            }
        }
        public void Add(CslaObjectInfo mainObject)
        {
            if (RelationRulesEngine.IsAllowedEntityObject(mainObject))
            {
                var entity = new AssociativeEntity(GeneratorController.Current.CurrentUnit);
                entity.RelationType      = ObjectRelationType.OneToMultiple;
                entity.ObjectName        = mainObject.ObjectName;
                entity.MainObject        = mainObject.ObjectName;
                entity.MainLazyLoad      = false;
                entity.SecondaryLazyLoad = false;

                var mainCriteriaInfo    = typeof(CslaObjectInfo).GetProperty("CriteriaObjects");
                var mainCriteriaObjects = mainCriteriaInfo.GetValue(mainObject, null);
                foreach (var crit in (CriteriaCollection)mainCriteriaObjects)
                {
                    foreach (var prop in crit.Properties)
                    {
                        entity.MainLoadProperties.Add(CriteriaProperty.Clone(prop));
                    }
                }

                Add(entity);
            }
            else
            {
                throw new Exception(mainObject + " isn't a suitable object for this builder.");
            }
        }
        private void DeleteDefaultCollectionCriteria(CslaObjectInfo info, string critName)
        {
            StringBuilder sb;

            var collCriteria = info.CriteriaObjects;

            foreach (var crit in collCriteria)
            {
                if (crit.Name != critName)
                {
                    if (crit.Properties.Count > 0)
                    {
                        // clear CriteriaGet properties
                        crit.Properties.Clear();

                        // display message to the user
                        sb = new StringBuilder();
                        sb.AppendFormat("Not SelfLoad - successfully removed all criteria properties of {0} on {1} collection object.", critName, info.ObjectName);
                        OutputWindow.Current.AddOutputInfo(sb.ToString());
                    }
                }
                collCriteria.Remove(crit);
                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Not SelfLoad - successfully removed criteria {0} to {1} collection object.", critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
                break;
            }
        }
Beispiel #20
0
        public void DeleteObject()
        {
            if (_currentCslaObject != null && _currentUnit != null)
            {
                int currentIndex = 0;
                if (frmGenerator.CslaObjectList.SelectedIndices.Count > 0)
                {
                    currentIndex = frmGenerator.CslaObjectList.SelectedIndices[0];
                    CslaObjectInfo obj = (CslaObjectInfo)((DictionaryEntry)frmGenerator.CslaObjectList.Items[currentIndex]).Value;
                    _currentUnit.CslaObjects.Remove(obj);
                    BindCslaList();
                }

                if (frmGenerator.CslaObjectList.Items.Count > 0)
                {
                    if (currentIndex + 1 < frmGenerator.CslaObjectList.Items.Count)
                    {
                        frmGenerator.CslaObjectList.SelectedIndex = currentIndex;
                    }
                    else
                    {
                        currentIndex--;
                        if (currentIndex < 0)
                        {
                            currentIndex = 0;
                        }
                        frmGenerator.CslaObjectList.SelectedIndex = currentIndex;
                    }
                }
                else
                {
                    AddNewObject();
                }
            }
        }
Beispiel #21
0
        // changed visibility so ActiveObjects settings can be hidden dynamicaly
        internal void ReloadPropertyGrid()
        {
            if (_dbSchemaPanel != null)
            {
                _dbSchemaPanel.CslaObjectInfo = null;
            }

            var selectedItems = new List <CslaObjectInfo>();

            foreach (CslaObjectInfo obj in _frmGenerator.ProjectPanel.ListObjects.SelectedItems)
            {
                selectedItems.Add(obj);
                if (!IsLoading && _dbSchemaPanel != null)
                {
                    _currentCslaObject            = obj;
                    _dbSchemaPanel.CslaObjectInfo = obj;
                }
            }

            if (_dbSchemaPanel != null && selectedItems.Count != 1)
            {
                _currentCslaObject            = null;
                _dbSchemaPanel.CslaObjectInfo = null;
            }

            if (selectedItems.Count == 0)
            {
                _frmGenerator.PropertyGrid.SelectedObject = null;
            }
            else
            {
                _frmGenerator.PropertyGrid.SelectedObject = new PropertyBag(selectedItems.ToArray(), _propertyContext);
            }
        }
        private void FillPropertyGrid(TypeInfo typeInfo, string stringType)
        {
            CslaObjectInfo usedType = null;

            if (stringType != "(None)")
            {
                foreach (var baseType in _baseTypes)
                {
                    if (baseType.TypeName ==
                        BusinessRuleTypeEditor.StripKnownNamespaces(_sizeSortedNamespaces, stringType))
                    {
                        usedType = baseType.Type;
                    }
                }
            }

            if (usedType == null)
            {
                typeInfo.IsGenericType = false;
            }
            else
            {
                typeInfo.IsGenericType = usedType.IsGenericType;
            }
        }
        private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var result = new CriteriaPropertyCollection();
            var index  = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                          CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
Beispiel #24
0
        private string GetNamespaceDirectory(string targetDir, CslaObjectInfo info, bool isBaseClass, bool separateNamespaces, bool isClassComment)
        {
            if (targetDir.EndsWith(@"\") == false)
            {
                targetDir += @"\";
            }

            if (separateNamespaces)
            {
                string namespaceSubFolder = info.ObjectNamespace.Replace(".", @"\");

                targetDir += namespaceSubFolder;
                if (targetDir.EndsWith(@"\") == false)
                {
                    targetDir += @"\";
                }
            }

            if (!info.Folder.Trim().Equals(String.Empty))
            {
                targetDir += info.Folder + @"\";
            }
            //if(baseClass && info.ObjectType != CslaObjectType.NameValueList) { targetDir += @"Base\"; }
            if (isBaseClass)
            {
                targetDir += @"Base\";
            }
            if (isClassComment)
            {
                targetDir += @"Comment\";
            }
            CheckDirectory(targetDir);
            return(targetDir);
        }
        private List <string> AddCriteriaProperties(CslaObjectInfo info, Criteria crit, CslaObjectInfo myRootInfo, CslaObjectInfo otherRootInfo, bool isGet, bool isManyToMany)
        {
            List <string>        addedProperties      = new List <string>();
            List <ValueProperty> primaryKeyProperties = new List <ValueProperty>();

            // for 1 to N relations use object ValueProperty instead of root's
            if (!isManyToMany)
            {
                myRootInfo = info;
            }

            if (!isGet)
            {
                // retrieve own primary key properties
                foreach (ValueProperty prop in myRootInfo.ValueProperties)
                {
                    if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                    {
                        primaryKeyProperties.Add(prop);
                    }
                }
            }

            if (isManyToMany || isGet)
            {
                // retrieve related primary key properties
                foreach (ValueProperty prop in otherRootInfo.ValueProperties)
                {
                    if (prop.PrimaryKey != ValueProperty.UserDefinedKeyBehaviour.Default)
                    {
                        primaryKeyProperties.Add(prop);
                    }
                }
            }

            foreach (ValueProperty rootProp in primaryKeyProperties)
            {
                ValueProperty prop = null;
                if (isManyToMany)
                {
                    prop = GetRelatedValueProperty(rootProp);
                }

                if (prop == null)
                {
                    prop = rootProp;
                }

                if (!crit.Properties.Contains(prop.Name))
                {
                    CriteriaProperty p = new CriteriaProperty(prop.Name, prop.PropertyType);
                    p.DbBindColumn = (DbBindColumn)prop.DbBindColumn.Clone();
                    crit.Properties.Add(p);
                    addedProperties.Add(prop.Name);
                }
            }

            return(addedProperties);
        }
Beispiel #26
0
 public DbSchemaPanel(CslaGeneratorUnit cslagenunit, CslaObjectInfo cslaobject, string connection)
 {
     _currentUnit       = cslagenunit;
     cn                 = connection;
     _currentCslaObject = cslaobject;
     // This call is required by the Windows.Forms Form Designer.
     InitializeComponent();
 }
Beispiel #27
0
 private void Init()
 {
     _frmGenerator = new CSLAgen(this);
     _frmGenerator.ProjectPanel.SelectedItemsChanged           += CslaObjectList_SelectedItemsChanged;
     _frmGenerator.ProjectPanel.LastItemRemoved                += delegate { _currentCslaObject = null; };
     _frmGenerator.ObjectRelationsBuilder.SelectedItemsChanged += AssociativeEntitiesList_SelectedItemsChanged;
     _frmGenerator.Show();
 }
Beispiel #28
0
 private void GenerateUpdateProcedure(CslaObjectInfo info, string dir)
 {
     if (info.UpdateProcedureName != "")
     {
         string proc = GenerateProcedure(info, null, "UpdateProcedure.cst", info.UpdateProcedureName);
         WriteToFile(GetSprocFileInfo(info.UpdateProcedureName), proc);
     }
 }
Beispiel #29
0
 public void NewCslaUnit()
 {
     _currentUnit                  = new CslaGeneratorUnit();
     _currentCslaObject            = null;
     _currentUnit.ConnectionString = ConnectionFactory.ConnectionString;
     BindControls();
     EnableButtons();
 }
Beispiel #30
0
        private void GenerateAllSprocsFile(CslaObjectInfo info, string dir, GenerationParameters generationParams)
        {
            var selfLoad = CslaTemplateHelper.GetSelfLoad(info);

            StringBuilder proc = new StringBuilder();

            //make sure we don't generate selects when we don't need to.
            if (!((info.ObjectType == CslaObjectType.EditableChildCollection ||
                   info.ObjectType == CslaObjectType.EditableChild) && !selfLoad))
            {
                foreach (Criteria crit in info.CriteriaObjects)
                {
                    if (crit.GetOptions.Procedure && !String.IsNullOrEmpty(crit.GetOptions.ProcedureName))
                    {
                        proc.AppendLine(GenerateProcedure(info, crit, "SelectProcedure.cst",
                                                          crit.GetOptions.ProcedureName));
                    }
                }
            }

            if (info.ObjectType != CslaObjectType.ReadOnlyObject &&
                info.ObjectType != CslaObjectType.ReadOnlyCollection &&
                info.ObjectType != CslaObjectType.EditableRootCollection &&
                info.ObjectType != CslaObjectType.DynamicEditableRootCollection &&
                info.ObjectType != CslaObjectType.EditableChildCollection &&
                info.ObjectType != CslaObjectType.NameValueList)
            {
                //Insert
                if (info.InsertProcedureName != "")
                {
                    proc.AppendLine(GenerateProcedure(info, null, "InsertProcedure.cst", info.InsertProcedureName));
                }

                //update
                if (info.UpdateProcedureName != "")
                {
                    proc.AppendLine(GenerateProcedure(info, null, "UpdateProcedure.cst", info.UpdateProcedureName));
                }

                //delete
                foreach (Criteria crit in info.CriteriaObjects)
                {
                    if (crit.DeleteOptions.Procedure && !String.IsNullOrEmpty(crit.DeleteOptions.ProcedureName))
                    {
                        proc.AppendLine(GenerateProcedure(info, crit, "DeleteProcedure.cst", crit.DeleteOptions.ProcedureName));
                    }
                }
                if (_targetFramework != TargetFramework.CSLA40 && info.ObjectType == CslaObjectType.EditableChild)
                {
                    proc.AppendLine(GenerateProcedure(info, null, "DeleteProcedure.cst", info.DeleteProcedureName));
                }
            }
            if (proc.Length > 0)
            {
                CheckDirectory(dir + @"\sprocs");
                WriteToFile(dir + @"\sprocs\" + info.ObjectName + ".sql", proc.ToString());
            }
        }