ByName() public static method

public static ByName ( string dataTypeName ) : DataType
dataTypeName string
return DataType
Exemplo n.º 1
0
 public void RenderValuesToHtmlInsideDataSet(DataSet ds, bool filterScript = false)
 {
     foreach (var fieldType in DataType.AllDataTypes)
     {
         DataType.ByName(fieldType).RenderValuesToHtmlInsideDataSet(ds, ModuleId, filterScript);
     }
 }
Exemplo n.º 2
0
        public bool IsValid()
        {
            //Is required and empty
            if (Required && IsNull())
            {
                ValidationMessage = Localization.GetString("Required2.ErrorMessage", LocalResourceFile);
            }

            //TypeValidation
            else if (!IsValidType())
            {
                ValidationMessage = Localization.GetString(string.Format("{0}.ErrorMessage", FieldType),
                                                           LocalResourceFile);
            }
            //CustomValidation
            else if (DataType.ByName(FieldType).SupportsValidation)
            {
                if (!IsValidCustom())
                {
                    ValidationMessage = _customValidationMessage;
                }
            }


            var isValid = string.IsNullOrEmpty(ValidationMessage);

            if (!isValid)
            {
                Controls.Add(new LiteralControl(string.Format("<span class=\"dnnFormMessage dnnFormError\">{0}</span>", ValidationMessage)));
            }
            return(isValid);
        }
Exemplo n.º 3
0
        void SetEditLinksAndVisibilityBasedOnPermissions(DataSet ds)
        {
            if (User != null && TabId != Null.NullInteger)
            {
                //Provide a permission aware EditLink as an additional column to the dataset
                var security            = new ModuleSecurity(ModuleId, TabId, Settings);
                var createdByColumnName = ColumnNameByDataType(ds, DataTypeNames.UDT_DataType_CreatedBy);

                ds.Tables[DataSetTableName.Data].Columns.Add(DataTableColumn.EditLink, typeof(string));

                var urlPattern = EditUrlPattern ?? Globals.NavigateURL(TabId, "edit", "mid=" + ModuleId, DataTableColumn.RowId + "={0}");

                foreach (DataRow row in ds.Tables[DataSetTableName.Data].Rows)
                {
                    var rowCreatorUserName = row[createdByColumnName].ToString();
                    var isRowOwner         =
                        Convert.ToBoolean((rowCreatorUserName == User.Username) &&
                                          rowCreatorUserName != Definition.NameOfAnonymousUser);
                    if (security.IsAllowedToEditRow(isRowOwner))
                    {
                        row[DataTableColumn.EditLink] = string.Format(urlPattern, row[DataTableColumn.RowId]);
                    }
                }
                //Adjust visibility to actual permissions
                foreach (DataRow row in ds.Tables[DataSetTableName.Fields].Rows)
                {
                    row[FieldsTableColumn.Visible] = Convert.ToBoolean(row[FieldsTableColumn.Visible]) ||
                                                     (security.IsAllowedToSeeAllUserDefinedColumns() &&
                                                      (DataType.ByName(row[FieldsTableColumn.Type].ToString()).
                                                       IsUserDefinedField ||
                                                       Settings.ShowSystemColumns));
                }
            }
        }
Exemplo n.º 4
0
        void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Page.IsPostBack == false)
                {
                    EnsureActionButton();
                    ClientAPI.AddButtonConfirm(cmdDelete, Localization.GetString("DeleteItem", LocalResourceFile));
                }

                if (!IsNewRow)
                {
                    if (!Page.IsPostBack)
                    {
                        //Clear all default values
                        foreach (var edit in _editControls.Values)
                        {
                            edit.Value = "";
                        }
                    }
                    foreach (DataRow field in Data.Tables[DataSetTableName.Fields].Rows)
                    {
                        var dataTypeName = field[FieldsTableColumn.Type].AsString();
                        var dataType     = DataType.ByName(dataTypeName);
                        var value        = CurrentRow[field[FieldsTableColumn.Title].ToString()].ToString();
                        if (!dataType.IsSeparator)
                        {
                            if (!Page.IsPostBack)
                            {
                                _editControls[field[FieldsTableColumn.Title].ToString()].Value = value;
                            }
                            if (field[FieldsTableColumn.Type].ToString() == "CreatedBy")
                            {
                                CheckPermission(value);
                            }
                        }
                    }
                }
                else //New Entry
                {
                    //Default Values already have been set in BuildEditForms
                    cmdDelete.Visible = false;
                    CheckPermission();
                    if (!Page.IsPostBack && Request.QueryString["OnSubmit"].AsInt() == ModuleContext.ModuleId)
                    {
                        ShowUponSubmit();
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
                CheckPermission(false);
            }
        }
