The UserDefinedTableController class provides Business Layer methods of UDT for managing, editing and diplaying User Defined Table
Inheritance: DotNetNuke.Modules.UserDefinedTable.Components.BaseController
Exemplo n.º 1
0
        void ExportData(string folder, string strFileName, string delimiter)
        {
            var ds     = new UserDefinedTableController(_moduleId, TabId, UserInfo).GetDataSet(true);
            var data   = ds.Tables[0];
            var fields = ds.Tables[1];

            WriteData(data, fields, folder, strFileName, delimiter);
        }
Exemplo n.º 2
0
 DataSet CreateFields(IEnumerable <string> columns, UserDefinedTableController udtController)
 {
     udtController.ResetModule();
     FieldController.GetFieldsTable(ModuleId);
     foreach (var column in columns)
     {
         FieldController.AddField(ModuleId, column);
     }
     return(udtController.GetRow(-1, false));
 }
Exemplo n.º 3
0
 static void AddData(UserDefinedTableController udtController, DataSet ds)
 {
     if (ds.Tables[DataSetTableName.Data] != null)
     {
         for (var rowNr = 0; rowNr <= ds.Tables[DataSetTableName.Data].Rows.Count - 1; rowNr++)
         {
             udtController.UpdateRow(ds, rowNr, isDataToImport: true);
         }
     }
 }
Exemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                PortalController.Instance.GetCurrentPortalSettings();

                if ((context.Request.QueryString["tabid"] == null || context.Request.QueryString["mid"] == null) ||
                    !(context.Request.IsAuthenticated))
                {
                    return;
                }
                // get TabId
                var tabId = Convert.ToInt32(-1);
                if (context.Request.QueryString["tabid"] != null)
                {
                    tabId = int.Parse(context.Request.QueryString["tabid"]);
                }

                // get ModuleId
                var moduleId = Convert.ToInt32(-1);
                if (context.Request.QueryString["mid"] != null)
                {
                    moduleId = int.Parse(context.Request.QueryString["mid"]);
                }

                var userInfo = UserController.Instance.GetCurrentUserInfo();
                var mc       = new ModuleController();

                var moduleInfo = new ModuleController().GetModule(moduleId, tabId);
                var settings   = moduleInfo.ModuleSettings;

                if (ModulePermissionController.CanManageModule(moduleInfo))
                {
                    var udt = new UserDefinedTableController(moduleId, tabId, userInfo);
                    var ds  = udt.GetDataSet(true);

                    ds.Tables.Add(udt.Context(moduleInfo, userInfo,
                                              context.Request[Definition.QueryStringParameter].AsString(),
                                              settings[SettingName.SortField].AsString(),
                                              settings[SettingName.SortOrder].AsString(),
                                              settings[SettingName.Paging].AsString()));
                    context.Response.ContentType = "Text/Xml";
                    ds.WriteXml(context.Response.OutputStream);
                }
            }
            catch (Exception)
            {
                context.Response.Write("Not defined");
            }
        }
Exemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            try
            {
                PortalController.GetCurrentPortalSettings();

                if ((context.Request.QueryString["tabid"] == null || context.Request.QueryString["mid"] == null) ||
                    !(context.Request.IsAuthenticated))
                {
                    return;
                }
                // get TabId
                var tabId = Convert.ToInt32(-1);
                if (context.Request.QueryString["tabid"] != null)
                {
                    tabId = int.Parse(context.Request.QueryString["tabid"]);
                }

                // get ModuleId
                var moduleId = Convert.ToInt32(-1);
                if (context.Request.QueryString["mid"] != null)
                {
                    moduleId = int.Parse(context.Request.QueryString["mid"]);
                }

                var userInfo = UserController.GetCurrentUserInfo();
                var mc = new ModuleController();
                var settings = mc.GetModuleSettings(moduleId);
                var moduleInfo = new ModuleController().GetModule(moduleId, tabId);

                if (ModulePermissionController.CanManageModule(moduleInfo))
                {
                    var udt = new UserDefinedTableController(moduleId, tabId, userInfo);
                    var ds = udt.GetDataSet(true);

                    ds.Tables.Add(udt.Context(moduleInfo, userInfo,
                                                 context.Request[Definition.QueryStringParameter].AsString(),
                                                 settings[SettingName.SortField].AsString(),
                                                 settings[SettingName.SortOrder].AsString(),
                                                 settings[SettingName.Paging].AsString()));
                    context.Response.ContentType = "Text/Xml";
                    ds.WriteXml(context.Response.OutputStream);
                }
            }
            catch (Exception)
            {
                context.Response.Write("Not defined");
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Implements the enhanced Import Interface for DotNetNuke
        /// </summary>
        public void ImportModule(int moduleId, int tabId, string content, string version, int userId, bool isInstance)
        {
            // save script timeout
            var scriptTimeOut = HttpContext.Current.Server.ScriptTimeout;

            try
            {
                // temporarily set script timeout to large value ( this value is only applicable when application is not running in Debug mode )
                HttpContext.Current.Server.ScriptTimeout = int.MaxValue;

                var udtController = new UserDefinedTableController(moduleId);
                using (var ds = new DataSet())
                {
                    var xmlNode = Globals.GetContent(content, string.Empty);
                    ds.ReadXml(new XmlNodeReader(xmlNode));
                    var modules     = new ModuleController();
                    var tabModuleId = Null.NullInteger;
                    if (tabId != Null.NullInteger)
                    {
                        var moduleInfo = modules.GetModule(moduleId, tabId);
                        tabModuleId = moduleInfo.TabModuleID;
                    }
                    if (tabModuleId != Null.NullInteger && ds.Tables[DataSetTableName.TabSettings] != null)
                    {
                        AddTabModuleSettings(modules, tabModuleId, ds);
                    }
                    if (!isInstance)
                    {
                        AddModuleSettings(moduleId, modules, ds);
                        //Fields - first delete old Fields
                        udtController.ResetModule();
                        AddFields(moduleId, ds);
                        AddData(udtController, ds);
                    }
                    if (ds.Tables.Contains(DataSetTableName.Stylesheets))
                    {
                        ImportStyleSheet(moduleId, isInstance, tabModuleId, modules, ds);
                    }
                }
            }
            finally
            {
                // reset script timeout
                HttpContext.Current.Server.ScriptTimeout = scriptTimeOut;
            }
        }
Exemplo n.º 7
0
        public DataSet ExportModuleDataSet(int moduleId, int tabId)
        {
            DataSet ds;

            if (tabId == Null.NullInteger)
            {
                var udtController = new UserDefinedTableController(moduleId);
                ds = udtController.GetDataSet(false);
                ds.Tables.Add(GetSettingsTable(moduleId, SettingsType.ModuleSettings));
            }
            else
            {
                var moduleInfo    = new ModuleController().GetModule(moduleId, tabId);
                var udtController = new UserDefinedTableController(moduleInfo);
                ds = udtController.GetDataSet(false);
                ds.Tables.Add(GetSettingsTable(moduleId, SettingsType.ModuleSettings));
                ds.Tables.Add(GetSettingsTable(moduleInfo.TabModuleID, SettingsType.TabModuleSettings));
                ds.Tables.Add(GetStylesheetTable(udtController.Settings, moduleInfo.PortalID));
            }
            return(ds);
        }
        string ImportModule(int moduleId, string fileName, string folder, string delimiter)
        {
            var strMessage = "";

            var mc = new ModuleController();
            var moduleInfo = mc.GetModule(moduleId, TabId, false);

            if (Path.GetExtension(fileName).ToUpper() == ".CSV" && moduleInfo != null)
            {
                var udtController = new UserDefinedTableController(ModuleContext );
              
                var file = FileManager.Instance.GetFile(PortalId, Path.Combine(folder, fileName));
                using (var stream = FileManager.Instance.GetFileContent(file))
                {
                    // Open the stream and read it back.
                    using (var reader = new TextFieldParser(stream))
                    {
                        reader.TextFieldType = FieldType.Delimited;
                        reader.SetDelimiters(delimiter);

                        DataSet ds = null;
                        DataTable dataTable = null;
                        string colChangedBy = null;
                        string colChangedAt = null;
                        string colCreatedBy = null;
                        string colCreatedAt = null;
                        var obligateDataTypesCount = DataType.SystemDataTypes().Count;

                        try
                        {
                            while (!reader.EndOfData)
                            {
                                var linecsv = reader.ReadFields();
                                if (dataTable == null)
                                {
                                    ds = CreateFields(linecsv, udtController);
                                    dataTable = ds.Tables[DataSetTableName.Data];
                                    colChangedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedBy);
                                    colChangedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedAt);
                                    colCreatedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedBy);
                                    colCreatedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedAt);
                                }
                                else
                                {
                                    var insertTime = DateTime.Now.ToString("s");
                                    var newRow = dataTable.NewRow();
                                    newRow[DataTableColumn.RowId] = -1;
                                    newRow[colChangedBy] = UserInfo.Username;
                                    newRow[colCreatedBy] = UserInfo.Username;
                                    newRow[colChangedAt] = insertTime;
                                    newRow[colCreatedAt] = insertTime;
                                    dataTable.Rows.Add(FillRow(linecsv, newRow, obligateDataTypesCount));
                                }
                            }

                            if (ds != null)
                            {
                                for (var rowNr = 0; rowNr <= dataTable.Rows.Count - 1; rowNr++)
                                {
                                    udtController.UpdateRow(ds, rowNr, isDataToImport: true);
                                }
                                mc.UpdateModuleSetting(moduleId, SettingName.ListOrForm, "List");
                            }
                        }
                        catch (Exception ex)
                        {
                            strMessage = string.Format(Localization.GetString("importError", LocalResourceFile), ex.Message);
                        }
                    }
                }

                
            }

            return strMessage;
        }
