コード例 #1
0
        private bool AddField(SPListEventProperties properties)
        {
            bool   isSuccessful = true;
            string tableName    = string.Empty;
            string ssTableName  = string.Empty;
            var    rb           = new ReportBiz(properties.SiteId);

            try
            {
                var rd   = new ReportData(properties.SiteId);
                var cols = new ColumnDefCollection();
                tableName   = rd.GetTableName(properties.ListId);
                ssTableName = rd.GetTableNameSnapshot(properties.ListId);

                if (!rd.ColumnExists(tableName, properties.Field.InternalName))
                {
                    cols.AddColumn(properties.Field);
                    rd.AddColumns(tableName, cols);
                    rd.AddColumns(ssTableName, cols);
                    rd.InsertListColumns(properties.ListId, cols);
                }
                rd.Dispose();
            }
            catch (Exception ex)
            {
                var DAO = new EPMData(properties.SiteId);
                DAO.LogStatus(properties.ListId.ToString(), properties.FieldName,
                              "Database column add attempt: Unable to add column " + properties.FieldName + ". " + ex.Message,
                              ex.StackTrace, 2, 5, Guid.NewGuid().ToString()); //Logged in the RefreshAll event log.
                DAO.Dispose();
            }

            if (properties.Field is SPFieldLookup)
            {
                try
                {
                    //FOREIGN IMPLEMENTATION -- START
                    var DAO = new EPMData(properties.SiteId);
                    rb.UpdateForeignKeys(DAO);
                    DAO.Dispose();
                    // -- END
                }
                catch (Exception ex)
                {
                    isSuccessful = false;
                    SPSecurity.RunWithElevatedPrivileges(delegate
                    {
                        if (!EventLog.SourceExists("EPMLive Reporting - UpdateForeignKeys"))
                        {
                            EventLog.CreateEventSource("EPMLive Reporting - UpdateForeignKeys", "EPM Live");
                        }

                        LogEntry(ex, "EPMLive Reporting - UpdateForeignKeys");
                    });
                }
            }

            return(isSuccessful);
        }