Exemplo n.º 1
0
        public static void SetDbBindColumn(IDataBaseObject obj, IResultSet rs, IColumnInfo p, DbBindColumn dbc)
        {
            var sp = obj as IStoredProcedureInfo;

            if (sp != null)
            {
                obj = sp;
                dbc.SpResultIndex = sp.ResultSets.IndexOf(rs);
            }

            switch (rs.Type)
            {
            case ResultType.Table:
                dbc.ColumnOriginType = ColumnOriginType.Table;
                break;

            case ResultType.View:
                dbc.ColumnOriginType = ColumnOriginType.View;
                break;

            case ResultType.StoredProcedure:
                dbc.ColumnOriginType = ColumnOriginType.StoredProcedure;
                break;
            }

            //dbc.ColumnOriginType=
            dbc.CatalogName = obj.ObjectCatalog;
            dbc.SchemaName  = obj.ObjectSchema;
            dbc.ObjectName  = obj.ObjectName;
            dbc.ColumnName  = p.ColumnName;
            dbc.LoadColumn(GeneratorController.Catalog);
        }
Exemplo n.º 2
0
 private SqlHelper()
 {
     if (_dataBaseObject == null)
     {
         string DbTypeString      = ConfigurationManager.AppSettings["DataBaseType"];
         CreateDataBaseFactory df = new CreateDataBaseFactory();
         _dataBaseObject = df.CreateDataBase(DbTypeString);
     }
 }
Exemplo n.º 3
0
        private string GetObjectName(IDataBaseObject obj)
        {
            if (obj.ObjectCatalog != null && obj.ObjectSchema != null)
            {
                return(obj.ObjectSchema + "." + obj.ObjectName);
            }

            return(obj.ObjectName);
        }
Exemplo n.º 4
0
 public void LoadNode(TreeNode node, IDataBaseObject obj)
 {
     if (obj is IStoredProcedureInfo)
     {
         LoadStoredProcedureNode(node, (IStoredProcedureInfo)obj);
     }
     else if (obj is IViewInfo)
     {
         LoadViewNode(node, (IViewInfo)obj);
     }
     else if (obj is ITableInfo)
     {
         LoadTableNode(node, (ITableInfo)obj);
     }
 }
        /// <summary>
        /// Initializes a new instance of the ObjectFactory class.
        /// </summary>
        /// <param name="currentUnit">The current unit.</param>
        /// <param name="entity">The associative entity.</param>
        public ObjectRelationsFactory(CslaGeneratorUnit currentUnit, AssociativeEntity entity)
        {
            _currentUnit               = currentUnit;
            _cslaObjects               = _currentUnit.CslaObjects;
            _entity                    = entity;
            MainObjectInfo             = _cslaObjects.Find(_entity.MainObject);
            MainRootCriteriaProperties = GetCriteriaProperties(MainObjectInfo);

            if (entity.RelationType == ObjectRelationType.ManyToMany)
            {
                SecondaryObjectInfo             = _cslaObjects.Find(_entity.SecondaryObject);
                SecondaryRootCriteriaProperties = GetCriteriaProperties(SecondaryObjectInfo);

                _associativeTable = FindAssociativeTable(MainObjectInfo, SecondaryObjectInfo);

                _resultSet = new TableResultSet(
                    _associativeTable.ResultIndex,
                    _associativeTable.Columns,
                    _associativeTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associativeTable.ObjectCatalog,
                    _associativeTable.ObjectName,
                    _associativeTable.ObjectSchema,
                    _associativeTable.Catalog);
            }
            else
            {
                var mainItemObjectInfo = _cslaObjects.Find(_entity.MainItemTypeName);

                _associatedTable = FindAssociatedTable(MainObjectInfo, mainItemObjectInfo);

                _resultSet = new TableResultSet(
                    _associatedTable.ResultIndex,
                    _associatedTable.Columns,
                    _associatedTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associatedTable.ObjectCatalog,
                    _associatedTable.ObjectName,
                    _associatedTable.ObjectSchema,
                    _associatedTable.Catalog);
            }
        }
