Exemple #1
0
        /// <summary>
        /// This adds the ability to generate notifications for a specific table. It accepts a tablename. It then create a new
        /// Notification table from the received tablename. There is also a foreign link which is created between parent table
        /// and notification table.
        /// </summary>
        /// <param name="DB_PLATFORM"></param>
        /// <param name="connAuth"></param>
        /// <param name="OwnerName"></param>
        /// <param name="TableName"></param>
        /// <returns></returns>
        public List <CommandResult> ADD_SCAFFOLD_NOTIFICATION(IConnectToDB _Connect, string TableName)
        {
            Tools.Box            er_tools   = new Tools.Box();
            ER_DDL               ddl        = new ER_DDL();
            ER_Generate          gen        = new ER_Generate();
            List <CommandResult> HoldResult = new List <CommandResult>();

            string newTableName       = er_tools.MaxNameLength(TableName, (128 - 16));
            string Notification_Table = newTableName + "_NTFY";

            HoldResult.Add(new CommandResult {
                _Response = "---Start Notification Scaffold " + TableName + "", _Successful = true
            });
            List <ColumnStructure> ColumnsList = new List <ColumnStructure>();

            //HoldResult.Add(ER_DDL._ADD_TABLE(_Connect, Perm_Table, "Permission"));
            HoldResult.AddRange(ER_DDL._ADD_TABLE(_Connect, Notification_Table, "Notification"));

            ColumnsList.Add(new ColumnStructure {
                _Name = "OBJECT_TYPE", _DataType = "Characters(120)", _IsNull = false, _DefaultValue = ""
            });
            ColumnsList.Add(new ColumnStructure {
                _Name = TableName + "_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
            });
            //ColumnsList.Add(new ColumnStructure { _Name = "APPLICATIONS_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = "" });

            HoldResult.AddRange(ddl.ADD_COLUMNS(_Connect, Notification_Table, ColumnsList));

            HoldResult.AddRange(gen.ADD_PROCEDURE_INSERT(_Connect, Notification_Table, ""));

            ColumnsList.Clear();

            ColumnsList.Add(new ColumnStructure {
                _Name = TableName + "_UUID", _DataType = "Guid", _IsNull = false, _DefaultValue = ""
            });

            HoldResult.AddRange(ddl.ADD_KEY_FOREIGN(_Connect, TableName + "_NTFY", Notification_Table, TableName, ColumnsList, ColumnsList));

            //ColumnsList.Clear();

            //ColumnsList.Add(new ColumnStructure { _Name = "APPLICATIONS_ID", _DataType = "bigint", _IsNull = false, _DefaultValue = "" });

            //HoldResult.Add(ADD_KEY_FOREIGN(_Connect, TableName + "APP_NTFY", Notification_Table, "Applications", ColumnsList, ColumnsList));

            StringBuilder TriggerBody = new StringBuilder();

            TriggerBody.AppendLine("EXEC SP_I_" + TableName + "_NTFY 'Notification', @" + TableName + "_ID, @outval;");

            ER_DDL._ADD_TRIGGER(_Connect, "Insert", "Before", TableName, TriggerBody);

            HoldResult.Add(new CommandResult {
                _Response = "---End Security Scaffold " + TableName + "", _Successful = true
            });
            return(HoldResult);
        }