Click here to Skip to main content
15,893,663 members
Articles / Desktop Programming / WPF

DBTool for Oracle - Part 1

Rate me:
Please Sign up or sign in to vote.
4.92/5 (45 votes)
13 Apr 2014CPOL18 min read 138K   5.1K   88  
Enhance productivity and reliability, write your own tools.
using System;
using Harlinn.Oracle.DBTool.Types.Database;
using System.Collections.Generic;

using Harlinn.Oracle.DBTool.Utils;

namespace Harlinn.Oracle.DBTool.Types.Projects
{
    [Serializable]
    public class ProjectTabularReference : ProjectElement
    {
        private string referencedSchema;
        private string referencedTable;
        private bool isLookup;

        public ProjectTabularReference()
        {

        }
        public ProjectTabularReference(ProjectTabularReferences parent, DBUserTableConstraint dbConstraint)
            : base(parent, dbConstraint.Name)
        {
            DBUserTableConstraint referencedConstraint = dbConstraint.GetReferencedConstraint();
            DBUserTable dbReferencedTable = referencedConstraint.Constraints.Table;

            referencedSchema = dbReferencedTable.GetOwner();
            referencedTable = dbReferencedTable.Name;

            GetColumns().AddColumns(dbConstraint, referencedConstraint);
        }

        public override ProjectElementType ElementType
        {
            get
            {
                return ProjectElementType.ProjectTabularReference;
            }
        }


        public override void WriteElement(System.IO.BinaryWriter writer)
        {
            base.WriteElement(writer);

            writer.WriteNullable(ReferencedSchema);
            writer.WriteNullable(ReferencedTable);
            writer.Write(IsLookup);

            ProjectTabularReferenceColumns projectTabularReferenceColumns = GetColumns();
            projectTabularReferenceColumns.WriteElement(writer);

        }

        public override void ReadElement(System.IO.BinaryReader reader)
        {
            base.ReadElement(reader);
            ReferencedSchema = reader.ReadNullableString();
            ReferencedTable = reader.ReadNullableString();
            IsLookup = reader.ReadBoolean();

            Children.Clear();

            ProjectTabularReferenceColumns columns = new ProjectTabularReferenceColumns(this);
            Children.Add(columns);
            columns.ReadElement(reader);

        }



        public override void Refresh()
        {
            base.Refresh();
            Children.Clear();

            ProjectTabularReferenceColumns columns = new ProjectTabularReferenceColumns(this);
            Children.Add(columns);
        }

        public ProjectTabularReferences GetReferences()
        {
            ProjectTabularReferences result = (ProjectTabularReferences)Parent;
            return result;
        }



        public ProjectTabularReferenceColumns GetColumns()
        {
            ProjectTabularReferenceColumns result = GetChildByName<ProjectTabularReferenceColumns>("Columns");
            return result;
        }


        public ProjectTabularReferenceColumn GetColumn(string name)
        {
            return GetColumns().GetColumn(name);
        }


        public string ReferencedSchema
        {
            get
            {
                return referencedSchema;
            }
            set
            {
                if (referencedSchema == value)
                    return;
                referencedSchema = value;
                OnPropertyChanged("ReferencedSchema");
            }
        }
        public string ReferencedTable
        {
            get
            {
                return referencedTable;
            }
            set
            {
                if (referencedTable == value)
                    return;
                referencedTable = value;
                OnPropertyChanged("ReferencedTable");
            }
        }


        public bool IsLookup
        {
            get
            {
                return isLookup;
            }
            set
            {
                if (isLookup == value)
                    return;
                isLookup = value;
            }
        }


        public ProjectTabular GetTabular()
        {
            ProjectTabular result = GetReferences().GetTabular();
            return result;
        }


        public List<ProjectTabularField> GetFieldList()
        {

            List<ProjectTabularField> result = new List<ProjectTabularField>();
            ProjectTabular tabular = GetTabular();

            if (tabular != null)
            {
                ProjectTabularReferenceColumns columns = GetColumns();
                ProjectTabularFields fields = tabular.GetFields();

                foreach (ProjectTabularReferenceColumn column in columns.Children)
                {
                    string columnName = column.Name;
                    ProjectTabularField field = fields.GetField(columnName);
                    if (field != null)
                    {
                        result.Add(field);
                    }
                }
            }

            return result;
        }


    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect Sea Surveillance AS
Norway Norway
Chief Architect - Sea Surveillance AS.

Specializing in integrated operations and high performance computing solutions.

I’ve been fooling around with computers since the early eighties, I’ve even done work on CP/M and MP/M.

Wrote my first “real” program on a BBC micro model B based on a series in a magazine at that time. It was fun and I got hooked on this thing called programming ...

A few Highlights:

  • High performance application server development
  • Model Driven Architecture and Code generators
  • Real-Time Distributed Solutions
  • C, C++, C#, Java, TSQL, PL/SQL, Delphi, ActionScript, Perl, Rexx
  • Microsoft SQL Server, Oracle RDBMS, IBM DB2, PostGreSQL
  • AMQP, Apache qpid, RabbitMQ, Microsoft Message Queuing, IBM WebSphereMQ, Oracle TuxidoMQ
  • Oracle WebLogic, IBM WebSphere
  • Corba, COM, DCE, WCF
  • AspenTech InfoPlus.21(IP21), OsiSoft PI


More information about what I do for a living can be found at: harlinn.com or LinkedIn

You can contact me at espen@harlinn.no

Comments and Discussions