Пример #1
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            for (int i = Controls.Count - 1; i >= 0; i--)
            {
                Control control = Controls[i];
                control.Focus();
                if (!Validate())
                {
                    DialogResult = DialogResult.None;
                    return;
                }
            }

            if (_index == null)
            {
                _index = new Index(textBoxName.Text, true, textBoxType.Text, _parent, false, false);
            }
            else
            {
                _index.Name = textBoxName.Text;
                _index.Type = textBoxType.Text;
            }
            _index.Alias = textBoxAlias.Text;
            _index.Description = textBoxDescription.Text;
        }
Пример #2
0
        public FormIndex(Index index)
        {
            InitializeComponent();
            this.BackColor = Slyce.Common.Colors.BackgroundColor;

            _parent = index.Parent;
            _index = index;
            ucHeading1.Text = "";
            Controller.ShadeMainForm();
        }
Пример #3
0
        public FormIndex(Index index)
        {
            InitializeComponent();
            BackColor = Slyce.Common.Colors.BackgroundColor;

            _parent = index.Parent;
            _index = index;
            ucHeading1.Text = "";
            Interfaces.Events.ShadeMainForm();
        }
Пример #4
0
        public static Index[] GetEnabledIndexs(Index[] indexes)
        {
            List<Index> enabledIndexes = new List<Index>();
            foreach (Index index in indexes)
            {
                if (index.Enabled)
                {
                    enabledIndexes.Add(index);
                }
            }

            return enabledIndexes.ToArray();
        }
Пример #5
0
        public static int GetAliasCount(Index[] indexes, string alias)
        {
            int count = 0;

            foreach (Index index in indexes)
            {
                if (index.Alias == alias)
                {
                    count++;
                }
            }
            return count;
        }
Пример #6
0
        public static Index[] GetUserDefinedIndexes(Index[] indexes)
        {
            List<Index> userDefinedIndexes = new List<Index>();

            foreach (Index index in indexes)
            {
                if (index.IsUserDefined)
                {
                    userDefinedIndexes.Add(index);
                }
            }
            return userDefinedIndexes.ToArray();
        }