Exemplo n.º 5
0
 bool TestForValidEmailSources(DataTable fields, string emailSources)
 {
     foreach (var sx in emailSources.Split(';'.ToString(CultureInfo.InvariantCulture).ToCharArray()))
     {
         var source = sx.Trim();
         if (source.Length > 0)
         {
             if (source.StartsWith("[") && source.EndsWith("]"))
             {
                 var fieldtitle = source.Substring(1, source.Length - 2);
                 var rows       = fields.Select(string.Format("{0}=\'{1}\'", FieldsTableColumn.Title, fieldtitle));
                 if (rows.Length == 1)
                 {
                     var type = DataType.ByName((string)(rows[0][FieldsTableColumn.Type]));
                     if (!(type is IEmailAdressSource))
                     {
                         UI.Skins.Skin.AddModuleMessage(this,
                                                        string.Format(
                                                            Localization.GetString("NotEmailSource",
                                                                                   LocalResourceFile), fieldtitle),
                                                        ModuleMessage.ModuleMessageType.YellowWarning);
                         return(false);
                     }
                 }
                 else if (rows.Length == 0)
                 {
                     UI.Skins.Skin.AddModuleMessage(this,
                                                    string.Format(
                                                        Localization.GetString("NotEmailSource",
                                                                               LocalResourceFile), fieldtitle),
                                                    ModuleMessage.ModuleMessageType.YellowWarning);
                     return(false);
                 }
             }
             else
             {
                 if (!Mail.IsValidEmailAddress(source, ModuleContext.PortalId))
                 {
                     UI.Skins.Skin.AddModuleMessage(this,
                                                    string.Format(
                                                        Localization.GetString("NotEmailAddress",
                                                                               LocalResourceFile), source),
                                                    ModuleMessage.ModuleMessageType.YellowWarning);
                     return(false);
                 }
             }
         }
     }
     return(true);
 }
Exemplo n.º 6
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        ///   set up Fielddefinitions for Datagrid
        /// </summary>
        /// -----------------------------------------------------------------------------
        void PopulateDataGridColumns()
        {
            for (var intColumn = grdData.Columns.Count - 1; intColumn >= 1; intColumn--)
            {
                grdData.Columns.RemoveAt(intColumn);
            }
            foreach (DataRow row in DataSet.Tables[DataSetTableName.Fields].Rows)
            {
                //Add Fields dynamically to the grdData
                var colField = new BoundField
                {
                    HeaderText     = row[FieldsTableColumn.Title].ToString(),
                    DataField      = row[FieldsTableColumn.Title].ToString(),
                    HtmlEncode     = false,
                    Visible        = Convert.ToBoolean(row[FieldsTableColumn.Visible]),
                    SortExpression = string.Format("{0}|ASC", row[FieldsTableColumn.Title])
                };
                //Add a sorting indicator to the headertext
                if (row[FieldsTableColumn.Title].ToString() == SortField && colField.Visible)
                {
                    if (SortOrder == "ASC")
                    {
                        colField.HeaderText +=
                            string.Format(
                                "<img src=\"{0}/images/sortascending.gif\" border=\"0\" alt=\"Sorted By {1} In Ascending Order\"/>",
                                (Request.ApplicationPath == "/" ? string.Empty : Request.ApplicationPath), SortField);
                    }
                    else
                    {
                        colField.HeaderText +=
                            string.Format(
                                "<img src=\"{0}/images/sortdescending.gif\" border=\"0\" alt=\"Sorted By {1} In Descending Order\"/>",
                                (Request.ApplicationPath == "/" ? string.Empty : Request.ApplicationPath), SortField);
                    }
                }
                //Column settings depending on the fieldtype
                DataType.ByName(row[FieldsTableColumn.Type].ToString()).
                SetStylesAndFormats(colField, row[FieldsTableColumn.OutputSettings].AsString());
                grdData.Columns.Add(colField);
            }
            var editLinkNeed = DataSet.Tables[DataSetTableName.Data].Rows
                               .Cast <DataRow>()
                               .Any(row => !string.IsNullOrEmpty(row[DataTableColumn.EditLink] as string));

            if (!editLinkNeed)
            {
                grdData.Columns.RemoveAt(0);
            }
        }