Exemplo n.º 6
0
        public static void SetDbBindColumn(TreeNode node, IColumnInfo p, DbBindColumn dbc)
        {
            //TreeNode node = TreeViewSchema.SelectedNode;
            IResultSet           rs = (IResultSet)node.Tag;
            IStoredProcedureInfo sp = null;

            if (node.Parent.Tag != null)
            {
                sp = (IStoredProcedureInfo)node.Parent.Tag;
            }
            IDataBaseObject obj = null;

            if (sp != null)
            {
                obj = sp;
                dbc.SpResultIndex = sp.ResultSets.IndexOf(rs);
            }
            else
            {
                obj = (IDataBaseObject)rs;
            }

            switch (rs.Type)
            {
            case ResultType.Table:
                dbc.ColumnOriginType = ColumnOriginType.Table;
                break;

            case ResultType.View:
                dbc.ColumnOriginType = ColumnOriginType.View;
                break;

            case ResultType.StoredProcedure:
                dbc.ColumnOriginType = ColumnOriginType.StoredProcedure;
                break;
            }

            //dbc.ColumnOriginType=
            dbc.CatalogName = obj.ObjectCatalog;
            dbc.SchemaName  = obj.ObjectSchema;
            dbc.ObjectName  = obj.ObjectName;
            dbc.ColumnName  = p.ColumnName;
            dbc.LoadColumn(GeneratorController.Catalog);
        }
Exemplo n.º 7
0
        private void reloadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IDataBaseObject obj = currentTreeNode.Tag as IDataBaseObject;

            if (obj != null)
            {
                try
                {
                    obj.Reload(true);
                    dbTreeView1.LoadNode(currentTreeNode, obj);
                    TreeNodeSelected(currentTreeNode);
                }
                catch (Exception ex)
                {
                    OutputWindow.Current.ClearOutput();
                    OutputWindow.Current.AddOutputInfo(ex.Message, 2);
                    //OutputWindow.Current.AddOutputInfo(ex.StackTrace, 2);
                }
            }
        }
Exemplo n.º 8
0
        private void AddPropertiesForSelectedColumns()
        {
            if (_currentCslaObject == null)
            {
                return;
            }
            if (SelectedColumnsCount == 0)
            {
                MessageBox.Show(this, @"You must first select a column to add.", @"Warning");
                return;
            }

            List <IColumnInfo> columns = new List <IColumnInfo>();

            for (int i = 0; i < SelectedColumns.Count; i++)
            {
                columns.Add((IColumnInfo)dbColumns1.ListColumns.SelectedItems[i]);
            }

            IDataBaseObject dbObject  = GetCurrentDBObject();
            IResultSet      resultSet = GetCurrentResultSet();

            _currentFactory.AddProperties(_currentCslaObject, dbObject, resultSet, columns, true, false);
        }