Exemplo n.º 9
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   Implements the search interface for DotNetNuke
        /// </summary>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo modInfo)
        {
            var searchItemCollection = new SearchItemInfoCollection();
            var udtController        = new UserDefinedTableController(modInfo);

            try
            {
                var dsUserDefinedRows = udtController.GetDataSet(withPreRenderedValues: false);

                //Get names of ChangedBy and ChangedAt columns
                var colnameChangedBy = udtController.ColumnNameByDataType(dsUserDefinedRows,
                                                                          DataTypeNames.UDT_DataType_ChangedBy);
                var colnameChangedAt = udtController.ColumnNameByDataType(dsUserDefinedRows,
                                                                          DataTypeNames.UDT_DataType_ChangedAt);

                var moduleController = new ModuleController();
                var settings         = moduleController.GetModuleSettings(modInfo.ModuleID);
                var includeInSearch  = !(settings[SettingName.ExcludeFromSearch].AsBoolean());

                if (includeInSearch)
                {
                    foreach (DataRow row in dsUserDefinedRows.Tables[DataSetTableName.Data].Rows)
                    {
                        var changedDate     = DateTime.Today;
                        var changedByUserId = 0;

                        if (colnameChangedAt != string.Empty && !Information.IsDBNull(row[colnameChangedAt]))
                        {
                            changedDate = Convert.ToDateTime(row[colnameChangedAt]);
                        }
                        if (colnameChangedBy != string.Empty && !Information.IsDBNull(row[colnameChangedBy]))
                        {
                            changedByUserId = ModuleSecurity.UserId(row[colnameChangedBy].ToString(), modInfo.PortalID);
                        }

                        var desc = string.Empty;
                        foreach (DataRow col in dsUserDefinedRows.Tables[DataSetTableName.Fields].Rows)
                        {
                            var fieldType  = col[FieldsTableColumn.Type].ToString();
                            var fieldTitle = col[FieldsTableColumn.Title].ToString();
                            var visible    = Convert.ToBoolean(col[FieldsTableColumn.Visible]);
                            if (visible &&
                                (fieldType.StartsWith("Text") || fieldType == DataTypeNames.UDT_DataType_String))
                            {
                                desc += string.Format("{0} &bull; ", Convert.ToString(row[fieldTitle]));
                            }
                        }
                        if (desc.EndsWith("<br/>"))
                        {
                            desc = desc.Substring(0, Convert.ToInt32(desc.Length - 5));
                        }
                        var searchItem = new SearchItemInfo(modInfo.ModuleTitle, desc, changedByUserId, changedDate,
                                                            modInfo.ModuleID, row[DataTableColumn.RowId].ToString(),
                                                            desc);
                        searchItemCollection.Add(searchItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

            return(searchItemCollection);
        }
Exemplo n.º 10
0
        private void LoadFnL()
        {
            EnsureConfigurationIsLoaded();

            // Preferred way in Form and List
            var udt = new UserDefinedTableController();
            var ds = udt.GetDataSet(ModuleId);
            DtDs = DataSource.GetDataSource<DataTableDataSource>(valueCollectionProvider: ConfigurationProvider);
            DtDs.Source = ds.Tables["Data"];
            DtDs.EntityIdField = "UserDefinedRowId";         // default column created by UDT
            DtDs.ContentType = ContentType;

            // clean up column names if possible, remove spaces in the column-names
            for (var i = 0; i < DtDs.Source.Columns.Count; i++)
                DtDs.Source.Columns[i].ColumnName = DtDs.Source.Columns[i].ColumnName
                    .Replace(" ", "");

            // Set the title-field - either the configured one, or if missing, just the first column we find
            if (string.IsNullOrWhiteSpace(TitleField))
                TitleField = DtDs.Source.Columns[1].ColumnName;
            DtDs.TitleField = TitleField;
        }
Exemplo n.º 11
0
        void ExportData(string folder, string strFileName, string delimiter)
        {
            var ds = new UserDefinedTableController(_moduleId, TabId, UserInfo).GetDataSet(true);
            var data = ds.Tables[0];
            var fields = ds.Tables[1];

            WriteData(data, fields, folder, strFileName, delimiter);
        }
Exemplo n.º 12
0
  DataSet CreateFields(IEnumerable<string> columns, UserDefinedTableController udtController)
 {
     udtController.ResetModule();
     FieldController.GetFieldsTable(ModuleId );
     foreach (var column in columns)
     {
         FieldController.AddField(ModuleId, column);
     }
     return udtController.GetRow(- 1, false);
 }
Exemplo n.º 13
0
        string ImportModule(int moduleId, string fileName, string folder, string delimiter)
        {
            var strMessage = "";

            var mc         = new ModuleController();
            var moduleInfo = mc.GetModule(moduleId, TabId, false);

            if (Path.GetExtension(fileName).ToUpper() == ".CSV" && moduleInfo != null)
            {
                var udtController = new UserDefinedTableController(ModuleContext);

                var file = FileManager.Instance.GetFile(PortalId, Path.Combine(folder, fileName));
                using (var stream = FileManager.Instance.GetFileContent(file))
                {
                    // Open the stream and read it back.
                    using (var reader = new TextFieldParser(stream))
                    {
                        reader.TextFieldType = FieldType.Delimited;
                        reader.SetDelimiters(delimiter);

                        DataSet   ds                     = null;
                        DataTable dataTable              = null;
                        string    colChangedBy           = null;
                        string    colChangedAt           = null;
                        string    colCreatedBy           = null;
                        string    colCreatedAt           = null;
                        var       obligateDataTypesCount = DataType.SystemDataTypes().Count;

                        try
                        {
                            while (!reader.EndOfData)
                            {
                                var linecsv = reader.ReadFields();
                                if (dataTable == null)
                                {
                                    ds           = CreateFields(linecsv, udtController);
                                    dataTable    = ds.Tables[DataSetTableName.Data];
                                    colChangedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedBy);
                                    colChangedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_ChangedAt);
                                    colCreatedBy = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedBy);
                                    colCreatedAt = udtController.ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedAt);
                                }
                                else
                                {
                                    var insertTime = DateTime.Now.ToString("s");
                                    var newRow     = dataTable.NewRow();
                                    newRow[DataTableColumn.RowId] = -1;
                                    newRow[colChangedBy]          = UserInfo.Username;
                                    newRow[colCreatedBy]          = UserInfo.Username;
                                    newRow[colChangedAt]          = insertTime;
                                    newRow[colCreatedAt]          = insertTime;
                                    dataTable.Rows.Add(FillRow(linecsv, newRow, obligateDataTypesCount));
                                }
                            }

                            if (ds != null)
                            {
                                for (var rowNr = 0; rowNr <= dataTable.Rows.Count - 1; rowNr++)
                                {
                                    udtController.UpdateRow(ds, rowNr, isDataToImport: true);
                                }
                                mc.UpdateModuleSetting(moduleId, SettingName.ListOrForm, "List");
                            }
                        }
                        catch (Exception ex)
                        {
                            strMessage = string.Format(Localization.GetString("importError", LocalResourceFile), ex.Message);
                        }
                    }
                }
            }

            return(strMessage);
        }
 static void AddData(UserDefinedTableController udtController, DataSet ds)
 {
     if (ds.Tables[DataSetTableName.Data] != null)
     {
         for (var rowNr = 0; rowNr <= ds.Tables[DataSetTableName.Data].Rows.Count - 1; rowNr++)
         {
             udtController.UpdateRow(ds, rowNr, isDataToImport: true);
         }
     }
 }
        /// <summary>
        ///   Implements the enhanced Import Interface for DotNetNuke
        /// </summary>
        public void ImportModule(int moduleId, int tabId, string content, string version, int userId, bool isInstance)
        {
            // save script timeout
            var scriptTimeOut = HttpContext.Current.Server.ScriptTimeout;

            try
            {
                // temporarily set script timeout to large value ( this value is only applicable when application is not running in Debug mode )
                HttpContext.Current.Server.ScriptTimeout = int.MaxValue;

                var udtController = new UserDefinedTableController(moduleId);
                using (var ds = new DataSet())
                {
                    var xmlNode = Globals.GetContent(content, string.Empty);
                    ds.ReadXml(new XmlNodeReader(xmlNode));
                    var modules = new ModuleController();
                    var tabModuleId = Null.NullInteger;
                    if (tabId != Null.NullInteger)
                    {
                        var moduleInfo = modules.GetModule(moduleId, tabId);
                        tabModuleId = moduleInfo.TabModuleID;
                    }
                    if (tabModuleId != Null.NullInteger && ds.Tables[DataSetTableName.TabSettings] != null)
                    {
                        AddTabModuleSettings(modules, tabModuleId, ds);
                    }
                    if (! isInstance)
                    {
                        AddModuleSettings(moduleId, modules, ds);
                        //Fields - first delete old Fields
                        udtController.ResetModule();
                        AddFields(moduleId, ds);
                        AddData(udtController, ds);
                    }
                    if (ds.Tables.Contains(DataSetTableName.Stylesheets))
                    {
                        ImportStyleSheet(moduleId, isInstance, tabModuleId, modules, ds);
                    }
                }
            }
            finally
            {
                // reset script timeout
                HttpContext.Current.Server.ScriptTimeout = scriptTimeOut;
            }
        }
        public DataSet ExportModuleDataSet(int moduleId, int tabId)
        {
            DataSet ds;

            if (tabId == Null.NullInteger)
            {
                var udtController = new UserDefinedTableController(moduleId);
                ds = udtController.GetDataSet(false);
                ds.Tables.Add(GetSettingsTable(moduleId, SettingsType.ModuleSettings));
            }
            else
            {
                var moduleInfo = new ModuleController().GetModule(moduleId, tabId);
                var udtController = new UserDefinedTableController(moduleInfo);
                ds = udtController.GetDataSet(false);
                ds.Tables.Add(GetSettingsTable(moduleId, SettingsType.ModuleSettings));
                ds.Tables.Add(GetSettingsTable(moduleInfo.TabModuleID, SettingsType.TabModuleSettings));
                ds.Tables.Add(GetStylesheetTable(udtController.Settings, moduleInfo.PortalID));
            }
            return (ds);
        }
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   Implements the search interface for DotNetNuke
        /// </summary>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo modInfo)
        {
            var searchItemCollection = new SearchItemInfoCollection();
            var udtController = new UserDefinedTableController(modInfo);

            try
            {
                var dsUserDefinedRows = udtController.GetDataSet(withPreRenderedValues: false);

                //Get names of ChangedBy and ChangedAt columns
                var colnameChangedBy = udtController.ColumnNameByDataType(dsUserDefinedRows,
                                                                          DataTypeNames.UDT_DataType_ChangedBy);
                var colnameChangedAt = udtController.ColumnNameByDataType(dsUserDefinedRows,
                                                                          DataTypeNames.UDT_DataType_ChangedAt);

                var moduleController = new ModuleController();
                var settings = moduleController.GetModuleSettings(modInfo.ModuleID);
                var includeInSearch = !(settings[SettingName.ExcludeFromSearch].AsBoolean());

                if (includeInSearch)
                {
                    foreach (DataRow row in dsUserDefinedRows.Tables[DataSetTableName.Data].Rows)
                    {
                        var changedDate = DateTime.Today;
                        var changedByUserId = 0;

                        if (colnameChangedAt != string.Empty && ! Information.IsDBNull(row[colnameChangedAt]))
                        {
                            changedDate = Convert.ToDateTime(row[colnameChangedAt]);
                        }
                        if (colnameChangedBy != string.Empty && ! Information.IsDBNull(row[colnameChangedBy]))
                        {
                            changedByUserId = ModuleSecurity.UserId(row[colnameChangedBy].ToString(), modInfo.PortalID);
                        }

                        var desc = string.Empty;
                        foreach (DataRow col in dsUserDefinedRows.Tables[DataSetTableName.Fields].Rows)
                        {
                            var fieldType = col[FieldsTableColumn.Type].ToString();
                            var fieldTitle = col[FieldsTableColumn.Title].ToString();
                            var visible = Convert.ToBoolean(col[FieldsTableColumn.Visible]);
                            if (visible &&
                                (fieldType.StartsWith("Text") || fieldType == DataTypeNames.UDT_DataType_String))
                            {
                                desc += string.Format("{0} &bull; ", Convert.ToString(row[fieldTitle]));
                            }
                        }
                        if (desc.EndsWith("<br/>"))
                        {
                            desc = desc.Substring(0, Convert.ToInt32(desc.Length - 5));
                        }
                        var searchItem = new SearchItemInfo(modInfo.ModuleTitle, desc, changedByUserId, changedDate,
                                                            modInfo.ModuleID, row[DataTableColumn.RowId].ToString(),
                                                            desc);
                        searchItemCollection.Add(searchItem);
                    }
                }
            }
            catch (Exception ex)
            {
                Exceptions.LogException(ex);
            }

            return searchItemCollection;
        }