Exemplo n.º 7
0
        DataSet BuildMainDataSet(DataTable fieldsTable, IDataReader dr, bool rowMode)
        {
            fieldsTable.Columns.Add(FieldsTableColumn.ValueColumn, typeof(string));
            fieldsTable.Columns.Add(FieldsTableColumn.SortColumn, typeof(string));
            var strFields = "";

            foreach (DataRow row in fieldsTable.Rows)
            {
                strFields += string.Format("{0}{1}|", (strFields != string.Empty ? "," : string.Empty),
                                           row[FieldsTableColumn.Title]);
                if (rowMode)
                {
                    strFields += "String";
                }
                else
                {
                    //DataSet expects the FieldType to be in the namespace "System."
                    //so replace all UDT-specific field types by their .net-equivalent
                    strFields += DataType.ByName(row[FieldsTableColumn.Type].ToString()).SystemTypeName;
                }

                //needed for generic Xsl Transformations - Data Names is XmlEncoded too
                var xmlEncodedTitle = XmlConvert.EncodeName(row[FieldsTableColumn.Title].ToString());
                row[FieldsTableColumn.ValueColumn] = xmlEncodedTitle;
                // gets altered in RenderValuesToHtmlInsideDataSet depending on Datatype
                row[FieldsTableColumn.SortColumn] = xmlEncodedTitle;
            }


            var ds = Globals.BuildCrossTabDataSet("UserDefinedTable", dr, DataTableColumn.RowId + "|Int32", strFields,
                                                  DataTableColumn.RowId, FieldsTableColumn.Title, string.Empty,
                                                  DataTableColumn.Value, string.Empty, CultureInfo.InvariantCulture);

            dr.Close();

            ds.Tables[0].TableName = DataSetTableName.Data;
            fieldsTable.TableName  = DataSetTableName.Fields;
            ds.Tables.Add(fieldsTable);
            return(ds);
        }