Пример #7
0
        private Model.Table GetNewTable(string schema, string tableName)
        {
            Interfaces.Events.RaiseObjectBeingProcessedEvent(tableName, "Table");
            Model.Table table = new Model.Table(tableName, false);

            #region Columns
            DataRow[] columnRows = Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'", schema, tableName));

            foreach (DataRow columnRow in columnRows)
            {
                bool isReadOnly = false;

                if (!columnRow.IsNull("IsIdentity") && (int)columnRow["IsIdentity"] == 1)
                {
                    isReadOnly = true;
                }
                else if (!columnRow.IsNull("IsComputed") && (int)columnRow["IsComputed"] == 1)
                {
                    isReadOnly = true;
                }
                else if (Slyce.Common.Utility.StringsAreEqual((string)columnRow["DATA_TYPE"], "timestamp", false))
                {
                    isReadOnly = true;
                }
                Column column = new Column(
                    (string)columnRow["COLUMN_NAME"],
                    false,
                    table,
                    (int)columnRow["ORDINAL_POSITION"],
                    Slyce.Common.Utility.StringsAreEqual((string)columnRow["IS_NULLABLE"], "YES", false),
                    (string)columnRow["DATA_TYPE"],
                    columnRow.IsNull("CHARACTER_MAXIMUM_LENGTH") ? 0 : Convert.ToInt32(columnRow["CHARACTER_MAXIMUM_LENGTH"]),
                    (int)columnRow["InPrimaryKey"] == 1,
                    columnRow.IsNull("IsIdentity") ? false : Convert.ToInt32(columnRow["IsIdentity"]) == 1,
                    columnRow.IsNull("COLUMN_DEFAULT") ? "" : (string)columnRow["COLUMN_DEFAULT"],
                    isReadOnly,
                    columnRow.IsNull("IsComputed") ? false : Convert.ToInt32(columnRow["IsComputed"]) == 1,
                    columnRow.IsNull("NUMERIC_PRECISION") ? 0 : Convert.ToInt32(columnRow["NUMERIC_PRECISION"]),
                    columnRow.IsNull("NUMERIC_SCALE") ? 0 : Convert.ToInt32(columnRow["NUMERIC_SCALE"]));

                if (IsSupported(column))
                {
                    table.AddColumn(column);
                }
            }

            #endregion

            #region Indexes
            DataRow[] indexRows = Indexes.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'", schema, tableName));
            //foreach (DataRow indexRow in indexRows)
            for (int i = 0; i < indexRows.Length; i++)
            {
                DataRow indexRow = indexRows[i];
                string indexType;
                string indexKeyType = indexRow["CONSTRAINT_TYPE"].ToString();

                if (indexKeyType == "PRIMARY KEY")
                {
                    indexType = DatabaseConstant.IndexType.PrimaryKey;
                    //continue;
                }
                else if (indexKeyType == "FOREIGN KEY")
                {
                    indexType = DatabaseConstant.IndexType.ForeignKey;
                    //continue;
                }
                else if (indexKeyType == "UNIQUE")
                {
                    //continue;
                    indexType = DatabaseConstant.IndexType.Unique;
                }
                else if (indexKeyType == "CHECK")
                {
                    indexType = DatabaseConstant.IndexType.Check;
                }
                else if (indexKeyType == "NONE")    //TODO check is NONE
                {
                    indexType = DatabaseConstant.IndexType.None;
                }
                else
                {
                    //continue;
                    throw new Exception("IndexType " + indexKeyType + " Not Defined");
                }
                List<DataRow> indexColumnRows = new List<DataRow>();// = IndexColumns.Select(string.Format("TABLE_NAME = '{0}' AND CONSTRAINT_NAME  = '{1}'", tableName, indexRow["CONSTRAINT_NAME"]));

                indexColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME  = '{2}'", schema, tableName, indexRow["COLUMN_NAME"])));

                while ((i < indexRows.Length - 1) && (string)indexRows[i + 1]["TABLE_NAME"] == tableName && (string)indexRows[i + 1]["CONSTRAINT_NAME"] == (string)indexRow["CONSTRAINT_NAME"])
                {
                    i++;
                    indexRow = indexRows[i];
                    indexColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME  = '{2}'", schema, tableName, indexRow["COLUMN_NAME"])));
                }
                bool isUnique = (int)indexRow["IS_UNIQUE"] == 1 ? true : false;
                bool isClustered = (int)indexRow["IS_CLUSTERED"] == 1 ? true : false;
                Index index = new Index(indexRow["CONSTRAINT_NAME"].ToString(), false, indexType, table, isUnique, isClustered);

                // Fill Columns
                foreach (DataRow indexColumnRow in indexColumnRows)
                {
                    Column indexColumn = new Column(indexColumnRow["COLUMN_NAME"].ToString(), false);
                    index.AddColumn(indexColumn);
                }
                index.ResetDefaults();
                table.AddIndex(index);
            }

            // Indexes -- that should be keys
            DataRow[] keyRows = Indexes.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}'", schema, tableName));

            //foreach (DataRow keyRow in indexRows)
            for (int i = 0; i < keyRows.Length; i++)
            {
                DataRow keyRow = keyRows[i];
                string keyType;
                string indexKeyType = keyRow["CONSTRAINT_TYPE"].ToString();

                if (indexKeyType == "PRIMARY KEY")
                {
                    keyType = DatabaseConstant.KeyType.Primary;
                }
                else if (indexKeyType == "FOREIGN KEY")
                {
                    keyType = DatabaseConstant.KeyType.Foreign;
                }
                else if (indexKeyType == "UNIQUE")
                {
                    keyType = DatabaseConstant.KeyType.Unique;
                }
                else
                {
                    continue;
                }
                Key key = new Key(keyRow["CONSTRAINT_NAME"].ToString(), false, keyType, table, false);

                // Fill Columns
                List<DataRow> keyColumnRows = new List<DataRow>();
                keyColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, keyRow["COLUMN_NAME"])));

                while ((i < keyRows.Length - 1) && (string)keyRows[i + 1]["TABLE_NAME"] == tableName && (string)keyRows[i + 1]["CONSTRAINT_NAME"] == (string)keyRow["CONSTRAINT_NAME"])
                {
                    i++;
                    keyRow = keyRows[i];
                    keyColumnRows.AddRange(Columns.Select(string.Format("TABLE_SCHEMA = '{0}' AND TABLE_NAME = '{1}' AND COLUMN_NAME = '{2}'", schema, tableName, keyRow["COLUMN_NAME"])));
                }
                // Fill Columns
                foreach (DataRow keyColumnRow in keyColumnRows)
                {
                    Column keyColumn = new Column(keyColumnRow["COLUMN_NAME"].ToString(), false);
                    keyColumn.DataType = (string)keyColumnRow["DATA_TYPE"];
                    key.AddColumn(keyColumn);
                }
                if (keyType == DatabaseConstant.KeyType.Foreign)
                {
                    DataRow[] keyReferencedColumnRows = IndexReferencedColumns.Select(string.Format("ForeignKeySchema = '{0}' AND ForeignKeyTable = '{1}' AND ForeignKey = '{2}'", schema, tableName, keyRow["CONSTRAINT_NAME"]));
                    DataRow firstKeyReferencedColumnRow = keyReferencedColumnRows[0];

                    // Fill References
                    key.ReferencedTable = new Model.Table(firstKeyReferencedColumnRow["ReferencedTable"].ToString(), false) { Schema = firstKeyReferencedColumnRow["ReferencedSchema"].ToString() };
                    key.ReferencedKey = new Key(firstKeyReferencedColumnRow["ReferencedKey"].ToString(), false, true);

                    // Fill Referenced Columns
                    foreach (DataRow keyReferencedColumnRow in keyReferencedColumnRows)
                    {
                        Column keyReferencedColumn = new Column(keyReferencedColumnRow["ReferencedColumn"].ToString(), false);
                        key.AddReferencedColumn(keyReferencedColumn);
                    }
                }
                key.ResetDefaults();
                table.AddKey(key);
            }

            #endregion

            return table;
        }