Exemplo n.º 9
0
        internal void LoadColumn(ICatalog catalog)
        {
            _catalog        = catalog;
            _resultSet      = null;
            _databaseObject = null;
            _column         = null;
            string cat = null;

            if (_catalogName != null)
            {
                if (string.Compare(_catalogName, _catalog.CatalogName, true) != 0)
                {
                    cat = null; //When connecting to a DB with a different name
                }
                else
                {
                    cat = _catalogName;
                }
            }
            try
            {
                switch (_columnOriginType)
                {
                case ColumnOriginType.Table:
                    ITableInfo tInfo = _catalog.Tables[cat, _schemaName, _objectName];
                    if (tInfo != null)
                    {
                        _databaseObject = tInfo;
                        _resultSet      = tInfo;
                    }
                    break;

                case ColumnOriginType.View:
                    //_Column = _Catalog.Views[_CatalogName, _SchemaName, _objectName].Columns[_columnName];
                    IViewInfo vInfo = _catalog.Views[cat, _schemaName, _objectName];
                    if (vInfo != null)
                    {
                        _databaseObject = vInfo;
                        _resultSet      = vInfo;
                    }
                    break;

                case ColumnOriginType.StoredProcedure:
                    IStoredProcedureInfo pInfo = _catalog.Procedures[cat, _schemaName, _objectName];
                    if (pInfo != null)
                    {
                        _databaseObject = pInfo;
                        if (pInfo.ResultSets.Count > _spResultSetIndex)
                        {
                            _resultSet = pInfo.ResultSets[_spResultSetIndex];
                        }
                    }
                    break;

                case ColumnOriginType.None:

                    break;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            if (_resultSet != null)
            {
                _column = _resultSet.Columns[_columnName];
            }
            ReloadColumnInfo();
        }
Exemplo n.º 10
0
 /// <summary>
 /// Adds the specified list of columns from the specified resultset and database object to the current object.
 /// </summary>
 /// <param name="currentCslaObject">The current csla object.</param>
 /// <param name="obj">The database object.</param>
 /// <param name="rs">The result set.</param>
 /// <param name="selectedColumns">The selected columns.</param>
 /// <param name="createDefaultCriteria">If true, it calls AddDefaultCriteriaAndParameters() automatically</param>
 /// <param name="askConfirmation">if set to <c>true</c> [ask confirmation].</param>
 public void AddProperties(CslaObjectInfo currentCslaObject, IDataBaseObject obj, IResultSet rs,
                           IList <IColumnInfo> selectedColumns, bool createDefaultCriteria, bool askConfirmation)
 {
     AddProperties(currentCslaObject, obj, rs, selectedColumns, createDefaultCriteria, askConfirmation,
                   string.Empty);
 }
Exemplo n.º 11
0
        public void SetValuePropertyInfo(IDataBaseObject obj, IResultSet rs, IColumnInfo prop, ValueProperty destination)
        {
            var p = prop;

            SetDbBindColumn(obj, rs, p, destination.DbBindColumn);
            destination.Nullable = (p.IsNullable);

            if (p.NativeType == "timestamp")
            {
                destination.ReadOnly        = true;
                destination.Undoable        = false;
                destination.DeclarationMode = PropertyDeclaration.Managed;
            }

            if (_currentCslaObject.IsReadOnlyObject() || _currentCslaObject.IsNameValueList())
            {
                destination.DeclarationMode = PropertyDeclaration.Managed;
                destination.ReadOnly        = true;
            }

            if (p.IsPrimaryKey)
            {
                destination.Undoable = false;
                if (p.IsIdentity)
                {
                    destination.PrimaryKey           = ValueProperty.UserDefinedKeyBehaviour.DBProvidedPK;
                    destination.ReadOnly             = true;
                    destination.PropSetAccessibility = AccessorVisibility.Default;
                }
                else
                {
                    destination.PrimaryKey = ValueProperty.UserDefinedKeyBehaviour.UserProvidedPK;
                }

                if (destination.PropertyType == TypeCodeEx.Guid)
                {
                    destination.DefaultValue = _currentUnit.Params.IDGuidDefaultValue;
                }
                else if (p.IsIdentity && _currentCslaObject.IsNotReadOnlyObject() && _currentCslaObject.IsNotNameValueList())
                {
                    switch (p.DbType)
                    {
                    case DbType.Int16:
                        destination.DefaultValue = _currentUnit.Params.IDInt16DefaultValue;
                        break;

                    case DbType.Int32:
                        destination.DefaultValue = _currentUnit.Params.IDInt32DefaultValue;
                        break;

                    case DbType.Int64:
                        destination.DefaultValue = _currentUnit.Params.IDInt64DefaultValue;
                        break;
                    }
                }
            }

            if (_currentUnit.Params.CreationDateColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.Undoable             = false;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                destination.DataAccess           = ValueProperty.DataAccessBehaviour.CreateOnly;
                if (destination.PropertyType == TypeCodeEx.SmartDate)
                {
                    destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                        ? "new SmartDate(" + GetNowValue(TypeCodeEx.DateTime) + ")"
                        : "new SmartDate(DateTime.Today)";
                }
                else
                {
                    destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                        ? GetNowValue(destination.PropertyType)
                        : "DateTime.Today";
                }
            }
            else if (_currentUnit.Params.CreationUserColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.Undoable             = false;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                destination.DataAccess           = ValueProperty.DataAccessBehaviour.CreateOnly;
                destination.DefaultValue         = _currentUnit.Params.GetUserMethod;
            }
            else if (_currentUnit.Params.ChangedDateColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.Undoable             = false;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                if (_currentCslaObject.IsCreationDateColumnPresent())
                {
                    destination.DefaultValue = "$" + _currentUnit.Params.CreationDateColumn;
                }
                else
                {
                    if (destination.PropertyType == TypeCodeEx.SmartDate)
                    {
                        destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                            ? "new SmartDate(" + GetNowValue(TypeCodeEx.DateTime) + ")"
                            : "new SmartDate(DateTime.Today)";
                    }
                    else
                    {
                        destination.DefaultValue = _currentUnit.Params.LogDateAndTime
                            ? GetNowValue(destination.PropertyType)
                            : "DateTime.Today";
                    }
                }
            }
            else if (_currentUnit.Params.ChangedUserColumn == p.ColumnName)
            {
                destination.ReadOnly             = true;
                destination.Undoable             = false;
                destination.PropSetAccessibility = AccessorVisibility.Default;
                if (_currentCslaObject.IsCreationUserColumnPresent())
                {
                    destination.DefaultValue = "$" + _currentUnit.Params.CreationUserColumn;
                }
                else
                {
                    destination.DefaultValue = _currentUnit.Params.GetUserMethod;
                }
            }
            else if (_currentUnit.Params.DatesDefaultStringWithTypeConversion &&
                     (destination.PropertyType == TypeCodeEx.SmartDate ||
                      destination.PropertyType == TypeCodeEx.DateTime ||
                      destination.PropertyType == TypeCodeEx.DateTimeOffset))
            {
                destination.BackingFieldType = destination.PropertyType;
                destination.PropertyType     = TypeCodeEx.String;
                destination.DeclarationMode  = PropertyDeclaration.ManagedWithTypeConversion;
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Adds the specified list of columns from the specified resultset and database object to the current object.
        /// </summary>
        /// <param name="obj">The database object.</param>
        /// <param name="rs">The result set.</param>
        /// <param name="selectedColumns">The selected columns.</param>
        /// <param name="createDefaultCriteria">If true, it calls AddDefaultCriteriaAndParameters() automatically</param>
        /// <param name="askConfirmation">if set to <c>true</c> [ask confirmation].</param>
        /// <param name="getSprocName">Name of the get sproc.</param>
        public void AddProperties(IDataBaseObject obj, IResultSet rs, IList <IColumnInfo> selectedColumns,
                                  bool createDefaultCriteria, bool askConfirmation, string getSprocName)
        {
            if (_currentCslaObject == null || selectedColumns.Count == 0)
            {
                return;
            }

            var         added         = false;
            var         addedProps    = new List <ValueProperty>();
            var         notAddedProps = new StringCollection();
            var         origin        = ColumnOriginType.Table;
            IColumnInfo col;

            for (var i = 0; i < selectedColumns.Count; i++)
            {
                col = selectedColumns[i];
                // use name of column to see if a property of the same name exists
                var propertyName = col.ColumnName;
                if (PropertyExists(propertyName))
                {
                    var count = 1;
                    while (PropertyExists(propertyName + count))
                    {
                        count += 1;
                    }
                    propertyName += count.ToString();
                }

                var newProp = new ValueProperty();

                newProp.Name         = propertyName;
                newProp.Summary      = col.ColumnDescription;
                newProp.PropertyType = col.ManagedType.GetTypeCodeEx();
                SetValuePropertyInfo(obj, rs, col, newProp);
                if (newProp.DbBindColumn.ColumnOriginType != ColumnOriginType.Table)
                {
                    origin = newProp.DbBindColumn.ColumnOriginType;
                }
                if (!askConfirmation)
                {
                    _currentCslaObject.ValueProperties.Add(newProp);
                    added = true;
                }
                addedProps.Add(newProp);
            }

            if (addedProps.Count > 0 && askConfirmation)
            {
                var msg = new StringBuilder();
                msg.Append("The properties listed below are missing.\r\n\r\n" +
                           "Do you want to add the following properties:" +
                           Environment.NewLine);
                foreach (var valueProperty in addedProps)
                {
                    msg.AppendFormat(" - {0}.{1}\r\n", _currentCslaObject.ObjectName, valueProperty.Name);
                }

                var response = MessageBox.Show(msg.ToString(), @"Missing ValueProperty found.",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Error);
                if (response == DialogResult.Yes)
                {
                    foreach (var valueProperty in addedProps)
                    {
                        _currentCslaObject.ValueProperties.Add(valueProperty);
                    }
                    added = true;
                }
            }

            // Add Get-, New- and DeleteObjectCriteria and linked parameters
            if (createDefaultCriteria)
            {
                AddDefaultCriteriaAndParameters(getSprocName);
            }

            // Display message to the user
            var sb = new StringBuilder();

            if (addedProps.Count > 0 && added)
            {
                sb.Append("Successfully added the following Value Properties:" + Environment.NewLine);
                foreach (var propName in addedProps)
                {
                    sb.AppendFormat("\t{0}.{1}\r\n", _currentCslaObject.ObjectName, propName.Name);
                }
            }

            if (notAddedProps.Count > 0)
            {
                sb.Append("The following properties already exist:" + Environment.NewLine);
                foreach (var propName in notAddedProps)
                {
                    sb.Append("\t" + propName + Environment.NewLine);
                }
            }

            if (origin != ColumnOriginType.Table && origin != ColumnOriginType.View)
            {
                _currentCslaObject.GenerateSprocs = false;
                sb.Append(Environment.NewLine);
                sb.Append(
                    "Note: \"Generate stored procedures\" was set to false because the origin of the columns is a Stored Procedure result set." +
                    Environment.NewLine);

                var parent = _currentCslaObject.Parent.CslaObjects.Find(_currentCslaObject.ParentType);
                if (parent != null)
                {
                    parent.GenerateSprocs = false;
                    parent.ContainsItem   = false;
                    sb.Append(
                        "Note: \"Use Contains Methods\" was set to false because there is no defined Primary Key property." +
                        Environment.NewLine);
                }
            }

            if (sb.ToString().Length > 0)
            {
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }
        }
Exemplo n.º 13
0
 /// <summary>
 /// Adds the specified list of columns from the specified resultset and database object to the current object.
 /// </summary>
 /// <param name="currentCslaObject">The current csla object.</param>
 /// <param name="obj">The database object.</param>
 /// <param name="rs">The result set.</param>
 /// <param name="selectedColumns">The selected columns.</param>
 /// <param name="createDefaultCriteria">If true, it calls AddDefaultCriteriaAndParameters() automatically</param>
 /// <param name="askConfirmation">if set to <c>true</c> [ask confirmation].</param>
 /// <param name="getSprocName">Name of the get sproc.</param>
 public void AddProperties(CslaObjectInfo currentCslaObject, IDataBaseObject obj, IResultSet rs,
                           IList <IColumnInfo> selectedColumns, bool createDefaultCriteria, bool askConfirmation, string getSprocName)
 {
     _currentCslaObject = currentCslaObject;
     AddProperties(obj, rs, selectedColumns, createDefaultCriteria, askConfirmation, getSprocName);
 }