Exemplo n.º 8
0
        void WriteData(DataTable data, DataTable fields, string folder, string fileName, string delimiter)
        {
            using (var sw = new StringWriter())
            {
                var columns = new List <string>();
                //Writing top line with column names
                foreach (DataRow row in fields.Rows)
                {
                    var typeName = (row[FieldsTableColumn.Type].ToString());
                    //ignore system fields
                    if (DataType.ByName(typeName).IsUserDefinedField)
                    {
                        columns.Add(row[FieldsTableColumn.Title].ToString());
                    }
                }

                //write colums name as first line
                CSVWriter.WriteCSV(columns.ToArray(), sw, delimiter);

                //writing data
                foreach (DataRow row in data.Rows)
                {
                    var values = new List <string>();
                    //getting values for all colums
                    foreach (var fieldTitle in columns)
                    {
                        var valueName = ((data.Columns.Contains(fieldTitle + DataTableColumn.Appendix_Original))
                                             ? fieldTitle + DataTableColumn.Appendix_Original
                                             : fieldTitle);
                        var value = row[valueName].AsString();
                        values.Add(value);
                    }
                    CSVWriter.WriteCSV(values.ToArray(), sw, delimiter);
                }
                WriteFile(folder, fileName, sw);
            }
        }
        void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (ModuleContext.PortalSettings.UserId == -1 && Settings.ForceCaptchaForAnonymous && Settings.PreferReCaptcha)
                {
                    cmdUpdate.Attributes["disabled"] = "disabled";
                    cmdUpdate.CssClass += " disabled";

                    DotNetNuke.Framework.CDefault page = (DotNetNuke.Framework.CDefault) this.Page;
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine(@"<script type=""text/javascript"">");
                    sb.AppendLine("var onSubmit = function(token) {");
                    sb.AppendLine("$('#" + cmdUpdate.ClientID + "').removeAttr('disabled');");
                    sb.AppendLine("$('#" + cmdUpdate.ClientID + "').removeClass('disabled');");
                    sb.AppendLine("};");
                    sb.AppendLine("var onloadCallback = function() {");
                    sb.AppendLine("grecaptcha.render('" + gRecaptcha.ClientID + "', {");
                    sb.AppendLine("'sitekey' : '" + Settings.ReCaptchaSiteKey + "',");
                    sb.AppendLine("'callback' : onSubmit");
                    sb.AppendLine("});");
                    sb.AppendLine("};");
                    sb.AppendLine("</script>");
                    page.Header.Controls.Add(new LiteralControl(sb.ToString()));
                    string languageCode = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
                    page.Header.Controls.Add(new LiteralControl(@"<script src=""https://www.google.com/recaptcha/api.js?onload=onloadCallback&render=explicit&hl=" + languageCode + @""" async defer ></script>"));
                }
                if (Page.IsPostBack == false)
                {
                    EnsureActionButton();
                    ClientAPI.AddButtonConfirm(cmdDelete, Localization.GetString("DeleteItem", LocalResourceFile));
                }

                if (!IsNewRow)
                {
                    if (!Page.IsPostBack)
                    {
                        //Clear all default values
                        foreach (var edit in _editControls.Values)
                        {
                            edit.Value = "";
                        }
                    }
                    foreach (DataRow field in Data.Tables[DataSetTableName.Fields].Rows)
                    {
                        var dataTypeName = field[FieldsTableColumn.Type].AsString();
                        var dataType     = DataType.ByName(dataTypeName);
                        var value        = CurrentRow[field[FieldsTableColumn.Title].ToString()].ToString();
                        if (!dataType.IsSeparator)
                        {
                            if (!Page.IsPostBack)
                            {
                                _editControls[field[FieldsTableColumn.Title].ToString()].Value = value;
                            }
                            if (field[FieldsTableColumn.Type].ToString() == "CreatedBy")
                            {
                                CheckPermission(value);
                            }
                        }
                    }
                }
                else //New Entry
                {
                    //Default Values already have been set in BuildEditForms
                    cmdDelete.Visible = false;
                    CheckPermission();
                    if (!Page.IsPostBack && Request.QueryString["OnSubmit"].AsInt() == ModuleContext.ModuleId)
                    {
                        ShowUponSubmit();
                    }
                }
            }
            catch (Exception exc) //Module failed to load
            {
                Exceptions.ProcessModuleLoadException(this, exc);
                CheckPermission(false);
            }
        }
        void BuildEditForm()
        {
            var            fieldSettingsTable = FieldSettingsController.GetFieldSettingsTable(ModuleId);
            var            editForm           = new List <FormColumnInfo>();
            FormColumnInfo currentField;
            var            security = new ModuleSecurity(ModuleContext);

            _editControls = new EditControls(ModuleContext);

            foreach (DataRow dr in Data.Tables[DataSetTableName.Fields].Rows)
            {
                var fieldTitle   = dr[FieldsTableColumn.Title].AsString();
                var dataTypeName = dr[FieldsTableColumn.Type].AsString();
                var dataType     = DataType.ByName(dataTypeName);

                var isColumnEditable =
                    Convert.ToBoolean((!dataType.SupportsHideOnEdit ||
                                       Convert.ToBoolean(dr[FieldsTableColumn.ShowOnEdit])) &&
                                      (!Convert.ToBoolean(dr[FieldsTableColumn.IsPrivate]) ||
                                       security.IsAllowedToEditAllColumns()));

                //If Column is hidden, the Fieldtype falls back to "String" as the related EditControl works perfect even if it is not visibile
                //EditControls of other user defined datatypes may use core controls (e.g. UrlControl or RTE) which are not rock solid regarding viewstate.
                if (!isColumnEditable && dataType.IsUserDefinedField)
                {
                    dataTypeName = "String";
                }

                currentField = new FormColumnInfo {
                    IsUserDefinedField = dataType.IsUserDefinedField
                };

                if (dataType.IsSeparator)
                {
                    var fieldId = (int)dr[FieldsTableColumn.Id];
                    currentField.IsCollapsible = Data.Tables[DataSetTableName.FieldSettings].GetFieldSetting("IsCollapsible", fieldId).AsBoolean();
                    currentField.IsSeparator   = true;
                    if (dr[FieldsTableColumn.Visible].AsBoolean())
                    {
                        currentField.Title = fieldTitle;
                    }
                    currentField.Visible = isColumnEditable;
                }
                else
                {
                    currentField.Help     = dr[FieldsTableColumn.HelpText].AsString();
                    currentField.Title    = dr[FieldsTableColumn.Title].AsString();
                    currentField.Required =
                        Convert.ToBoolean(dr[FieldsTableColumn.Required].AsBoolean() &&
                                          dataType.IsUserDefinedField);

                    //advanced Settings: Dynamic control
                    currentField.EditControl = _editControls.Add(dr[FieldsTableColumn.Title].AsString(),
                                                                 dataTypeName, Convert.ToInt32(dr[FieldsTableColumn.Id]),
                                                                 dr[FieldsTableColumn.HelpText].AsString(),
                                                                 dr[FieldsTableColumn.Default].AsString(),
                                                                 dr[FieldsTableColumn.Required].AsBoolean(),
                                                                 dr[FieldsTableColumn.ValidationRule].AsString(),
                                                                 dr[FieldsTableColumn.ValidationMessage].AsString(),
                                                                 dr[FieldsTableColumn.EditStyle].AsString(),
                                                                 dr[FieldsTableColumn.InputSettings].AsString(),
                                                                 dr[FieldsTableColumn.OutputSettings].AsString(),
                                                                 dr[FieldsTableColumn.NormalizeFlag].AsBoolean(),
                                                                 dr[FieldsTableColumn.MultipleValues].AsBoolean(),
                                                                 fieldSettingsTable,
                                                                 this);
                    currentField.Visible = isColumnEditable;
                }
                editForm.Add(currentField);
            }

            if (CaptchaNeeded())
            {
                if (!Settings.PreferReCaptcha)
                {
                    // use DnnCaptcha
                    _ctlCaptcha = new CaptchaControl
                    {
                        ID            = "Captcha",
                        CaptchaWidth  = Unit.Pixel(130),
                        CaptchaHeight = Unit.Pixel(40),
                        ToolTip       = Localization.GetString("CaptchaToolTip", LocalResourceFile),
                        ErrorMessage  = Localization.GetString("CaptchaError", LocalResourceFile)
                    };
                    currentField = new FormColumnInfo
                    {
                        Title              = Localization.GetString("Captcha", LocalResourceFile),
                        EditControl        = _ctlCaptcha,
                        Visible            = true,
                        IsUserDefinedField = false
                    };
                    editForm.Add(currentField);
                }
            }

            var enableFormTemplate = Settings.EnableFormTemplate;
            var formTemplate       = Settings.FormTemplate;

            if (enableFormTemplate && !string.IsNullOrEmpty(formTemplate))
            {
                BuildTemplateForm(editForm, formTemplate);
            }
            else
            {
                BuildCssForm(editForm);
            }
            //Change captions of buttons in Form mode
            if (IsNewRow && Settings.ListOrForm.Contains("Form"))
            {
                cmdUpdate.Attributes["resourcekey"] = "cmdSend.Text";
            }
        }
Exemplo n.º 11
0
        public void UpdateRow(DataSet ds, int rowNr, bool isDataToImport)
        {
            var currentRow = ds.Tables[DataSetTableName.Data].Rows[rowNr];

            var rowHasContent = false;

            foreach (DataRow field in ds.Tables[DataSetTableName.Fields].Rows)
            {
                if (DataType.ByName(field[FieldsTableColumn.Type].ToString()).IsUserDefinedField)
                {
                    var strColumnName  = field[FieldsTableColumn.Title].ToString();
                    var strValueColumn = ((isDataToImport &&
                                           ds.Tables[DataSetTableName.Data].Columns.Contains(strColumnName +
                                                                                             DataTableColumn.
                                                                                             Appendix_Original))
                                              ? strColumnName + DataTableColumn.Appendix_Original
                                              : strColumnName);
                    rowHasContent = Convert.ToBoolean(currentRow[strValueColumn].AsString() != string.Empty);
                    if (rowHasContent)
                    {
                        break;
                    }
                }
            }

            var userDefinedRowId = Convert.ToInt32(currentRow[DataTableColumn.RowId]);
            var isNew            = isDataToImport || (userDefinedRowId == -1);

            if (isNew && rowHasContent)
            {
                //New entries need AddRow first
                userDefinedRowId = AddRow();
                currentRow[DataTableColumn.RowId] = userDefinedRowId;
            }

            if (rowHasContent)
            {
                var values = new Dictionary <int, string>();
                foreach (DataRow field in ds.Tables[DataSetTableName.Fields].Rows)
                {
                    var strColumnName  = field[FieldsTableColumn.Title].ToString();
                    var strValueColumn = ((!isDataToImport &&
                                           ds.Tables[DataSetTableName.Data].Columns.Contains(strColumnName +
                                                                                             DataTableColumn.
                                                                                             Appendix_Original))
                                              ? strColumnName + DataTableColumn.Appendix_Original
                                              : strColumnName);
                    if (ds.Tables[DataSetTableName.Data].Columns.Contains(strValueColumn))
                    {
                        values.Add(field[FieldsTableColumn.Id].AsInt(), currentRow[strValueColumn].AsString());
                    }
                }
                UpdateData(userDefinedRowId, values);
                if (!isDataToImport)
                {
                    TrackingController.OnAction(
                        isNew ? TrackingController.Trigger.New : TrackingController.Trigger.Update, userDefinedRowId, this);
                }
            }
            else
            {
                DeleteRow(userDefinedRowId);
            }
        }