/// <summary> /// Initializes a new instance of the <see cref="ClientSideRequiredFieldValidator" /> class. /// </summary> /// <param name="prefix">The prefix.</param> /// <param name="cell">The cell.</param> /// <param name="enabled">If the validator is e enabled.</param> public ClientSideRequiredFieldValidator(string prefix, StoredValue cell, bool enabled = true) { this.ID = prefix + "_" + cell.Alias + "_required"; this.Enabled = enabled; this.CssClass = "validator"; this.ClientValidationFunction = "RequiredFieldValidate"; this.Display = ValidatorDisplay.Dynamic; this.ErrorMessage = cell.Name + " is mandatory"; // Set control to validate this.Attributes["data-controltovalidate"] = DataTypeHandlerServiceLocator.Instance.GetControlToValidate(cell.Value, cell.Value.DataEditor.Editor).ClientID; var validationAttribute = (ValidationPropertyAttribute)TypeDescriptor.GetAttributes(cell.Value.DataEditor.Editor)[typeof(ValidationPropertyAttribute)]; if (validationAttribute != null) { this.Attributes["data-validationproperty"] = validationAttribute.Name; } }
/// <summary> /// Generates the validation controls. /// </summary> /// <param name="parent">The parent.</param> /// <param name="name">The name.</param> /// <param name="config">The config.</param> /// <param name="list">The list.</param> private void GenerateValidationControls(Control parent, string name, StoredValue config, IEnumerable<StoredValue> list) { var control = parent.FindControl(config.Value.DataEditor.Editor.ID); // If the name starts with a hash, get the dictionary item if (config.Name.StartsWith("#")) { var key = config.Name.Substring(1, config.Name.Length - 1); config.Name = uQuery.GetDictionaryItem(key, key); } // Mandatory if (this.ColumnConfigurations.Single(x => x.Alias == config.Alias).Mandatory && control != null) { try { var wrapper = new Panel(); var validator = new ClientSideRequiredFieldValidator(name, config, false); wrapper.Controls.Add(validator); parent.Controls.Add(wrapper); } catch (Exception ex) { HttpContext.Current.Trace.Warn("DataTypeGrid", "EditorControl (" + config.Value.DataTypeName + ") does not support validation", ex); } } // Regex if (!string.IsNullOrEmpty(this.ColumnConfigurations.First(x => x.Alias == config.Alias).ValidationExpression) && control != null) { try { var wrapper = new Panel(); var regex = new Regex(this.ColumnConfigurations.First(x => x.Alias == config.Alias).ValidationExpression); var validator = new ClientSideRegexValidator(name, config, false) { ValidationExpression = regex.ToString() }; wrapper.Controls.Add(validator); parent.Controls.Add(wrapper); } catch (ArgumentException ex) { parent.Controls.Add( new HtmlGenericControl("span") { InnerText = string.Concat( "Regex validation expression is invalid. Validation will not occur.", "<!-- ", ex, " -->") }); } } }
/// <summary> /// Handles the Click event of the addRow control. /// </summary> /// <param name="sender"> /// The source of the event. /// </param> /// <param name="e"> /// The <see cref="System.EventArgs"/> instance containing the event data. /// </param> protected void addRow_Click(object sender, EventArgs e) { var row = new StoredValueRow { Id = this.GetAvailableId(), SortOrder = this.Rows.Count() + 1 }; foreach (var t in this.InsertDataTypes) { // Save value to datatype DataTypeHandlerServiceLocator.Instance.Save(t.Value, new DataTypeSaveEventArgs(this, DataTypeAction.Add)); // Create new storedvalue object var v = new StoredValue { Name = t.Name, Alias = t.Alias, Value = t.Value }; row.Cells.Add(v); } this.Rows.Add(row); Store(); Save(); }
/// <summary> /// Gets the insert data types. /// </summary> /// <returns> /// </returns> private IEnumerable<StoredValue> GetInsertDataTypes() { var list = new List<StoredValue>(); foreach (var config in this.ColumnConfigurations) { var dtd = DataTypeDefinition.GetDataTypeDefinition(config.DataTypeId); var dt = dtd.DataType; var s = new StoredValue { Name = config.Name, Alias = config.Alias, Value = dt }; list.Add(s); } return list; }
/// <summary> /// The get edit data types. /// </summary> /// <returns> /// </returns> private IEnumerable<StoredValue> GetEditDataTypes() { var list = new List<StoredValue>(); if (this.CurrentRow > 0) { list = this.GetStoredValueRow(this.CurrentRow).Cells; } else { foreach (var config in this.ColumnConfigurations) { var dtd = DataTypeDefinition.GetDataTypeDefinition(config.DataTypeId); var dt = dtd.DataType; var s = new StoredValue { Name = config.Name, Alias = config.Alias, Value = dt }; list.Add(s); } } return list; }
/// <summary> /// Initializes a new instance of the <see cref="StoredValueRowCollection"/> class. /// </summary> /// <param name="columnConfigurations">The column configurations.</param> /// <param name="xml">The XML.</param> public StoredValueRowCollection(IEnumerable <PreValueRow> columnConfigurations, string xml) : this(columnConfigurations) { if (!string.IsNullOrEmpty(xml)) { var doc = new XmlDocument(); doc.LoadXml(xml); // Create and add XML declaration. var xmldecl = doc.CreateXmlDeclaration("1.0", null, null); var root = doc.DocumentElement; doc.InsertBefore(xmldecl, root); // Get stored values from database if (root.ChildNodes.Count > 0) { foreach (XmlNode container in root.ChildNodes) { // <DataTypeGrid> var valueRow = new StoredValueRow(); if (container.Attributes["id"] != null) { valueRow.Id = int.Parse(container.Attributes["id"].Value); } if (container.Attributes["sortOrder"] != null) { valueRow.SortOrder = int.Parse(container.Attributes["sortOrder"].Value); } foreach (PreValueRow config in this.columnConfigurations) { var value = new StoredValue { Name = config.Name, Alias = config.Alias }; var datatypeid = config.DataTypeId; if (datatypeid != 0) { var dtd = DataTypeDefinition.GetDataTypeDefinition(datatypeid); var dt = dtd.DataType; dt.Data.Value = string.Empty; value.Value = dt; foreach (XmlNode node in container.ChildNodes) { if (config.Alias.Equals(node.Name)) { try { value.Value.Data.Value = node.InnerText; } catch (Exception) { Helper.Log.Warn <DataType>(string.Format("DataTypeGrid", "Stored data ({0}) for '{1}' is incompatible with the datatype '{2}'", node.InnerText, value.Alias, value.Value.DataTypeName)); } } } valueRow.Cells.Add(value); } } this.Add(valueRow); } } } }