Пример #8
0
        public bool NameValidate(Index index, out string failReason)
        {
            failReason = "";
            /*Don't check items that are not enabled*/

            if (!index.Enabled)
            {
                return true;
            }
            if (string.IsNullOrEmpty(index.Name))
            {
                failReason = "Name cannot be zero-length.";
                return false;
            }
            if (index.Name.IndexOf(" ") >= 0)
            {
                failReason = "Name cannot have spaces.";
                return false;
            }
            return true;
        }
Пример #9
0
 public static string GetFilterAlias(Index index)
 {
     string alias = "Get" + index.Parent.Alias + "By" + Parameter.GetNameAfterSplit(index.Alias, '_');
     return alias;
 }
Пример #10
0
 public bool AliasValidate(Index index, out string failReason)
 {
     failReason = "";
     return true;
 }
Пример #11
0
 public virtual string AliasPluralDefault(Index index)
 {
     return ArchAngel.Providers.Database.Helper.Script.GetPlural(index.Alias);
 }
Пример #12
0
 public string AliasDefault(Index index)
 {
     return index.Name.Trim();
 }
Пример #13
0
 /// <summary>
 /// TODO: I don't think this should be exposed to the user???
 /// </summary>
 /// <param name="indexOf"></param>
 /// <param name="index"></param>
 public void UpdateIndex(int indexOf, Index index)
 {
     Interfaces.Events.RaiseDataChangedEvent(GetType(), (MethodInfo)MethodBase.GetCurrentMethod(), _indexes[indexOf], index);
     _indexes[indexOf] = index;
 }
Пример #14
0
 /// <summary>
 /// TODO: I don't think this should be exposed to the user???
 /// </summary>
 /// <param name="index"></param>
 public void RemoveIndex(Index index)
 {
     Interfaces.Events.RaiseDataChangedEvent(GetType(), (MethodInfo)MethodBase.GetCurrentMethod(), index, null);
     _indexes.Remove(index);
 }